1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (c) 2021-2024, STMicroelectronics - All Rights Reserved 4 */ 5 6 #ifndef STM32_PKA_H 7 #define STM32_PKA_H 8 9 #include <drivers/clk.h> 10 #include <drivers/rstctrl.h> 11 #include <kernel/mutex.h> 12 #include <mm/core_memprot.h> 13 #include <stdint.h> 14 15 #define PKA_MAX_ECC_LEN 640 16 #define PKA_MAX_ECC_SIZE (PKA_MAX_ECC_LEN / 8) 17 18 enum stm32_pka_curve_id { 19 PKA_NIST_P192, 20 PKA_NIST_P224, 21 PKA_NIST_P256, 22 PKA_NIST_P384, 23 PKA_NIST_P521, 24 25 PKA_LAST_CID 26 }; 27 28 /* 29 * struct stm32_pka_bn - Internal representation of binary number 30 * 31 * @val: a byte array with most significant bytes first 32 * @size: number of bytes in @val 33 */ 34 struct stm32_pka_bn { 35 uint8_t *val; 36 size_t size; 37 }; 38 39 struct stm32_pka_point { 40 struct stm32_pka_bn x; 41 struct stm32_pka_bn y; 42 }; 43 44 TEE_Result stm32_pka_get_max_size(size_t *bytes, size_t *bits, 45 const enum stm32_pka_curve_id cid); 46 TEE_Result stm32_pka_compute_montgomery(const struct stm32_pka_bn *n, 47 const size_t n_len, 48 struct stm32_pka_bn *r2modn); 49 TEE_Result stm32_pka_ecc_compute_montgomery(struct stm32_pka_bn *r2modn, 50 const enum stm32_pka_curve_id cid); 51 TEE_Result stm32_pka_is_point_on_curve(const struct stm32_pka_point *p, 52 const struct stm32_pka_bn *r2modn, 53 const enum stm32_pka_curve_id cid); 54 TEE_Result stm32_pka_ecc_scalar_mul(const struct stm32_pka_bn *k, 55 const struct stm32_pka_point *p, 56 struct stm32_pka_point *kp, 57 const enum stm32_pka_curve_id cid); 58 TEE_Result stm32_pka_edac_gen_pubkey(const struct stm32_pka_bn *k, 59 struct stm32_pka_point *pk, 60 const enum stm32_pka_curve_id cid); 61 TEE_Result stm32_pka_ecdsa_sign(const void *hash, unsigned int hash_size, 62 struct stm32_pka_bn *sig_r, 63 struct stm32_pka_bn *sig_s, 64 const struct stm32_pka_bn *d, 65 const struct stm32_pka_bn *k, 66 const enum stm32_pka_curve_id cid); 67 TEE_Result stm32_pka_ecdsa_verif(const void *hash, unsigned int hash_size, 68 const struct stm32_pka_bn *sig_r, 69 const struct stm32_pka_bn *sig_s, 70 const struct stm32_pka_point *pk, 71 const enum stm32_pka_curve_id cid); 72 #endif /* STM32_PKA_H */ 73