Lines Matching refs:ctx

99 	CMAC_CTX *ctx;
100 ctx = OPENSSL_malloc(sizeof(CMAC_CTX));
101 if (!ctx)
103 EVP_CIPHER_CTX_init(&ctx->cctx);
104 ctx->nlast_block = -1;
105 return ctx;
108 void CMAC_CTX_cleanup(CMAC_CTX *ctx)
111 if (FIPS_mode() && !ctx->cctx.engine)
113 FIPS_cmac_ctx_cleanup(ctx);
117 EVP_CIPHER_CTX_cleanup(&ctx->cctx);
118 OPENSSL_cleanse(ctx->tbl, EVP_MAX_BLOCK_LENGTH);
119 OPENSSL_cleanse(ctx->k1, EVP_MAX_BLOCK_LENGTH);
120 OPENSSL_cleanse(ctx->k2, EVP_MAX_BLOCK_LENGTH);
121 OPENSSL_cleanse(ctx->last_block, EVP_MAX_BLOCK_LENGTH);
122 ctx->nlast_block = -1;
125 EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx)
127 return &ctx->cctx;
130 void CMAC_CTX_free(CMAC_CTX *ctx)
132 CMAC_CTX_cleanup(ctx);
133 OPENSSL_free(ctx);
152 int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
160 if ((impl || ctx->cctx.engine)
161 && !(ctx->cctx.flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
170 if (!impl && !ctx->cctx.engine)
171 return FIPS_cmac_init(ctx, key, keylen, cipher, NULL);
178 if (ctx->nlast_block == -1)
180 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
182 memset(ctx->tbl, 0, EVP_CIPHER_CTX_block_size(&ctx->cctx));
183 ctx->nlast_block = 0;
187 if (cipher && !EVP_EncryptInit_ex(&ctx->cctx, cipher, impl, NULL, NULL))
193 if (!EVP_CIPHER_CTX_cipher(&ctx->cctx))
195 if (!EVP_CIPHER_CTX_set_key_length(&ctx->cctx, keylen))
197 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, key, zero_iv))
199 bl = EVP_CIPHER_CTX_block_size(&ctx->cctx);
200 if (!EVP_Cipher(&ctx->cctx, ctx->tbl, zero_iv, bl))
202 make_kn(ctx->k1, ctx->tbl, bl);
203 make_kn(ctx->k2, ctx->k1, bl);
204 OPENSSL_cleanse(ctx->tbl, bl);
206 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
209 memset(ctx->tbl, 0, bl);
210 ctx->nlast_block = 0;
215 int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)
220 if (FIPS_mode() && !ctx->cctx.engine)
221 return FIPS_cmac_update(ctx, in, dlen);
223 if (ctx->nlast_block == -1)
227 bl = EVP_CIPHER_CTX_block_size(&ctx->cctx);
229 if (ctx->nlast_block > 0)
232 nleft = bl - ctx->nlast_block;
235 memcpy(ctx->last_block + ctx->nlast_block, data, nleft);
237 ctx->nlast_block += nleft;
243 if (!EVP_Cipher(&ctx->cctx, ctx->tbl, ctx->last_block,bl))
249 if (!EVP_Cipher(&ctx->cctx, ctx->tbl, data, bl))
255 memcpy(ctx->last_block, data, dlen);
256 ctx->nlast_block = dlen;
261 int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen)
265 if (FIPS_mode() && !ctx->cctx.engine)
266 return FIPS_cmac_final(ctx, out, poutlen);
268 if (ctx->nlast_block == -1)
270 bl = EVP_CIPHER_CTX_block_size(&ctx->cctx);
274 lb = ctx->nlast_block;
279 out[i] = ctx->last_block[i] ^ ctx->k1[i];
283 ctx->last_block[lb] = 0x80;
285 memset(ctx->last_block + lb + 1, 0, bl - lb - 1);
287 out[i] = ctx->last_block[i] ^ ctx->k2[i];
289 if (!EVP_Cipher(&ctx->cctx, out, out, bl))
297 int CMAC_resume(CMAC_CTX *ctx)
299 if (ctx->nlast_block == -1)
307 return EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, ctx->tbl);