Fix Issue OSS-Fuzz: Branch on uninitialized memory (in ccm code).
[openssl.git] / providers / common / ciphers / cipher_aria_gcm_hw.inc
1 /*
2  * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 /*-
11  * Generic support for ARIA GCM.
12  * This file is included by cipher_gcm_hw.c
13  */
14
15 #if !defined(OPENSSL_NO_ARIA) && !defined(FIPS_MODE)
16
17 static int aria_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
18                             size_t keylen)
19 {
20     PROV_ARIA_GCM_CTX *actx = (PROV_ARIA_GCM_CTX *)ctx;
21     ARIA_KEY *ks = &actx->ks.ks;
22
23     SET_KEY_CTR_FN(ks, aria_set_encrypt_key, aria_encrypt, NULL);
24     return 1;
25 }
26
27 static int aria_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
28                               size_t len, unsigned char *out)
29 {
30     if (ctx->enc) {
31         if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
32             return 0;
33     } else {
34         if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
35             return 0;
36     }
37     return 1;
38 }
39
40 static const PROV_GCM_HW aria_gcm = {
41     aria_gcm_initkey,
42     gcm_setiv,
43     gcm_aad_update,
44     aria_cipher_update,
45     gcm_cipher_final,
46     gcm_one_shot
47 };
48 const PROV_GCM_HW *PROV_ARIA_HW_gcm(size_t keybits)
49 {
50     return &aria_gcm;
51 }
52
53 #endif /* !defined(OPENSSL_NO_ARIA) && !defined(FIPS_MODE) */