1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef PKA_ECC_EXPORT_H 8 #define PKA_ECC_EXPORT_H 9 10 11 #ifdef __cplusplus 12 extern "C" 13 { 14 #endif 15 16 /* 17 * All the includes that are needed for code using this module to 18 * compile correctly should be #included here. 19 */ 20 #include "cc_pal_types.h" 21 #include "cc_rnd_common.h" 22 #include "cc_ecpki_types.h" 23 24 25 /* Temporary buffers used for the functions called from ECDSA */ 26 typedef struct{ 27 //! Debug : set to 10, may be less? 28 CCEcdsaSignIntBuff_t tempBuff; 29 }EcWrstDsaSignDb_t; 30 31 /* Temporary buffers used for the functions called from ECDSA */ 32 typedef struct{ 33 CCEcdsaVerifyIntBuff_t tempBuff; 34 }EcWrstDsaVerifyDb_t; 35 36 37 /* internal ECPKI buffer structure used on LLF and containing Barrett tags for* 38 * modulus and gen.order */ 39 typedef struct { 40 uint32_t modTag[CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS]; 41 uint32_t ordTag[CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS]; 42 }EcWrstDomain_t; 43 44 /* affine ec-point in uint32 arrays format) */ 45 typedef struct{ 46 uint32_t x[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 47 uint32_t y[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 48 } EcWrstAffPoint_t; 49 50 /* modified jacobian ec-point: X:x/z^2, Y:y/z^3, t:a*z^4 (uint32 arrays) */ 51 typedef struct{ 52 uint32_t x[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 53 uint32_t y[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 54 uint32_t z[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 55 uint32_t t[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 56 } EcwrstMdfPoint_t; 57 58 /* EC curve (domain) structure as uint32 array */ 59 typedef struct{ 60 uint32_t p[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; // modulo 61 uint32_t a[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 62 uint32_t b[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; // y^2 = x^3 + a.x + b (mod p) 63 uint32_t Gx[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; 64 uint32_t Gy[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; // generator 65 uint32_t n[CC_ECPKI_ORDER_MAX_LENGTH_IN_WORDS]; // ord(G) = n 66 uint32_t h[CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS]; // cofactor: #E = n.h 67 uint32_t np[CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS]; // Barrett tag for modulus 68 uint32_t nn[CC_PKA_BARRETT_MOD_TAG_BUFF_SIZE_IN_WORDS]; // Barrett tag for order 69 } EcwrstCurve_t; 70 71 void EcWrstDsaTruncateMsg(uint32_t *pMsgOut, 72 uint8_t *pMsgIn, 73 uint32_t outSizeBits); 74 75 76 77 CCError_t EcWrstInitPubKey(CCEcpkiPublKey_t *pPublKey, 78 uint8_t pointCtl); 79 80 81 CCError_t EcWrstFullCheckPublKey(CCEcpkiPublKey_t *pPublKey, 82 uint32_t *pTempBuff); 83 84 /* EC WRST DSA */ 85 CCError_t EcWrstDsaSign(CCRndContext_t *pRndContext, 86 CCEcpkiPrivKey_t *pSignPrivKey, 87 uint32_t *pMsgRepres, 88 uint32_t isEphemerKeyInternal, 89 uint32_t *pEphemKey, 90 uint32_t *pSignC, 91 uint32_t *pSignD, 92 uint32_t *pTempBuff); 93 94 CCError_t EcWrstDsaVerify(CCEcpkiPublKey_t *signPublKey, 95 uint32_t *messageRepresent, 96 uint32_t messRepresSizeWords, 97 uint32_t *signC, 98 uint32_t *signD); 99 100 101 102 /* EC WRST DH */ 103 CCError_t EcWrstDhDeriveSharedSecret(CCEcpkiPublKey_t *pPublKey, 104 CCEcpkiPrivKey_t *pPrivKey, 105 uint8_t *pSharedSecretValue, 106 CCEcdhTempData_t *pTempBuff); 107 108 109 110 111 /* EC WRST Key Generate */ 112 CEXPORT_C CCError_t EcWrstGenKeyPair(const CCEcpkiDomain_t *pDomain, 113 CCEcpkiUserPrivKey_t *pUserPrivKey, 114 CCEcpkiUserPublKey_t *pUserPublKey, 115 CCEcpkiKgTempData_t *pTempBuff); 116 117 /* EC WRST Key Generate with configurable base point */ 118 CEXPORT_C CCError_t EcWrstGenKeyPairBase(const CCEcpkiDomain_t *pDomain, 119 const uint32_t ecX [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS], 120 const uint32_t ecY [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS], 121 CCEcpkiUserPrivKey_t *pUserPrivKey, 122 CCEcpkiUserPublKey_t *pUserPublKey, 123 CCEcpkiKgTempData_t *pTempBuff); 124 125 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif 132 133 134