-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix #66 reverse_k
signature digest
#67
Conversation
msg_scalar
with k_digest
msg_scalar
The most recent commit adds All of the tests pass again but there are still two outstanding issues Signature verificationSignatures produced with a reversed digest still can't be verified by their signer because the function called by InterpreterThe multisig tests in |
Fixed the outstanding issues in |
msg_scalar
reverse_k
signature digest
I do like this PR, while I do have some concerns about the changes to the API for backwards compatibility's sake, I dont mind adding another flag to the already low level ECDSA functions. What about instead of adding a reverse_k boolean to the function signature, you create a new enum and do something like Option where DigestOptions is an enum such as DigestOptions::ReverseK This way you can tweak the ECDSA method as you need but if you pass None to the function call, it acts as it does currently and is thus at least functionally backwards compatible? |
Totally agree this should all be opt-in. I added a These two function will still need flags though since their impls are
I went ahead & implemented them as you suggested
|
Hmm that's an interesting option to add new functions. If we do go that route, I do have a request that kind of adds some scope but @deanmlittle brought up with me during some quick discussions. He mentioned instead of the library reversing anything, you should be passing digests in already formatted how you need them to be. Do you think it would be worth adding a new function to handle that case? @deanmlittle did I explain what you had in mind accurately enough? |
I like the idea of handling digests outside the library. Would you like to keep the existing functions unchanged & add new functions that accept the digest directly? How would we handle functions that call As for the digests I think a good option would be to implement them as an associated trait type of vecs & slices. Something like this pub trait ToDigest {
type HashDigest: digest::FixedOutput<OutputSize = digest::consts::U32>
+ digest::BlockInput
+ Clone
+ Default
+ digest::Reset
+ digest::Update
+ FixedOutput
+ ReversibleDigest;
fn to_digest(&self, hash_algo: SigningHash, reverse: bool) -> Self::HashDigest;
}
impl<T> ToDigest for T
where
T: AsRef<[u8]>,
{
type HashDigest = Sha256r;
fn to_digest(&self, hash_algo: SigningHash, reverse: bool) -> Self::HashDigest {
let d = match hash_algo {
SigningHash::Sha256 => Digest::chain(Self::HashDigest::default(), self.as_ref()),
SigningHash::Sha256d => Digest::chain(Self::HashDigest::default(), Self::HashDigest::digest(self.as_ref())),
};
match reverse {
true => d.reverse(),
false => d,
}
}
} Then you could just go let message = b"Hello";
let digest = message.to_digest(SigningHash::Sha256d, true); |
I do really like your trait idea. Not sure how that would work in Javascript but worth playing around with. I think lets go with a fresh function call for externally created digests, we can figure out what to do with the other functions later based on usage. Thanks again for your input! |
This reverts commit 236df59.
DigestAction
enum to handle the byte order of thek_digest
andmsg_scalar
during ECDSA sign/verifySighashSignature::from_der_impl
now checks the sig length before attempting to remove the sighash bytechecksig
andmultisig
will verify the reverse digest ifverify_tx_signature
fails the first time. This guarantees that the interpreter can validate signatures regardless of the byte order used for the digest