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