2 * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #include "prov/ciphercommon.h"
11 #include "prov/ciphercommon_gcm.h"
14 int ossl_gcm_setiv(PROV_GCM_CTX *ctx, const unsigned char *iv, size_t ivlen)
16 CRYPTO_gcm128_setiv(&ctx->gcm, iv, ivlen);
20 int ossl_gcm_aad_update(PROV_GCM_CTX *ctx, const unsigned char *aad,
23 return CRYPTO_gcm128_aad(&ctx->gcm, aad, aad_len) == 0;
26 int ossl_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
27 size_t len, unsigned char *out)
30 if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
33 if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
39 int ossl_gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag)
42 CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE);
43 ctx->taglen = GCM_TAG_MAX_SIZE;
45 if (CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
51 int ossl_gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len,
52 const unsigned char *in, size_t in_len,
53 unsigned char *out, unsigned char *tag, size_t tag_len)
58 if (!ctx->hw->aadupdate(ctx, aad, aad_len))
60 if (!ctx->hw->cipherupdate(ctx, in, in_len, out))
62 ctx->taglen = GCM_TAG_MAX_SIZE;
63 if (!ctx->hw->cipherfinal(ctx, tag))