mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
Merge pull request #1 from mogorman/master
added support for getting public key from a private key.
This commit is contained in:
commit
1f75cd031b
20
ecdsa.c
20
ecdsa.c
@ -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[1] = i;
|
||||||
*sig_len = i + 2;
|
*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);
|
||||||
|
}
|
||||||
|
|
||||||
|
1
ecdsa.h
1
ecdsa.h
@ -28,5 +28,6 @@
|
|||||||
|
|
||||||
// uses secp256k1 curve
|
// 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_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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user