diff options
Diffstat (limited to 'src/util/test_crypto_ecc.c')
-rw-r--r-- | src/util/test_crypto_ecc.c | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c index d61ba816e..4cb8f1dbc 100644 --- a/src/util/test_crypto_ecc.c +++ b/src/util/test_crypto_ecc.c | |||
@@ -39,147 +39,6 @@ static struct GNUNET_CRYPTO_EccPrivateKey *key; | |||
39 | 39 | ||
40 | 40 | ||
41 | static int | 41 | static int |
42 | testEncryptDecrypt () | ||
43 | { | ||
44 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey; | ||
45 | struct GNUNET_CRYPTO_EccEncryptedData target; | ||
46 | char result[MAX_TESTVAL]; | ||
47 | int i; | ||
48 | struct GNUNET_TIME_Absolute start; | ||
49 | int ok; | ||
50 | |||
51 | FPRINTF (stderr, "%s", "W"); | ||
52 | GNUNET_CRYPTO_ecc_key_get_public (key, &pkey); | ||
53 | ok = 0; | ||
54 | start = GNUNET_TIME_absolute_get (); | ||
55 | for (i = 0; i < ITER; i++) | ||
56 | { | ||
57 | FPRINTF (stderr, "%s", "."); | ||
58 | if (GNUNET_SYSERR == | ||
59 | GNUNET_CRYPTO_ecc_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey, | ||
60 | &target)) | ||
61 | { | ||
62 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n"); | ||
63 | ok++; | ||
64 | continue; | ||
65 | } | ||
66 | if (-1 == | ||
67 | GNUNET_CRYPTO_ecc_decrypt (key, &target, result, | ||
68 | strlen (TESTSTRING) + 1)) | ||
69 | { | ||
70 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_decrypt returned SYSERR\n"); | ||
71 | ok++; | ||
72 | continue; | ||
73 | |||
74 | } | ||
75 | if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) | ||
76 | { | ||
77 | printf ("%s != %.*s - testEncryptDecrypt failed!\n", TESTSTRING, | ||
78 | (int) MAX_TESTVAL, result); | ||
79 | ok++; | ||
80 | continue; | ||
81 | } | ||
82 | } | ||
83 | printf ("%d ECC encrypt/decrypt operations %s (%d failures)\n", | ||
84 | ITER, | ||
85 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), | ||
86 | ok); | ||
87 | if (ok == 0) | ||
88 | return GNUNET_OK; | ||
89 | return GNUNET_SYSERR; | ||
90 | } | ||
91 | |||
92 | |||
93 | #if PERF | ||
94 | static int | ||
95 | testEncryptPerformance () | ||
96 | { | ||
97 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey; | ||
98 | struct GNUNET_CRYPTO_EccEncryptedData target; | ||
99 | int i; | ||
100 | struct GNUNET_TIME_Absolute start; | ||
101 | int ok; | ||
102 | |||
103 | FPRINTF (stderr, "%s", "W"); | ||
104 | GNUNET_CRYPTO_ecc_key_get_public (key, &pkey); | ||
105 | ok = 0; | ||
106 | start = GNUNET_TIME_absolute_get (); | ||
107 | for (i = 0; i < ITER; i++) | ||
108 | { | ||
109 | FPRINTF (stderr, "%s", "."); | ||
110 | if (GNUNET_SYSERR == | ||
111 | GNUNET_CRYPTO_ecc_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, &pkey, | ||
112 | &target)) | ||
113 | { | ||
114 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n"); | ||
115 | ok++; | ||
116 | continue; | ||
117 | } | ||
118 | } | ||
119 | printf ("%d ECC encrypt operations %llu ms (%d failures)\n", ITER, | ||
120 | (unsigned long long) | ||
121 | GNUNET_TIME_absolute_get_duration (start).rel_value, ok); | ||
122 | if (ok != 0) | ||
123 | return GNUNET_SYSERR; | ||
124 | return GNUNET_OK; | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static int | ||
129 | testEncryptDecryptSK () | ||
130 | { | ||
131 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey; | ||
132 | struct GNUNET_CRYPTO_EccEncryptedData target; | ||
133 | struct GNUNET_CRYPTO_AesSessionKey insk; | ||
134 | struct GNUNET_CRYPTO_AesSessionKey outsk; | ||
135 | int i; | ||
136 | struct GNUNET_TIME_Absolute start; | ||
137 | int ok; | ||
138 | |||
139 | FPRINTF (stderr, "%s", "W"); | ||
140 | GNUNET_CRYPTO_ecc_key_get_public (key, &pkey); | ||
141 | ok = 0; | ||
142 | start = GNUNET_TIME_absolute_get (); | ||
143 | for (i = 0; i < ITER; i++) | ||
144 | { | ||
145 | FPRINTF (stderr, "%s", "."); | ||
146 | GNUNET_CRYPTO_aes_create_session_key (&insk); | ||
147 | if (GNUNET_SYSERR == | ||
148 | GNUNET_CRYPTO_ecc_encrypt (&insk, | ||
149 | sizeof (struct GNUNET_CRYPTO_AesSessionKey), | ||
150 | &pkey, &target)) | ||
151 | { | ||
152 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_encrypt returned SYSERR\n"); | ||
153 | ok++; | ||
154 | continue; | ||
155 | } | ||
156 | if (-1 == | ||
157 | GNUNET_CRYPTO_ecc_decrypt (key, &target, &outsk, | ||
158 | sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | ||
159 | { | ||
160 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_decrypt returned SYSERR\n"); | ||
161 | ok++; | ||
162 | continue; | ||
163 | } | ||
164 | if (0 != | ||
165 | memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | ||
166 | { | ||
167 | printf ("testEncryptDecryptSK failed!\n"); | ||
168 | ok++; | ||
169 | continue; | ||
170 | } | ||
171 | } | ||
172 | printf ("%d ECC encrypt/decrypt SK operations %s (%d failures)\n", | ||
173 | ITER, | ||
174 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), | ||
175 | ok); | ||
176 | if (ok != 0) | ||
177 | return GNUNET_SYSERR; | ||
178 | return GNUNET_OK; | ||
179 | } | ||
180 | |||
181 | |||
182 | static int | ||
183 | testSignVerify () | 42 | testSignVerify () |
184 | { | 43 | { |
185 | struct GNUNET_CRYPTO_EccSignature sig; | 44 | struct GNUNET_CRYPTO_EccSignature sig; |
@@ -330,15 +189,9 @@ main (int argc, char *argv[]) | |||
330 | failureCount++; | 189 | failureCount++; |
331 | GNUNET_SCHEDULER_run (&test_async_creation, NULL); | 190 | GNUNET_SCHEDULER_run (&test_async_creation, NULL); |
332 | #if PERF | 191 | #if PERF |
333 | if (GNUNET_OK != testEncryptPerformance ()) | ||
334 | failureCount++; | ||
335 | if (GNUNET_OK != testSignPerformance ()) | 192 | if (GNUNET_OK != testSignPerformance ()) |
336 | failureCount++; | 193 | failureCount++; |
337 | #endif | 194 | #endif |
338 | if (GNUNET_OK != testEncryptDecryptSK ()) | ||
339 | failureCount++; | ||
340 | if (GNUNET_OK != testEncryptDecrypt ()) | ||
341 | failureCount++; | ||
342 | if (GNUNET_OK != testSignVerify ()) | 195 | if (GNUNET_OK != testSignVerify ()) |
343 | failureCount++; | 196 | failureCount++; |
344 | GNUNET_CRYPTO_ecc_key_free (key); | 197 | GNUNET_CRYPTO_ecc_key_free (key); |