1/* 2 * Copyright 2022-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 * RISC-V 32 ZKND ZKNE support for AES CCM. 12 * This file is included by cipher_aes_ccm_hw.c 13 */ 14 15static int ccm_rv32i_zknd_zkne_initkey(PROV_CCM_CTX *ctx, const unsigned char *key, 16 size_t keylen) 17{ 18 PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx; 19 20 AES_HW_CCM_SET_KEY_FN(rv32i_zkne_set_encrypt_key, rv32i_zkne_encrypt, 21 NULL, NULL); 22 return 1; 23} 24 25static int ccm_rv32i_zbkb_zknd_zkne_initkey(PROV_CCM_CTX *ctx, const unsigned char *key, 26 size_t keylen) 27{ 28 PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx; 29 30 AES_HW_CCM_SET_KEY_FN(rv32i_zbkb_zkne_set_encrypt_key, rv32i_zkne_encrypt, 31 NULL, NULL); 32 return 1; 33} 34 35static const PROV_CCM_HW rv32i_zknd_zkne_ccm = { 36 ccm_rv32i_zknd_zkne_initkey, 37 ossl_ccm_generic_setiv, 38 ossl_ccm_generic_setaad, 39 ossl_ccm_generic_auth_encrypt, 40 ossl_ccm_generic_auth_decrypt, 41 ossl_ccm_generic_gettag 42}; 43 44static const PROV_CCM_HW rv32i_zbkb_zknd_zkne_ccm = { 45 ccm_rv32i_zbkb_zknd_zkne_initkey, 46 ossl_ccm_generic_setiv, 47 ossl_ccm_generic_setaad, 48 ossl_ccm_generic_auth_encrypt, 49 ossl_ccm_generic_auth_decrypt, 50 ossl_ccm_generic_gettag 51}; 52 53const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits) 54{ 55 if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) 56 return &rv32i_zbkb_zknd_zkne_ccm; 57 if (RISCV_HAS_ZKND_AND_ZKNE()) 58 return &rv32i_zknd_zkne_ccm; 59 return &aes_ccm; 60} 61