~ubuntu-branches/ubuntu/natty/libgcrypt11/natty-proposed

« back to all changes in this revision

Viewing changes to tests/benchmark.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2009-02-21 13:46:58 UTC
  • mto: (1.1.6 upstream) (2.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090221134658-855twvcr4ezk2ron
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#else
30
30
#include <sys/times.h>
31
31
#endif
32
 
#include <gcrypt.h>
 
32
 
 
33
#ifdef _GCRYPT_IN_LIBGCRYPT
 
34
# include "../src/gcrypt.h"
 
35
#else
 
36
# include <gcrypt.h>
 
37
#endif
 
38
 
33
39
 
34
40
#define PGM "benchmark"
35
41
 
41
47
/* Number of cipher repetitions.  */
42
48
static int cipher_repetitions;
43
49
 
 
50
/* Whether fips mode was active at startup.  */
 
51
static int in_fips_mode;
 
52
 
44
53
 
45
54
static const char sample_private_dsa_key_1024[] =
46
55
"(private-key\n"
321
330
  t2 += (((unsigned long long)stopped_at.user_time.dwHighDateTime << 32)
322
331
        + stopped_at.user_time.dwLowDateTime);
323
332
  t = (t2 - t1)/10000;
324
 
  snprintf (buf, sizeof buf, "%5lums", (unsigned long)t );
 
333
  snprintf (buf, sizeof buf, "%5.0fms", (double)t );
325
334
#else
326
335
  snprintf (buf, sizeof buf, "%5.0fms",
327
336
            (((double) (stopped_at - started_at))/CLOCKS_PER_SEC)*10000000);
373
382
  if (!algoname)
374
383
    {
375
384
      for (i=1; i < 400; i++)
376
 
        if ( !gcry_md_test_algo (i) )
 
385
        if (in_fips_mode && i == GCRY_MD_MD5)
 
386
          ; /* Don't use MD5 in fips mode.  */
 
387
        else if ( !gcry_md_test_algo (i) )
377
388
          md_bench (gcry_md_algo_name (i));
378
389
      return;
379
390
    }
629
640
      fflush (stdout);
630
641
 
631
642
      err = gcry_sexp_build (&key_spec, NULL,
632
 
                             "(genkey (RSA (nbits %d)))", p_sizes[testno]);
 
643
                             gcry_fips_mode_active ()
 
644
                             ? "(genkey (RSA (nbits %d)))"
 
645
                             : "(genkey (RSA (nbits %d)(transient-key)))",
 
646
                             p_sizes[testno]);
633
647
      if (err)
634
648
        die ("creating S-expression failed: %s\n", gcry_strerror (err));
635
649
 
987
1001
{
988
1002
  int last_argc = -1;
989
1003
  int no_blinding = 0;
990
 
 
 
1004
  int use_random_daemon = 0;
991
1005
 
992
1006
  if (argc)
993
1007
    { argc--; argv++; }
994
1008
 
995
 
  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
996
 
  if (!gcry_check_version (GCRYPT_VERSION))
997
 
    {
998
 
      fprintf (stderr, PGM ": version mismatch\n");
999
 
      exit (1);
1000
 
    }
1001
 
  if (argc && !strcmp (*argv, "--use-random-daemon"))
1002
 
    {
1003
 
      gcry_control (GCRYCTL_USE_RANDOM_DAEMON, 1);
1004
 
      argc--; argv++;
1005
 
    }
1006
 
 
1007
1009
  while (argc && last_argc != argc )
1008
1010
    {
1009
1011
      last_argc = argc;
1021
1023
        }
1022
1024
      else if (!strcmp (*argv, "--verbose"))
1023
1025
        {
1024
 
          verbose = 1;
 
1026
          verbose++;
1025
1027
          argc--; argv++;
1026
1028
        }
1027
1029
      else if (!strcmp (*argv, "--use-random-daemon"))
1028
1030
        {
1029
 
          gcry_control (GCRYCTL_USE_RANDOM_DAEMON, 1);
 
1031
          use_random_daemon = 1;
1030
1032
          argc--; argv++;
1031
1033
        }
1032
1034
      else if (!strcmp (*argv, "--no-blinding"))
1048
1050
              argc--; argv++;
1049
1051
            }
1050
1052
        }
 
1053
      else if (!strcmp (*argv, "--fips"))
 
1054
        {
 
1055
          argc--; argv++;
 
1056
          /* This command needs to be called before gcry_check_version.  */
 
1057
          gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
 
1058
        }
1051
1059
    }          
 
1060
 
 
1061
  gcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
 
1062
 
 
1063
  if (!gcry_check_version (GCRYPT_VERSION))
 
1064
    {
 
1065
      fprintf (stderr, PGM ": version mismatch\n");
 
1066
      exit (1);
 
1067
    }
 
1068
 
 
1069
  if (gcry_fips_mode_active ())
 
1070
    in_fips_mode = 1;
 
1071
  else
 
1072
    gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
 
1073
 
 
1074
  if (use_random_daemon)
 
1075
    gcry_control (GCRYCTL_USE_RANDOM_DAEMON, 1);
 
1076
 
1052
1077
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
1053
1078
 
 
1079
 
1054
1080
  if (cipher_repetitions < 1)
1055
1081
    cipher_repetitions = 1;
1056
1082
  
1122
1148
      fprintf (stderr, PGM ": bad arguments\n");
1123
1149
      return 1;
1124
1150
    }
 
1151
 
 
1152
 
 
1153
  if (in_fips_mode && !gcry_fips_mode_active ())
 
1154
    fprintf (stderr, PGM ": FIPS mode is not anymore active\n");
1125
1155
  
1126
1156
  return 0;
1127
1157
}