Skip to content

Commit

Permalink
Changed the conversion function names. Added usage note to the read me.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken MacKay committed Jun 30, 2013
1 parent abe93b0 commit ac0d7a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <n>` to generate n keys.
Expand Down
14 changes: 7 additions & 7 deletions ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<NUM_ECC_DIGITS; ++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;
for(i=0; i<NUM_ECC_DIGITS; ++i)
{
uint8_t *p_digit = p_bytes + 4 * (NUM_ECC_DIGITS - 1 - i);
p_digit[0] = p_int[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];
}
}
12 changes: 6 additions & 6 deletions ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit ac0d7a3

Please sign in to comment.