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

Negative BigInt should be an error #107

Open
survived opened this issue Feb 12, 2021 · 0 comments
Open

Negative BigInt should be an error #107

survived opened this issue Feb 12, 2021 · 0 comments

Comments

@survived
Copy link
Contributor

We use BigInt mostly in modular arithmetic where there's no negative numbers. However, negative BigInt can be mistakenly constructed and cause a wrong behaviour.

One way to work around this problem would be replacing BigInt with BigUint that has no sign. Achieving negative number (e.g. BigUint::zero() - BigUint::one()) would cause a panic. But this is not a reliable solution for cryptographic library.

Better option would be allowing BigInt to participate only in modular arithmetic operations. I.e. arithmetic expression should not be evaluated unless module value is specified. This reminds me a lazy evaluation from functional world. I've wrote a simple PoC: here.

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

No branches or pull requests

1 participant