Lines Matching refs:ctr

58 static void inc_128(PROV_DRBG_CTR *ctr)
60 unsigned char *p = &ctr->V[0];
71 static void ctr_XOR(PROV_DRBG_CTR *ctr, const unsigned char *in, size_t inlen)
82 n = inlen < ctr->keylen ? inlen : ctr->keylen;
84 ctr->K[i] ^= in[i];
85 if (inlen <= ctr->keylen)
88 n = inlen - ctr->keylen;
94 ctr->V[i] ^= in[i + ctr->keylen];
100 __owur static int ctr_BCC_block(PROV_DRBG_CTR *ctr, unsigned char *out,
108 if (!EVP_CipherUpdate(ctr->ctx_df, out, &outlen, out, len)
118 __owur static int ctr_BCC_blocks(PROV_DRBG_CTR *ctr, const unsigned char *in)
125 if (ctr->keylen != 16) {
129 return ctr_BCC_block(ctr, ctr->KX, in_tmp, AES_BLOCK_SIZE * num_of_blk);
136 __owur static int ctr_BCC_init(PROV_DRBG_CTR *ctr)
141 memset(ctr->KX, 0, 48);
142 num_of_blk = ctr->keylen == 16 ? 2 : 3;
145 return ctr_BCC_block(ctr, ctr->KX, bltmp, num_of_blk * AES_BLOCK_SIZE);
151 __owur static int ctr_BCC_update(PROV_DRBG_CTR *ctr,
158 if (ctr->bltmp_pos) {
159 size_t left = 16 - ctr->bltmp_pos;
163 memcpy(ctr->bltmp + ctr->bltmp_pos, in, left);
164 if (!ctr_BCC_blocks(ctr, ctr->bltmp))
166 ctr->bltmp_pos = 0;
174 if (!ctr_BCC_blocks(ctr, in))
180 memcpy(ctr->bltmp + ctr->bltmp_pos, in, inlen);
181 ctr->bltmp_pos += inlen;
186 __owur static int ctr_BCC_final(PROV_DRBG_CTR *ctr)
188 if (ctr->bltmp_pos) {
189 memset(ctr->bltmp + ctr->bltmp_pos, 0, 16 - ctr->bltmp_pos);
190 if (!ctr_BCC_blocks(ctr, ctr->bltmp))
196 __owur static int ctr_df(PROV_DRBG_CTR *ctr,
203 unsigned char *p = ctr->bltmp;
206 if (!ctr_BCC_init(ctr))
225 *p = (unsigned char)((ctr->keylen + 16) & 0xff);
226 ctr->bltmp_pos = 8;
227 if (!ctr_BCC_update(ctr, in1, in1len)
228 || !ctr_BCC_update(ctr, in2, in2len)
229 || !ctr_BCC_update(ctr, in3, in3len)
230 || !ctr_BCC_update(ctr, &c80, 1)
231 || !ctr_BCC_final(ctr))
234 if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->KX, NULL, -1))
237 if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX, &outlen, ctr->KX + ctr->keylen,
241 if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX + 16, &outlen, ctr->KX,
245 if (ctr->keylen != 16)
246 if (!EVP_CipherUpdate(ctr->ctx_ecb, ctr->KX + 32, &outlen,
247 ctr->KX + 16, AES_BLOCK_SIZE)
264 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
270 memcpy(V_tmp, ctr->V, 16);
271 inc_128(ctr);
272 memcpy(V_tmp + 16, ctr->V, 16);
273 if (ctr->keylen == 16) {
276 inc_128(ctr);
277 memcpy(V_tmp + 32, ctr->V, 16);
280 if (!EVP_CipherUpdate(ctr->ctx_ecb, out, &outlen, V_tmp, len)
283 memcpy(ctr->K, out, ctr->keylen);
284 memcpy(ctr->V, out + ctr->keylen, 16);
286 if (ctr->use_df) {
289 if (!ctr_df(ctr, in1, in1len, nonce, noncelen, in2, in2len))
293 ctr_XOR(ctr, ctr->KX, drbg->seedlen);
295 ctr_XOR(ctr, in1, in1len);
296 ctr_XOR(ctr, in2, in2len);
299 if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->K, NULL, -1)
300 || !EVP_CipherInit_ex(ctr->ctx_ctr, NULL, NULL, ctr->K, NULL, -1))
310 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
315 memset(ctr->K, 0, sizeof(ctr->K));
316 memset(ctr->V, 0, sizeof(ctr->V));
317 if (!EVP_CipherInit_ex(ctr->ctx_ecb, NULL, NULL, ctr->K, NULL, -1))
320 inc_128(ctr);
344 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
349 inc_128(ctr);
381 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
386 inc_128(ctr);
391 if (ctr->use_df) {
399 inc_128(ctr);
402 inc_128(ctr);
412 if (!EVP_CipherInit_ex(ctr->ctx_ctr,
413 NULL, NULL, NULL, ctr->V, -1))
426 ctr32 = GETU32(ctr->V + 12) + blocks;
434 ctr96_inc(ctr->V);
436 PUTU32(ctr->V + 12, ctr32);
438 if (!EVP_CipherUpdate(ctr->ctx_ctr, out, &outl, out, buflen)
464 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
466 OPENSSL_cleanse(ctr->K, sizeof(ctr->K));
467 OPENSSL_cleanse(ctr->V, sizeof(ctr->V));
468 OPENSSL_cleanse(ctr->bltmp, sizeof(ctr->bltmp));
469 OPENSSL_cleanse(ctr->KX, sizeof(ctr->KX));
470 ctr->bltmp_pos = 0;
482 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
484 PROV_DRBG_VERYIFY_ZEROIZATION(ctr->K);
485 PROV_DRBG_VERYIFY_ZEROIZATION(ctr->V);
486 PROV_DRBG_VERYIFY_ZEROIZATION(ctr->bltmp);
487 PROV_DRBG_VERYIFY_ZEROIZATION(ctr->KX);
488 if (ctr->bltmp_pos != 0)
495 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
500 if (ctr->use_df) {
508 if (ctr->keylen > 0) {
509 drbg->min_entropylen = ctr->keylen;
513 const size_t len = ctr->keylen > 0 ? drbg->seedlen : DRBG_MAX_LENGTH;
528 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
531 if (ctr->cipher_ctr == NULL) {
535 ctr->keylen = keylen = EVP_CIPHER_get_key_length(ctr->cipher_ctr);
536 if (ctr->ctx_ecb == NULL)
537 ctr->ctx_ecb = EVP_CIPHER_CTX_new();
538 if (ctr->ctx_ctr == NULL)
539 ctr->ctx_ctr = EVP_CIPHER_CTX_new();
540 if (ctr->ctx_ecb == NULL || ctr->ctx_ctr == NULL) {
545 if (!EVP_CipherInit_ex(ctr->ctx_ecb,
546 ctr->cipher_ecb, NULL, NULL, NULL, 1)
547 || !EVP_CipherInit_ex(ctr->ctx_ctr,
548 ctr->cipher_ctr, NULL, NULL, NULL, 1)) {
556 if (ctr->use_df) {
565 if (ctr->ctx_df == NULL)
566 ctr->ctx_df = EVP_CIPHER_CTX_new();
567 if (ctr->ctx_df == NULL) {
572 if (!EVP_CipherInit_ex(ctr->ctx_df,
573 ctr->cipher_ecb, NULL, df_key, NULL, 1)) {
581 EVP_CIPHER_CTX_free(ctr->ctx_ecb);
582 EVP_CIPHER_CTX_free(ctr->ctx_ctr);
583 ctr->ctx_ecb = ctr->ctx_ctr = NULL;
589 PROV_DRBG_CTR *ctr;
591 ctr = OPENSSL_secure_zalloc(sizeof(*ctr));
592 if (ctr == NULL) {
597 ctr->use_df = 1;
598 drbg->data = ctr;
614 PROV_DRBG_CTR *ctr;
616 if (drbg != NULL && (ctr = (PROV_DRBG_CTR *)drbg->data) != NULL) {
617 EVP_CIPHER_CTX_free(ctr->ctx_ecb);
618 EVP_CIPHER_CTX_free(ctr->ctx_ctr);
619 EVP_CIPHER_CTX_free(ctr->ctx_df);
620 EVP_CIPHER_free(ctr->cipher_ecb);
621 EVP_CIPHER_free(ctr->cipher_ctr);
623 OPENSSL_secure_clear_free(ctr, sizeof(*ctr));
631 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
635 if (p != NULL && !OSSL_PARAM_set_int(p, ctr->use_df))
640 if (ctr->cipher_ctr == NULL
642 EVP_CIPHER_get0_name(ctr->cipher_ctr)))
664 PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)ctx->data;
674 ctr->use_df = i != 0;
702 EVP_CIPHER_free(ctr->cipher_ecb);
703 EVP_CIPHER_free(ctr->cipher_ctr);
704 ctr->cipher_ctr = EVP_CIPHER_fetch(libctx, base, propquery);
705 ctr->cipher_ecb = EVP_CIPHER_fetch(libctx, ecb, propquery);
707 if (ctr->cipher_ctr == NULL || ctr->cipher_ecb == NULL) {