Skip to content

crypto.ecdsa: fix bug when signing with .with_no_hash options. - #23612

Merged
spytheman merged 1 commit into
vlang:masterfrom
blackshirt:ext_ecdsa
Jan 30, 2025
Merged

spytheman merged 1 commit into
vlang:masterfrom
blackshirt:ext_ecdsa

Conversation

@blackshirt

@blackshirt blackshirt commented Jan 30, 2025 •

Copy link
Copy Markdown
Contributor

This PR contains small fix bug when signing message with .with_no_hash options. The bug more clearly self-explained in this snippet

import crypto.ecdsa

fn main() {
        // default prime256v1 key was 32 bytes length
	pv := ecdsa.PrivateKey.new()!
        // creates message with length over key size
	msg_a := 'a'.repeat(34).bytes()
	opt := ecdsa.SignerOpts{
		hash_config: .with_no_hash
	}
	signed := pv.sign(msg_a, opt)!
	pb := pv.public_key()!
	st := pb.verify(msg_a, signed, opt)!
        // this should be true
	dump(st) 

	// different msg should not be verified under the same signature.
	msg_b := 'a'.repeat(392).bytes()
	ds := pb.verify(msg_b, signed, opt)!

	// should false
	dump(ds)
}

but the output was

[code.v:14] st: true
[code.v:19] ds: true

Its changed .with_no_hash to have the same behaviour with .with_recommended_hash. Its can be deprecated on next cycled.

Thanks

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-22037

@blackshirt

Copy link
Copy Markdown
Contributor Author

@spytheman : why the old commit 23612 thats already merged still included in this queue of PR ?

@spytheman

Copy link
Copy Markdown
Contributor

@spytheman : why the old commit 23612 thats already merged still included in this queue of PR ?

Most likely because you continued your development over the same branch, or on a new branch, based on the old.

You can try doing: git pull --rebase origin master, then git push -f, while being on your ext_ecdsa branch locally, to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants