-
Notifications
You must be signed in to change notification settings - Fork 17
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
add sign and verify test vectors #292
Conversation
this pr goes along with this one - decentralized-identity/web5-spec#172 |
private val rustCoreVerifier: RustCoreEd25519Verifier | ||
|
||
constructor(privateKey: Jwk) { | ||
this.rustCoreVerifier = RustCoreEd25519Verifier(privateKey) |
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.
I think with the latest on main
you'll need to rebase and then this'll be...
this.rustCoreVerifier = RustCoreEd25519Verifier(privateKey) | |
this.rustCoreVerifier = RustCoreEd25519Verifier(privateKey.rustCoreJwkData) |
val key: TestVectorJwk, | ||
) | ||
|
||
data class TestVectorJwk( |
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.
I know we're not testing the JWK in this test, but ideally we could use the real Jwk
, but to your point on the other PR, we may need to add #297 first?
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.
yup after 297 is in we can use it
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.
well done! I added one comment with respect to rebasing onto main
which needs addressed but after that this is good to go!
let signature = result.expect("Signing should not fail"); | ||
|
||
// Convert the signature to a hex string | ||
let signature_hex = byte_array_to_hex_string(&signature); |
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.
I'm surprised this works. ed25519 signatures are different every time because they use a random nonce to prevent computing the private key if the same private key is used for multiple signatures
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.
oh no..
This works in every sdk
Are we doing something wrong lol, let me check on this..
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.
I think we are good - https://cryptobook.nakov.com/digital-signatures/eddsa-and-ed25519
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.
see Section 4.2.5 on Deterministic Nonce Generation
Ed25519 uses deterministic signing which removes the need for fresh random numbers during the signing process. This does not lead to any particular consequences for our security analysis since we model the key derivation function as a random oracle. However, it is well known not to reduce security
|
||
let result = verifier.verify(&data, &signature); | ||
|
||
let is_valid = result.expect("Verification should not fail"); |
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.
what's the difference between Err() and Ok(false) for verifier.verify
?
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.
chad says:
Ok(false): The operation itself succeeded, but the verification result is false. This means that the signature is valid in terms of format and process, but it does not match the data or is otherwise invalid according to the verification logic.
and yea then err is an exception basically if I'm understnading rust correctly
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.
oh and as far as the implementation yea just verified false is invalid signature vs catastrophic failure
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.
Updating web5-spec and adding ed25519 test vectors