Involved Source Files
Package curve25519 provides an implementation of the X25519 function, which
performs scalar multiplication on the elliptic curve known as Curve25519.
See RFC 7748.
curve25519_amd64.gocurve25519_generic.gocurve25519_amd64.s
Package-Level Type Names (only one, which is unexported)
/* sort exporteds by: | */
fieldElement represents an element of the field GF(2^255 - 19). An element
t, entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
context.
func feAdd(dst, a, b *fieldElement)
func feCopy(dst, src *fieldElement)
func feCSwap(f, g *fieldElement, b int32)
func feFromBytes(dst *fieldElement, src *[32]byte)
func feInvert(out, z *fieldElement)
func feMul(h, f, g *fieldElement)
func feMul121666(h, f *fieldElement)
func feOne(fe *fieldElement)
func feSquare(h, f *fieldElement)
func feSub(dst, a, b *fieldElement)
func feToBytes(s *[32]byte, h *fieldElement)
func feZero(fe *fieldElement)
Package-Level Functions (total 32, in which 3 are exported)
ScalarBaseMult sets dst to the product scalar * base where base is the
standard generator.
It is recommended to use the X25519 function with Basepoint instead, as
copying into fixed size arrays can lead to unexpected bugs.
ScalarMult sets dst to the product scalar * point.
Deprecated: when provided a low-order point, ScalarMult will set dst to all
zeroes, irrespective of the scalar. Instead, use the X25519 function, which
will return an error.
X25519 returns the result of the scalar multiplication (scalar * point),
according to RFC 7748, Section 5. scalar, point and the return value are
slices of 32 bytes.
scalar can be generated at random, for example with crypto/rand. point should
be either Basepoint or the output of another X25519 call.
If point is Basepoint (but not if it's a different slice with the same
contents) a precomputed implementation might be used for performance.
feMul calculates h = f * g
Can overlap h with f or g.
Preconditions:
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|g| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
Postconditions:
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
Notes on implementation strategy:
Using schoolbook multiplication.
Karatsuba would save a little in some cost models.
Most multiplications by 2 and 19 are 32-bit precomputations;
cheaper than 64-bit postcomputations.
There is one remaining multiplication by 19 in the carry chain;
one *19 precomputation can be merged into this,
but the resulting data flow is considerably less clean.
There are 12 carries below.
10 of them are 2-way parallelizable and vectorizable.
Can get away with 11 carries, but then data flow is much deeper.
With tighter constraints on inputs can squeeze carries into int32.
feMul121666 calculates h = f * 121666. Can overlap h with f.
Preconditions:
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
Postconditions:
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
feSquare calculates h = f*f. Can overlap h with f.
Preconditions:
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
Postconditions:
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
feToBytes marshals h to s.
Preconditions:
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
Write p=2^255-19; q=floor(h/p).
Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
Proof:
Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
Also have |h-2^230 h9|<2^230 so |19 2^(-255)(h-2^230 h9)|<1/4.
Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
Then 0<y<1.
Write r=h-pq.
Have 0<=r<=p-1=2^255-20.
Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
Write x=r+19(2^-255)r+y.
Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
Package-Level Constants (total 2, both are exported)
PointSize is the size of the point input to X25519.
ScalarSize is the size of the scalar input to X25519.
The pages are generated with Goldsv0.4.2. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.