Exemplo n.º 1
0
void acc_verify_done(SshCryptoStatus status,
                     void *context)
{
  SshExternalKeyTestCtx ctx = context;

  ctx->accelerated_decrypts_pending--;
  ctx->operations_done++;
  if (status != SSH_CRYPTO_OK)
    ctx->operations_failed++;

  if (!continuous_test &&
      ctx->accelerated_encrypts_left == 0 &&
      ctx->accelerated_decrypts_pending == 0)
    {
      SshUInt64 secs;
      SshUInt32 nanos;
      SshUInt32 s;
      ssh_time_measure_get_value(ctx->timer,
                                 &secs, &nanos);
      s = (SshUInt32)secs;
      SSH_DEBUG(1, ("Signature test completed in %ds and %dns", s, nanos));
      print_stats(ctx);
      exit(0);
    }
}
Exemplo n.º 2
0
void acc_encrypt_done(SshCryptoStatus status,
                      const unsigned char *data,
                      size_t length,
                      void *context)
{
  SshEKTestOp tc = context, ntc;
  SshExternalKeyTestCtx ctx = tc->test_ctx;
  SshPrivateKey key;
  SshUInt32 nanos;
  SshUInt64 secs;
  SshUInt32 s;

  ctx->operations_done++;
  ssh_time_measure_get_value(tc->timer,
                             &secs, &nanos);

  s = (SshUInt32)secs;
  key = accelerator_test ? ctx->acc_prv_key : ctx->prv_key;

  ctx->accelerated_encrypts_pending--;
  SSH_DEBUG(2, ("Completed encrypt %d", tc->op_id));
  SSH_DEBUG(3, ("Time %ds %dns", s, nanos));
  ssh_time_measure_free(tc->timer);
  ssh_xfree(tc);
  SSH_DEBUG_HEXDUMP(7, ("Encrypted data of len %d:", length), data, length);


  if (status == SSH_CRYPTO_OK)
    {
      SSH_DEBUG(10, ("Got the data of len %d", length));

      SSH_DEBUG(10, ("Accelerated encrypt succesfull"));
      ctx->accelerated_decrypts_pending++;
      ntc = ssh_xcalloc(1, sizeof(*ntc));

      ntc->op_id = next_op_id++;
      ntc->test_ctx = ctx;
      ssh_private_key_decrypt_async(key,
                                    data, length,
                                    acc_decrypt_done, ntc);
    }
  else
    {
      SSH_DEBUG(1, ("Accelerated encrypt unsuccesfull"));
      ctx->operations_failed++;
    }

}
Exemplo n.º 3
0
void print_stats(SshExternalKeyTestCtx ctx)
{
  SshUInt64 s;
  SshUInt32 ms, sec;
  double ratio;

  ssh_time_measure_get_value(ctx->timer, &s, &ms);
  sec = (SshUInt32)s;
  ratio = (double)(ctx->operations_done)/
    ((SshInt64)s + ms / (double)1000000000);

  printf("Time consumed so far %ld secs and %ld ms.\n"
         "%ld operations completed (avg %f ops/sec) "
         "of which %ld have failed.\n",
         sec, ms, ctx->operations_done, ratio, ctx->operations_failed);
}
Exemplo n.º 4
0
void acc_decrypt_done(SshCryptoStatus status,
                      const unsigned char *data,
                      size_t length,
                      void *context)
{
  SshEKTestOp tc = context;
  SshExternalKeyTestCtx ctx = tc->test_ctx;
  ctx->operations_done++;

  SSH_DEBUG(2, ("Completed decrypt %d", tc->op_id));
  ssh_xfree(tc);
  if (status == SSH_CRYPTO_OK)
    {
      SSH_DEBUG_HEXDUMP(7, ("Decrypted data of len %d:",
                            length), data, length);
      if (memcmp(ctx->big_buf, data, length) != 0)
        ssh_fatal("Public encrypt or private decrypt failed, data mismatch");
    }
  else
    {
      SSH_DEBUG(1, ("Could not decrypt with the accelerated private key"));
      ctx->operations_failed++;
    }

  ctx->accelerated_decrypts_pending--;
  if (ctx->accelerated_encrypts_left == 0)
    {
      SSH_DEBUG(2, ("Pending decrypts %d",
                    ctx->accelerated_decrypts_pending));

      if (!continuous_test &&
          ctx->accelerated_decrypts_pending == 0)
        {
          SshUInt64 secs;
          SshUInt32 nanos;
          SshUInt32 s;
          ssh_time_measure_get_value(ctx->timer,
                                     &secs, &nanos);
          s = (SshUInt32)secs;
          SSH_DEBUG(1, ("Whole test completed in %ds and %dns", s, nanos));
          print_stats(ctx);
          exit(0);
        }
    }


}
Exemplo n.º 5
0
void acc_prv_decrypt_done(SshCryptoStatus status,
                          const unsigned char *data,
                          size_t length,
                          void *context)
{
  SshExternalKeyTestCtx ctx = context;
  ctx->accelerated_encrypts_pending--;
  ctx->operations_done++;

  if (status == SSH_CRYPTO_OK)
    {
      SSH_DEBUG(2, ("Completed private key decrypt succesfully.\n"
                    "Left: %d\n"
                    "Pending: %d",
                    ctx->accelerated_encrypts_left,
                    ctx->accelerated_encrypts_pending));
    }
  else
    {
      SSH_DEBUG(1, ("Decrypt failed."));
      ctx->operations_failed++;
    }
  if (!continuous_test &&
      ctx->accelerated_encrypts_left == 0 &&
      ctx->accelerated_encrypts_pending == 0)
    {
      SshUInt64 secs;
      SshUInt32 nanos;
      SshUInt32 s;
      ssh_time_measure_get_value(ctx->timer,
                                 &secs, &nanos);
      s = (SshUInt32)secs;
      SSH_DEBUG(1, ("Private key test completed in %ds and %dns", s, nanos));
      print_stats(ctx);
      exit(0);
    }
}
Exemplo n.º 6
0
/*
 * Get the cumulated running time of the timer in seconds.
 * Be aware that depending on SshTimeT, timer can overwrap
 * at some point.
 */
SshTimeT ssh_time_measure_get(SshTimeMeasure timer,
                              SshTimeGranularity granularity)
{
  SshUInt64 seconds;
  SshUInt32 nanoseconds;

  ssh_time_measure_get_value(timer, &seconds, &nanoseconds);
  switch (granularity) 
    {
    case SSH_TIME_GRANULARITY_NANOSECOND:
      return (((SSH_UINT64_TO_SSH_TIME_T(seconds)) * (SshTimeT)1000000000) +
              (((SshTimeT)nanoseconds)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MICROSECOND:
      return (((SSH_UINT64_TO_SSH_TIME_T(seconds)) * (SshTimeT)1000000) +
              (((SshTimeT)nanoseconds) / (SshTimeT)1000));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MILLISECOND:
      return (((SSH_UINT64_TO_SSH_TIME_T(seconds)) * (SshTimeT)1000) +
              (((SshTimeT)nanoseconds) / (SshTimeT)1000000));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_SECOND:
      return (((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
              (((SshTimeT)nanoseconds) / (SshTimeT)1000000000));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MINUTE:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)60));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_HOUR:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)(60 * 60)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_DAY:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)(60 * 60 * 24)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_WEEK:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)(60 * 60 * 24 * 7)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MONTH_SIDEREAL:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)2360592));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MONTH_SYNODIC:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)2551443));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_ANOMALISTIC:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)31558433));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_TROPICAL:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)31556926));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_SIDEREAL:
      return ((((SSH_UINT64_TO_SSH_TIME_T(seconds))) +
               (((SshTimeT)nanoseconds) / (SshTimeT)1000000000)) /
              ((SshTimeT)31558149));
      /*NOTREACHED*/

    default:
      ssh_warning("ssh_time_measure_stamp: Bad granularity.");
      return (SshTimeT)0;
      /*NOTREACHED*/
    }
  /*NOTREACHED*/
}
Exemplo n.º 7
0
/*
 * Return a time stamp from timer.  Values returned by this function
 * never overwrap.  Instead if maximum timer value is exceeded,
 * SSH_TIME_STAMP_MAX is always returned.
 */
SshUInt64 ssh_time_measure_stamp(SshTimeMeasure timer, 
                                 SshTimeGranularity granularity)
{
  SshUInt64 seconds;
  SshUInt32 nanoseconds;

  ssh_time_measure_get_value(timer, &seconds, &nanoseconds);
  switch (granularity) 
    {
    case SSH_TIME_GRANULARITY_NANOSECOND:
#ifdef SSHUINT64_IS_64BITS
      /* Overflow in > 100 years! XXX */
#else /* SSHUINT64_IS_64BITS */
      if (SSH_TIME_MEASURE_GT(seconds, nanoseconds,
                              4, 294967295) > 0)
        return SSH_TIME_STAMP_MAX;
#endif /* SSHUINT64_IS_64BITS */
      return ((((SshUInt64)seconds) * ((SshUInt64)1000000000)) +
              ((SshUInt64)nanoseconds));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MICROSECOND:
#ifdef SSHUINT64_IS_64BITS
      /* Overflow in > 100000 years! XXX */
#else /* SSHUINT64_IS_64BITS */
      if (SSH_TIME_MEASURE_GT(seconds, nanoseconds,
                              4294, 967295999) > 0)
        return SSH_TIME_STAMP_MAX;
#endif /* SSHUINT64_IS_64BITS */
      return ((((SshUInt64)seconds) * ((SshUInt64)1000000)) +
              (((SshUInt64)nanoseconds) / ((SshUInt64)1000)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MILLISECOND:
#ifdef SSHUINT64_IS_64BITS
      /* Overflow in > 100000000 years! XXX */
#else /* SSHUINT64_IS_64BITS */
      if (SSH_TIME_MEASURE_GT(seconds, nanoseconds,
                              4294967, 295999999) > 0)
        return SSH_TIME_STAMP_MAX;
#endif /* SSHUINT64_IS_64BITS */
      return ((((SshUInt64)seconds) * ((SshUInt64)1000)) +
              (((SshUInt64)nanoseconds) / ((SshUInt64)1000000)));
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_SECOND:
      return seconds;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MINUTE:
      return seconds / 60;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_HOUR:
      return seconds / (60 * 60);
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_DAY:
      return seconds / (60 * 60 * 24);
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_WEEK:
      return seconds / (60 * 60 * 24 * 7);
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MONTH_SIDEREAL:
      return seconds / 2360592;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_MONTH_SYNODIC:
      return seconds / 2551443;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_ANOMALISTIC:
      return seconds / 31558433;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_TROPICAL:
      return seconds / 31556926;
      /*NOTREACHED*/

    case SSH_TIME_GRANULARITY_YEAR_SIDEREAL:
      return seconds / 31558149;
      /*NOTREACHED*/

    default:
      ssh_warning("ssh_time_measure_stamp: Bad granularity.");
      return SSH_TIME_STAMP_MAX;
      /*NOTREACHED*/
    }
  /*NOTREACHED*/
}