-
Notifications
You must be signed in to change notification settings - Fork 145
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
Implement NTRU Prime #384
base: main
Are you sure you want to change the base?
Implement NTRU Prime #384
Conversation
Thank you for this, we will have a look. That might take some time. Where does this implementation come from? Did you implement it yourself from the spec or did you transliterate an existing implementation? |
Early comment: I see you use quite a lot of allocations:
Those should be around 1-5. For comparison:
Also, the operations are very slow compared to the cycle counts given in the round 3 submission. That one uses AVX2 intrinsics, but the difference is bigger than can be explained by that. |
I have translated it directly from the C reference/optimized implementation. |
Noted, I am having a look at it. I will revert back to you afterwards. |
I have managed to cut down the number of allocations.
The number of allocations for streamlined NTRU prime is given below:
I have identified that the remaining allocations come mostly from the the following functions:
Could I ask you to provide pointers on how to optimize these functions please? |
Then you should appropriately attribute the original. |
Are you familiar with Go's heap escape mechanism? Typically allocations can be removed by avoiding interfaces, function types and having the caller allocate values. For an example of the latter: func Pack(something T) []byte {
ret := make([]byte, 123)
// write into ret
return ret
} will have an unavoidable allocation, whereas func Pack(ret []byte, something T) {
// write into ret
}
func SomeOtherFunc() {
var something T
// ...
out := make([]byte, 123)
Pack(out, something)
} will not. |
@Keelan10 could you please format the files so the linter checks passes. |
I added it to the doc.go file.
Thank you for this. |
Yes, I have formatted the files accordingly. Thanks. |
After optimizing the Encode function, the number of allocations is as follows:
Also, I am not sure how to optimize the Decode function and any suggestion would be greatly appreciated. Thank you. |
Hello,
This is a draft of NTRU Prime which implements all the parameters specified in the round 3 submission.
It passes the KAT tests provided in the NIST submission package.
Thanks for reviewing the PR!