diff options
Diffstat (limited to 'src/util/test_crypto_symmetric.c')
-rw-r--r-- | src/util/test_crypto_symmetric.c | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/src/util/test_crypto_symmetric.c b/src/util/test_crypto_symmetric.c index d731c45b7..c6854711f 100644 --- a/src/util/test_crypto_symmetric.c +++ b/src/util/test_crypto_symmetric.c | |||
@@ -11,13 +11,13 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | 19 | ||
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * @file util/test_crypto_symmetric.c | 23 | * @file util/test_crypto_symmetric.c |
@@ -30,46 +30,46 @@ | |||
30 | #define INITVALUE "InitializationVectorValueinitializationvectorvalue" | 30 | #define INITVALUE "InitializationVectorValueinitializationvectorvalue" |
31 | 31 | ||
32 | static int | 32 | static int |
33 | testSymcipher () | 33 | testSymcipher() |
34 | { | 34 | { |
35 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | 35 | struct GNUNET_CRYPTO_SymmetricSessionKey key; |
36 | char result[100]; | 36 | char result[100]; |
37 | int size; | 37 | int size; |
38 | char res[100]; | 38 | char res[100]; |
39 | 39 | ||
40 | GNUNET_CRYPTO_symmetric_create_session_key (&key); | 40 | GNUNET_CRYPTO_symmetric_create_session_key(&key); |
41 | size = | 41 | size = |
42 | GNUNET_CRYPTO_symmetric_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &key, | 42 | GNUNET_CRYPTO_symmetric_encrypt(TESTSTRING, strlen(TESTSTRING) + 1, &key, |
43 | (const struct | 43 | (const struct |
44 | GNUNET_CRYPTO_SymmetricInitializationVector *) | 44 | GNUNET_CRYPTO_SymmetricInitializationVector *) |
45 | INITVALUE, result); | 45 | INITVALUE, result); |
46 | if (size == -1) | 46 | if (size == -1) |
47 | { | 47 | { |
48 | printf ("symciphertest failed: encryptBlock returned %d\n", size); | 48 | printf("symciphertest failed: encryptBlock returned %d\n", size); |
49 | return 1; | 49 | return 1; |
50 | } | 50 | } |
51 | size = | 51 | size = |
52 | GNUNET_CRYPTO_symmetric_decrypt (result, size, &key, | 52 | GNUNET_CRYPTO_symmetric_decrypt(result, size, &key, |
53 | (const struct | 53 | (const struct |
54 | GNUNET_CRYPTO_SymmetricInitializationVector *) | 54 | GNUNET_CRYPTO_SymmetricInitializationVector *) |
55 | INITVALUE, res); | 55 | INITVALUE, res); |
56 | if (strlen (TESTSTRING) + 1 != size) | 56 | if (strlen(TESTSTRING) + 1 != size) |
57 | { | 57 | { |
58 | printf ("symciphertest failed: decryptBlock returned %d\n", size); | 58 | printf("symciphertest failed: decryptBlock returned %d\n", size); |
59 | return 1; | 59 | return 1; |
60 | } | 60 | } |
61 | if (0 != strcmp (res, TESTSTRING)) | 61 | if (0 != strcmp(res, TESTSTRING)) |
62 | { | 62 | { |
63 | printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); | 63 | printf("symciphertest failed: %s != %s\n", res, TESTSTRING); |
64 | return 1; | 64 | return 1; |
65 | } | 65 | } |
66 | else | 66 | else |
67 | return 0; | 67 | return 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | static int | 71 | static int |
72 | verifyCrypto () | 72 | verifyCrypto() |
73 | { | 73 | { |
74 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | 74 | struct GNUNET_CRYPTO_SymmetricSessionKey key; |
75 | char result[GNUNET_CRYPTO_AES_KEY_LENGTH]; | 75 | char result[GNUNET_CRYPTO_AES_KEY_LENGTH]; |
@@ -103,68 +103,68 @@ verifyCrypto () | |||
103 | res = NULL; | 103 | res = NULL; |
104 | ret = 0; | 104 | ret = 0; |
105 | 105 | ||
106 | GNUNET_memcpy (key.aes_key, raw_key_aes, GNUNET_CRYPTO_AES_KEY_LENGTH); | 106 | GNUNET_memcpy(key.aes_key, raw_key_aes, GNUNET_CRYPTO_AES_KEY_LENGTH); |
107 | GNUNET_memcpy (key.twofish_key, raw_key_twofish, GNUNET_CRYPTO_AES_KEY_LENGTH); | 107 | GNUNET_memcpy(key.twofish_key, raw_key_twofish, GNUNET_CRYPTO_AES_KEY_LENGTH); |
108 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != | 108 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != |
109 | GNUNET_CRYPTO_symmetric_encrypt (plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, | 109 | GNUNET_CRYPTO_symmetric_encrypt(plain, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, |
110 | (const struct | 110 | (const struct |
111 | GNUNET_CRYPTO_SymmetricInitializationVector *) | 111 | GNUNET_CRYPTO_SymmetricInitializationVector *) |
112 | "testtesttesttesttesttesttesttest", | 112 | "testtesttesttesttesttesttesttest", |
113 | result)) | 113 | result)) |
114 | { | 114 | { |
115 | printf ("Wrong return value from encrypt block.\n"); | 115 | printf("Wrong return value from encrypt block.\n"); |
116 | ret = 1; | 116 | ret = 1; |
117 | goto error; | 117 | goto error; |
118 | } | 118 | } |
119 | 119 | ||
120 | if (0 != memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH)) | 120 | if (0 != memcmp(encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH)) |
121 | { | 121 | { |
122 | int i; | 122 | int i; |
123 | printf ("Encrypted result wrong.\n"); | 123 | printf("Encrypted result wrong.\n"); |
124 | for (i=0;i<GNUNET_CRYPTO_AES_KEY_LENGTH;i++) | 124 | for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) |
125 | printf ("%u, ", (uint8_t) result[i]); | 125 | printf("%u, ", (uint8_t)result[i]); |
126 | ret = 1; | 126 | ret = 1; |
127 | goto error; | 127 | goto error; |
128 | } | 128 | } |
129 | 129 | ||
130 | res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); | 130 | res = GNUNET_malloc(GNUNET_CRYPTO_AES_KEY_LENGTH); |
131 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != | 131 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != |
132 | GNUNET_CRYPTO_symmetric_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, | 132 | GNUNET_CRYPTO_symmetric_decrypt(result, GNUNET_CRYPTO_AES_KEY_LENGTH, &key, |
133 | (const struct | 133 | (const struct |
134 | GNUNET_CRYPTO_SymmetricInitializationVector *) | 134 | GNUNET_CRYPTO_SymmetricInitializationVector *) |
135 | "testtesttesttesttesttesttesttest", res)) | 135 | "testtesttesttesttesttesttesttest", res)) |
136 | { | 136 | { |
137 | printf ("Wrong return value from decrypt block.\n"); | 137 | printf("Wrong return value from decrypt block.\n"); |
138 | ret = 1; | 138 | ret = 1; |
139 | goto error; | 139 | goto error; |
140 | } | 140 | } |
141 | if (0 != memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH)) | 141 | if (0 != memcmp(res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH)) |
142 | { | 142 | { |
143 | printf ("Decrypted result does not match input.\n"); | 143 | printf("Decrypted result does not match input.\n"); |
144 | ret = 1; | 144 | ret = 1; |
145 | } | 145 | } |
146 | error: | 146 | error: |
147 | GNUNET_free_non_null (res); | 147 | GNUNET_free_non_null(res); |
148 | return ret; | 148 | return ret; |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | int | 152 | int |
153 | main (int argc, char *argv[]) | 153 | main(int argc, char *argv[]) |
154 | { | 154 | { |
155 | int failureCount = 0; | 155 | int failureCount = 0; |
156 | 156 | ||
157 | GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL); | 157 | GNUNET_log_setup("test-crypto-aes", "WARNING", NULL); |
158 | GNUNET_assert (strlen (INITVALUE) > | 158 | GNUNET_assert(strlen(INITVALUE) > |
159 | sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector)); | 159 | sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)); |
160 | failureCount += testSymcipher (); | 160 | failureCount += testSymcipher(); |
161 | failureCount += verifyCrypto (); | 161 | failureCount += verifyCrypto(); |
162 | 162 | ||
163 | if (failureCount != 0) | 163 | if (failureCount != 0) |
164 | { | 164 | { |
165 | printf ("%d TESTS FAILED!\n", failureCount); | 165 | printf("%d TESTS FAILED!\n", failureCount); |
166 | return -1; | 166 | return -1; |
167 | } | 167 | } |
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | 170 | ||