mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
caac02a77b
2/2 Added vendor/ dir to lock down dependent pkg versions. The author of git.schwanenlied.me/yawning/{chacha20,newhope,kyber}.git has copied their repos to gitlab.com/yawning/ but some imports of chacha20 from newhope still inconsistently refer to git.schwanenlied.me/, breaking build. Licenses for chacha20 also changed from CC0 to AGPL, which may or may not be an issue. Until the two aforementioned issues are resolved, locking to last-good versions is probably the best way forward for now. To build with vendored deps, use make VENDOR=1 clean all
32 lines
807 B
Go
32 lines
807 B
Go
// poly.go - NewHope reductions.
|
|
//
|
|
// To the extent possible under law, Yawning Angel has waived all copyright
|
|
// and related or neighboring rights to newhope, using the Creative
|
|
// Commons "CC0" public domain dedication. See LICENSE or
|
|
// <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
|
|
|
|
package newhope
|
|
|
|
// Incomplete-reduction routines; for details on allowed input ranges
|
|
// and produced output ranges, see the description in the paper:
|
|
// https://cryptojedi.org/papers/#newhope
|
|
|
|
const (
|
|
qinv = 12287 // -inverse_mod(p,2^18)
|
|
rlog = 18
|
|
)
|
|
|
|
func montgomeryReduce(a uint32) uint16 {
|
|
u := a * qinv
|
|
u &= ((1 << rlog) - 1)
|
|
u *= paramQ
|
|
a = (a + u) >> 18
|
|
return uint16(a)
|
|
}
|
|
|
|
func barrettReduce(a uint16) uint16 {
|
|
u := (uint32(a) * 5) >> 16
|
|
u *= paramQ
|
|
a -= uint16(u)
|
|
return a
|
|
}
|