jedisct1 / rust-blind-rsa-signatures

RSA blind signatures in Rust
MIT License
26 stars 12 forks source link

Pad computation results to the required length. #5

Closed gabi-250 closed 2 years ago

gabi-250 commented 2 years ago

I noticed pk.finalize() occasionally (and for no apparent reason) returns an UnsupportedParameters error, instead of the Ok result I would expect.

I don't have a minimal reproducible example I can share yet, but here are the steps I took to reproduce the issue:

This is what I think happens:

This patch fixes the problem for me (the solution seems to be to pad any vectors obtained using to_bytes_be to have a length of modulus_bytes).

jedisct1 commented 2 years ago

Good catch.

The Zig implementation doesn't have this issue since it defines a bn2binPadded() function for this.

Instead of adding zero_left_pad() calls, maybe it would be less error-prone to do something similar, and define a to_bytes_be_padded() function instead. That can be implemented as a trait.

gabi-250 commented 2 years ago

@jedisct1 Thank you for the review!

I addressed your comment in a separate commit, but I'm happy to squash it before merging.

jedisct1 commented 2 years ago

Looking good!

Thank you so much for this, Gabi!