From abe93b0b75ea502419b4c8685094d34a2d24194e Mon Sep 17 00:00:00 2001 From: Ken MacKay Date: Sun, 30 Jun 2013 11:01:13 -0700 Subject: [PATCH] Added functions for conversion to and from standard octet representation for integers. --- ecc.c | 23 +++++++++++++++++++++++ ecc.h | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ecc.c b/ecc.c index d985566..7453e40 100644 --- a/ecc.c +++ b/ecc.c @@ -1494,3 +1494,26 @@ int ecdsa_verify(EccPoint *p_publicKey, uint32_t p_hash[NUM_ECC_DIGITS], uint32_ /* Accept only if v == r. */ return (vli_cmp(rx, r) == 0); } + +void ecc_bytes2int(uint32_t p_int[NUM_ECC_DIGITS], uint8_t p_bytes[NUM_ECC_DIGITS*4]) +{ + unsigned i; + for(i=0; i> 24; + p_digit[1] = p_int[i] >> 16; + p_digit[2] = p_int[i] >> 8; + p_digit[3] = p_int[i]; + } +} diff --git a/ecc.h b/ecc.h index db71f2c..59b2146 100644 --- a/ecc.h +++ b/ecc.h @@ -30,7 +30,7 @@ with strange assembler messages. #define secp256r1 8 #define secp384r1 12 #ifndef ECC_CURVE - #define ECC_CURVE secp192r1 + #define ECC_CURVE secp256r1 #endif #if (ECC_CURVE != secp128r1 && ECC_CURVE != secp192r1 && ECC_CURVE != secp256r1 && ECC_CURVE != secp384r1) @@ -130,4 +130,26 @@ Returns 1 if the signature is valid, 0 if it is invalid. */ int ecdsa_verify(EccPoint *p_publicKey, uint32_t p_hash[NUM_ECC_DIGITS], uint32_t r[NUM_ECC_DIGITS], uint32_t s[NUM_ECC_DIGITS]); +/* ecc_bytes2int() function. +Convert an integer in standard octet representation to the native format. + +Outputs: + p_int - Will be filled in with the native integer value. + +Inputs: + p_bytes - The standard octet representation of the integer to convert. +*/ +void ecc_bytes2int(uint32_t p_int[NUM_ECC_DIGITS], uint8_t p_bytes[NUM_ECC_DIGITS*4]); + +/* ecc_int2bytes() function. +Convert an integer in native format to the standard octet representation. + +Outputs: + p_bytes - Will be filled in with the standard octet representation of the integer. + +Inputs: + p_int - The native integer value to convert. +*/ +void ecc_int2bytes(uint8_t p_bytes[NUM_ECC_DIGITS*4], uint32_t p_int[NUM_ECC_DIGITS]); + #endif /* _MICRO_ECC_H_ */