TrustCore SDK NanoCrypto API reference  version 7.0
ecc_edwards_keys.h File Reference

Header for curve25519 and curve448 key related methods. More...

Go to the source code of this file.

Enumerations

enum  edECCCurve { curveX25519 = 0, curveX448 = 1, curveEd25519 = 2, curveEd448 = 3 }
 Identifiers for the Edward's form curves and algorithms. More...
 

Functions

MOC_EXTERN MSTATUS edECC_calculatePubFromPriv (MOC_ECC(hwAccelDescr hwAccelCtx) ubyte *pPub, ubyte *pPriv, edECCCurve curve, BulkHashAlgo *pShaSuite, byteBoolean isShaEvp)
 Gets the raw public key from a raw private key. More...
 
MOC_EXTERN MSTATUS edECC_cloneKey (edECCKey **ppNew, edECCKey *pSrc, void *pExtCtx)
 Allocates and clones an Edward's form key. More...
 
MOC_EXTERN MSTATUS edECC_deleteKey (edECCKey **ppKey, void *pExtCtx)
 Deletes an Edward's form key. More...
 
MOC_EXTERN MSTATUS edECC_equalKey (edECCKey *pKey1, edECCKey *pKey2, byteBoolean *pMatch, void *pExtCtx)
 Tests if two Edward's form keys have identical public keys. More...
 
MOC_EXTERN MSTATUS edECC_generateKeyPair (MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *pKey, RNGFun rngFun, void *pRngArg, BulkHashAlgo *pShaSuite, void *pExtCtx)
 Generates a new Edward's form private key pair. More...
 
MOC_EXTERN MSTATUS edECC_getKeyLen (edECCKey *pKey, ubyte4 *pKeyLen, void *pExtCtx)
 Gets the key length associated with the given key. More...
 
MOC_EXTERN MSTATUS edECC_getKeyParametersAlloc (MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *pKey, ubyte **ppPubKey, ubyte4 *pPubLen, ubyte **ppPrivKey, ubyte4 *pPrivLen, void *pExtCtx)
 Gets the key parameters in an Edward's form key. More...
 
MOC_EXTERN MSTATUS edECC_getPublicKey (MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *pKey, ubyte *pOutBuffer, ubyte4 bufferLen, void *pExtCtx)
 Gets the public key from an Edward's form key. More...
 
MOC_EXTERN MSTATUS edECC_newKey (edECCKey **ppKey, edECCCurve curve, void *pExtCtx)
 Creates a new Edward's curve form key. More...
 
MOC_EXTERN MSTATUS edECC_setKeyParameters (MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *pKey, ubyte *pPubKey, ubyte4 pubKeyLen, ubyte *pPrivKey, ubyte4 privKeyLen, BulkHashAlgo *pShaSuite, void *pExtCtx)
 Sets the key parameters in an Edward's form key. More...
 
MOC_EXTERN MSTATUS edECC_validateKey (MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *pKey, BulkHashAlgo *pShaSuite, void *pExtCtx)
 Validates an Edward's form key. More...
 

Detailed Description

Documentation file for curve25519 and curve448 key related methods.

To enable the methods in this file one must define

  • __ENABLE_MOCANA_ECC__ and at least one or more of the following flags
  • __ENABLE_MOCANA_ECC_EDDH_25519__
  • __ENABLE_MOCANA_ECC_EDDSA_25519__
  • __ENABLE_MOCANA_ECC_EDDH_448__
  • __ENABLE_MOCANA_ECC_EDDSA_448__

ecc_edwards_keys.h

Enumeration Type Documentation

◆ edECCCurve

enum edECCCurve

Identifiers for the Edward's form curves and algorithms. Note we need an algorithm specifier too because the key form and even curve form is actually different for EdDH vs that of EdDSA.

Function Documentation

◆ edECC_calculatePubFromPriv()

MOC_EXTERN MSTATUS edECC_calculatePubFromPriv ( MOC_ECC(hwAccelDescr hwAccelCtx) ubyte *  pPub,
ubyte *  pPriv,
edECCCurve  curve,
BulkHashAlgo pShaSuite,
byteBoolean  isShaEvp 
)

Gets the raw public key from a raw private key.

Parameters
pPubBuffer to hold the resulting public key.
pPrivBuffer holding the input private key.
curveThe curve/alg in use.
pShaSuiteFor EdDSA private keys, the SHA suite used by the EdDSA algorithm. This must be SHA2-512 for curve25519 and SHA3-SHAKE256 for curve448. This param should be NULL for EdDH keys or public keys
isShaEvpTRUE if the pShaSuite contains init/update/final EVP style methods.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_cloneKey()

MOC_EXTERN MSTATUS edECC_cloneKey ( edECCKey **  ppNew,
edECCKey *  pSrc,
void *  pExtCtx 
)

Allocates and clones an Edward's form key. Be sure to call edECC_deleteKey to free the newly allocated key when done with it.

Parameters
ppNewPointer that will receive the location of the newly allocated key.
pSrcPointer to the existing key to be cloned.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_deleteKey()

MOC_EXTERN MSTATUS edECC_deleteKey ( edECCKey **  ppKey,
void *  pExtCtx 
)

Deletes an Edward's form key. This consists of zeroing sensative data and freeing allocated memory.

Parameters
ppKeyPointer that holds the location of the key to be deleted.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_equalKey()

MOC_EXTERN MSTATUS edECC_equalKey ( edECCKey *  pKey1,
edECCKey *  pKey2,
byteBoolean *  pMatch,
void *  pExtCtx 
)

Tests if two Edward's form keys have identical public keys. This may be used on private keys but only the curves and public keys are compared.

Parameters
pKey1Pointer to the first key.
pKey2Pointer to the second key.
pMatchContents will be set to TRUE if the public keys are identical. FALSE otherwise.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_generateKeyPair()

MOC_EXTERN MSTATUS edECC_generateKeyPair ( MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *  pKey,
RNGFun  rngFun,
void *  pRngArg,
BulkHashAlgo pShaSuite,
void *  pExtCtx 
)

Generates a new Edward's form private key pair.

Parameters
pKeyPointer to a previously allocated key.
rngFunFunction pointer callback to a method that will provide random entropy.
pRngArgOptional argument that may be needed by the rngFun provided.
pShaSuiteFor EdDSA keys only, the SHA suite used by the EdDSA algorithm. This must be SHA2-512 for curve25519 and SHA3-SHAKE256 for curve448. This param should be NULL for EdDH keys.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_getKeyLen()

MOC_EXTERN MSTATUS edECC_getKeyLen ( edECCKey *  pKey,
ubyte4 *  pKeyLen,
void *  pExtCtx 
)

Gets the key length associated with the given key.

Parameters
pKeyPointer to the input key.
pKeyLenContents will be set to the length of the key in bytes. Note that a public key is the same length as a private key.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_getKeyParametersAlloc()

MOC_EXTERN MSTATUS edECC_getKeyParametersAlloc ( MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *  pKey,
ubyte **  ppPubKey,
ubyte4 *  pPubLen,
ubyte **  ppPrivKey,
ubyte4 *  pPrivLen,
void *  pExtCtx 
)

Gets the key parameters in an Edward's form key. This may be used for a public key or a private key. This method allocates new buffers to hold the key values. Be sure to FREE them when done with them.

Parameters
pKeyPointer to a an exising key.
ppPubKeyPointer to the newly allocated buffer that will hold the resulting public key.
pPubLenContents will be set to the length of the public key in bytes.
ppPrivKeyPointer to the newly allocated buffer that will hold the resulting private key. This will be NULL for pKey a public key.
pPrivLenContents will be set to the length of the private key in bytes.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_getPublicKey()

MOC_EXTERN MSTATUS edECC_getPublicKey ( MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *  pKey,
ubyte *  pOutBuffer,
ubyte4  bufferLen,
void *  pExtCtx 
)

Gets the public key from an Edward's form private or public key.

Parameters
pKeyPointer to a an exising key.
pOutBufferBuffer that will hold the output public key.
bufferLenThe length of the pOutBuffer in bytes.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_newKey()

MOC_EXTERN MSTATUS edECC_newKey ( edECCKey **  ppKey,
edECCCurve  curve,
void *  pExtCtx 
)

Creates a new Edward's curve form key. The key will be allocated and be sure to call edECC_deleteKey to free the memory when done with the key.

Parameters
ppKeyPointer that will receive the location of the newly allocated key.
curveThe curve and algorithm to associate with the new key.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_setKeyParameters()

MOC_EXTERN MSTATUS edECC_setKeyParameters ( MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *  pKey,
ubyte *  pPubKey,
ubyte4  pubKeyLen,
ubyte *  pPrivKey,
ubyte4  privKeyLen,
BulkHashAlgo pShaSuite,
void *  pExtCtx 
)

Sets the key parameters in an Edward's form key. This may be used to set a public key or a private key. If setting a private key without a public key value input, the public key value will be generated.

Parameters
pKeyPointer to a previously allocated key.
pPubKeyBuffer holding the public key value to be set. This may be NULL for setting a private key, in which case the public value will be computed.
pubKeyLenThe length of the public key in bytes.
pPrivKeyBuffer holding the private key value to be set. This must be NULL when setting just a public key.
privKeyLenThe length of the private key in bytes.
pShaSuiteFor EdDSA private keys when pPubKey is NULL, the SHA suite used by the EdDSA algorithm. This must be SHA2-512 for curve25519 and SHA3-SHAKE256 for curve448. This param should be NULL for EdDH keys.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ edECC_validateKey()

MOC_EXTERN MSTATUS edECC_validateKey ( MOC_ECC(hwAccelDescr hwAccelCtx) edECCKey *  pKey,
BulkHashAlgo pShaSuite,
void *  pExtCtx 
)

Validates an Edward's form key. For private keys this consists of validating that the public key is correctly associated with the private key. For EdDSA public keys validation consists of validiting that it is a properly encoded point. For EdDH public keys no validation is needed and this method will always result in OK.

Parameters
pKeyPointer to the key to be validated. This may be public or private.
pShaSuiteFor EdDSA private keys, the SHA suite used by the EdDSA algorithm. This must be SHA2-512 for curve25519 and SHA3-SHAKE256 for curve448. This param should be NULL for EdDH keys or public keys.
pExtCtxAn extended context reserved for future use.
Returns
OK (0) if successful and the key is valid, otherwise a negative number error code from merrors.h