-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust 2018 & secp256k1 improvements #61
base: master
Are you sure you want to change the base?
Conversation
What is the impact of this change? looks like you created more LOC |
@omershlo And some |
ready to review & merge |
I don't think replacing |
"explicit is better than implicit" |
Some(BigInt::from(&y_vec[..])) | ||
} | ||
|
||
fn from_bytes(bytes: &[u8]) -> Result<Secp256k1Point, ErrorKey> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function may be the most refactored one, the logic is basically the same, except directly sending 65 or 33 bytes to secp256k1 lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for > 65 bytes input, the necessity of taking its first 64 bytes should be reconsidered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though I just keep the logic as same as before
v.extend(BigInt::to_vec(&self.y_coor().unwrap())); | ||
v | ||
fn pk_to_key_slice(&self) -> Vec<u8> { | ||
self.ge.serialize_uncompressed().to_vec() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less computation but the vec length should always be 65 bytes
} | ||
} | ||
} | ||
|
||
static mut CONTEXT: Option<Secp256k1<VerifyOnly>> = None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced by lazy_static
@@ -97,19 +108,16 @@ impl Zeroize for Secp256k1Scalar { | |||
} | |||
|
|||
impl ECScalar<SK> for Secp256k1Scalar { | |||
fn new_random() -> Secp256k1Scalar { | |||
let mut arr = [0u8; 32]; | |||
thread_rng().fill(&mut arr[..]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the private key may not be valid, should just use library's new
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the probability of getting invalid key is not high, but it's not zero
ECPoint::add_point(self, &minus_point.get_element()) | ||
} | ||
|
||
fn from_coor(x: &BigInt, y: &BigInt) -> Secp256k1Point { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another function replaced by succinct refactored version
I've added some notes on the part with possible logic change |
@omershlo |
sure |
fix #62