|
@@ -30,15 +30,15 @@ typedef struct {
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*init)(void **a);
|
|
int (*init)(void **a);
|
|
-
|
|
|
|
- /** init copy
|
|
|
|
|
|
+
|
|
|
|
+ /** init copy
|
|
@param dst The number to initialize and write to
|
|
@param dst The number to initialize and write to
|
|
@param src The number to copy from
|
|
@param src The number to copy from
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*init_copy)(void **dst, void *src);
|
|
int (*init_copy)(void **dst, void *src);
|
|
|
|
|
|
- /** deinit
|
|
|
|
|
|
+ /** deinit
|
|
@param a The number to free
|
|
@param a The number to free
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
@@ -52,30 +52,30 @@ typedef struct {
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*neg)(void *src, void *dst);
|
|
int (*neg)(void *src, void *dst);
|
|
-
|
|
|
|
- /** copy
|
|
|
|
|
|
+
|
|
|
|
+ /** copy
|
|
@param src The number to copy from
|
|
@param src The number to copy from
|
|
- @param dst The number to write to
|
|
|
|
|
|
+ @param dst The number to write to
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*copy)(void *src, void *dst);
|
|
int (*copy)(void *src, void *dst);
|
|
|
|
|
|
/* ---- trivial low level functions ---- */
|
|
/* ---- trivial low level functions ---- */
|
|
|
|
|
|
- /** set small constant
|
|
|
|
|
|
+ /** set small constant
|
|
@param a Number to write to
|
|
@param a Number to write to
|
|
- @param n Source upto bits_per_digit (actually meant for very small constants)
|
|
|
|
|
|
+ @param n Source upto bits_per_digit (actually meant for very small constants)
|
|
@return CRYPT_OK on succcess
|
|
@return CRYPT_OK on succcess
|
|
*/
|
|
*/
|
|
int (*set_int)(void *a, unsigned long n);
|
|
int (*set_int)(void *a, unsigned long n);
|
|
|
|
|
|
- /** get small constant
|
|
|
|
|
|
+ /** get small constant
|
|
@param a Number to read, only fetches upto bits_per_digit from the number
|
|
@param a Number to read, only fetches upto bits_per_digit from the number
|
|
@return The lower bits_per_digit of the integer (unsigned)
|
|
@return The lower bits_per_digit of the integer (unsigned)
|
|
*/
|
|
*/
|
|
unsigned long (*get_int)(void *a);
|
|
unsigned long (*get_int)(void *a);
|
|
|
|
|
|
- /** get digit n
|
|
|
|
|
|
+ /** get digit n
|
|
@param a The number to read from
|
|
@param a The number to read from
|
|
@param n The number of the digit to fetch
|
|
@param n The number of the digit to fetch
|
|
@return The bits_per_digit sized n'th digit of a
|
|
@return The bits_per_digit sized n'th digit of a
|
|
@@ -95,7 +95,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*compare)(void *a, void *b);
|
|
int (*compare)(void *a, void *b);
|
|
|
|
|
|
- /** compare against int
|
|
|
|
|
|
+ /** compare against int
|
|
@param a The left side integer
|
|
@param a The left side integer
|
|
@param b The right side integer (upto bits_per_digit)
|
|
@param b The right side integer (upto bits_per_digit)
|
|
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
|
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
|
@@ -108,7 +108,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*count_bits)(void * a);
|
|
int (*count_bits)(void * a);
|
|
|
|
|
|
- /** Count the number of LSB bits which are zero
|
|
|
|
|
|
+ /** Count the number of LSB bits which are zero
|
|
@param a The integer to count
|
|
@param a The integer to count
|
|
@return The number of contiguous zero LSB bits
|
|
@return The number of contiguous zero LSB bits
|
|
*/
|
|
*/
|
|
@@ -122,8 +122,8 @@ typedef struct {
|
|
int (*twoexpt)(void *a , int n);
|
|
int (*twoexpt)(void *a , int n);
|
|
|
|
|
|
/* ---- radix conversions ---- */
|
|
/* ---- radix conversions ---- */
|
|
-
|
|
|
|
- /** read ascii string
|
|
|
|
|
|
+
|
|
|
|
+ /** read ascii string
|
|
@param a The integer to store into
|
|
@param a The integer to store into
|
|
@param str The string to read
|
|
@param str The string to read
|
|
@param radix The radix the integer has been represented in (2-64)
|
|
@param radix The radix the integer has been represented in (2-64)
|
|
@@ -139,13 +139,13 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*write_radix)(void *a, char *str, int radix);
|
|
int (*write_radix)(void *a, char *str, int radix);
|
|
|
|
|
|
- /** get size as unsigned char string
|
|
|
|
|
|
+ /** get size as unsigned char string
|
|
@param a The integer to get the size (when stored in array of octets)
|
|
@param a The integer to get the size (when stored in array of octets)
|
|
@return The length of the integer
|
|
@return The length of the integer
|
|
*/
|
|
*/
|
|
unsigned long (*unsigned_size)(void *a);
|
|
unsigned long (*unsigned_size)(void *a);
|
|
|
|
|
|
- /** store an integer as an array of octets
|
|
|
|
|
|
+ /** store an integer as an array of octets
|
|
@param src The integer to store
|
|
@param src The integer to store
|
|
@param dst The buffer to store the integer in
|
|
@param dst The buffer to store the integer in
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
@@ -154,15 +154,15 @@ typedef struct {
|
|
|
|
|
|
/** read an array of octets and store as integer
|
|
/** read an array of octets and store as integer
|
|
@param dst The integer to load
|
|
@param dst The integer to load
|
|
- @param src The array of octets
|
|
|
|
- @param len The number of octets
|
|
|
|
|
|
+ @param src The array of octets
|
|
|
|
+ @param len The number of octets
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
|
|
int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
|
|
|
|
|
|
/* ---- basic math ---- */
|
|
/* ---- basic math ---- */
|
|
|
|
|
|
- /** add two integers
|
|
|
|
|
|
+ /** add two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer
|
|
@param b The second source integer
|
|
@param c The destination of "a + b"
|
|
@param c The destination of "a + b"
|
|
@@ -171,7 +171,7 @@ typedef struct {
|
|
int (*add)(void *a, void *b, void *c);
|
|
int (*add)(void *a, void *b, void *c);
|
|
|
|
|
|
|
|
|
|
- /** add two integers
|
|
|
|
|
|
+ /** add two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param c The destination of "a + b"
|
|
@param c The destination of "a + b"
|
|
@@ -179,7 +179,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*addi)(void *a, unsigned long b, void *c);
|
|
int (*addi)(void *a, unsigned long b, void *c);
|
|
|
|
|
|
- /** subtract two integers
|
|
|
|
|
|
+ /** subtract two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer
|
|
@param b The second source integer
|
|
@param c The destination of "a - b"
|
|
@param c The destination of "a - b"
|
|
@@ -187,7 +187,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*sub)(void *a, void *b, void *c);
|
|
int (*sub)(void *a, void *b, void *c);
|
|
|
|
|
|
- /** subtract two integers
|
|
|
|
|
|
+ /** subtract two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param c The destination of "a - b"
|
|
@param c The destination of "a - b"
|
|
@@ -195,7 +195,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*subi)(void *a, unsigned long b, void *c);
|
|
int (*subi)(void *a, unsigned long b, void *c);
|
|
|
|
|
|
- /** multiply two integers
|
|
|
|
|
|
+ /** multiply two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param c The destination of "a * b"
|
|
@param c The destination of "a * b"
|
|
@@ -203,7 +203,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*mul)(void *a, void *b, void *c);
|
|
int (*mul)(void *a, void *b, void *c);
|
|
|
|
|
|
- /** multiply two integers
|
|
|
|
|
|
+ /** multiply two integers
|
|
@param a The first source integer
|
|
@param a The first source integer
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param b The second source integer (single digit of upto bits_per_digit in length)
|
|
@param c The destination of "a * b"
|
|
@param c The destination of "a * b"
|
|
@@ -227,9 +227,9 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*mpdiv)(void *a, void *b, void *c, void *d);
|
|
int (*mpdiv)(void *a, void *b, void *c, void *d);
|
|
|
|
|
|
- /** divide by two
|
|
|
|
|
|
+ /** divide by two
|
|
@param a The integer to divide (shift right)
|
|
@param a The integer to divide (shift right)
|
|
- @param b The destination
|
|
|
|
|
|
+ @param b The destination
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*div_2)(void *a, void *b);
|
|
int (*div_2)(void *a, void *b);
|
|
@@ -242,7 +242,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*modi)(void *a, unsigned long b, unsigned long *c);
|
|
int (*modi)(void *a, unsigned long b, unsigned long *c);
|
|
|
|
|
|
- /** gcd
|
|
|
|
|
|
+ /** gcd
|
|
@param a The first integer
|
|
@param a The first integer
|
|
@param b The second integer
|
|
@param b The second integer
|
|
@param c The destination for (a, b)
|
|
@param c The destination for (a, b)
|
|
@@ -250,7 +250,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*gcd)(void *a, void *b, void *c);
|
|
int (*gcd)(void *a, void *b, void *c);
|
|
|
|
|
|
- /** lcm
|
|
|
|
|
|
+ /** lcm
|
|
@param a The first integer
|
|
@param a The first integer
|
|
@param b The second integer
|
|
@param b The second integer
|
|
@param c The destination for [a, b]
|
|
@param c The destination for [a, b]
|
|
@@ -260,7 +260,7 @@ typedef struct {
|
|
|
|
|
|
/** Modular multiplication
|
|
/** Modular multiplication
|
|
@param a The first source
|
|
@param a The first source
|
|
- @param b The second source
|
|
|
|
|
|
+ @param b The second source
|
|
@param c The modulus
|
|
@param c The modulus
|
|
@param d The destination (a*b mod c)
|
|
@param d The destination (a*b mod c)
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
@@ -277,7 +277,7 @@ typedef struct {
|
|
|
|
|
|
/** Modular inversion
|
|
/** Modular inversion
|
|
@param a The value to invert
|
|
@param a The value to invert
|
|
- @param b The modulus
|
|
|
|
|
|
+ @param b The modulus
|
|
@param c The destination (1/a mod b)
|
|
@param c The destination (1/a mod b)
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
@@ -286,13 +286,13 @@ typedef struct {
|
|
/* ---- reduction ---- */
|
|
/* ---- reduction ---- */
|
|
|
|
|
|
/** setup montgomery
|
|
/** setup montgomery
|
|
- @param a The modulus
|
|
|
|
- @param b The destination for the reduction digit
|
|
|
|
|
|
+ @param a The modulus
|
|
|
|
+ @param b The destination for the reduction digit
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*montgomery_setup)(void *a, void **b);
|
|
int (*montgomery_setup)(void *a, void **b);
|
|
|
|
|
|
- /** get normalization value
|
|
|
|
|
|
+ /** get normalization value
|
|
@param a The destination for the normalization value
|
|
@param a The destination for the normalization value
|
|
@param b The modulus
|
|
@param b The modulus
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
@@ -310,7 +310,7 @@ typedef struct {
|
|
/** clean up (frees memory)
|
|
/** clean up (frees memory)
|
|
@param a The value "b" from montgomery_setup()
|
|
@param a The value "b" from montgomery_setup()
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
- */
|
|
|
|
|
|
+ */
|
|
void (*montgomery_deinit)(void *a);
|
|
void (*montgomery_deinit)(void *a);
|
|
|
|
|
|
/* ---- exponentiation ---- */
|
|
/* ---- exponentiation ---- */
|
|
@@ -336,14 +336,14 @@ typedef struct {
|
|
/** ECC GF(p) point multiplication (from the NIST curves)
|
|
/** ECC GF(p) point multiplication (from the NIST curves)
|
|
@param k The integer to multiply the point by
|
|
@param k The integer to multiply the point by
|
|
@param G The point to multiply
|
|
@param G The point to multiply
|
|
- @param R The destination for kG
|
|
|
|
|
|
+ @param R The destination for kG
|
|
@param modulus The modulus for the field
|
|
@param modulus The modulus for the field
|
|
@param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
|
|
@param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
|
int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
|
|
|
|
|
- /** ECC GF(p) point addition
|
|
|
|
|
|
+ /** ECC GF(p) point addition
|
|
@param P The first point
|
|
@param P The first point
|
|
@param Q The second point
|
|
@param Q The second point
|
|
@param R The destination of P + Q
|
|
@param R The destination of P + Q
|
|
@@ -353,7 +353,7 @@ typedef struct {
|
|
*/
|
|
*/
|
|
int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
|
|
int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
|
|
|
|
|
|
- /** ECC GF(p) point double
|
|
|
|
|
|
+ /** ECC GF(p) point double
|
|
@param P The first point
|
|
@param P The first point
|
|
@param R The destination of 2P
|
|
@param R The destination of 2P
|
|
@param modulus The modulus
|
|
@param modulus The modulus
|
|
@@ -367,7 +367,7 @@ typedef struct {
|
|
@param modulus The modulus
|
|
@param modulus The modulus
|
|
@param mp The "b" value from montgomery_setup()
|
|
@param mp The "b" value from montgomery_setup()
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
- @remark The mapping can be different but keep in mind a ecc_point only has three
|
|
|
|
|
|
+ @remark The mapping can be different but keep in mind a ecc_point only has three
|
|
integers (x,y,z) so if you use a different mapping you have to make it fit.
|
|
integers (x,y,z) so if you use a different mapping you have to make it fit.
|
|
*/
|
|
*/
|
|
int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
|
|
int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
|
|
@@ -378,9 +378,9 @@ typedef struct {
|
|
@param B Second point to multiply
|
|
@param B Second point to multiply
|
|
@param kB What to multiple B by
|
|
@param kB What to multiple B by
|
|
@param C [out] Destination point (can overlap with A or B
|
|
@param C [out] Destination point (can overlap with A or B
|
|
- @param modulus Modulus for curve
|
|
|
|
|
|
+ @param modulus Modulus for curve
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
- */
|
|
|
|
|
|
+ */
|
|
int (*ecc_mul2add)(ecc_point *A, void *kA,
|
|
int (*ecc_mul2add)(ecc_point *A, void *kA,
|
|
ecc_point *B, void *kB,
|
|
ecc_point *B, void *kB,
|
|
ecc_point *C,
|
|
ecc_point *C,
|
|
@@ -388,7 +388,7 @@ typedef struct {
|
|
|
|
|
|
/* ---- (optional) rsa optimized math (for internal CRT) ---- */
|
|
/* ---- (optional) rsa optimized math (for internal CRT) ---- */
|
|
|
|
|
|
- /** RSA Key Generation
|
|
|
|
|
|
+ /** RSA Key Generation
|
|
@param prng An active PRNG state
|
|
@param prng An active PRNG state
|
|
@param wprng The index of the PRNG desired
|
|
@param wprng The index of the PRNG desired
|
|
@param size The size of the modulus (key size) desired (octets)
|
|
@param size The size of the modulus (key size) desired (octets)
|
|
@@ -397,7 +397,7 @@ typedef struct {
|
|
@return CRYPT_OK if successful, upon error all allocated ram is freed
|
|
@return CRYPT_OK if successful, upon error all allocated ram is freed
|
|
*/
|
|
*/
|
|
int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
|
|
int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
/** RSA exponentiation
|
|
/** RSA exponentiation
|
|
@param in The octet array representing the base
|
|
@param in The octet array representing the base
|
|
@@ -405,7 +405,7 @@ typedef struct {
|
|
@param out The destination (to be stored in an octet array format)
|
|
@param out The destination (to be stored in an octet array format)
|
|
@param outlen The length of the output buffer and the resulting size (zero padded to the size of the modulus)
|
|
@param outlen The length of the output buffer and the resulting size (zero padded to the size of the modulus)
|
|
@param which PK_PUBLIC for public RSA and PK_PRIVATE for private RSA
|
|
@param which PK_PUBLIC for public RSA and PK_PRIVATE for private RSA
|
|
- @param key The RSA key to use
|
|
|
|
|
|
+ @param key The RSA key to use
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
*/
|
|
*/
|
|
int (*rsa_me)(const unsigned char *in, unsigned long inlen,
|
|
int (*rsa_me)(const unsigned char *in, unsigned long inlen,
|
|
@@ -416,7 +416,7 @@ typedef struct {
|
|
|
|
|
|
/** Modular addition
|
|
/** Modular addition
|
|
@param a The first source
|
|
@param a The first source
|
|
- @param b The second source
|
|
|
|
|
|
+ @param b The second source
|
|
@param c The modulus
|
|
@param c The modulus
|
|
@param d The destination (a + b mod c)
|
|
@param d The destination (a + b mod c)
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|
|
@@ -425,7 +425,7 @@ typedef struct {
|
|
|
|
|
|
/** Modular substraction
|
|
/** Modular substraction
|
|
@param a The first source
|
|
@param a The first source
|
|
- @param b The second source
|
|
|
|
|
|
+ @param b The second source
|
|
@param c The modulus
|
|
@param c The modulus
|
|
@param d The destination (a - b mod c)
|
|
@param d The destination (a - b mod c)
|
|
@return CRYPT_OK on success
|
|
@return CRYPT_OK on success
|