Skip to content
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

Prevent panic when creating a Schnorr from slice #1056

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

germanop
Copy link
Contributor

If you pass a byte slice shorter than 32 bytes to Schnorr's Signature::try_from, it panics.

There is a unit test as first commit to test behaviour before and after the fix.

An easy fix would have been to check in try_from if the slice was shorted than Self::BYTES / 2 but this patch makes it more similar to bign256 and sm2.

germanop added 2 commits June 20, 2024 16:57
…nature

Introduced new safe builders, same as bign256 and sm2:
- `split_at` can panic if it receives a slice shorter than `Self::BYTES / 2`
- `split_at` is now use in the new `from_bytes` that accepts only byte arrays
  or the right size
- `from_slice` uses a safe conversion that does not panic when the slice is too short
- `try_from` slice uses `from_slice` internally, so it does not panic when a short slice
  is passed
- introduce safe type conversion from SignatureBytes
@germanop germanop force-pushed the schnorr_try_from_panic branch from 5b875c1 to a62494e Compare June 20, 2024 16:56
@tarcieri tarcieri merged commit bb1ee04 into RustCrypto:master Jun 28, 2024
19 checks passed
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