Try   HackMD

Barrett Reduction

Barrett reduction allows us to quickly calculate the quotient

q and reminder
r
of
a(modn)
, i.e.
a=qn+r,0r<n
.

GLV

One of the use case is in GLV decomposition. For simplicity, we consider all the integers below are less than

2256. We want to decompose
k=k1+k2λ
with both
k1,k2
are small. Here is the correspondence
ka,k1r,k2q,λn

When

λ is
128
bit, we can use Barrett reduction to derive
k1,k2
with
k1<2128,k2<2128
.

In the glv paper, it considers more general case where

λ might not be
128
bit and hence use lattice based algorithm to derive small
k1,k2
(which might not less than
2128
)

Barrett Reduction Algorithm

In practice, We use

β=2128 (or
2c
in general) for efficient calculation. For BLS12-381 curve, n=lambda=0xAC45A4010001A40200000000FFFFFFFF is exaclty
128
bit, hence satisfy algorithm's assumption.

Algorithm 1
Assume

0a<β2,
β/2<n<β
.
I=β2/nq=aIβ2r=aqnwhile r>=n:r=rn;q=q+1(at most 1 times)

Proof
It's easy to see
r(modn)=a(modn)
. We just need to prove
0r<2n
(value of
r
before while loop).
qaIβ2aβ2nβ2r0I>β2/n1In>β2nq>aIβ21β2q>aIβ2β2qn>aInβ2n>aβ2anβ2n>β2(a2n)aqn<2n

We prove a general algorithm.
Algorithm 2
Assume

0a<β2,
β/2<n<β
.
I=β2/na=a1γ+a2,a1=a/γ,a2=a(modγ)q=a1γIβ2,k=a0Iβ2r=aqnwhile r>=n:r=rn;q=q+1(at most 2+k times)

Proof
(In general, algorithm holds as long as
a0Iβ2k
for some integer
k
).
Define
q0=aIβ2=a1γIβ2+a0Iβ2
, we have
qq0a1γIβ2+k=q+k

By Algorithm 1, we have
aqna(q0k)n=aq0n+kn<(2+k)n

Example 1 If we choose

γ=β, we have
a0I/β2<β2β/β2=2
, we derive the algorithm in section 2.4.1 in Modern Computer Arithmetic (reference), where
r<4n
.

Example 2 If we choose

γ=β/2, we have
a0I/β2<γ2β/β21
. Thus
r<(2+k)n=3n
.

Reference

Faster Point Multiplication on Elliptic Curves
with Efficient Endomorphisms

Modern Computer Arithmetic

tags: public