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

Why the result of barrett_reduce is in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q? #64

Open
sduyyy opened this issue Oct 12, 2023 · 3 comments

Comments

@sduyyy
Copy link

sduyyy commented Oct 12, 2023

In the history implementation of barrett_reduce function, the output is in {0,...,q} congruent to a modulo q.
But in Commits on Nov 20, 2020, the output of barrett_reduce is in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q.
Why is it modified like this?

@sduyyy
Copy link
Author

sduyyy commented Oct 12, 2023

In addition, what is the input range?

@vincentvbh
Copy link

Hi, if I remember correctly, literature shows that signed arithmetic is faster for this size of modular arithmetic. For example, there are instructions smmulr in Armv7E-M and vpmulhrsw in AVX2. Both of them operate on signed inputs, and there is no unsigned counterparts.

However, I'm not sure if this is the reason for the changes. Maybe others working Kyber already can answer this.

@ronhombre
Copy link

I made an implementation in pure Kotlin. I even added Barrett and Montgomery reductions, but I still don't know why. All my functions work in the unsigned space only. Maybe it's worth it to dig through the commit history.

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

3 participants