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 * RISC-V 64 ZVKSED support for SM4 GCM. 12 * This file is included by cipher_sm4_gcm_hw.c 13 */ 14 15static int rv64i_zvksed_sm4_gcm_initkey(PROV_GCM_CTX *ctx, 16 const unsigned char *key, 17 size_t keylen) 18{ 19 PROV_SM4_GCM_CTX *actx = (PROV_SM4_GCM_CTX *)ctx; 20 SM4_KEY *ks = &actx->ks.ks; 21 22 SM4_GCM_HW_SET_KEY_CTR_FN(ks, rv64i_zvksed_sm4_set_encrypt_key, 23 rv64i_zvksed_sm4_encrypt, NULL); 24 return 1; 25} 26 27static const PROV_GCM_HW rv64i_zvksed_sm4_gcm = { 28 rv64i_zvksed_sm4_gcm_initkey, 29 ossl_gcm_setiv, 30 ossl_gcm_aad_update, 31 hw_gcm_cipher_update, 32 ossl_gcm_cipher_final, 33 ossl_gcm_one_shot 34}; 35 36const PROV_GCM_HW *ossl_prov_sm4_hw_gcm(size_t keybits) 37{ 38 if (RISCV_HAS_ZVKB_AND_ZVKSED() && riscv_vlen() >= 128) 39 return &rv64i_zvksed_sm4_gcm; 40 else 41 return &sm4_gcm; 42} 43