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

Header file for the Nanocrypto Finite Field Elliptic Curve API. More...

Go to the source code of this file.

Typedefs

typedef struct MEccKeyTemplate * MEccKeyTemplatePtr
 

Functions

MOC_EXTERN MSTATUS EC_addMultiplyPoint (PrimeFieldPtr pPF, PFEPtr pResX, PFEPtr pResY, ConstPFEPtr pAddedX, ConstPFEPtr pAddedY, ConstPFEPtr k, ConstPFEPtr pX, ConstPFEPtr pY)
 Computes a scalar-point multiplication plus an addition on a prime curve. More...
 
MOC_EXTERN MSTATUS EC_byteStringToPoint (PEllipticCurvePtr pEC, const ubyte *s, sbyte4 len, PFEPtr *ppX, PFEPtr *ppY)
 Converts an uncompressed form point to newly allocated prime field elements. More...
 
MOC_EXTERN MSTATUS EC_cloneKey (ECCKey **ppNew, const ECCKey *pSrc)
 Clones an ECCKey instance. More...
 
MOC_EXTERN MSTATUS EC_combSize (PrimeFieldPtr pPF, sbyte4 windowSize, sbyte4 *size)
 Computes the total number of pf_units that will be needed to store a comb. More...
 
MOC_EXTERN intBoolean EC_compareEllipticCurves (PEllipticCurvePtr pEC1, PEllipticCurvePtr pEC2)
 Compares if two elliptic curve pointers are the same curve. More...
 
MOC_EXTERN MSTATUS EC_computeYFromX (PEllipticCurvePtr pEC, ConstPFEPtr x, PFEPtr y)
 Computes a Y coordinate of a point on the curve from an X coordinate. More...
 
MOC_EXTERN MSTATUS EC_createPrimeCurveMutexes (void)
 Creates globally stored mutexes used for thread safety. More...
 
MOC_EXTERN MSTATUS EC_deleteComb (PrimeFieldPtr pPF, sbyte4 windowSize, PFEPtr *pComb)
 Zeros and frees a comb. More...
 
MOC_EXTERN MSTATUS EC_deleteKey (ECCKey **ppKey)
 Deletes an ECCKey instance. More...
 
MOC_EXTERN MSTATUS EC_deletePrimeCurveCombsAndMutexes (void)
 Zeros and frees globally stored combs and mutexes. More...
 
MOC_EXTERN MSTATUS EC_equalKey (const ECCKey *pKey1, const ECCKey *pKey2, byteBoolean *res)
 Tests whether two ECCKeys have identical public keys. More...
 
MOC_EXTERN MSTATUS EC_generateKeyPair (PEllipticCurvePtr pEC, RNGFun rngFun, void *rngArg, PFEPtr k, PFEPtr pQx, PFEPtr pQy)
 Generates a new ECC private/public key pair. More...
 
MOC_EXTERN MSTATUS EC_getPointByteStringLen (PEllipticCurvePtr pEC, sbyte4 *pLen)
 Gets the length in bytes of an arbitrary point's uncompressed form. More...
 
MOC_EXTERN PrimeFieldPtr EC_getUnderlyingField (PEllipticCurvePtr pEC)
 Gets the underlying prime field associated with a prime curve. More...
 
MOC_EXTERN MSTATUS EC_multiplyPoint (PrimeFieldPtr pPF, PFEPtr pResX, PFEPtr pResY, ConstPFEPtr k, ConstPFEPtr pX, ConstPFEPtr pY)
 Computes a scalar-point multiplication on a prime curve. More...
 
MOC_EXTERN MSTATUS EC_newKey (PEllipticCurvePtr pEC, ECCKey **ppNewKey)
 Allocates a new ECCKey instance. More...
 
MOC_EXTERN MSTATUS EC_pointToByteString (PEllipticCurvePtr pEC, ConstPFEPtr pX, ConstPFEPtr pY, ubyte **s, sbyte4 *pLen)
 Converts a point on the curve to an uncompressed form byte array. More...
 
MOC_EXTERN MSTATUS EC_precomputeComb (PrimeFieldPtr pPF, ConstPFEPtr pQx, ConstPFEPtr pQy, sbyte4 windowSize, PFEPtr *pPrecomputed)
 Computes the comb of a point on the curve. More...
 
MOC_EXTERN MSTATUS EC_precomputeCombOfCurve (PEllipticCurvePtr pEC, sbyte4 windowSize, PFEPtr *pCurvePrecomputed)
 Computes the comb of the curve's large cyclic group generator. More...
 
MOC_EXTERN MSTATUS EC_setKeyParameters (ECCKey *pKey, const ubyte *point, ubyte4 pointLen, const ubyte *scalar, ubyte4 scalarLen)
 Sets the key parameters of an ECCKey. More...
 
MOC_EXTERN MSTATUS EC_setPointToByteString (PEllipticCurvePtr pEC, const ubyte *s, sbyte4 len, PFEPtr pX, PFEPtr pY)
 Converts an uncompressed form point to prime field elements. More...
 
MOC_EXTERN MSTATUS EC_setPrivateKey (ECCKey *pKey, ubyte *pScalar, ubyte4 scalarLen)
 Sets the private key parameter of an ECCKey. More...
 
MOC_EXTERN MSTATUS EC_verifyKeyPair (PEllipticCurvePtr pEC, ConstPFEPtr k, ConstPFEPtr pQx, ConstPFEPtr pQy)
 Verifies that a given private key is associated with a given public key. More...
 
MOC_EXTERN MSTATUS EC_verifyPoint (PEllipticCurvePtr pEC, ConstPFEPtr pQx, ConstPFEPtr pQy)
 Verifies that a point is a valid point on the curve. More...
 
MOC_EXTERN MSTATUS EC_verifyPublicKey (PEllipticCurvePtr pEC, ConstPFEPtr pQx, ConstPFEPtr pQy)
 Verifies that a public key point is a valid point on the curve. More...
 
MOC_EXTERN MSTATUS EC_writePointToBuffer (PEllipticCurvePtr pEC, ConstPFEPtr pX, ConstPFEPtr pY, ubyte *s, sbyte4 len)
 Converts a point on the curve to an uncompressed form byte array. More...
 
MOC_EXTERN MSTATUS ECDH_generateSharedSecret (PEllipticCurvePtr pEC, const ubyte *pointByteString, sbyte4 pointByteStringLen, ConstPFEPtr scalarMultiplier, ubyte **sharedSecret, sbyte4 *sharedSecretLen)
 Generates a Diffie-Hellman shared secret from an uncompressed form public key. More...
 
MOC_EXTERN MSTATUS ECDH_generateSharedSecretAux (PEllipticCurvePtr pEC, ConstPFEPtr pX, ConstPFEPtr pY, ConstPFEPtr scalarMultiplier, ubyte **sharedSecret, sbyte4 *sharedSecretLen, sbyte4 flag)
 Generates a Diffie-Hellman shared secret. More...
 
MOC_EXTERN MSTATUS ECDH_keyAgreementSchemePrimeCurve (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. More...
 
MOC_EXTERN MSTATUS ECDSA_signDigestAux (PEllipticCurvePtr pEC, ConstPFEPtr d, RNGFun rngFun, void *rngArg, const ubyte *hash, ubyte4 hashLen, PFEPtr r, PFEPtr s)
 Signs a message digest via the ECDSA signature algorithm. More...
 
MOC_EXTERN MSTATUS ECDSA_verifySignature (PEllipticCurvePtr pEC, ConstPFEPtr pPublicKeyX, ConstPFEPtr pPublicKeyY, const ubyte *hash, ubyte4 hashLen, ConstPFEPtr r, ConstPFEPtr s)
 Verifies a message digest via the ECDSA signature algorithm. More...
 
MOC_EXTERN MSTATUS ECDSA_verifySignatureEx (PEllipticCurvePtr pEC, ConstPFEPtr pPublicKeyX, ConstPFEPtr pPublicKeyY, const ubyte *hash, ubyte4 hashLen, sbyte4 curveWinSize, ConstPFEPtr pCurvePrecomp, sbyte4 pubKeyWinSize, ConstPFEPtr pPubKeyPrecomp, ConstPFEPtr r, ConstPFEPtr s)
 Verifies a message digest via the ECDSA signature algorithm using provided combs. More...
 

Variables

MOC_EXTERN_PRIMEEC_H const PEllipticCurvePtr EC_P192
 
MOC_EXTERN_PRIMEEC_H const PEllipticCurvePtr EC_P224
 
MOC_EXTERN_PRIMEEC_H const PEllipticCurvePtr EC_P256
 
MOC_EXTERN_PRIMEEC_H const PEllipticCurvePtr EC_P384
 
MOC_EXTERN_PRIMEEC_H const PEllipticCurvePtr EC_P521
 

Detailed Description

This file documents the definitions, enumerations, structures, and functions of the NanoCrypto Finite Field Elliptic Curve (EC) API.

To enable the functions in primeec.{c,h}, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_ECC__

primeec.h

Function Documentation

◆ EC_addMultiplyPoint()

MOC_EXTERN MSTATUS EC_addMultiplyPoint ( PrimeFieldPtr  pPF,
PFEPtr  pResX,
PFEPtr  pResY,
ConstPFEPtr  pAddedX,
ConstPFEPtr  pAddedY,
ConstPFEPtr  k,
ConstPFEPtr  pX,
ConstPFEPtr  pY 
)

Computes a scalar-point multiplication plus an addition on a prime curve. This is essentially (pResX, pResY) = k * (pX, pY) + (pAddedX, pAddedY). It is not checked that the input points are valid points on the curve.

Parameters
pPFThe globally defined prime field associated with the prime curve.
pResXThe resulting point's X coordinate.
pResYThe resulting point's Y coordinate.
pAddedXThe addended point's X coordinate.
pAddedYThe addended point's Y coordinate.
kThe input scalar stored in the form of a prime field element. This need not be a reduced prime field element.
pXThe to be scaled point's X coordinate.
pYThe to be scaled point's Y coordinate.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_byteStringToPoint()

MOC_EXTERN MSTATUS EC_byteStringToPoint ( PEllipticCurvePtr  pEC,
const ubyte *  s,
sbyte4  len,
PFEPtr *  ppX,
PFEPtr *  ppY 
)

Converts a byte array form uncompressed point to the point in the form of two newly allocated prime field elements. Be sure to free these elements when done with them by calling PRIMEFIELD_deleteElement on each.

Parameters
pECPointer to the globally defined prime curve in question.
sBuffer holding the uncompressed form point. This should begin with an 0x04 byte followed by X and Y in Big Endian each properly padded to the prime field's element length.
lenThe length of the buffer s in bytes.
ppXPointer to the location that will hold the resulting X coordinate as a prime field element.
ppYPointer to the location that will hold the resulting Y coordinate as a prime field element.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_cloneKey()

MOC_EXTERN MSTATUS EC_cloneKey ( ECCKey **  ppNew,
const ECCKey *  pSrc 
)

Allocates a new copy of an already existing ECCKey. Be sure to free this key when done with it by calling EC_deleteKey.

Parameters
ppNewPointer to the location that will receive the new key.
pSrcPointer to the previously existing key that will be cloned.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_combSize()

MOC_EXTERN MSTATUS EC_combSize ( PrimeFieldPtr  pPF,
sbyte4  windowSize,
sbyte4 *  size 
)

Computes the total number of pf_units that will be needed to store a comb with a given window size w. This is 2 * (2^w - 2) * n where n is the number of pf_units in a prime field element.

Parameters
pPFThe globally defined prime field associated to the curve in question.
windowSizeThe input window size. This must be 2 or larger.
sizeContents will be set to the comb size.

To use this method one must define ENABLE_MOCANA_ECC_COMB and have ENABLE_MOCANA_SMALL_CODE_FOOTPRINT not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_compareEllipticCurves()

MOC_EXTERN intBoolean EC_compareEllipticCurves ( PEllipticCurvePtr  pEC1,
PEllipticCurvePtr  pEC2 
)

Compares if two elliptic curve pointers are the same curve.

Parameters
pEC1Pointer to the first curve.
pEC2Pointer to the second curve.
Returns
TRUE if the the two curves are the same, FALSE otherwise.

◆ EC_computeYFromX()

MOC_EXTERN MSTATUS EC_computeYFromX ( PEllipticCurvePtr  pEC,
ConstPFEPtr  x,
PFEPtr  y 
)

Computes a Y coordinate of a point on the curve from an X coordinate. It will compute one of the two possible Y coordinates if it exists. If no such point (X,Y) exists then ERR_NOT_FOUND (-6009) is returned.

Parameters
pECPointer to the globally defined prime curve in question.
xThe input X coordinate.
yThe resulting Y coordinate.
Returns
OK (0) if successful and such an (X,Y) exists. If no such (X,Y) exists then ERR_NOT_FOUND (-6009) is returned.

◆ EC_createPrimeCurveMutexes()

MOC_EXTERN MSTATUS EC_createPrimeCurveMutexes ( void  )

Creates globally stored mutexes used for thread safety among comb generation for each of the prime curve's cyclic group generators. This method should only be called once and in an initialization phase, for example from CRYPTO_MOC_init. Be sure to then also call EC_deletePrimeCurveCombsAndMutexes in an appropriate cleanup phase.

To use this method one must define ENABLE_MOCANA_SIGNED_ODD_COMB_PERSIST and not have DISABLE_MOCANA_SIGNED_ODD_COMB not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_deleteComb()

MOC_EXTERN MSTATUS EC_deleteComb ( PrimeFieldPtr  pPF,
sbyte4  windowSize,
PFEPtr *  pComb 
)

Zeros and frees a comb allocated by the EC_precomputeCombOfCurve or EC_precomputeComb methods.

Parameters
pPFThe globally defined prime field associated to the curve in question.
windowSizeThe input comb's window size. This MUST match the window size used when the comb was created.
pCombPointer to the location of the comb to be deleted.

To use this method one must define ENABLE_MOCANA_ECC_COMB and have ENABLE_MOCANA_SMALL_CODE_FOOTPRINT not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_deleteKey()

MOC_EXTERN MSTATUS EC_deleteKey ( ECCKey **  ppKey)

Zeroes and frees memory allocated within and for an ECCKey.

Parameters
ppKeyPointer to the location of the key that will be deleted.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_deletePrimeCurveCombsAndMutexes()

MOC_EXTERN MSTATUS EC_deletePrimeCurveCombsAndMutexes ( void  )

Zeros and frees globally stored combs and mutexes. These are the mutexes created by the EC_createPrimeCurveMutexes method. The comb's will have been generated as needed by the ECDSA signing algorithm.

To use this method one must define ENABLE_MOCANA_SIGNED_ODD_COMB_PERSIST and not have DISABLE_MOCANA_SIGNED_ODD_COMB not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_equalKey()

MOC_EXTERN MSTATUS EC_equalKey ( const ECCKey *  pKey1,
const ECCKey *  pKey2,
byteBoolean *  res 
)

Tests whether two ECCKeys have identical public keys. The private key portions for private keys are ignored.

Parameters
pKey1The first input key.
pKey2The second input key.
resContents will be set to TRUE if the two public keys are the same point on the curve and FALSE otherwise.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_generateKeyPair()

MOC_EXTERN MSTATUS EC_generateKeyPair ( PEllipticCurvePtr  pEC,
RNGFun  rngFun,
void *  rngArg,
PFEPtr  k,
PFEPtr  pQx,
PFEPtr  pQy 
)

Generates a new ECC private/public key pair in prime field element forms.

Parameters
pECThe curve to associate with the key. This is should be one of the globally defined prime field curves.

EC_P192 (if enabled) EC_P224 EC_P256 EC_P384 EC_P521

Parameters
rngFunFunction pointer callback to a method that will provide random entropy.
rngArgOptional argument that may be needed by the rngFun provided.
kThe resuling private key scalar in a prime field element form.
pQxThe resulting public key point's X coordinate.
pQyThe resulting public key point's Y coordinate.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_getPointByteStringLen()

MOC_EXTERN MSTATUS EC_getPointByteStringLen ( PEllipticCurvePtr  pEC,
sbyte4 *  pLen 
)

Gets the length in bytes of an arbitrary point's uncompressed form. All points on the curve will have this same length (ie will be properly zero padded if neccessary).

Parameters
pECPointer to the globally defined prime curve in question.
pLenContents will be set to the number of bytes in an uncompressed form point.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_getUnderlyingField()

MOC_EXTERN PrimeFieldPtr EC_getUnderlyingField ( PEllipticCurvePtr  pEC)

Gets the underlying prime field associated with a prime curve.

Parameters
pECPointer to the globally defined prime curve in question.
Returns
A pointer to the global prime field associated with the input curve.

◆ EC_multiplyPoint()

MOC_EXTERN MSTATUS EC_multiplyPoint ( PrimeFieldPtr  pPF,
PFEPtr  pResX,
PFEPtr  pResY,
ConstPFEPtr  k,
ConstPFEPtr  pX,
ConstPFEPtr  pY 
)

Computes a scalar-point multiplication on a prime curve. It is not checked that the input coordinates (pX,pY) represent a valid point.

Parameters
pPFThe globally defined prime field associated with the prime curve.
pResXThe resulting point's X coordinate.
pResYThe resulting point's Y coordinate.
kThe input scalar stored in the form of a prime field element. This need not be a reduced prime field element.
pXThe input point's X coordinate.
pYThe input point's Y coordinate.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_newKey()

MOC_EXTERN MSTATUS EC_newKey ( PEllipticCurvePtr  pEC,
ECCKey **  ppNewKey 
)

Allocates a new ECCKey instance. Be sure to call EC_deleteKey when done in order to free the allocated memory.

Parameters
pECOne of the globally defined prime field curves.
              EC_P192 (if enabled)
              EC_P224
              EC_P256
              EC_P384
              EC_P521
ppNewKeyPointer to the location that will receive the new key.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_pointToByteString()

MOC_EXTERN MSTATUS EC_pointToByteString ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pX,
ConstPFEPtr  pY,
ubyte **  s,
sbyte4 *  pLen 
)

Allocates a buffer and converts a point on the curve to an uncompressed form byte array. This byte array will begin with a 0x04 byte followed by the X and Y coordinates in Big Endian, each of length equal to the standard prime field element length. Be sure to FREE this buffer when done with it.

Parameters
pECPointer to the globally defined prime curve in question.
pXThe point's X coordinate.
pYThe point's Y coordinate.
sLocation of the newly allocated buffer that will hold the resulting uncompressed form point.
pLenContents will be set to the length of the newly allocated buffer in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_precomputeComb()

MOC_EXTERN MSTATUS EC_precomputeComb ( PrimeFieldPtr  pPF,
ConstPFEPtr  pQx,
ConstPFEPtr  pQy,
sbyte4  windowSize,
PFEPtr *  pPrecomputed 
)

Computes the comb of a point on the curve. The table created can be used to speed up multiplication of a scalar times the point in question. The table will be allocated so be sure to call EC_deleteComb to free such memory when done with it.

Parameters
pPFThe globally defined prime field associated to the curve in question.
pQxThe input point's X coordinate.
pQyThe input point's Y coordinate.
windowSizeThe input window size. This must be 2 or larger and is a memory vs speed tradeoff. Generally 4 or 5 is optimal.
pPrecomputedPointer to the location of a newly allocated array of PFEPtrs representing the comb table of the input point.

To use this method one must define ENABLE_MOCANA_ECC_COMB and have ENABLE_MOCANA_SMALL_CODE_FOOTPRINT not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_precomputeCombOfCurve()

MOC_EXTERN MSTATUS EC_precomputeCombOfCurve ( PEllipticCurvePtr  pEC,
sbyte4  windowSize,
PFEPtr *  pCurvePrecomputed 
)

Computes the comb of the curve's large cyclic group generator. The table created can be used to speed up multiplication of a scalar times the generator. The table will be allocated so be sure to call EC_deleteComb to free such memory when done with it.

Parameters
pECPointer to the globally defined prime curve in question.
windowSizeThe input window size. This must be 2 or larger and is a memory vs speed tradeoff. Generally 4 or 5 is optimal.
pCurvePrecomputedPointer to the location of a newly allocated array of PFEPtrs representing the comb table of the generator point.

To use this method one must define ENABLE_MOCANA_ECC_COMB and have ENABLE_MOCANA_SMALL_CODE_FOOTPRINT not defined.

Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_setKeyParameters()

MOC_EXTERN MSTATUS EC_setKeyParameters ( ECCKey *  pKey,
const ubyte *  point,
ubyte4  pointLen,
const ubyte *  scalar,
ubyte4  scalarLen 
)

Sets the key parameters of an ECCKey. This method can set a public key by passing in NULL for the scalar parameter, or it can be used to set a private key by passing the scalar in along with the public point.

Parameters
pKeyPointer to a previously allocated key.
pointBuffer holding the point in an uncompressed form. This form must begin with a 0x04 byte followed by the X and Y coordinates in Big Endian, each zero padded to the proper prime field element length. If not provided, the public key will still be set in pKey from the private key.
pointLenThe length of the point buffer in bytes.
scalarOptional. The scalar as Big Endian byte array. If this is NULL then the key type will be public, and otherwise private. Note this value is required to be less than the prime number associated with the curve in question.
scalarLenThe length of the scalar in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_setPointToByteString()

MOC_EXTERN MSTATUS EC_setPointToByteString ( PEllipticCurvePtr  pEC,
const ubyte *  s,
sbyte4  len,
PFEPtr  pX,
PFEPtr  pY 
)

Converts a byte array form uncompressed point to the point in the form of two prime field elements.

Parameters
pECPointer to the globally defined prime curve in question.
sBuffer holding the uncompressed form point. This should begin with an 0x04 byte followed by X and Y in Big Endian each properly padded to the prime field's element length.
lenThe length of the buffer s in bytes.
pXThe resulting X coordinate as a prime field element.
pYThe resulting Y coordinate as a prime field element.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_setPrivateKey()

MOC_EXTERN MSTATUS EC_setPrivateKey ( ECCKey *  pKey,
ubyte *  pScalar,
ubyte4  scalarLen 
)

Sets the private key parameter of an ECCKey. The public key will be left NULL.

Parameters
pKeyPointer to a previously allocated key.
scalarThe scalar as Big Endian byte array.
scalarLenThe length of the scalar in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ EC_verifyKeyPair()

MOC_EXTERN MSTATUS EC_verifyKeyPair ( PEllipticCurvePtr  pEC,
ConstPFEPtr  k,
ConstPFEPtr  pQx,
ConstPFEPtr  pQy 
)

Verifies that a given private key, ie a scalar, is associated with a given public key, ie a point.

Parameters
pECPointer to the globally defined prime curve in question.
kThe private key scalar stored in the form of a prime field element.
pQxThe public key point's X coordinate.
pQyThe public key point's Y coordinate.
Returns
OK (0) if successful and the input consists of a valid key pair, otherwise a negative number error code from merrors.h

◆ EC_verifyPoint()

MOC_EXTERN MSTATUS EC_verifyPoint ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pQx,
ConstPFEPtr  pQy 
)

Verifies that a point is a valid point on the curve. This method is the same as EC_verifyPublicKey execpt the input is not validated as reduced prime field elements. Non-reduced elements will produce garbage results.

Parameters
pECPointer to the globally defined prime curve in question.
pQxThe public key point's X coordinate.
pQyThe public key point's Y coordinate.
Returns
OK (0) if successful and the input consists of a valid point, otherwise a negative number error code from merrors.h

◆ EC_verifyPublicKey()

MOC_EXTERN MSTATUS EC_verifyPublicKey ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pQx,
ConstPFEPtr  pQy 
)

Verifies that a public key point is a valid point on the curve. This method is the same as EC_verifyPoint except the input is also validated to be reduced prime field elements.

Parameters
pECPointer to the globally defined prime curve in question.
pQxThe public key point's X coordinate.
pQyThe public key point's Y coordinate.
Returns
OK (0) if successful and the input consists of a valid public key point, otherwise a negative number error code from merrors.h

◆ EC_writePointToBuffer()

MOC_EXTERN MSTATUS EC_writePointToBuffer ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pX,
ConstPFEPtr  pY,
ubyte *  s,
sbyte4  len 
)

Converts a point on the curve to an uncompressed form byte array in a previously existing buffer. This byte array will begin with a 0x04 byte followed by the X and Y coordinates in Big Endian, each of length equal to the standard prime field element length.

Parameters
pECPointer to the globally defined prime curve in question.
pXThe point's X coordinate.
pYThe point's Y coordinate.
sBuffer that will hold the resulting uncompressed form point.
lenThe length of the buffer s in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ ECDH_generateSharedSecret()

MOC_EXTERN MSTATUS ECDH_generateSharedSecret ( PEllipticCurvePtr  pEC,
const ubyte *  pointByteString,
sbyte4  pointByteStringLen,
ConstPFEPtr  scalarMultiplier,
ubyte **  sharedSecret,
sbyte4 *  sharedSecretLen 
)

Generates a Diffie-Hellman shared secret from an uncompressed form public key and places it in a newly allocated buffer. The shared secret will consist of just the X-coordinate in Big Endian form with leading zeros preserved. Be sure to FREE this buffer when done with it.

Parameters
pECPointer to the globally defined prime curve.
pointByteStringThe other party's public key as an uncompressed form byte array. This should begin with an 0x04 byte followed by X and Y in Big Endian each properly padded to the prime field's element length.
pointByteStringLenThe length of the uncompressed form byte array in bytes.
scalarMultiplierOur private key scalar stored as a prime field element.
sharedSecretPointer to the location of the newly allocated buffer that will store the shared secret.
sharedSecretLenContents will be set to the length of the shared secret in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ ECDH_generateSharedSecretAux()

MOC_EXTERN MSTATUS ECDH_generateSharedSecretAux ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pX,
ConstPFEPtr  pY,
ConstPFEPtr  scalarMultiplier,
ubyte **  sharedSecret,
sbyte4 *  sharedSecretLen,
sbyte4  flag 
)

Generates a Diffie-Hellman shared secret and places it in a newly allocated buffer. Be sure to FREE this buffer when done with it.

Parameters
pECPointer to the globally defined prime curve.
pXThe other party's public key's X-coordinate.
pYThe other party's public key's Y-coordinate.
scalarMultiplierOur private key scalar stored as a prime field element.
sharedSecretPointer to the location of the newly allocated buffer that will store the shared secret.
sharedSecretLenContents will be set to the length of the shared secret in bytes.
flagUse ECDH_X_CORD_ONLY (1) for a shared secret consisting of just the X-coordinate in Big Endian form with leading zeros preserved (typically called Z). Use ECDH_XY_CORD (0) for a shared secret consisting of a concatenated X and Y in such form.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ ECDH_keyAgreementSchemePrimeCurve()

MOC_EXTERN MSTATUS ECDH_keyAgreementSchemePrimeCurve ( 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. This method allocates a buffer to hold the secret. Be sure to FREE this buffer when done with it.

To use this method one must define ENABLE_MOCANA_ECDH_MODES

Parameters
modeOne of the following macro values
  • FULL_UNIFIED
  • FULL_MQV
  • EPHEMERAL_UNIFIED
  • ONE_PASS_UNIFIED_U
  • ONE_PASS_UNIFIED_V
  • ONE_PASS_MQV_U
  • ONE_PASS_MQV_V
  • ONE_PASS_DH_U
  • ONE_PASS_DH_V
  • STATIC_UNIFIED
pStaticOur private static key.
pEphemeralOur private ephemeral key.
pOtherPartysStaticThe other party's static public key as an uncompressed form byte array.
otherStaticLenThe length of the uncompressed form static key byte array in bytes.
pOtherPartysEphemeralThe other party's ephemeral public key as an uncompressed form byte array.
otherEphemeralLenThe length of the uncompressed form ephemeral key byte array in bytes.
ppSharedSecretPointer to the location of the newly allocated buffer that will store the shared secret.
pSharedSecretLenContents will be set to the length of the shared secret in bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ ECDSA_signDigestAux()

MOC_EXTERN MSTATUS ECDSA_signDigestAux ( PEllipticCurvePtr  pEC,
ConstPFEPtr  d,
RNGFun  rngFun,
void *  rngArg,
const ubyte *  hash,
ubyte4  hashLen,
PFEPtr  r,
PFEPtr  s 
)

Signs a message digest via the ECDSA signature algorithm. The computed signature (r,s) will be in the form of prime field elements.

Parameters
pECPointer to the globally defined prime curve.
dThe private key scalar stored as a prime field element.
rngFunFunction pointer callback to a method that will provide random entropy.
rngArgOptional argument that may be needed by the rngFun provided.
hashBuffer holding the digest of the message to be signed.
hashLenThe length of the message digest in bytes.
rThe resulting signature's r value stored as a prime field element.
sThe resulting signature's s value stored as a prime field element.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ ECDSA_verifySignature()

MOC_EXTERN MSTATUS ECDSA_verifySignature ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pPublicKeyX,
ConstPFEPtr  pPublicKeyY,
const ubyte *  hash,
ubyte4  hashLen,
ConstPFEPtr  r,
ConstPFEPtr  s 
)

Verifies a message digest via the ECDSA signature algorithm.

Parameters
pECPointer to the globally defined prime curve.
pPublicKeyXThe public key's X-coordinate.
pPublicKeyYThe public key's Y-coordinate.
hashBuffer holding the digest of the message to be verified.
hashLenThe length of the message digest in bytes.
rThe input signature's r value stored as a prime field element.
sThe input signature's s value stored as a prime field element.
Returns
OK (0) if successful AND the signature is valid, otherwise a negative number error code from merrors.h

◆ ECDSA_verifySignatureEx()

MOC_EXTERN MSTATUS ECDSA_verifySignatureEx ( PEllipticCurvePtr  pEC,
ConstPFEPtr  pPublicKeyX,
ConstPFEPtr  pPublicKeyY,
const ubyte *  hash,
ubyte4  hashLen,
sbyte4  curveWinSize,
ConstPFEPtr  pCurvePrecomp,
sbyte4  pubKeyWinSize,
ConstPFEPtr  pPubKeyPrecomp,
ConstPFEPtr  r,
ConstPFEPtr  s 
)

Verifies a message digest via the ECDSA signature algorithm using provided combs. The comb(s) may have been generated in the signing phase and stored alongside the public key. This will greatly improve efficiency in the verification algorithm.

Parameters
pECPointer to the globally defined prime curve.
pPublicKeyXThe public key's X-coordinate.
pPublicKeyYThe public key's Y-coordinate.
hashBuffer holding the digest of the message to be verified.
hashLenThe length of the message digest in bytes.
curveWinSizeThe window size of the input pCurvePrecomp comb. Use 0 if no comb is provided.
pCurvePrecompOptional pointer to a comb of the curve's large cyclic group generator.
pubKeyWinSizeThe window size of the input pPubKeyPrecomp comb. Use 0 if no comb is provided.
pPubKeyPrecompOptional pointer to a comb of the public key point.
rThe input signature's r value stored as a prime field element.
sThe input signature's s value stored as a prime field element.
Returns
OK (0) if successful AND the signature is valid, otherwise a negative number error code from merrors.h