|
|
@ -4,8 +4,8 @@ |
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/ |
|
|
|
**********************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SECP256K1_ECKEY_IMPL_H_ |
|
|
|
#ifndef SECP256K1_ECKEY_IMPL_H |
|
|
|
#define _SECP256K1_ECKEY_IMPL_H_ |
|
|
|
#define SECP256K1_ECKEY_IMPL_H |
|
|
|
|
|
|
|
|
|
|
|
#include "eckey.h" |
|
|
|
#include "eckey.h" |
|
|
|
|
|
|
|
|
|
|
@ -15,16 +15,17 @@ |
|
|
|
#include "ecmult_gen.h" |
|
|
|
#include "ecmult_gen.h" |
|
|
|
|
|
|
|
|
|
|
|
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) { |
|
|
|
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) { |
|
|
|
if (size == 33 && (pub[0] == 0x02 || pub[0] == 0x03)) { |
|
|
|
if (size == 33 && (pub[0] == SECP256K1_TAG_PUBKEY_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_ODD)) { |
|
|
|
secp256k1_fe x; |
|
|
|
secp256k1_fe x; |
|
|
|
return secp256k1_fe_set_b32(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == 0x03); |
|
|
|
return secp256k1_fe_set_b32(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == SECP256K1_TAG_PUBKEY_ODD); |
|
|
|
} else if (size == 65 && (pub[0] == 0x04 || pub[0] == 0x06 || pub[0] == 0x07)) { |
|
|
|
} else if (size == 65 && (pub[0] == 0x04 || pub[0] == 0x06 || pub[0] == 0x07)) { |
|
|
|
secp256k1_fe x, y; |
|
|
|
secp256k1_fe x, y; |
|
|
|
if (!secp256k1_fe_set_b32(&x, pub+1) || !secp256k1_fe_set_b32(&y, pub+33)) { |
|
|
|
if (!secp256k1_fe_set_b32(&x, pub+1) || !secp256k1_fe_set_b32(&y, pub+33)) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
secp256k1_ge_set_xy(elem, &x, &y); |
|
|
|
secp256k1_ge_set_xy(elem, &x, &y); |
|
|
|
if ((pub[0] == 0x06 || pub[0] == 0x07) && secp256k1_fe_is_odd(&y) != (pub[0] == 0x07)) { |
|
|
|
if ((pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD) && |
|
|
|
|
|
|
|
secp256k1_fe_is_odd(&y) != (pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return secp256k1_ge_is_valid_var(elem); |
|
|
|
return secp256k1_ge_is_valid_var(elem); |
|
|
@ -42,10 +43,10 @@ static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *p |
|
|
|
secp256k1_fe_get_b32(&pub[1], &elem->x); |
|
|
|
secp256k1_fe_get_b32(&pub[1], &elem->x); |
|
|
|
if (compressed) { |
|
|
|
if (compressed) { |
|
|
|
*size = 33; |
|
|
|
*size = 33; |
|
|
|
pub[0] = 0x02 | (secp256k1_fe_is_odd(&elem->y) ? 0x01 : 0x00); |
|
|
|
pub[0] = secp256k1_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
*size = 65; |
|
|
|
*size = 65; |
|
|
|
pub[0] = 0x04; |
|
|
|
pub[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED; |
|
|
|
secp256k1_fe_get_b32(&pub[33], &elem->y); |
|
|
|
secp256k1_fe_get_b32(&pub[33], &elem->y); |
|
|
|
} |
|
|
|
} |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
@ -96,4 +97,4 @@ static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif /* SECP256K1_ECKEY_IMPL_H */ |
|
|
|