X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Ftest_crypto_aes_weak.c;h=f2ddf2012574ab8af7fe378c15cfa45fe3d6e1c5;hb=72c8645af31896829b674b575c5375706f362a30;hp=73e52ba0184253a4eb83c88095db792e762af7fc;hpb=38b29592cf2e8b816cab68579e07e2477153f739;p=oweals%2Fgnunet.git diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 73e52ba01..f2ddf2012 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c @@ -38,10 +38,11 @@ static void printWeakKey (struct GNUNET_CRYPTO_AesSessionKey *key) { int i; + for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) - { - printf ("%x ", (int) (key->key[i])); - } + { + printf ("%x ", (int) (key->key[i])); + } } static int @@ -56,7 +57,7 @@ testWeakKey () memset (&INITVALUE, 42, sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); /* sorry, this is not a weak key -- I don't have - any at the moment! */ + * any at the moment! */ weak_key.key[0] = (char) (0x4c); weak_key.key[1] = (char) (0x31); weak_key.key[2] = (char) (0xc6); @@ -90,31 +91,29 @@ testWeakKey () weak_key.key[30] = (char) (0xaa); weak_key.key[31] = (char) (0xaa); /* memset(&weak_key, 0, 32); */ - weak_key.crc32 = - htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); - - size = GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, - strlen (WEAK_KEY_TESTSTRING) + 1, - &weak_key, &INITVALUE, result); + size = + GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, + strlen (WEAK_KEY_TESTSTRING) + 1, &weak_key, + &INITVALUE, result); if (size == -1) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } if (0 != strcmp (res, WEAK_KEY_TESTSTRING)) - { - GNUNET_break (0); - return 1; - } + { + GNUNET_break (0); + return 1; + } else return 0; } @@ -131,44 +130,42 @@ getWeakKeys () for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS; number_of_runs++) + { + + if (number_of_runs % 1000 == 0) + FPRINTF (stderr, "%s", "."); + /*printf("Got to run number %d.\n", number_of_runs); */ + GNUNET_CRYPTO_aes_create_session_key (&sessionkey); + + rc = gcry_cipher_open (&handle, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, + 0); + + if (rc) { + printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", + number_of_runs, gcry_strerror (rc)); + continue; + } - if (number_of_runs % 1000 == 0) - fprintf (stderr, "."); - /*printf("Got to run number %d.\n", number_of_runs); */ - GNUNET_CRYPTO_aes_create_session_key (&sessionkey); - - rc = gcry_cipher_open (&handle, - GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, 0); - - if (rc) - { - printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", - number_of_runs, gcry_strerror (rc)); - continue; - } - - rc = - gcry_cipher_setkey (handle, &sessionkey, - GNUNET_CRYPTO_AES_KEY_LENGTH); - - if ((char) rc == GPG_ERR_WEAK_KEY) - { - printf ("\nWeak key (in hex): "); - printWeakKey (&sessionkey); - printf ("\n"); - number_of_weak_keys++; - } - else if (rc) - { - printf ("\nUnexpected error generating keys. Error is %s\n", - gcry_strerror (rc)); - } - - gcry_cipher_close (handle); + rc = gcry_cipher_setkey (handle, &sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); + if ((char) rc == GPG_ERR_WEAK_KEY) + { + printf ("\nWeak key (in hex): "); + printWeakKey (&sessionkey); + printf ("\n"); + number_of_weak_keys++; + } + else if (rc) + { + printf ("\nUnexpected error generating keys. Error is %s\n", + gcry_strerror (rc)); } + gcry_cipher_close (handle); + + } + return number_of_weak_keys; } @@ -178,21 +175,20 @@ main (int argc, char *argv[]) int weak_keys; GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); - GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GENERATE_WEAK_KEYS) + { + weak_keys = getWeakKeys (); + + if (weak_keys == 0) + { + printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); + } + else { - weak_keys = getWeakKeys (); - - if (weak_keys == 0) - { - printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); - } - else - { - printf ("\n%d weak keys found in %d runs.\n", - weak_keys, MAX_WEAK_KEY_TRIALS); - } + printf ("\n%d weak keys found in %d runs.\n", weak_keys, + MAX_WEAK_KEY_TRIALS); } + } if (testWeakKey () != 0) return -1;