Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: srtp/crypto/test/stat_driver.c

Issue 2344973002: Update libsrtp to version 2.0 (Closed)
Patch Set: Add '.' back to include_dirs Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « srtp/crypto/test/sha1_driver.c ('k') | srtp/doc/.cvsignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * stat-driver.c
3 *
4 * test driver for the stat_test functions
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9
10 /*
11 *
12 * Copyright (c) 2001-2006, Cisco Systems, Inc.
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials provided
25 * with the distribution.
26 *
27 * Neither the name of the Cisco Systems, Inc. nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
35 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
36 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
42 * OF THE POSSIBILITY OF SUCH DAMAGE.
43 *
44 */
45
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49
50 #include <stdio.h> /* for printf() */
51
52 #include "err.h"
53 #include "stat.h"
54 #include "srtp.h"
55
56 #include "cipher.h"
57
58 typedef struct {
59 void *state;
60 } random_source_t;
61
62 err_status_t
63 random_source_alloc(void);
64
65 void
66 err_check(err_status_t s) {
67 if (s) {
68 printf("error (code %d)\n", s);
69 exit(1);
70 }
71 }
72
73 int
74 main (int argc, char *argv[]) {
75 uint8_t buffer[2532];
76 unsigned int buf_len = 2500;
77 int i, j;
78 extern cipher_type_t aes_icm;
79 #ifdef OPENSSL
80 extern cipher_type_t aes_gcm_128_openssl;
81 extern cipher_type_t aes_gcm_256_openssl;
82 #endif
83 cipher_t *c;
84 uint8_t key[46] = {
85 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
86 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
87 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
88 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
89 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
90 0x00, 0x01, 0x02, 0x03, 0x04, 0x05
91 };
92 v128_t nonce;
93 int num_trials = 500;
94 int num_fail;
95
96 printf("statistical tests driver\n");
97
98 v128_set_to_zero(&nonce);
99 for (i=0; i < 2500; i++)
100 buffer[i] = 0;
101
102 /* run tests */
103 printf("running stat_tests on all-null buffer, expecting failure\n");
104 printf("monobit %d\n", stat_test_monobit(buffer));
105 printf("poker %d\n", stat_test_poker(buffer));
106 printf("runs %d\n", stat_test_runs(buffer));
107
108 for (i=0; i < 2500; i++)
109 buffer[i] = rand();
110 printf("running stat_tests on rand(), expecting success\n");
111 printf("monobit %d\n", stat_test_monobit(buffer));
112 printf("poker %d\n", stat_test_poker(buffer));
113 printf("runs %d\n", stat_test_runs(buffer));
114
115 printf("running stat_tests on AES-128-ICM, expecting success\n");
116 /* set buffer to cipher output */
117 for (i=0; i < 2500; i++)
118 buffer[i] = 0;
119 err_check(cipher_type_alloc(&aes_icm, &c, 30, 0));
120 err_check(cipher_init(c, key));
121 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
122 err_check(cipher_encrypt(c, buffer, &buf_len));
123 /* run tests on cipher outout */
124 printf("monobit %d\n", stat_test_monobit(buffer));
125 printf("poker %d\n", stat_test_poker(buffer));
126 printf("runs %d\n", stat_test_runs(buffer));
127
128 printf("runs test (please be patient): ");
129 fflush(stdout);
130 num_fail = 0;
131 v128_set_to_zero(&nonce);
132 for(j=0; j < num_trials; j++) {
133 for (i=0; i < 2500; i++)
134 buffer[i] = 0;
135 nonce.v32[3] = i;
136 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
137 err_check(cipher_encrypt(c, buffer, &buf_len));
138 if (stat_test_runs(buffer)) {
139 num_fail++;
140 }
141 }
142
143 printf("%d failures in %d tests\n", num_fail, num_trials);
144 printf("(nota bene: a small fraction of stat_test failures does not \n"
145 "indicate that the random source is invalid)\n");
146
147 err_check(cipher_dealloc(c));
148
149 printf("running stat_tests on AES-256-ICM, expecting success\n");
150 /* set buffer to cipher output */
151 for (i=0; i < 2500; i++)
152 buffer[i] = 0;
153 err_check(cipher_type_alloc(&aes_icm, &c, 46, 0));
154 err_check(cipher_init(c, key));
155 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
156 err_check(cipher_encrypt(c, buffer, &buf_len));
157 /* run tests on cipher outout */
158 printf("monobit %d\n", stat_test_monobit(buffer));
159 printf("poker %d\n", stat_test_poker(buffer));
160 printf("runs %d\n", stat_test_runs(buffer));
161
162 printf("runs test (please be patient): ");
163 fflush(stdout);
164 num_fail = 0;
165 v128_set_to_zero(&nonce);
166 for(j=0; j < num_trials; j++) {
167 for (i=0; i < 2500; i++)
168 buffer[i] = 0;
169 nonce.v32[3] = i;
170 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
171 err_check(cipher_encrypt(c, buffer, &buf_len));
172 if (stat_test_runs(buffer)) {
173 num_fail++;
174 }
175 }
176
177 #ifdef OPENSSL
178 {
179 printf("running stat_tests on AES-128-GCM, expecting success\n");
180 /* set buffer to cipher output */
181 for (i=0; i < 2500; i++) {
182 buffer[i] = 0;
183 }
184 err_check(cipher_type_alloc(&aes_gcm_128_openssl, &c, AES_128_GCM_KEYSIZE_WS ALT, 8));
185 err_check(cipher_init(c, key));
186 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
187 err_check(cipher_encrypt(c, buffer, &buf_len));
188 /* run tests on cipher outout */
189 printf("monobit %d\n", stat_test_monobit(buffer));
190 printf("poker %d\n", stat_test_poker(buffer));
191 printf("runs %d\n", stat_test_runs(buffer));
192 fflush(stdout);
193 num_fail = 0;
194 v128_set_to_zero(&nonce);
195 for(j=0; j < num_trials; j++) {
196 for (i=0; i < 2500; i++) {
197 buffer[i] = 0;
198 }
199 nonce.v32[3] = i;
200 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
201 err_check(cipher_encrypt(c, buffer, &buf_len));
202 buf_len = 2500;
203 if (stat_test_runs(buffer)) {
204 num_fail++;
205 }
206 }
207
208 printf("running stat_tests on AES-256-GCM, expecting success\n");
209 /* set buffer to cipher output */
210 for (i=0; i < 2500; i++) {
211 buffer[i] = 0;
212 }
213 err_check(cipher_type_alloc(&aes_gcm_256_openssl, &c, AES_256_GCM_KEYSIZE_WS ALT, 16));
214 err_check(cipher_init(c, key));
215 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
216 err_check(cipher_encrypt(c, buffer, &buf_len));
217 /* run tests on cipher outout */
218 printf("monobit %d\n", stat_test_monobit(buffer));
219 printf("poker %d\n", stat_test_poker(buffer));
220 printf("runs %d\n", stat_test_runs(buffer));
221 fflush(stdout);
222 num_fail = 0;
223 v128_set_to_zero(&nonce);
224 for(j=0; j < num_trials; j++) {
225 for (i=0; i < 2500; i++) {
226 buffer[i] = 0;
227 }
228 nonce.v32[3] = i;
229 err_check(cipher_set_iv(c, &nonce, direction_encrypt));
230 err_check(cipher_encrypt(c, buffer, &buf_len));
231 buf_len = 2500;
232 if (stat_test_runs(buffer)) {
233 num_fail++;
234 }
235 }
236 }
237 #endif
238
239 printf("%d failures in %d tests\n", num_fail, num_trials);
240 printf("(nota bene: a small fraction of stat_test failures does not \n"
241 "indicate that the random source is invalid)\n");
242
243 err_check(cipher_dealloc(c));
244
245 return 0;
246 }
OLDNEW
« no previous file with comments | « srtp/crypto/test/sha1_driver.c ('k') | srtp/doc/.cvsignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698