/src/openssl111/crypto/rand/drbg_ctr.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include <stdlib.h> |
11 | | #include <string.h> |
12 | | #include <openssl/crypto.h> |
13 | | #include <openssl/err.h> |
14 | | #include <openssl/rand.h> |
15 | | #include "modes_local.h" |
16 | | #include "internal/thread_once.h" |
17 | | #include "rand_local.h" |
18 | | |
19 | | /* |
20 | | * Implementation of NIST SP 800-90A CTR DRBG. |
21 | | */ |
22 | | |
23 | | static void inc_128(RAND_DRBG_CTR *ctr) |
24 | 105k | { |
25 | 105k | unsigned char *p = &ctr->V[0]; |
26 | 105k | u32 n = 16, c = 1; |
27 | | |
28 | 1.68M | do { |
29 | 1.68M | --n; |
30 | 1.68M | c += p[n]; |
31 | 1.68M | p[n] = (u8)c; |
32 | 1.68M | c >>= 8; |
33 | 1.68M | } while (n); |
34 | 105k | } |
35 | | |
36 | | static void ctr_XOR(RAND_DRBG_CTR *ctr, const unsigned char *in, size_t inlen) |
37 | 35.1k | { |
38 | 35.1k | size_t i, n; |
39 | | |
40 | 35.1k | if (in == NULL || inlen == 0) |
41 | 0 | return; |
42 | | |
43 | | /* |
44 | | * Any zero padding will have no effect on the result as we |
45 | | * are XORing. So just process however much input we have. |
46 | | */ |
47 | 35.1k | n = inlen < ctr->keylen ? inlen : ctr->keylen; |
48 | 1.16M | for (i = 0; i < n; i++) |
49 | 1.12M | ctr->K[i] ^= in[i]; |
50 | 35.1k | if (inlen <= ctr->keylen) |
51 | 0 | return; |
52 | | |
53 | 35.1k | n = inlen - ctr->keylen; |
54 | 35.1k | if (n > 16) { |
55 | | /* Should never happen */ |
56 | 0 | n = 16; |
57 | 0 | } |
58 | 597k | for (i = 0; i < n; i++) |
59 | 562k | ctr->V[i] ^= in[i + ctr->keylen]; |
60 | 35.1k | } |
61 | | |
62 | | /* |
63 | | * Process a complete block using BCC algorithm of SP 800-90A 10.3.3 |
64 | | */ |
65 | | __owur static int ctr_BCC_block(RAND_DRBG_CTR *ctr, unsigned char *out, |
66 | | const unsigned char *in, int len) |
67 | 70.3k | { |
68 | 70.3k | int i, outlen = AES_BLOCK_SIZE; |
69 | | |
70 | 3.44M | for (i = 0; i < len; i++) |
71 | 3.37M | out[i] ^= in[i]; |
72 | | |
73 | 70.3k | if (!EVP_CipherUpdate(ctr->ctx_df, out, &outlen, out, len) |
74 | 70.3k | || outlen != len) |
75 | 0 | return 0; |
76 | 70.3k | return 1; |
77 | 70.3k | } |
78 | | |
79 | | |
80 | | /* |
81 | | * Handle several BCC operations for as much data as we need for K and X |
82 | | */ |
83 | | __owur static int ctr_BCC_blocks(RAND_DRBG_CTR *ctr, const unsigned char *in) |
84 | 52.7k | { |
85 | 52.7k | unsigned char in_tmp[48]; |
86 | 52.7k | unsigned char num_of_blk = 2; |
87 | | |
88 | 52.7k | memcpy(in_tmp, in, 16); |
89 | 52.7k | memcpy(in_tmp + 16, in, 16); |
90 | 52.7k | if (ctr->keylen != 16) { |
91 | 52.7k | memcpy(in_tmp + 32, in, 16); |
92 | 52.7k | num_of_blk = 3; |
93 | 52.7k | } |
94 | 52.7k | return ctr_BCC_block(ctr, ctr->KX, in_tmp, AES_BLOCK_SIZE * num_of_blk); |
95 | 52.7k | } |
96 | | |
97 | | /* |
98 | | * Initialise BCC blocks: these have the value 0,1,2 in leftmost positions: |
99 | | * see 10.3.1 stage 7. |
100 | | */ |
101 | | __owur static int ctr_BCC_init(RAND_DRBG_CTR *ctr) |
102 | 17.5k | { |
103 | 17.5k | unsigned char bltmp[48] = {0}; |
104 | 17.5k | unsigned char num_of_blk; |
105 | | |
106 | 17.5k | memset(ctr->KX, 0, 48); |
107 | 17.5k | num_of_blk = ctr->keylen == 16 ? 2 : 3; |
108 | 17.5k | bltmp[(AES_BLOCK_SIZE * 1) + 3] = 1; |
109 | 17.5k | bltmp[(AES_BLOCK_SIZE * 2) + 3] = 2; |
110 | 17.5k | return ctr_BCC_block(ctr, ctr->KX, bltmp, num_of_blk * AES_BLOCK_SIZE); |
111 | 17.5k | } |
112 | | |
113 | | /* |
114 | | * Process several blocks into BCC algorithm, some possibly partial |
115 | | */ |
116 | | __owur static int ctr_BCC_update(RAND_DRBG_CTR *ctr, |
117 | | const unsigned char *in, size_t inlen) |
118 | 70.3k | { |
119 | 70.3k | if (in == NULL || inlen == 0) |
120 | 35.1k | return 1; |
121 | | |
122 | | /* If we have partial block handle it first */ |
123 | 35.1k | if (ctr->bltmp_pos) { |
124 | 17.5k | size_t left = 16 - ctr->bltmp_pos; |
125 | | |
126 | | /* If we now have a complete block process it */ |
127 | 17.5k | if (inlen >= left) { |
128 | 17.5k | memcpy(ctr->bltmp + ctr->bltmp_pos, in, left); |
129 | 17.5k | if (!ctr_BCC_blocks(ctr, ctr->bltmp)) |
130 | 0 | return 0; |
131 | 17.5k | ctr->bltmp_pos = 0; |
132 | 17.5k | inlen -= left; |
133 | 17.5k | in += left; |
134 | 17.5k | } |
135 | 17.5k | } |
136 | | |
137 | | /* Process zero or more complete blocks */ |
138 | 52.7k | for (; inlen >= 16; in += 16, inlen -= 16) { |
139 | 17.5k | if (!ctr_BCC_blocks(ctr, in)) |
140 | 0 | return 0; |
141 | 17.5k | } |
142 | | |
143 | | /* Copy any remaining partial block to the temporary buffer */ |
144 | 35.1k | if (inlen > 0) { |
145 | 17.5k | memcpy(ctr->bltmp + ctr->bltmp_pos, in, inlen); |
146 | 17.5k | ctr->bltmp_pos += inlen; |
147 | 17.5k | } |
148 | 35.1k | return 1; |
149 | 35.1k | } |
150 | | |
151 | | __owur static int ctr_BCC_final(RAND_DRBG_CTR *ctr) |
152 | 17.5k | { |
153 | 17.5k | if (ctr->bltmp_pos) { |
154 | 17.5k | memset(ctr->bltmp + ctr->bltmp_pos, 0, 16 - ctr->bltmp_pos); |
155 | 17.5k | if (!ctr_BCC_blocks(ctr, ctr->bltmp)) |
156 | 0 | return 0; |
157 | 17.5k | } |
158 | 17.5k | return 1; |
159 | 17.5k | } |
160 | | |
161 | | __owur static int ctr_df(RAND_DRBG_CTR *ctr, |
162 | | const unsigned char *in1, size_t in1len, |
163 | | const unsigned char *in2, size_t in2len, |
164 | | const unsigned char *in3, size_t in3len) |
165 | 17.5k | { |
166 | 17.5k | static unsigned char c80 = 0x80; |
167 | 17.5k | size_t inlen; |
168 | 17.5k | unsigned char *p = ctr->bltmp; |
169 | 17.5k | int outlen = AES_BLOCK_SIZE; |
170 | | |
171 | 17.5k | if (!ctr_BCC_init(ctr)) |
172 | 0 | return 0; |
173 | 17.5k | if (in1 == NULL) |
174 | 0 | in1len = 0; |
175 | 17.5k | if (in2 == NULL) |
176 | 17.5k | in2len = 0; |
177 | 17.5k | if (in3 == NULL) |
178 | 17.5k | in3len = 0; |
179 | 17.5k | inlen = in1len + in2len + in3len; |
180 | | /* Initialise L||N in temporary block */ |
181 | 17.5k | *p++ = (inlen >> 24) & 0xff; |
182 | 17.5k | *p++ = (inlen >> 16) & 0xff; |
183 | 17.5k | *p++ = (inlen >> 8) & 0xff; |
184 | 17.5k | *p++ = inlen & 0xff; |
185 | | |
186 | | /* NB keylen is at most 32 bytes */ |
187 | 17.5k | *p++ = 0; |
188 | 17.5k | *p++ = 0; |
189 | 17.5k | *p++ = 0; |
190 | 17.5k | *p = (unsigned char)((ctr->keylen + 16) & 0xff); |
191 | 17.5k | ctr->bltmp_pos = 8; |
192 | 17.5k | if (!ctr_BCC_update(ctr, in1, in1len) |
193 | 17.5k | || !ctr_BCC_update(ctr, in2, in2len) |
194 | 17.5k | || !ctr_BCC_update(ctr, in3, in3len) |
195 | 17.5k | || !ctr_BCC_update(ctr, &c80, 1) |
196 | 17.5k | || !ctr_BCC_final(ctr)) |
197 | 0 | return 0; |
198 | | /* Set up key K */ |
199 | 17.5k | if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->KX, NULL, -1)) |
200 | 0 | return 0; |
201 | | /* X follows key K */ |
202 | 17.5k | if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX, &outlen, ctr->KX + ctr->keylen, |
203 | 17.5k | AES_BLOCK_SIZE) |
204 | 17.5k | || outlen != AES_BLOCK_SIZE) |
205 | 0 | return 0; |
206 | 17.5k | if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX + 16, &outlen, ctr->KX, |
207 | 17.5k | AES_BLOCK_SIZE) |
208 | 17.5k | || outlen != AES_BLOCK_SIZE) |
209 | 0 | return 0; |
210 | 17.5k | if (ctr->keylen != 16) |
211 | 17.5k | if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX + 32, &outlen, |
212 | 17.5k | ctr->KX + 16, AES_BLOCK_SIZE) |
213 | 17.5k | || outlen != AES_BLOCK_SIZE) |
214 | 0 | return 0; |
215 | 17.5k | return 1; |
216 | 17.5k | } |
217 | | |
218 | | /* |
219 | | * NB the no-df Update in SP800-90A specifies a constant input length |
220 | | * of seedlen, however other uses of this algorithm pad the input with |
221 | | * zeroes if necessary and have up to two parameters XORed together, |
222 | | * so we handle both cases in this function instead. |
223 | | */ |
224 | | __owur static int ctr_update(RAND_DRBG *drbg, |
225 | | const unsigned char *in1, size_t in1len, |
226 | | const unsigned char *in2, size_t in2len, |
227 | | const unsigned char *nonce, size_t noncelen) |
228 | 35.1k | { |
229 | 35.1k | RAND_DRBG_CTR *ctr = &drbg->data.ctr; |
230 | 35.1k | int outlen = AES_BLOCK_SIZE; |
231 | 35.1k | unsigned char V_tmp[48], out[48]; |
232 | 35.1k | unsigned char len; |
233 | | |
234 | | /* correct key is already set up. */ |
235 | 35.1k | memcpy(V_tmp, ctr->V, 16); |
236 | 35.1k | inc_128(ctr); |
237 | 35.1k | memcpy(V_tmp + 16, ctr->V, 16); |
238 | 35.1k | if (ctr->keylen == 16) { |
239 | 0 | len = 32; |
240 | 35.1k | } else { |
241 | 35.1k | inc_128(ctr); |
242 | 35.1k | memcpy(V_tmp + 32, ctr->V, 16); |
243 | 35.1k | len = 48; |
244 | 35.1k | } |
245 | 35.1k | if (!EVP_CipherUpdate(ctr->ctx_ecb, out, &outlen, V_tmp, len) |
246 | 35.1k | || outlen != len) |
247 | 0 | return 0; |
248 | 35.1k | memcpy(ctr->K, out, ctr->keylen); |
249 | 35.1k | memcpy(ctr->V, out + ctr->keylen, 16); |
250 | | |
251 | 35.1k | if ((drbg->flags & RAND_DRBG_FLAG_CTR_NO_DF) == 0) { |
252 | | /* If no input reuse existing derived value */ |
253 | 35.1k | if (in1 != NULL || nonce != NULL || in2 != NULL) |
254 | 17.5k | if (!ctr_df(ctr, in1, in1len, nonce, noncelen, in2, in2len)) |
255 | 0 | return 0; |
256 | | /* If this a reuse input in1len != 0 */ |
257 | 35.1k | if (in1len) |
258 | 35.1k | ctr_XOR(ctr, ctr->KX, drbg->seedlen); |
259 | 35.1k | } else { |
260 | 0 | ctr_XOR(ctr, in1, in1len); |
261 | 0 | ctr_XOR(ctr, in2, in2len); |
262 | 0 | } |
263 | | |
264 | 35.1k | if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->K, NULL, -1) |
265 | 35.1k | || !EVP_CipherInit_ex(ctr->ctx_ctr, NULL, NULL, ctr->K, NULL, -1)) |
266 | 0 | return 0; |
267 | 35.1k | return 1; |
268 | 35.1k | } |
269 | | |
270 | | __owur static int drbg_ctr_instantiate(RAND_DRBG *drbg, |
271 | | const unsigned char *entropy, size_t entropylen, |
272 | | const unsigned char *nonce, size_t noncelen, |
273 | | const unsigned char *pers, size_t perslen) |
274 | 2 | { |
275 | 2 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; |
276 | | |
277 | 2 | if (entropy == NULL) |
278 | 0 | return 0; |
279 | | |
280 | 2 | memset(ctr->K, 0, sizeof(ctr->K)); |
281 | 2 | memset(ctr->V, 0, sizeof(ctr->V)); |
282 | 2 | if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->K, NULL, -1)) |
283 | 0 | return 0; |
284 | | |
285 | 2 | inc_128(ctr); |
286 | 2 | if (!ctr_update(drbg, entropy, entropylen, pers, perslen, nonce, noncelen)) |
287 | 0 | return 0; |
288 | 2 | return 1; |
289 | 2 | } |
290 | | |
291 | | __owur static int drbg_ctr_reseed(RAND_DRBG *drbg, |
292 | | const unsigned char *entropy, size_t entropylen, |
293 | | const unsigned char *adin, size_t adinlen) |
294 | 0 | { |
295 | 0 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; |
296 | |
|
297 | 0 | if (entropy == NULL) |
298 | 0 | return 0; |
299 | | |
300 | 0 | inc_128(ctr); |
301 | 0 | if (!ctr_update(drbg, entropy, entropylen, adin, adinlen, NULL, 0)) |
302 | 0 | return 0; |
303 | 0 | return 1; |
304 | 0 | } |
305 | | |
306 | | static void ctr96_inc(unsigned char *counter) |
307 | 0 | { |
308 | 0 | u32 n = 12, c = 1; |
309 | |
|
310 | 0 | do { |
311 | 0 | --n; |
312 | 0 | c += counter[n]; |
313 | 0 | counter[n] = (u8)c; |
314 | 0 | c >>= 8; |
315 | 0 | } while (n); |
316 | 0 | } |
317 | | |
318 | | __owur static int drbg_ctr_generate(RAND_DRBG *drbg, |
319 | | unsigned char *out, size_t outlen, |
320 | | const unsigned char *adin, size_t adinlen) |
321 | 17.5k | { |
322 | 17.5k | RAND_DRBG_CTR *ctr = &drbg->data.ctr; |
323 | 17.5k | unsigned int ctr32, blocks; |
324 | 17.5k | int outl, buflen; |
325 | | |
326 | 17.5k | if (adin != NULL && adinlen != 0) { |
327 | 17.5k | inc_128(ctr); |
328 | | |
329 | 17.5k | if (!ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0)) |
330 | 0 | return 0; |
331 | | /* This means we reuse derived value */ |
332 | 17.5k | if ((drbg->flags & RAND_DRBG_FLAG_CTR_NO_DF) == 0) { |
333 | 17.5k | adin = NULL; |
334 | 17.5k | adinlen = 1; |
335 | 17.5k | } |
336 | 17.5k | } else { |
337 | 0 | adinlen = 0; |
338 | 0 | } |
339 | | |
340 | 17.5k | inc_128(ctr); |
341 | | |
342 | 17.5k | if (outlen == 0) { |
343 | 0 | inc_128(ctr); |
344 | |
|
345 | 0 | if (!ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0)) |
346 | 0 | return 0; |
347 | 0 | return 1; |
348 | 0 | } |
349 | | |
350 | 17.5k | memset(out, 0, outlen); |
351 | | |
352 | 17.5k | do { |
353 | 17.5k | if (!EVP_CipherInit_ex(ctr->ctx_ctr, |
354 | 17.5k | NULL, NULL, NULL, ctr->V, -1)) |
355 | 0 | return 0; |
356 | | |
357 | | /*- |
358 | | * outlen has type size_t while EVP_CipherUpdate takes an |
359 | | * int argument and thus cannot be guaranteed to process more |
360 | | * than 2^31-1 bytes at a time. We process such huge generate |
361 | | * requests in 2^30 byte chunks, which is the greatest multiple |
362 | | * of AES block size lower than or equal to 2^31-1. |
363 | | */ |
364 | 17.5k | buflen = outlen > (1U << 30) ? (1U << 30) : outlen; |
365 | 17.5k | blocks = (buflen + 15) / 16; |
366 | | |
367 | 17.5k | ctr32 = GETU32(ctr->V + 12) + blocks; |
368 | 17.5k | if (ctr32 < blocks) { |
369 | | /* 32-bit counter overflow into V. */ |
370 | 0 | if (ctr32 != 0) { |
371 | 0 | blocks -= ctr32; |
372 | 0 | buflen = blocks * 16; |
373 | 0 | ctr32 = 0; |
374 | 0 | } |
375 | 0 | ctr96_inc(ctr->V); |
376 | 0 | } |
377 | 17.5k | PUTU32(ctr->V + 12, ctr32); |
378 | | |
379 | 17.5k | if (!EVP_CipherUpdate(ctr->ctx_ctr, out, &outl, out, buflen) |
380 | 17.5k | || outl != buflen) |
381 | 0 | return 0; |
382 | | |
383 | 17.5k | out += buflen; |
384 | 17.5k | outlen -= buflen; |
385 | 17.5k | } while (outlen); |
386 | | |
387 | 17.5k | if (!ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0)) |
388 | 0 | return 0; |
389 | 17.5k | return 1; |
390 | 17.5k | } |
391 | | |
392 | | static int drbg_ctr_uninstantiate(RAND_DRBG *drbg) |
393 | 2 | { |
394 | 2 | EVP_CIPHER_CTX_free(drbg->data.ctr.ctx_ecb); |
395 | 2 | EVP_CIPHER_CTX_free(drbg->data.ctr.ctx_ctr); |
396 | 2 | EVP_CIPHER_CTX_free(drbg->data.ctr.ctx_df); |
397 | 2 | OPENSSL_cleanse(&drbg->data.ctr, sizeof(drbg->data.ctr)); |
398 | 2 | return 1; |
399 | 2 | } |
400 | | |
401 | | static RAND_DRBG_METHOD drbg_ctr_meth = { |
402 | | drbg_ctr_instantiate, |
403 | | drbg_ctr_reseed, |
404 | | drbg_ctr_generate, |
405 | | drbg_ctr_uninstantiate |
406 | | }; |
407 | | |
408 | | int drbg_ctr_init(RAND_DRBG *drbg) |
409 | 2 | { |
410 | 2 | RAND_DRBG_CTR *ctr = &drbg->data.ctr; |
411 | 2 | size_t keylen; |
412 | | |
413 | 2 | switch (drbg->type) { |
414 | 0 | default: |
415 | | /* This can't happen, but silence the compiler warning. */ |
416 | 0 | return 0; |
417 | 0 | case NID_aes_128_ctr: |
418 | 0 | keylen = 16; |
419 | 0 | ctr->cipher_ecb = EVP_aes_128_ecb(); |
420 | 0 | ctr->cipher_ctr = EVP_aes_128_ctr(); |
421 | 0 | break; |
422 | 0 | case NID_aes_192_ctr: |
423 | 0 | keylen = 24; |
424 | 0 | ctr->cipher_ecb = EVP_aes_192_ecb(); |
425 | 0 | ctr->cipher_ctr = EVP_aes_192_ctr(); |
426 | 0 | break; |
427 | 2 | case NID_aes_256_ctr: |
428 | 2 | keylen = 32; |
429 | 2 | ctr->cipher_ecb = EVP_aes_256_ecb(); |
430 | 2 | ctr->cipher_ctr = EVP_aes_256_ctr(); |
431 | 2 | break; |
432 | 2 | } |
433 | | |
434 | 2 | drbg->meth = &drbg_ctr_meth; |
435 | | |
436 | 2 | ctr->keylen = keylen; |
437 | 2 | if (ctr->ctx_ecb == NULL) |
438 | 2 | ctr->ctx_ecb = EVP_CIPHER_CTX_new(); |
439 | 2 | if (ctr->ctx_ctr == NULL) |
440 | 2 | ctr->ctx_ctr = EVP_CIPHER_CTX_new(); |
441 | 2 | if (ctr->ctx_ecb == NULL || ctr->ctx_ctr == NULL |
442 | 2 | || !EVP_CipherInit_ex(ctr->ctx_ecb, |
443 | 2 | ctr->cipher_ecb, NULL, NULL, NULL, 1) |
444 | 2 | || !EVP_CipherInit_ex(ctr->ctx_ctr, |
445 | 2 | ctr->cipher_ctr, NULL, NULL, NULL, 1)) |
446 | 0 | return 0; |
447 | | |
448 | 2 | drbg->meth = &drbg_ctr_meth; |
449 | 2 | drbg->strength = keylen * 8; |
450 | 2 | drbg->seedlen = keylen + 16; |
451 | | |
452 | 2 | if ((drbg->flags & RAND_DRBG_FLAG_CTR_NO_DF) == 0) { |
453 | | /* df initialisation */ |
454 | 2 | static const unsigned char df_key[32] = { |
455 | 2 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
456 | 2 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
457 | 2 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
458 | 2 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
459 | 2 | }; |
460 | | |
461 | 2 | if (ctr->ctx_df == NULL) |
462 | 2 | ctr->ctx_df = EVP_CIPHER_CTX_new(); |
463 | 2 | if (ctr->ctx_df == NULL) |
464 | 0 | return 0; |
465 | | /* Set key schedule for df_key */ |
466 | 2 | if (!EVP_CipherInit_ex(ctr->ctx_df, |
467 | 2 | ctr->cipher_ecb, NULL, df_key, NULL, 1)) |
468 | 0 | return 0; |
469 | | |
470 | 2 | drbg->min_entropylen = ctr->keylen; |
471 | 2 | drbg->max_entropylen = DRBG_MAX_LENGTH; |
472 | 2 | drbg->min_noncelen = drbg->min_entropylen / 2; |
473 | 2 | drbg->max_noncelen = DRBG_MAX_LENGTH; |
474 | 2 | drbg->max_perslen = DRBG_MAX_LENGTH; |
475 | 2 | drbg->max_adinlen = DRBG_MAX_LENGTH; |
476 | 2 | } else { |
477 | 0 | drbg->min_entropylen = drbg->seedlen; |
478 | 0 | drbg->max_entropylen = drbg->seedlen; |
479 | | /* Nonce not used */ |
480 | 0 | drbg->min_noncelen = 0; |
481 | 0 | drbg->max_noncelen = 0; |
482 | 0 | drbg->max_perslen = drbg->seedlen; |
483 | 0 | drbg->max_adinlen = drbg->seedlen; |
484 | 0 | } |
485 | | |
486 | 2 | drbg->max_request = 1 << 16; |
487 | | |
488 | 2 | return 1; |
489 | 2 | } |