1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci/*-
11e1051a39Sopenharmony_ci * Generic support for ARIA CCM.
12e1051a39Sopenharmony_ci */
13e1051a39Sopenharmony_ci
14e1051a39Sopenharmony_ci#include "cipher_aria_ccm.h"
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_cistatic int ccm_aria_initkey(PROV_CCM_CTX *ctx,
17e1051a39Sopenharmony_ci                            const unsigned char *key, size_t keylen)
18e1051a39Sopenharmony_ci{
19e1051a39Sopenharmony_ci    PROV_ARIA_CCM_CTX *actx = (PROV_ARIA_CCM_CTX *)ctx;
20e1051a39Sopenharmony_ci
21e1051a39Sopenharmony_ci    ossl_aria_set_encrypt_key(key, keylen * 8, &actx->ks.ks);
22e1051a39Sopenharmony_ci    CRYPTO_ccm128_init(&ctx->ccm_ctx, ctx->m, ctx->l, &actx->ks.ks,
23e1051a39Sopenharmony_ci                       (block128_f)ossl_aria_encrypt);
24e1051a39Sopenharmony_ci    ctx->str = NULL;
25e1051a39Sopenharmony_ci    ctx->key_set = 1;
26e1051a39Sopenharmony_ci    return 1;
27e1051a39Sopenharmony_ci}
28e1051a39Sopenharmony_ci
29e1051a39Sopenharmony_cistatic const PROV_CCM_HW ccm_aria = {
30e1051a39Sopenharmony_ci    ccm_aria_initkey,
31e1051a39Sopenharmony_ci    ossl_ccm_generic_setiv,
32e1051a39Sopenharmony_ci    ossl_ccm_generic_setaad,
33e1051a39Sopenharmony_ci    ossl_ccm_generic_auth_encrypt,
34e1051a39Sopenharmony_ci    ossl_ccm_generic_auth_decrypt,
35e1051a39Sopenharmony_ci    ossl_ccm_generic_gettag
36e1051a39Sopenharmony_ci};
37e1051a39Sopenharmony_ciconst PROV_CCM_HW *ossl_prov_aria_hw_ccm(size_t keybits)
38e1051a39Sopenharmony_ci{
39e1051a39Sopenharmony_ci    return &ccm_aria;
40e1051a39Sopenharmony_ci}
41