diff --git a/README.md b/README.md index d5d19f8..64aff73 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Usage Notes To reduce code size, all large integers are represented using little-endian words - so the least significant word is first. For example, the standard representation of the prime modulus for the curve secp128r1 is `FFFFFFFD FFFFFFFF FFFFFFFF FFFFFFFF`; in micro-ecc, this would be represented as `uint32_t p[4] = {0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffd};`. +You can use the `ecc_bytes2native()` and `ecc_native2bytes()` functions to convert between the native integer representation and the standardized octet representation. + #### Generating Keys #### You can use the `makekeys` program in the `apps` directory to generate keys (on Linux or OS X). You can run `make` in that directory to build for your native platform (or use [emk](http://kmackay.ca/emk)). To generate a single public/private key pair, run `makekeys`. It will print out the public and private keys in a representation suitable to be copied into your source code. You can generate multiple key pairs at once using `makekeys ` to generate n keys. diff --git a/ecc.c b/ecc.c index 7453e40..91f2411 100644 --- a/ecc.c +++ b/ecc.c @@ -1495,25 +1495,25 @@ int ecdsa_verify(EccPoint *p_publicKey, uint32_t p_hash[NUM_ECC_DIGITS], uint32_ return (vli_cmp(rx, r) == 0); } -void ecc_bytes2int(uint32_t p_int[NUM_ECC_DIGITS], uint8_t p_bytes[NUM_ECC_DIGITS*4]) +void ecc_bytes2native(uint32_t p_native[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]; + p_digit[0] = p_native[i] >> 24; + p_digit[1] = p_native[i] >> 16; + p_digit[2] = p_native[i] >> 8; + p_digit[3] = p_native[i]; } } diff --git a/ecc.h b/ecc.h index 59b2146..39f4fc5 100644 --- a/ecc.h +++ b/ecc.h @@ -130,26 +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. +/* ecc_bytes2native() function. Convert an integer in standard octet representation to the native format. Outputs: - p_int - Will be filled in with the native integer value. + p_native - 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]); +void ecc_bytes2native(uint32_t p_native[NUM_ECC_DIGITS], uint8_t p_bytes[NUM_ECC_DIGITS*4]); -/* ecc_int2bytes() function. +/* ecc_native2bytes() 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. + p_native - The native integer value to convert. */ -void ecc_int2bytes(uint8_t p_bytes[NUM_ECC_DIGITS*4], uint32_t p_int[NUM_ECC_DIGITS]); +void ecc_native2bytes(uint8_t p_bytes[NUM_ECC_DIGITS*4], uint32_t p_native[NUM_ECC_DIGITS]); #endif /* _MICRO_ECC_H_ */