1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00

Merge pull request #1 from mogorman/master

added support for getting public key from a private key.
This commit is contained in:
Pavol Rusnak 2013-09-05 03:38:27 -07:00
commit 1f75cd031b
2 changed files with 21 additions and 0 deletions

20
ecdsa.c
View File

@ -513,3 +513,23 @@ void ecdsa_sign(uint8_t *priv_key, uint8_t *msg, uint32_t msg_len, uint8_t *sig,
sig[1] = i;
*sig_len = i + 2;
}
void ecdsa_pubkey(uint8_t *priv_key, uint8_t *public_key_x, uint8_t *public_key_y)
{
uint32_t i;
uint64_t temp;
curve_point G;
bignum256 da;
temp = 0;
for (i = 0; i < 8; i++) {
temp += (((uint64_t)read_be(priv_key + (7 - i) * 4)) << (2 * i));
da.val[i] = temp & 0x3FFFFFFF;
temp >>= 30;
}
da.val[8] = temp;
scalar_multiply(&da, &G);
write_der(&G.x, public_key_x);
write_der(&G.y, public_key_y);
}

View File

@ -28,5 +28,6 @@
// uses secp256k1 curve
void ecdsa_sign(uint8_t *priv_key, uint8_t *msg, uint32_t msg_len, uint8_t *sig, uint32_t *sig_len);
void ecdsa_pubkey(uint8_t *priv_key, uint8_t *public_key_x, uint8_t *public_key_y);
#endif