Debian Codegraph @

README.md

raw symbols SCIP
1 go-ristretto
2 ============
3
4 Many cryptographic schemes need a group of prime order. Popular and
5 efficient elliptic curves like (Edwards25519 of `ed25519` fame) are
6 rarely of prime order. There is, however, a convenient method
7 to construct a prime order group from such curves,
8 called [Ristretto](https://ristretto.group) proposed by
9 [Mike Hamburg](https://www.shiftleft.org).
10
11 This is a pure Go implementation of the group operations on the
12 Ristretto prime-order group built from Edwards25519.
13 Documentation is on [godoc](https://godoc.org/github.com/bwesterb/go-ristretto).
14
15 Example: El'Gamal encryption
16 ----------------------------
17
18 ```go
19 // Generate an El'Gamal keypair
20 var secretKey ristretto.Scalar
21 var publicKey ristretto.Point
22
23 secretKey.Rand() // generate a new secret key
24 publicKey.ScalarMultBase(&secretKey) // compute public key
25
26 // El'Gamal encrypt a random curve point p into a ciphertext-pair (c1,c2)
27 var p ristretto.Point
28 var r ristretto.Scalar
29 var c1 ristretto.Point
30 var c2 ristretto.Point
31 p.Rand()
32 r.Rand()
33 c2.ScalarMultBase(&r)
34 c1.PublicScalarMult(&publicKey, &r)
35 c1.Add(&c1, &p)
36
37 // Decrypt (c1,c2) back to p
38 var blinding, p2 ristretto.Point
39 blinding.ScalarMult(&c2, &secretKey)
40 p2.Sub(&c1, &blinding)
41
42 fmt.Printf("%v", bytes.Equal(p.Bytes(), p2.Bytes()))
43 // Output:
44 // true
45 ```
46
47 Compatibility with `ristretto255` RFC draft
48 -------------------------------------------
49
50 An [RFC has been proposed](https://datatracker.ietf.org/doc/draft-hdevalence-cfrg-ristretto/)
51 to standardise Ristretto over Ed25519. This RFC is compatible with `go-ristretto`. There
52 is one caveat: one should use `Point.DeriveDalek` instead of `Point.Derive` to derive a point
53 from a string.
54
55
56 References
57 ----------
58
59 The curve and Ristretto implementation is based on the unpublished
60 [PandA](https://link.springer.com/chapter/10.1007/978-3-319-04873-4_14)
61 library by
62 [Chuengsatiansup](https://perso.ens-lyon.fr/chitchanok.chuengsatiansup/),
63 [Ribarski](http://panceribarski.com) and
64 [Schwabe](https://cryptojedi.org/peter/index.shtml),
65 see [cref/cref.c](cref/cref.c). The old generic radix 25.5 field operations borrow
66 from [Adam Langley](https://www.imperialviolet.org)'s
67 [ed25519](http://github.com/agl/ed25519).
68 The amd64 optimized field arithmetic are from George Tankersley's
69 [ed25519 patch](https://go-review.googlesource.com/c/crypto/+/71950),
70 which in turn is based on SUPERCOP's
71 [`amd64-51-30k`](https://github.com/floodyberry/supercop/tree/master/crypto_sign/ed25519/amd64-51-30k)
72 by Bernstein, Duif, Lange, Schwabe and Yang.
73 The new generic radix 51 field operations are also based on `amd64-51-30k`.
74 The variable-time scalar multiplication code is based on that
75 of [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek).
76 The Lizard encoding was proposed by [Bram Westerbaan](https://bram.westerbaan.name/).
77 The quick RistrettoElligator inversion for it is joint work
78 with [Bram Westerbaan](https://bram.westerbaan.name/)
79 and [Mike Hamburg](https://www.shiftleft.org).
80
81 ### other platforms
82 * [Rust](https://github.com/dalek-cryptography/curve25519-dalek)
83 * [Javascript](https://github.com/jedisct1/wasm-crypto)
84 * [C (part of `libsodium`)](https://libsodium.gitbook.io/doc/advanced/point-arithmetic/ristretto)
85
86
87 Changes
88 -------
89
90 ### 1.2.4 (16-07-2026)
91 - Add Scalar.SetBytesStrict() that checks whether the scalar is reduced
92 as recommended by the RFC.
93
94 ### 1.2.3 (16-03-2023)
95 - Panic when reading randomness fails.
96
97 ### 1.2.2 (29-07-2022)
98 - Add Point.ConditionalSet() and Scalar.ConditionalSet().
99
100 ### 1.2.1 (08-11-2021)
101 - Add Scalar.SetUint64().
102
103 ### 1.2.0 (17-02-2021)
104
105 - Add Point.Double(). See issue #21.
106 - To align more closely with the RFC, Point.SetBytes()
107 and Point.UnmarshalBinary() will now reject points with non-canonical
108 encodings. See #20.
109
110 ### 1.1.1 (24-09-2019)
111
112 - Only use bits.Add64 from Go 1.13 onwards to make sure we're constant-time
113 on non-amd64 platforms. Thanks @Yawning; see issue #17.
114
115 ### 1.1.0 (13-05-2019)
116
117 - Add support for the Lizard 16-bytes-to-point-injection.
118 See `ristretto.Point.`{`SetLizard()`, `Lizard()`,`LizardInto()`}.
119 - Add `Scalar.DeriveShort()` to derive a half-length scalar.
120 (Warning: half-length scalars are unsafe in almost every application.)
121
122 - (internal) Add `ExtendedPoint.RistrettoElligator2Inverse()` to compute
123 all preimages of a given point up-to Ristretto equivalence
124 of `CompletedPoint.SetRistrettoElligator2()`.