1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /*! 8 @addtogroup cc_pka_defs_hw 9 @{ 10 */ 11 12 /*! 13 @file 14 @brief This file contains all of the enums and definitions that are used in 15 PKA APIs. 16 */ 17 18 #ifndef _CC_PKA_DEFS_HW_H_ 19 #define _CC_PKA_DEFS_HW_H_ 20 21 #include "cc_pal_types.h" 22 #include "cc_pka_hw_plat_defs.h" 23 24 /* The valid key sizes in bits for RSA primitives (exponentiation) */ 25 /*! The maximal RSA modulus size. */ 26 #define CC_RSA_MAXIMUM_MOD_BUFFER_SIZE_IN_WORDS ((CC_RSA_MAX_VALID_KEY_SIZE_VALUE_IN_BITS + CC_PKA_WORD_SIZE_IN_BITS) / CC_BITS_IN_32BIT_WORD ) 27 /*! The maximal EC modulus size. */ 28 #define CC_ECPKI_MODUL_MAX_LENGTH_IN_BITS 521 29 30 /*! The size of the buffers for Barrett modulus tag NP, used in PKI 31 algorithms. */ 32 #define CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS 5 33 /*! The size of the buffers for Barrett modulus tag NP, used in ECC. */ 34 #define CC_PKA_ECPKI_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS 35 /*! The actual size of Barrett modulus tag NP in words for current 36 HW platform. */ 37 #define CC_PKA_BARRETT_MOD_TAG_SIZE_IN_WORDS \ 38 (((CC_PKA_WORD_SIZE_IN_BITS + PKA_EXTRA_BITS - 1) + (CC_BITS_IN_32BIT_WORD - 1)) / CC_BITS_IN_32BIT_WORD ) 39 /*! The maximal size of the PKA modulus. */ 40 #define CC_PKA_MAXIMUM_MOD_BUFFER_SIZE_IN_WORDS CC_RSA_MAXIMUM_MOD_BUFFER_SIZE_IN_WORDS 41 /*! The maximal size of the PKA public-key in words. */ 42 #define CC_PKA_PUB_KEY_BUFF_SIZE_IN_WORDS (2*CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS) 43 /*! The maximal size of the PKA private-key in words. */ 44 #define CC_PKA_PRIV_KEY_BUFF_SIZE_IN_WORDS (2*CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS) 45 /*! The maximal size of the PKA KG buffer in words */ 46 #define CC_PKA_KGDATA_BUFF_SIZE_IN_WORDS (3*CC_PKA_MAXIMUM_MOD_BUFFER_SIZE_IN_WORDS + 3*CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS) 47 48 /*! The maximal size of the EC modulus in words. */ 49 #define CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS 18 /*!< \internal [(CC_ECPKI_MODUL_MAX_LENGTH_IN_BITS + 31)/(sizeof(uint32_t)) + 1] */ 50 /*! The maximal size of the EC order in words. */ 51 #define CC_ECPKI_ORDER_MAX_LENGTH_IN_WORDS (CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS + 1) 52 /*! The maximal size of the EC domain in words. */ 53 #define CC_PKA_DOMAIN_BUFF_SIZE_IN_WORDS (2*CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS) 54 55 /*! The ECC NAF buffer definitions. */ 56 #define COUNT_NAF_WORDS_PER_KEY_WORD 8 /*!< \internal Change according to NAF representation (? 2)*/ 57 /*! The maximal length of the ECC NAF buffer. */ 58 #define CC_PKA_ECDSA_NAF_BUFF_MAX_LENGTH_IN_WORDS (COUNT_NAF_WORDS_PER_KEY_WORD*CC_ECPKI_ORDER_MAX_LENGTH_IN_WORDS + 1) 59 60 #ifndef CC_SUPPORT_ECC_SCA_SW_PROTECT 61 /* on fast SCA non protected mode required additional buffers for NAF key */ 62 /*! The size of the Scalar buffer in words. */ 63 #define CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS (CC_PKA_ECDSA_NAF_BUFF_MAX_LENGTH_IN_WORDS+CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS+2) 64 #else 65 /*! The size of the Scalar buffer in words. */ 66 #define CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS 1 /*(4*CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS)*/ 67 #endif 68 /*! The size of the ECC temporary buffer in words. */ 69 #define CC_PKA_ECPKI_BUILD_TMP_BUFF_MAX_LENGTH_IN_WORDS (3*CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS+CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS) 70 /*! The size of the ECC sign temporary buffer in words. */ 71 #define CC_PKA_ECDSA_SIGN_BUFF_MAX_LENGTH_IN_WORDS (6*CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS+CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS) 72 /*! The size of the ECC ECDH temporary-buffer in words. */ 73 #define CC_PKA_ECDH_BUFF_MAX_LENGTH_IN_WORDS (2*CC_ECPKI_ORDER_MAX_LENGTH_IN_WORDS + CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS) 74 /*! The size of the PKA KG temporary-buffer in words. */ 75 #define CC_PKA_KG_BUFF_MAX_LENGTH_IN_WORDS (2*CC_ECPKI_ORDER_MAX_LENGTH_IN_WORDS + CC_PKA_ECPKI_SCALAR_MUL_BUFF_MAX_LENGTH_IN_WORDS) 76 /*! The size of the ECC verify temporary-buffer in words. */ 77 #define CC_PKA_ECDSA_VERIFY_BUFF_MAX_LENGTH_IN_WORDS (3*CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS) 78 79 /* *************************************************************************** */ 80 /*! The maximal size of the modulus buffers for CC_EC_MONT and EC_EDW in 81 bytes.*/ 82 #define CC_EC_MONT_EDW_MODULUS_MAX_SIZE_IN_BYTES 32U /*!< \internal for Curve25519 */ 83 /*! The maximal size of the modulus buffers for CC_EC_MONT and EC_EDW in 84 words. */ 85 #define CC_EC_MONT_EDW_MODULUS_MAX_SIZE_IN_WORDS 8U /*!< \internal for Curve25519 */ 86 /*! The size of the ECC Montgomery temporary buffer in words. */ 87 #define CC_EC_MONT_TEMP_BUFF_SIZE_IN_32BIT_WORDS (8 * CC_EC_MONT_EDW_MODULUS_MAX_SIZE_IN_WORDS) /*!< \internal Change according to actual requirements */ 88 /*! The size of the ECC Edwards temporary buffer in words. */ 89 #define CC_EC_EDW_TEMP_BUFF_SIZE_IN_32BIT_WORDS (8*CC_EC_MONT_EDW_MODULUS_MAX_SIZE_IN_WORDS + (sizeof(CCHashUserContext_t)+CC_32BIT_WORD_SIZE-1)/CC_32BIT_WORD_SIZE) 90 91 /*! 92 @} 93 */ 94 #endif /*_CC_PKA_DEFS_HW_H_*/ 95