aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_crypto_aes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_crypto_aes.c')
-rw-r--r--src/util/test_crypto_aes.c120
1 files changed, 60 insertions, 60 deletions
diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c
index 971e9afbe..e928b96a7 100644
--- a/src/util/test_crypto_aes.c
+++ b/src/util/test_crypto_aes.c
@@ -40,30 +40,30 @@ testSymcipher ()
40 40
41 GNUNET_CRYPTO_aes_create_session_key (&key); 41 GNUNET_CRYPTO_aes_create_session_key (&key);
42 size = 42 size =
43 GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key, 43 GNUNET_CRYPTO_aes_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key,
44 (const struct 44 (const struct
45 GNUNET_CRYPTO_AesInitializationVector *) 45 GNUNET_CRYPTO_AesInitializationVector *)
46 INITVALUE, result); 46 INITVALUE, result);
47 if (size == -1) 47 if (size == -1)
48 { 48 {
49 printf ("symciphertest failed: encryptBlock returned %d\n", size); 49 printf ("symciphertest failed: encryptBlock returned %d\n", size);
50 return 1; 50 return 1;
51 } 51 }
52 size = 52 size =
53 GNUNET_CRYPTO_aes_decrypt (result, size, &key, 53 GNUNET_CRYPTO_aes_decrypt (result, size, &key,
54 (const struct 54 (const struct
55 GNUNET_CRYPTO_AesInitializationVector *) 55 GNUNET_CRYPTO_AesInitializationVector *)
56 INITVALUE, res); 56 INITVALUE, res);
57 if (strlen (TESTSTRING) + 1 != size) 57 if (strlen (TESTSTRING) + 1 != size)
58 { 58 {
59 printf ("symciphertest failed: decryptBlock returned %d\n", size); 59 printf ("symciphertest failed: decryptBlock returned %d\n", size);
60 return 1; 60 return 1;
61 } 61 }
62 if (0 != strcmp (res, TESTSTRING)) 62 if (0 != strcmp (res, TESTSTRING))
63 { 63 {
64 printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); 64 printf ("symciphertest failed: %s != %s\n", res, TESTSTRING);
65 return 1; 65 return 1;
66 } 66 }
67 else 67 else
68 return 0; 68 return 0;
69} 69}
@@ -77,16 +77,16 @@ verifyCrypto ()
77 int ret; 77 int ret;
78 78
79 unsigned char plain[] = 79 unsigned char plain[] =
80 { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, 80 { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249,
81 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164 81 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164
82 }; 82 };
83 unsigned char raw_key[] = 83 unsigned char raw_key[] =
84 { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, 84 { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25,
85 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184, 85 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184,
86 34, 191 86 34, 191
87 }; 87 };
88 unsigned char encrresult[] = 88 unsigned char encrresult[] =
89 { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, 89 { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75,
90 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25, 90 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25,
91 102 91 102
92 }; 92 };
@@ -96,54 +96,54 @@ verifyCrypto ()
96 96
97 memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH); 97 memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH);
98 key.crc32 = 98 key.crc32 =
99 htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); 99 htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH));
100 100
101 if (ntohl (key.crc32) != (unsigned int) 38125195LL) 101 if (ntohl (key.crc32) != (unsigned int) 38125195LL)
102 { 102 {
103 printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32), 103 printf ("Static key has different CRC: %u - %u\n", ntohl (key.crc32),
104 key.crc32); 104 key.crc32);
105 105
106 ret = 1; 106 ret = 1;
107 goto error; 107 goto error;
108 } 108 }
109 109
110 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 110 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
111 GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, 111 GNUNET_CRYPTO_aes_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
112 (const struct 112 (const struct
113 GNUNET_CRYPTO_AesInitializationVector *) 113 GNUNET_CRYPTO_AesInitializationVector *)
114 "testtesttesttest", result)) 114 "testtesttesttest", result))
115 { 115 {
116 printf ("Wrong return value from encrypt block.\n"); 116 printf ("Wrong return value from encrypt block.\n");
117 ret = 1; 117 ret = 1;
118 goto error; 118 goto error;
119 } 119 }
120 120
121 if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) 121 if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
122 { 122 {
123 printf ("Encrypted result wrong.\n"); 123 printf ("Encrypted result wrong.\n");
124 ret = 1; 124 ret = 1;
125 goto error; 125 goto error;
126 } 126 }
127 127
128 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); 128 res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH);
129 129
130 if (GNUNET_CRYPTO_AES_KEY_LENGTH != 130 if (GNUNET_CRYPTO_AES_KEY_LENGTH !=
131 GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, 131 GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key,
132 (const struct 132 (const struct
133 GNUNET_CRYPTO_AesInitializationVector *) 133 GNUNET_CRYPTO_AesInitializationVector *)
134 "testtesttesttest", res)) 134 "testtesttesttest", res))
135 { 135 {
136 printf ("Wrong return value from decrypt block.\n"); 136 printf ("Wrong return value from decrypt block.\n");
137 ret = 1; 137 ret = 1;
138 goto error; 138 goto error;
139 } 139 }
140 140
141 if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) 141 if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0)
142 { 142 {
143 printf ("Decrypted result does not match input.\n"); 143 printf ("Decrypted result does not match input.\n");
144 144
145 ret = 1; 145 ret = 1;
146 } 146 }
147 147
148error: 148error:
149 149
@@ -160,15 +160,15 @@ main (int argc, char *argv[])
160 GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL); 160 GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL);
161 GNUNET_CRYPTO_random_disable_entropy_gathering (); 161 GNUNET_CRYPTO_random_disable_entropy_gathering ();
162 GNUNET_assert (strlen (INITVALUE) > 162 GNUNET_assert (strlen (INITVALUE) >
163 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 163 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
164 failureCount += testSymcipher (); 164 failureCount += testSymcipher ();
165 failureCount += verifyCrypto (); 165 failureCount += verifyCrypto ();
166 166
167 if (failureCount != 0) 167 if (failureCount != 0)
168 { 168 {
169 printf ("%d TESTS FAILED!\n", failureCount); 169 printf ("%d TESTS FAILED!\n", failureCount);
170 return -1; 170 return -1;
171 } 171 }
172 return 0; 172 return 0;
173} 173}
174 174