Lines Matching defs:ctx
89 __owur static ossl_inline int siv128_do_s2v_p(SIV128_CONTEXT *ctx, SIV_BLOCK *out,
97 mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init);
105 siv128_xorblock(&t, &ctx->d);
112 siv128_dbl(&ctx->d);
113 siv128_xorblock(&t, &ctx->d);
129 __owur static ossl_inline int siv128_do_encrypt(EVP_CIPHER_CTX *ctx, unsigned char *out,
135 if (!EVP_CipherInit_ex(ctx, NULL, NULL, NULL, icv->byte, 1))
137 return EVP_EncryptUpdate(ctx, out, &out_len, in, out_len);
147 SIV128_CONTEXT *ctx;
150 if ((ctx = OPENSSL_malloc(sizeof(*ctx))) != NULL) {
151 ret = ossl_siv128_init(ctx, key, klen, cbc, ctr, libctx, propq);
153 return ctx;
154 OPENSSL_free(ctx);
163 int ossl_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen,
173 if (ctx == NULL)
176 memset(&ctx->d, 0, sizeof(ctx->d));
177 EVP_CIPHER_CTX_free(ctx->cipher_ctx);
178 EVP_MAC_CTX_free(ctx->mac_ctx_init);
179 EVP_MAC_free(ctx->mac);
180 ctx->mac = NULL;
181 ctx->cipher_ctx = NULL;
182 ctx->mac_ctx_init = NULL;
194 if ((ctx->cipher_ctx = EVP_CIPHER_CTX_new()) == NULL
195 || (ctx->mac =
197 || (ctx->mac_ctx_init = EVP_MAC_CTX_new(ctx->mac)) == NULL
198 || !EVP_MAC_CTX_set_params(ctx->mac_ctx_init, params)
199 || !EVP_EncryptInit_ex(ctx->cipher_ctx, ctr, NULL, key + klen, NULL)
200 || (mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init)) == NULL
202 || !EVP_MAC_final(mac_ctx, ctx->d.byte, &out_len,
203 sizeof(ctx->d.byte))) {
204 EVP_CIPHER_CTX_free(ctx->cipher_ctx);
205 EVP_MAC_CTX_free(ctx->mac_ctx_init);
207 EVP_MAC_free(ctx->mac);
212 ctx->final_ret = -1;
213 ctx->crypto_ok = 1;
246 int ossl_siv128_aad(SIV128_CONTEXT *ctx, const unsigned char *aad,
253 siv128_dbl(&ctx->d);
255 if ((mac_ctx = EVP_MAC_CTX_dup(ctx->mac_ctx_init)) == NULL
265 siv128_xorblock(&ctx->d, &mac_out);
273 int ossl_siv128_encrypt(SIV128_CONTEXT *ctx,
280 if (ctx->crypto_ok == 0)
282 ctx->crypto_ok--;
284 if (!siv128_do_s2v_p(ctx, &q, in, len))
287 memcpy(ctx->tag.byte, &q, SIV_LEN);
291 if (!siv128_do_encrypt(ctx->cipher_ctx, out, in, len, &q))
293 ctx->final_ret = 0;
300 int ossl_siv128_decrypt(SIV128_CONTEXT *ctx,
309 if (ctx->crypto_ok == 0)
311 ctx->crypto_ok--;
313 memcpy(&q, ctx->tag.byte, SIV_LEN);
317 if (!siv128_do_encrypt(ctx->cipher_ctx, out, in, len, &q)
318 || !siv128_do_s2v_p(ctx, &t, out, len))
321 p = ctx->tag.byte;
329 ctx->final_ret = 0;
336 int ossl_siv128_finish(SIV128_CONTEXT *ctx)
338 return ctx->final_ret;
344 int ossl_siv128_set_tag(SIV128_CONTEXT *ctx, const unsigned char *tag, size_t len)
350 memcpy(ctx->tag.byte, tag, len);
357 int ossl_siv128_get_tag(SIV128_CONTEXT *ctx, unsigned char *tag, size_t len)
363 memcpy(tag, ctx->tag.byte, len);
370 int ossl_siv128_cleanup(SIV128_CONTEXT *ctx)
372 if (ctx != NULL) {
373 EVP_CIPHER_CTX_free(ctx->cipher_ctx);
374 ctx->cipher_ctx = NULL;
375 EVP_MAC_CTX_free(ctx->mac_ctx_init);
376 ctx->mac_ctx_init = NULL;
377 EVP_MAC_free(ctx->mac);
378 ctx->mac = NULL;
379 OPENSSL_cleanse(&ctx->d, sizeof(ctx->d));
380 OPENSSL_cleanse(&ctx->tag, sizeof(ctx->tag));
381 ctx->final_ret = -1;
382 ctx->crypto_ok = 1;
387 int ossl_siv128_speed(SIV128_CONTEXT *ctx, int arg)
389 ctx->crypto_ok = (arg == 1) ? -1 : 1;