1/*
2 * Copyright 2023 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 * RV64I ZVKSED support for SM4 CCM.
12 * This file is included by cipher_sm4_ccm_hw.c
13 */
14
15static int rv64i_zvksed_sm4_ccm_initkey(PROV_CCM_CTX *ctx,
16                                        const unsigned char *key,
17                                        size_t keylen)
18{
19    PROV_SM4_CCM_CTX *actx = (PROV_SM4_CCM_CTX *)ctx;
20
21    SM4_HW_CCM_SET_KEY_FN(rv64i_zvksed_sm4_set_encrypt_key,
22                          rv64i_zvksed_sm4_encrypt, NULL, NULL);
23    return 1;
24}
25
26static const PROV_CCM_HW rv64i_zvksed_sm4_ccm = {
27    rv64i_zvksed_sm4_ccm_initkey,
28    ossl_ccm_generic_setiv,
29    ossl_ccm_generic_setaad,
30    ossl_ccm_generic_auth_encrypt,
31    ossl_ccm_generic_auth_decrypt,
32    ossl_ccm_generic_gettag
33};
34
35const PROV_CCM_HW *ossl_prov_sm4_hw_ccm(size_t keybits)
36{
37    if (RISCV_HAS_ZVKB_AND_ZVKSED() && riscv_vlen() >= 128)
38        return &rv64i_zvksed_sm4_ccm;
39    else
40        return &ccm_sm4;
41}
42