Try   HackMD

Understanding The Wagon - From Bandersnatch to Banderwagon

Introduction

This document explains the transformation from bandersnatch to banderwagon. The particular technique for doing this was independently found by Gottfried Herold. In short, he found that one can create a prime order subgroup by quotienting out the group of rational points in the bandersnatch group.

The main purpose is to give one an intuition of why and how banderwagon works. For a concise handling of the topic, check out Gottfried's Implementation notes.

Acknowledgments

Thanks to Gottfried for reading, commenting and correcting both mathematical and grammar mistakes. In particular, Gottfried noted that the use of affine co-ordinates to speak about the points at infinity was imprecise. The section on special points has thus been reduced to only note that these four points exist and not on how to derive them using Bessalov's technique.

Twisted Edwards Curve

We define a Twisted Edwards curve over

Fp as:

Ea,d:ax2+y2=1+dx2y2

  • x,y,a,dFp
  • d1
  • char(p)2

Remark: When

a=1 we call this called an Edwards curve. Twisted Edwards curves can therefore be seen as a generalisation of Edwards curves.

Group Law

After choosing the identity point to be

(0,1).

We define the addition of two points

(x1,y1),
(x2,y2)
to be:

(x1,y1)+(x2,y2)=(x1y2+y1x21+dx1y2y1y2,y1y2ax1x21dx1x2y1y2)=(x3,y3)

The doubling of a point is :

2(x1,y1)=(2x1y11+dx12y12,y12ax121dx12y12)=(x2,y2)

It is possible to replace the denominator in the doubling formula using the curve equation, note that this will speed up the doubling of a point relative to using the point addition formula. Consequently leading to side-channel attacks during scalar multiplication since a doubling can now be differentiated from a addition.

The fact that we can use one formula for both point addition and point doubling is known as unification.

Base Points

Twisted Edwards curves have four base points which can be found when

x=0 and
y=0
.

x=0:

We find the following points:

(0,1),
(0,1)

(0,1) is the identity element and
(0,1)
is a rational point of order two. The order can be verified using the group law or by checking that the points and its negation are equal.

  • We now refer to
    (0,1)
    as
    D0

y=0:

We find the following points:

(1a,0),
(1a,0)

  • We refer to
    (1a,0)
    and
    (1a,0)
    as
    F0
    and
    F1
    respectively

These points are rational and have order 4 if

a is a square.

Remark: All edwards curves have at least 2 rational points of order 4, since

a=1 is always a square.

Remark: All twisted edwards curves have an order 2 point

(0,1)

Bandersnatch base points

For the field that bandersnatch is defined over,

a is not a square. This means that
F0
and
F1
are not points in the group.

Special points

These points are referred to as points at infinity or exceptional points. Generally one wants to avoid these points during elliptic curve cryptography. It is analogous to avoiding

10.

Twisted Edwards Elliptic curves have four points at infinity

D1,D2,F2,F3.

  • D1,D2
    have order 2
  • F2,F3
    have order 4

Bandersnatch special points

For the field that bandersnatch is defined over,

d is not a square, so
F2
and
F3
are not rational points. However, since
a
is also non-square
D1
and
D2
are in the group.

Bandersnatch has two special points in its group. These two points both have order 2.

Bandersnatch Subgroup

The group structure of bandersnatch is

Z2×Z2×p, where
p
is a prime.

The non-cyclic subgroup which we may refer to as the 2 torsion subgroup is :

E[2]={(0,1),D0,D1,D2}

Remark: All of these points have order 2 or 1, so it is sufficient to double any point in the bandersnatch group to clear the cofactor. ie one does not need to multiply by the cofactor; 4.
Remark: We may also refer to the 2 torsion subgroup as the small order subgroup.

Bandersnatch group structure

For a point

P in the subgroup, we have the following coset:

P+E[2]={P+(0,1),P+D0,P+D1,P+D2}

When

P is the neutral element, the coset is
E[2]
, otherwise when
P
is in the prime order subgroup we can explicitly write the coset as:

P+E[2]={(x,y),(x,y),(1adx1,ady1),(1adx1,ady1)

Notice that each pair of points differ by

D0, we can see this better if we explicitly write:

P+E[2]={P,P+D0,P+D1,P+D1+D0}

Halving a point

Halving a point is the opposite of doubling a point.

Given a point

Q in the prime order subgroup of size
p
. We can halve it by multiplying
Q
by
p+12
. This will result in a point
P
in the prime order subgroup such that
2P=Q
.

Observe however that there are 3 more points which when doubled will result in

Q these points are exactly the points in the coset
P+E[2]
. Moreover, note that since there are no rational points of order 4, the only points which are halvable are the points in the prime order subgroup with 4 solutions; 3 of them have order
2p
and one has order
p
. If
Q
is the neutral element then the four solutions are instead
E[2]
. See here for an extended explanation.

Necessary condition for halving a point is
(1aX2p)=1

Here it is shown that a necessary condition for halving a bandersnatch point is that

1aX2 must be a square. It is not a sufficient condition and the easiest way to see this, is to notice that it is true for both a prime order point
(x,y)
and also
(x,y)
due to the
X2
term.

It is also shown that:

  • (1aX2p)=1
    can be used to recognise
    (±x,±y)
    when
    (x,y)
    has prime order
  • This checks rejects any point of the form
    P+D1
    and
    P+D2
  • The number of points that pass this check is
    2p

Gottfried (emphasis): In particular, points that pass the check are not at infinity. So we can ignore them, greatly simplifying things.

Quotient group

The

1aX2 checks allows us to reduce the effective group size to
2p
. It is still not a prime order group and consequently, it is still vulnerable to small subgroup attacks. The usual trick is to check if the point is in the prime order subgroup, however this is expensive and moreover does not need
1aX2
.

We want to halve the size of the group from

2p to
p
and we will use quotient groups to achieve this. A quotient group can be seen as a method for making two elements equal. The strategy will be to make
(x,y)
and
(x,y)
be seen as a single element; they will be in the same equivalence class.

Example

Lets look at the integers modulo 5 for an intuition of how we will do this.

4 and 9 are different integers in

Z, but in
Z/5Z
they are seen as equivalent. If we were to directly check
4=?9
this would fail, but if we check
4 mod 5=?9 mod 5
this passes. In a way, we have merged
4
and
9
to be identified as the same element. When we look at them modulo
5
they are in the same equivalence class.
Following this, the first place to modify will be the equality check between points.

Equality check

To merge

(x1,y1) and
(x1,y1)
, we no longer check
x=?x
and
y=?y
.

We now check:

x1y1=?x2y2.

In general, for two points

(x1,y1),(x2,y2), we check they are equal with the equation
x1y1=?x2y2
. This is equivalent to checking
x1×y2=?x2×y1

Zero case

Lets analyse the cases when

x or
y
are zero.

x=0:

When

x=0 we have two points which are on the curve and pass the
1aX2
check;
(0,1)
and
(0,1)
. These two points should be merged and seen as equal since they differ by
D0
. They are the identity element of the quotient group.

Note: To check for the identity element, one only needs to check if

x=0.

y=0:

There is no point on the bandersnatch curve with

y=0 due to the fact that
a
is non-square.

Note: If the point is not on the curve or does not pass the

1aX2 check, then the equality check is not sound. There should be no API build a banderwagon point without performing these checks. Furthermore, the internal representation should be seen as a blackbox. This is also the suggestion that the Ristretto/Decaf RFC states.

Serialisation

When serialising a point, remember we want

(x,y) and
(x,y)
to serialise to the same bitstring. This can be done by taking the sign of the
y
co-ordinate, multiplying it by the
x
co-ordinate and sending the result as a bit string. This works because

serialise(x,y) = sign(y)×x

serialise(-x,-y) = sign(-y)×-x = sign(y)×x

Deserialisation (Informal)

Upon receiving

sign(y)×x, one must check that
1aX2
is a square. The
sign(y)
does not matter as we are squaring
X
. If this check passes, we then find the corresponding
y
using the curve equation.

Note: The curve equation will return

y and
y
for some choice of positiveness. We want to choose positive
y
. Choosing
(x,y)
will give you an element that is valid, but equivalent to the negation of
(x,y)
.
Remark: Negating a point in the quotient group can be done by negating either the
x
or the
y
co-ordinate

Note: If

p3 mod 4 then the
sign
function can be implemented with a quadratic residue check

Deserialisation (Formal)

This is also described here

  • Receive
    t=sign(y)×x
    . This will be a bit string.
  • Interpret the bit string
    t
    as a field element
    Fp
    in the interval
    [0,p1]
    . The interpreted field element is now denoted
    xk
    .
    xk
    will be the
    x
    co-ordinate of our deserialised point.
  • Check whether
    1axk2
    is a square. If it is not, Abort.
  • Using the curve equation, we can find
    yk2=1axk21dxk2
  • Take the square root of
    yk2
    . If it does not exist, Abort.
  • Pick the value of
    yk
    such that
    sign(yk)=1

Group law

The group law does not change because what we quotiented by was a subgroup. These are still points on the bandersnatch curve and form a group under point addition.

Map To Field

Since we are only dealing with the points

(x,y) and
(x,y)
which are considered equal, we can create the following injective maps from the quotient group to the field
Fp
:

  • xy
  • x×y

Since

y0 ,
xy
is never undefined. For banderwagon, the choice made was to use
xy
, because in projective co-ordinates
xy=XY
while
xy=XYZ2

Remark: This map is not injective if you are mapping from the bandersnatch group to

Fp because for one,
(x,y)
and
(x,y)
are not considered to be equal.

Banderwagon Abstraction

The combination of checking if

1aX2 is a square, and the serialisation strategy over bandersnatch is what is known as banderwagon.

Conclusion

Using banderwagon, one is able to view the group as prime order subgroup with an injective map to the field

Fp. Moreover, the points at infinity are not in this prime order group abstraction, so the group law is complete.

Appendix

Theorem 1:
(1dX2p)=(1aX2p)
when
X
is on the curve

Proof.

The curve equation is given as:

ax2+y2=1+dx2y2

1ax2=y2dx2y2

1ax2=y2(1dx2)

Hence for a point on the curve,

1dx2 and
1ax2
are either both squares or both non-squares.

Proof done.

This means that we could check if

1dX2 is a square, but this is not done because its more expensive than
1aX2
since
a
is smaller than
d

Theorem 2:
(1ax2p)(1y2p)=(adp)

read: the legendre symbol of the lhs is equal to the legendre symbol of the rhs

Proof

(1ax2)(1y2)

(1y2)ax2+ax2y2 (expanding the brackets)

(ax2dx2y2)ax2+ax2y2 (using the curve equation)

(ad)(xy)2 (cancel and group terms)

Since

(xy)2 is always a quadratic residue, the legendre symbol of
(ad)(xy)2
is determined by
(ad)

Corrolary:
(1ax2p)=1 implies (1y2p)=1

Given that

(1ax2p)(1y2p)=(adp)

Plugging in our condition:

(1ax2p)=1

We arrive at:

(1y2p)=(adp)

For bandersnatch,

ad is a quadratic non-residue, hence it is sufficient to check that:

(1y2p)=1

It seems that we could check if

1y2 is a non-residue, instead of checking if
1aX2
is a residue. The problem is that the identity element is an edge case, it would return a legendre symbol of
0
. We would need to check that case separately, which trades developer complexity for CPU time.

What points are halvable?

Moved to here