Elliptic Curve Digital Signature Algorithm Library
This Library provides a set of routines for easier handling of the Elliptic Curve Digital Signature Algorithm module available on CEC1702.
These routines are embedded into the program Flash memory.
Library Routines
ec_point_double
Prototype |
uint8_t ec_point_double(const uint8_t * pxy, const uint16_t coord_len, const uint8_t msbf);
|
Description |
This routine performs a point doubling operation.
|
Parameters |
pxy: pointer to the point on EC curve.
coord_len: length filled for the coordinates passed in bytes (px+py ).
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_point_add
Prototype |
uint8_t ec_point_add(const uint8_t * p1xy, const uint8_t * p2xy, const uint16_t coord_len, const uint8_t msbf);
|
Description |
This routine performs addition of two points on EC curve.
|
Parameters |
p1xy: Pointer to the point1 coordinates on EC curve.
p2xy: Pointer to the point2 coordinates on EC curve.
coord_len: length filled for the coordinates passed in bytes (px+py) .
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_point_scalar_mult2
Prototype |
uint8_t ec_point_scalar_mult2(const uint8_t* px, const uint8_t* py, const uint8_t* pscalar, const uint16_t byte_len, const uint8_t msbf);
|
Description |
This routine performs multiplication of EC curve (P (px,py)) to a scalar data.
|
Parameters |
px: Pointer to point EC curve for the px coordinates (128 bits on the EC curve Px).
py: Pointer to point EC curve for the py coordinates (128 bits on the EC curve Py).
pscalar: Pointer to scalar data to be multiplied with.
byte_len: Length field for the scalar data transferred in byte.
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_point_scalar_mult3
Prototype |
uint8_t ec_point_scalar_mult3(const uint8_t* pxy, const uint8_t* pscalar, const uint16_t byte_len, const uint8_t msbf);
|
Description |
This routine performs multiplication of EC curve (P (px,py)) to a scalar data.
|
Parameters |
px: Pointer to point coordinates px followed by py.
pscalar: Pointer to scalar data to be multiplied with.
byte_len: Length field for the scalar data transferred in byte.
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_point_scalar_mult3
Prototype |
uint8_t ec_point_scalar_mult3(const uint8_t* pxy, const uint8_t* pscalar, const uint16_t byte_len, const uint8_t msbf);
|
Description |
This routine performs multiplication of EC curve (P (px,py)) to a scalar data.
|
Parameters |
px: Pointer to point coordinates px followed by py.
pscalar: Pointer to scalar data to be multiplied with .
byte_len: Length field for the scalar data transferred in byte .
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_check_poc2
Prototype |
uint8_t ec_check_poc2(const uint8_t* px, const uint8_t* py, const uint16_t plen, const uint8_t msbf);
|
Description |
This routine check if the point lies on the EC curve.
|
Parameters |
px: Pointer to parameter px.
px: Pointer to parameter py.
plen: Byte length of coordinates passed px, py.
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_check_poc3
Prototype |
uint8_t ec_check_poc3(const uint8_t* p, const uint16_t plen, const uint8_t msbf);
|
Description |
This routine check if the point lies on the EC curve.
|
Parameters |
p: Pointer to point to check.
plen: length for the EC curve passed for the coordinates (Px+py).
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_check_point_less_prime
Prototype |
uint8_t ec_check_point_less_prime(const uint8_t* pxy, const uint16_t plen, const uint8_t msbf);
|
Description |
This routine check Points coordinates are less than prime.
|
Parameters |
pxy: Pointer to point coordinates.
plen: length for the EC curve passed for the coordinates (Px+py).
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - this error value is returned if input parameters are invalid.
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Caller must have previously programmed elliptic curve into PKE block via ec_prog_curve.
|
Notes |
None.
|
ec_check_ab
Prototype |
uint8_t ec_check_ab(const uint8_t* pxy, const uint16_t plen, const uint8_t msbf);
|
Description |
This routine checks EC Curve parameters a & b.
|
Parameters |
None.
|
Returns |
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Caller must have previously programmed elliptic curve into PKE block via ec_prog_curve.
|
Notes |
None.
|
ec_check_n
Prototype |
uint8_t ec_check_n();
|
Description |
This routine checks EC Curve order (parameter n).
|
Parameters |
None.
|
Returns |
ECC_ERR_BUSY - this error value is returned if PKE block is busy.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Caller must have previously programmed elliptic curve into PKE block via ec_prog_curve.
|
Notes |
None.
|
ec_prog_curve
Prototype |
uint8_t ec_prog_curve(const ELLIPTIC_CURVE* curve_p);
|
Description |
This routine programs the elliptic curve parameters into the PKE block shared crypto memory. It programs the EC parameters prime to slot 0, order to slot 1, generator point x-coordinate to slot 2, generator point y-coordinate to slot 3, curve parameter a to slot 4 and curve parameter b to slot 5.
All parameters are zero extended to end of the slot. The PKE block slots size is 512 bytes. This routine also programs the following register fields in command register..
|
Parameters |
|
Returns |
ECC_ERR_BAD_PARAM - This error value is returned if curve_p points to NULL or if any of the pointers in the curve parameters point to NULL.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ecdsa_verify
Prototype |
uint8_t ecdsa_verify(const uint8_t * Q, const uint8_t * S, const uint8_t * digest, uint16_t elen, uint16_t dlen, uint8_t msbf);
|
Description |
This routine verifies a signature using standard EC Digital Signature Algorithm.
|
Parameters |
Q: pointer to constant data containing Public Key Q.
S: pointer to constant data consisting of signature point S.
digest: pointer to constant data consisting of hash digest of message.
Elen: length of Qx and Qy.
Qx in 0 <= index < elen, Qy in elen <= index < 2*elen.
Sx in 0 <= index < elen, Sy in elen <= index < 2*elen.
dlen: length of digest.
msbf: byte order. Valid values :
Value |
Description |
1 |
Most significant byte first (reverse byte order). |
0 |
Least significant byte first (reverse byte order). |
|
Returns |
ECC_ERR_BAD_PARAM - This error value is returned if Q, S or digest is a NULL pointer, if elen or dlen is zero.
ECC_ERR_BUSY - This error value is returned if PKE block is busy.
ECC_ERR_ZERO_LEN_PARAM - This error value is returned if not equal to curve parameter length.
PKE_RET_OK - this value indicates a successful execution of requested operation.
|
Requires |
Nothing.
|
Notes |
None.
|
ec_kcdsa_keygen
Prototype |
uint8_t ec_kcdsa_keygen(const uint8_t* d, const uint16_t plen, uint16_t flags);
|
Description |
This routine generates a public key for use with Korean Elliptic curve digital signature algorithm.
|
Parameters |
d: Pointer to array containing EC private key.
plen: Byte length of d.
flags: Byte order :
- bit[0] = 0 (d is LSBF), 1 (d is MSBF)
|
Returns |
ECC_ERR_BAD_PARAM: this error value is returned if d is a null pointer, if plen is zero or greater than curve parameter length../li>
PKE_RET_OK: if operation requested is successful (PKE block started).
|
Requires |
Caller must have previously programmed elliptic curve into PKE block via ec_prog_curve.
|
Notes |
None.
|
ec_kcdsa_sign
Prototype |
uint8_t ec_kcdsa_sign(const uint8_t* prv_key, uint16_t plen, const uint8_t* r, uint16_t rlen, const uint8_t* hash, uint16_t hlen, uint16_t flags);
|
Description |
This routine signs the hash message using Korean EC signature algorithm.
|
Parameters |
prv_key: Pointer to array containing EC private key.
plen: Byte length of prv_key.
r: Pointer to array containing r component of signature.
rlen: Byte length of r.
hash: Pointer to hash digest of message.
hlen: Byte length of hash digest.
flags: Byte order :
- bit[0] = 0 (prv_key is LSBF), 1 (prv_key is MSBF)
- bit[1] = 0 (r is LSBF), 1 (r is MSBF)
- bit[2] = 0 (hash digest is LSBF), 1 (hash digest is MSBF)
|
Returns |
ECC_ERR_BAD_PARAM: this error value is returned if prv_key , r , hash are a null pointer, if plen , rlen , hlen is zero or greater than curve parameter length.
PKE_RET_OK: if operation requested is successful (PKE block started).
|
Requires |
Caller must have previously programmed elliptic curve into PKE block e.g. ec_prog_curve.
|
Notes |
None.
|
ec_kcdsa_verify
Prototype |
uint8_t ec_kcdsa_verify(const uint8_t* q, unsigned int qlen, const uint8_t* sig, unsigned int slen, const uint8_t* hash, unsigned int hlen, unsigned int flags);
|
Description |
This routine performs signature verification operation.
|
Parameters |
Q: Pointer to array containing Qx and Qy.
qlen: Byte length of Q.
Sig: Pointer to array containing r & s.
slen: Byte length of sig.
hash: Pointer to hash digest of message.
hlen: Byte length of hash digest.
flags: Byte order :
- bit[0] = 0 (Qx,y is LSBF), 1 (Qx,y is MSBF)
- bit[1] = 0 (r,s is LSBF), 1 (r,s is MSBF)
- bit[2] = 0 (digest is LSBF), 1 (digest is MSBF)
|
Returns |
ECC_ERR_BAD_PARAM: this error value is returned if Q , sig or hash is a Null pointer, if qlen , slen or heln is zero or greater than curve parameter length.
PKE_RET_OK: if operation requested is successful (PKE block started).
|
Requires |
Caller must have previously programmed elliptic curve into PKE block e.g. ec_prog_curve.
|
Notes |
None.
|
ec25519_point_mult
Prototype |
uint8_t ec25519_point_mult(const uint8_t* p1x, uint16_t p1x_len, const uint8_t* k, uint16_t k_len, uint16_t flags);
|
Description |
This routine performs an elliptic curve scalar point multiple using the Elliptic Curve 25519.
|
Parameters |
P1x: Pointer to array containing Qx and Qy.
P1x_len: Byte length of Q.
K: Pointer to array containing r & s.
K_len: Byte length of sig.
flags: Byte order :
- bit[0] = 0 (px byte array is LSBF), 1 (point is MSBF)
- bit[1] = 0 (k byte array is LSBF), 1 (MSBF)
|
Returns |
PKE_RET_OK: operation was successful.
ECC_ERR_BAD_PARAM: this error value is returned if either p1x or K is a null pointer.
|
Requires |
Nothing.
|
Notes |
None.
|
ec25519_xrecover
Prototype |
uint8_t ec25519_xrecover(const uint8_t* y, uint16_t ylen, uint16_t flags);
|
Description |
This routine derives the X-coordinate on an elliptic curve 25519, given the Y-Coordinate. The result is stored in Slot[0x06]..
|
Parameters |
y: Pointer to array containing Qx and Qy.
ylen: Byte length of y.
flags: Byte order, 0 (point byte array is LSBF), 1 (point byte array is MSBF)
|
Returns |
PKE_RET_OK: operation was successful.
ECC_ERR_BAD_PARAM: this error value indicates that Y is a NULL pointer..
|
Requires |
Nothing.
|
Notes |
None.
|
ed25519_scalar_mult
Prototype |
uint8_t ed25519_scalar_mult(const uint8_t* py, uint16_t pylen, const uint8_t* e, uint16_t elen, uint16_t flags);
|
Description |
This routine multiplies point by a scalar for Elliptic Curve 25519. When done, result is located in SCM at Slot[0xA] = x-coordinate, Slot[0xB] = y-coordinate.
|
Parameters |
Px: Pointer to parameter px
Pxlen: Byte length of px.
Py: Pointer to parameter py.
Pylen: Byte length of py.
E: Pointer to parameter e.
Elen: Byte length of e.
flags: Byte order,
- bit[0] = 0 (px byte array is LSBF), 1 (point is MSBF)
- bit[1] = 0 (py byte array is LSBF), 1 (MSBF)
- bit[2] = 0 (e byte array is LSBF), 1 (MSBF)
|
Returns |
PKE_RET_OK: operation was successful.
ECC_ERR_BAD_PARAM: this error value indicates that either px , py , or e points to null or elen is zero.
|
Requires |
Nothing.
|
Notes |
None.
|
ed25519_valid_sig
Prototype |
uint8_t ed25519_valid_sig(const Ed25519_SIG_VERIFY* psv);
|
Description |
This routine Checks signature (point) against message string (hash).
|
Parameters |
|
Returns |
PKE_RET_OK: operation was successful.
ECC_ERR_BAD_PARAM: this error value is returned if psv or any of its members points to NULL.
|
Requires |
Nothing.
|
Notes |
None.
|
Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
What do you think about this topic ?
Send us feedback!
Want more examples and libraries?
Find them on