Changed the conversion function names. Added usage note to the read me.

This commit is contained in:
Ken MacKay
2013-06-30 11:11:39 -07:00
parent abe93b0b75
commit ac0d7a3fab
3 changed files with 15 additions and 13 deletions
+2
View File
@@ -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};`. 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 #### #### 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 <n>` to generate n 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 <n>` to generate n keys.
+7 -7
View File
@@ -1495,25 +1495,25 @@ int ecdsa_verify(EccPoint *p_publicKey, uint32_t p_hash[NUM_ECC_DIGITS], uint32_
return (vli_cmp(rx, r) == 0); 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; unsigned i;
for(i=0; i<NUM_ECC_DIGITS; ++i) for(i=0; i<NUM_ECC_DIGITS; ++i)
{ {
uint8_t *p_digit = p_bytes + 4 * (NUM_ECC_DIGITS - 1 - i); uint8_t *p_digit = p_bytes + 4 * (NUM_ECC_DIGITS - 1 - i);
p_int[i] = (p_digit[0] << 24) | (p_digit[1] << 16) | (p_digit[2] << 8) | p_digit[3]; p_native[i] = (p_digit[0] << 24) | (p_digit[1] << 16) | (p_digit[2] << 8) | p_digit[3];
} }
} }
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])
{ {
unsigned i; unsigned i;
for(i=0; i<NUM_ECC_DIGITS; ++i) for(i=0; i<NUM_ECC_DIGITS; ++i)
{ {
uint8_t *p_digit = p_bytes + 4 * (NUM_ECC_DIGITS - 1 - i); uint8_t *p_digit = p_bytes + 4 * (NUM_ECC_DIGITS - 1 - i);
p_digit[0] = p_int[i] >> 24; p_digit[0] = p_native[i] >> 24;
p_digit[1] = p_int[i] >> 16; p_digit[1] = p_native[i] >> 16;
p_digit[2] = p_int[i] >> 8; p_digit[2] = p_native[i] >> 8;
p_digit[3] = p_int[i]; p_digit[3] = p_native[i];
} }
} }
+6 -6
View File
@@ -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]); 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. Convert an integer in standard octet representation to the native format.
Outputs: Outputs:
p_int - Will be filled in with the native integer value. p_native - Will be filled in with the native integer value.
Inputs: Inputs:
p_bytes - The standard octet representation of the integer to convert. 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. Convert an integer in native format to the standard octet representation.
Outputs: Outputs:
p_bytes - Will be filled in with the standard octet representation of the integer. p_bytes - Will be filled in with the standard octet representation of the integer.
Inputs: 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_ */ #endif /* _MICRO_ECC_H_ */