TrustCore SDK Crypto Interface API reference  version 2.0
crypto_interface_ecc.h
Go to the documentation of this file.
1 /*
2  * crypto_interface_ecc.h
3  *
4  * Cryptographic Interface header file for declaring ECC functions
5  * for the Crypto Interface.
6  *
7  * Copyright 2019-2024 DigiCert, Inc. All Rights Reserved.
8  * Proprietary and Confidential Material.
9  *
10  */
11 
19 #ifndef __CRYPTO_INTERFACE_ECC_HEADER__
20 #define __CRYPTO_INTERFACE_ECC_HEADER__
21 
22 #include "../cap/capasym.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
43 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_newKeyEx (
44  ubyte4 curveId,
45  ECCKey** ppNewKey,
46  ubyte4 keyType,
47  void *pKeyAttributes
48  );
49 
59 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_isKeyPrivate (
60  ECCKey *pKey,
61  intBoolean *pResult
62  );
63 
88  MOC_ECC(hwAccelDescr hwAccelCtx)
89  ubyte4 curveId,
90  void **ppNewKey,
91  RNGFun rngFun,
92  void* rngArg,
93  ubyte4 keyType,
94  void *pKeyAttributes
95  );
96 
109 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_newKeyAux (
110  ubyte4 curveId,
111  ECCKey** ppNewKey
112  );
113 
122 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_deleteKeyAux (
123  ECCKey **ppKey
124  );
125 
136 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_cloneKeyAux (
137  MOC_ECC(hwAccelDescr hwAccelCtx)
138  ECCKey **ppNewKey,
139  ECCKey *pSrc
140  );
141 
154 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_equalKeyAux (
155  MOC_ECC(hwAccelDescr hwAccelCtx)
156  ECCKey *pKey1,
157  ECCKey *pKey2,
158  byteBoolean *pRes
159  );
160 
178 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_verifyKeyPairAux (
179  MOC_ECC(hwAccelDescr hwAccelCtx)
180  ECCKey *pPrivateKey,
181  ECCKey *pPublicKey,
182  byteBoolean *pVfy
183  );
184 
198 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_verifyPublicKeyAux (
199  MOC_ECC(hwAccelDescr hwAccelCtx)
200  ECCKey *pKey,
201  byteBoolean *pIsValid
202  );
203 
216  ECCKey *pKey,
217  ubyte4 *pLen
218  );
219 
231 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getCurveIdFromKeyAux (
232  ECCKey *pKey,
233  ubyte4 *pCurveId
234  );
235 
248  ubyte4 curveId,
249  ubyte4 *pLen
250  );
251 
265  ECCKey *pKey,
266  ubyte4 *pLen
267  );
268 
294  MOC_ECC(hwAccelDescr hwAccelCtx)
295  ECCKey *pKey,
296  MEccKeyTemplate *pTemplate,
297  ubyte reqType
298  );
299 
310 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_freeKeyTemplateAux (
311  ECCKey *pKey,
312  MEccKeyTemplate *pTemplate
313  );
314 
338 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_setKeyParametersAux (
339  MOC_ECC(hwAccelDescr hwAccelCtx)
340  ECCKey *pKey,
341  ubyte *pPoint,
342  ubyte4 pointLen,
343  ubyte *pScalar,
344  ubyte4 scalarLen
345  );
346 
362 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_setPrivateKey(
363  MOC_ECC(hwAccelDescr hwAccelCtx)
364  ECCKey *pKey,
365  ubyte *pScalar,
366  ubyte4 scalarLen
367  );
368 
393  MOC_ECC(hwAccelDescr hwAccelCtx)
394  ECCKey *pKey,
395  ubyte *pBuffer,
396  ubyte4 bufferSize
397  );
398 
419  MOC_ECC(hwAccelDescr hwAccelCtx)
420  ECCKey *pKey,
421  ubyte **ppBuffer,
422  ubyte4 *pBufferSize
423  );
424 
447  MOC_ECC(hwAccelDescr hwAccelCtx)
448  ubyte4 curveId,
449  ECCKey **ppNewKey,
450  ubyte *pByteString,
451  ubyte4 byteStringLen
452  );
453 
471 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_generateKeyPairAux (
472  MOC_ECC(hwAccelDescr hwAccelCtx)
473  ECCKey *pKey,
474  RNGFun rngFun,
475  void *pRngFunArg
476  );
477 
498  MOC_ECC(hwAccelDescr hwAccelCtx)
499  ubyte4 curveId,
500  ECCKey **ppKey,
501  RNGFun rngFun,
502  void *pRngFunArg
503  );
504 
537 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_signDigestAux (
538  MOC_ECC(hwAccelDescr hwAccelCtx)
539  ECCKey *pKey,
540  RNGFun rngFun,
541  void *rngArg,
542  ubyte *pHash,
543  ubyte4 hashLen,
544  ubyte *pSignature,
545  ubyte4 bufferSize,
546  ubyte4 *pSignatureLen
547  );
548 
579  MOC_ECC(hwAccelDescr hwAccelCtx)
580  ECCKey *pPublicKey,
581  ubyte *pHash,
582  ubyte4 hashLen,
583  ubyte *pR,
584  ubyte4 rLen,
585  ubyte *pS,
586  ubyte4 sLen,
587  ubyte4 *pVerifyFailures
588  );
589 
617  MOC_ECC(hwAccelDescr hwAccelCtx)
618  ECCKey *pPrivateKey,
619  ECCKey *pPublicKey,
620  ubyte **ppSharedSecret,
621  ubyte4 *pSharedSecretLen,
622  sbyte4 flag,
623  void *pKdfInfo
624  );
625 
656  MOC_ECC(hwAccelDescr hwAccelCtx)
657  ECCKey *pPrivateKey,
658  ubyte *pPublicPointByteString,
659  ubyte4 pointByteStringLen,
660  ubyte **ppSharedSecret,
661  ubyte4 *pSharedSecretLen,
662  sbyte4 flag,
663  void *pKdfInfo
664  );
665 
699  MOC_ECC(hwAccelDescr hwAccelCtx)
700  ubyte4 mode,
701  ECCKey *pStatic,
702  ECCKey *pEphemeral,
703  ubyte *pOtherPartysStatic,
704  ubyte4 otherStaticLen,
705  ubyte *pOtherPartysEphemeral,
706  ubyte4 otherEphemeralLen,
707  ubyte **ppSharedSecret,
708  ubyte4 *pSharedSecretLen);
709 
740 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_signMessageExt (
741  MOC_ECC(hwAccelDescr hwAccelCtx)
742  ECCKey *pPrivateKey,
743  RNGFun rngFUN,
744  void *pRngArg,
745  ubyte hashAlgo,
746  ubyte *pMessage,
747  ubyte4 messageLen,
748  ubyte *pSignature,
749  ubyte4 bufferSize,
750  ubyte4 *pSignatureLen,
751  void *pExtCtx
752  );
753 
775 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_verifyMessageExt (
776  MOC_ECC(hwAccelDescr hwAccelCtx)
777  ECCKey *pPublicKey,
778  ubyte hashAlgo,
779  ubyte *pMessage,
780  ubyte4 messageLen,
781  ubyte *pSignature,
782  ubyte4 signatureLen,
783  ubyte4 *pVerifyFailures,
784  void *pExtCtx
785  );
786 
804 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_initVerifyExt (
805  MOC_ECC(hwAccelDescr hwAccelCtx)
806  ECDSA_CTX *pCtx,
807  ECCKey *pPublicKey,
808  ubyte hashAlgo,
809  ubyte *pSignature,
810  ubyte4 signatureLen,
811  void *pExtCtx
812  );
813 
827 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_updateVerifyExt (
828  MOC_ECC(hwAccelDescr hwAccelCtx)
829  ECDSA_CTX *pCtx,
830  ubyte *pMessage,
831  ubyte4 messageLen,
832  void *pExtCtx
833  );
834 
848 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_finalVerifyExt (
849  MOC_ECC(hwAccelDescr hwAccelCtx)
850  ECDSA_CTX *pCtx,
851  ubyte4 *pVerifyFailures,
852  void *pExtCtx
853  );
854 
879 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EdDSA_signInput (
880  MOC_ECC(hwAccelDescr hwAccelCtx)
881  ECCKey *pKey,
882  ubyte *pInput,
883  ubyte4 inputLen,
884  byteBoolean isPreHash,
885  ubyte *pCtx,
886  ubyte4 ctxLen,
887  ubyte *pSignature,
888  ubyte4 bufferSize,
889  ubyte4 *pSignatureLen,
890  void *pExtCtx
891  );
892 
914 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EdDSA_verifyInput (
915  MOC_ECC(hwAccelDescr hwAccelCtx)
916  ECCKey *pKey,
917  ubyte *pInput,
918  ubyte4 inputLen,
919  byteBoolean isPreHash,
920  ubyte *pCtx,
921  ubyte4 ctxLen,
922  ubyte *pSignature,
923  ubyte4 signatureLen,
924  ubyte4 *pVerifyFailures,
925  void *pExtCtx
926  );
927 
936 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_createCombMutexes(void);
937 
938 
946 MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_deleteAllCombsAndMutexes(void);
947 
948 #ifdef __cplusplus
949 }
950 #endif
951 
952 #endif /* __CRYPTO_INTERFACE_ECC_HEADER__ */
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_signDigestAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, RNGFun rngFun, void *rngArg, ubyte *pHash, ubyte4 hashLen, ubyte *pSignature, ubyte4 bufferSize, ubyte4 *pSignatureLen)
Perform an ECDSA signing operation on the provided digest, producing the raw signature value...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_freeKeyTemplateAux(ECCKey *pKey, MEccKeyTemplate *pTemplate)
Frees the key data stored within the provided template structure.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EdDSA_verifyInput(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte *pInput, ubyte4 inputLen, byteBoolean isPreHash, ubyte *pCtx, ubyte4 ctxLen, ubyte *pSignature, ubyte4 signatureLen, ubyte4 *pVerifyFailures, void *pExtCtx)
Performs an EdDSA verify operation on the input provided.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getElementByteStringLenAux(ECCKey *pKey, ubyte4 *pLen)
Get the length of an individual prime field element when represented as a bytestring.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_verifyMessageExt(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPublicKey, ubyte hashAlgo, ubyte *pMessage, ubyte4 messageLen, ubyte *pSignature, ubyte4 signatureLen, ubyte4 *pVerifyFailures, void *pExtCtx)
Performs an ECDSA verify operation on the message provided.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_newKeyAux(ubyte4 curveId, ECCKey **ppNewKey)
Create a new key from a curve identifier.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_generateKeyPairAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, RNGFun rngFun, void *pRngFunArg)
Generate a key pair previously allocated with CRYPTO_INTERFACE_EC_newKeyAux.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_updateVerifyExt(MOC_ECC(hwAccelDescr hwAccelCtx) ECDSA_CTX *pCtx, ubyte *pMessage, ubyte4 messageLen, void *pExtCtx)
Updates a context for an ECDSA verify operation.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_verifyKeyPairAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPrivateKey, ECCKey *pPublicKey, byteBoolean *pVfy)
Validate that a given public and private key are consistent.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_initVerifyExt(MOC_ECC(hwAccelDescr hwAccelCtx) ECDSA_CTX *pCtx, ECCKey *pPublicKey, ubyte hashAlgo, ubyte *pSignature, ubyte4 signatureLen, void *pExtCtx)
Initializes a context for an ECDSA verify operation.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getCurveIdFromKeyAux(ECCKey *pKey, ubyte4 *pCurveId)
Retrieve the curve identifier from a key previously created with CRYPTO_INTERFACE_EC_newKeyAux or gen...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_deleteAllCombsAndMutexes(void)
Delete's all created global combs for ecc and the associated mutex's.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_generateKeyPairAlloc(MOC_ECC(hwAccelDescr hwAccelCtx) ubyte4 curveId, void **ppNewKey, RNGFun rngFun, void *rngArg, ubyte4 keyType, void *pKeyAttributes)
Generate a key pair on the curve specified from the curve id.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDH_generateSharedSecretFromKeysAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPrivateKey, ECCKey *pPublicKey, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen, sbyte4 flag, void *pKdfInfo)
Generate an ECDH shared secret from a public and private key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_deleteKeyAux(ECCKey **ppKey)
Free an ECC Key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getPointByteStringLenAux(ECCKey *pKey, ubyte4 *pLen)
Get the length of the bytestring representation of the public key, typically used to determine the bu...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_newKeyEx(ubyte4 curveId, ECCKey **ppNewKey, ubyte4 keyType, void *pKeyAttributes)
Create a new key from a curve identifier.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDH_generateSharedSecretFromPublicByteStringAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPrivateKey, ubyte *pPublicPointByteString, ubyte4 pointByteStringLen, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen, sbyte4 flag, void *pKdfInfo)
Generate an ECDH shared secret from private key and bytestring representation of the public point...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_newPublicKeyFromByteStringAux(MOC_ECC(hwAccelDescr hwAccelCtx) ubyte4 curveId, ECCKey **ppNewKey, ubyte *pByteString, ubyte4 byteStringLen)
Create a new ECC public key from the bytestring representation of public point.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_createCombMutexes(void)
Creates mutex's for ecc combs so that only a single thread can create and persist a globally used com...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_verifyPublicKeyAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, byteBoolean *pIsValid)
Check that the public key is valid, which ensures the public point is valid and lies on the curve...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_equalKeyAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey1, ECCKey *pKey2, byteBoolean *pRes)
Tests if the public key portion of two ECCKeys are equal.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_finalVerifyExt(MOC_ECC(hwAccelDescr hwAccelCtx) ECDSA_CTX *pCtx, ubyte4 *pVerifyFailures, void *pExtCtx)
Finalizes a context for an ECDSA verify operation and computes whether the signature is valid...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getPointByteStringLenByCurveId(ubyte4 curveId, ubyte4 *pLen)
Get the length of the public value based on the curve ID.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_writePublicKeyToBufferAllocAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte **ppBuffer, ubyte4 *pBufferSize)
Allocate a new buffer and writes the public point to it.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_isKeyPrivate(ECCKey *pKey, intBoolean *pResult)
Determines if a key is a private key or a public key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_writePublicKeyToBufferAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte *pBuffer, ubyte4 bufferSize)
Write the public point to a buffer.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_verifySignatureDigestAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPublicKey, ubyte *pHash, ubyte4 hashLen, ubyte *pR, ubyte4 rLen, ubyte *pS, ubyte4 sLen, ubyte4 *pVerifyFailures)
Verify individual signature values with the provided public key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_generateKeyPairAllocAux(MOC_ECC(hwAccelDescr hwAccelCtx) ubyte4 curveId, ECCKey **ppKey, RNGFun rngFun, void *pRngFunArg)
Generate a key pair on the curve specified from the curve id.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EdDSA_signInput(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte *pInput, ubyte4 inputLen, byteBoolean isPreHash, ubyte *pCtx, ubyte4 ctxLen, ubyte *pSignature, ubyte4 bufferSize, ubyte4 *pSignatureLen, void *pExtCtx)
Perform an EdDSA signing operation on the provided input.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_getKeyParametersAllocAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, MEccKeyTemplate *pTemplate, ubyte reqType)
Allocates and sets the appropriate keys parameters of pTemplate with that from the passed in pKey...
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDH_keyAgreementScheme(MOC_ECC(hwAccelDescr hwAccelCtx) ubyte4 mode, ECCKey *pStatic, ECCKey *pEphemeral, ubyte *pOtherPartysStatic, ubyte4 otherStaticLen, ubyte *pOtherPartysEphemeral, ubyte4 otherEphemeralLen, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen)
Generates a Diffie-Hellman shared secret via one of the major modes.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ECDSA_signMessageExt(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pPrivateKey, RNGFun rngFUN, void *pRngArg, ubyte hashAlgo, ubyte *pMessage, ubyte4 messageLen, ubyte *pSignature, ubyte4 bufferSize, ubyte4 *pSignatureLen, void *pExtCtx)
Performs an ECDSA sign operation on the message provided.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_cloneKeyAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey **ppNewKey, ECCKey *pSrc)
Allocates and clones an existing key.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_setPrivateKey(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte *pScalar, ubyte4 scalarLen)
Sets the private key parameter of an ECCKey.
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_EC_setKeyParametersAux(MOC_ECC(hwAccelDescr hwAccelCtx) ECCKey *pKey, ubyte *pPoint, ubyte4 pointLen, ubyte *pScalar, ubyte4 scalarLen)
Sets the public key portion of an ECCKey and optionally the private key portion.