Commit 92ce32a
authored
fix: Enforce byte input length for the given prime field (#50)
Before this change, we were enforcing only the upper limit of the byte
input lenghts in `hash_bytes_be` and `hash_bytes_le` methods. The limit
is indicated by the amount of bytes needed to represent the modulus of
the given prime field. For the `Fr` field, the limit is 32 bytes.
At the same time, we were allowing smaller byte slices. For example,
we were allowing either a full 32-byte array with explicit padding:
```
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1
]
```
Or smaller arrays with smaller amount of leading or trailing bytes
(depending on endianness):
```
[0, 0, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 1]
[0, 1]
[1]
```
All these inputs produce the same hashes.
To avoid confusion, do not allow smaller inputs the modulus and make
padding mandatory.1 parent 50b40cb commit 92ce32a
2 files changed
Lines changed: 220 additions & 140 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
462 | | - | |
| 462 | + | |
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| |||
0 commit comments