Skip to content

Commit 3f3c87b

Browse files
committed
Rebasing on top of master.
1 parent 4456729 commit 3f3c87b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

sign/ed25519/ed25519_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import (
77
"github.com/cloudflare/circl/sign/ed25519"
88
)
99

10+
type zeroReader struct{}
11+
12+
func (zeroReader) Read(buf []byte) (int, error) {
13+
for i := range buf {
14+
buf[i] = 0
15+
}
16+
return len(buf), nil
17+
}
18+
1019
func TestMalleability(t *testing.T) {
1120
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
1221
// that s be in [0, order). This prevents someone from adding a multiple of

sign/ed448/ed448.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ import (
2828
"crypto"
2929
cryptoRand "crypto/rand"
3030
"crypto/subtle"
31-
"errors"
3231
"fmt"
3332
"io"
34-
"strconv"
3533

36-
"github.com/cloudflare/circl/ecc/goldilocks"
3734
sha3 "github.com/cloudflare/circl/internal/shake"
3835
"github.com/cloudflare/circl/sign"
36+
"github.com/cloudflare/circl/sign/ed448/internal/goldilocks"
3937
)
4038

4139
const (
@@ -66,7 +64,8 @@ type SignerOptions struct {
6664
// Its length must be less or equal than 255 bytes.
6765
Context string
6866

69-
// Scheme is an identifier for choosing a signature scheme.
67+
// Scheme is an identifier for choosing a signature scheme. The zero value
68+
// is ED448.
7069
Scheme SchemeID
7170
}
7271

@@ -154,7 +153,7 @@ func (priv PrivateKey) Sign(
154153
case scheme == ED448Ph && opts.HashFunc() == crypto.Hash(0):
155154
return SignPh(priv, message, ctx), nil
156155
default:
157-
return nil, errors.New("ed448: bad hash algorithm")
156+
return nil, fmt.Errorf("ed448: bad hash algorithm")
158157
}
159158
}
160159

@@ -170,9 +169,9 @@ func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
170169
return nil, nil, err
171170
}
172171

173-
privateKey := NewKeyFromSeed(seed)
174-
publicKey := make([]byte, PublicKeySize)
175-
copy(publicKey, privateKey[SeedSize:])
172+
privateKey := make(PrivateKey, PrivateKeySize)
173+
publicKey := make(PublicKey, PublicKeySize)
174+
newKeyFromSeed(privateKey, publicKey, seed)
176175

177176
return publicKey, privateKey, nil
178177
}
@@ -187,9 +186,9 @@ func NewKeyFromSeed(seed []byte) PrivateKey {
187186
return privateKey
188187
}
189188

190-
func newKeyFromSeed(privateKey, seed []byte) {
189+
func newKeyFromSeed(privateKey PrivateKey, publicKey PublicKey, seed []byte) {
191190
if l := len(seed); l != SeedSize {
192-
panic("ed448: bad seed length: " + strconv.Itoa(l))
191+
panic(fmt.Errorf("ed448: bad seed length: %v", l))
193192
}
194193

195194
var h [hashSize]byte
@@ -213,7 +212,7 @@ func newKeyFromSeed(privateKey, seed []byte) {
213212

214213
func signAll(signature []byte, privateKey PrivateKey, message, ctx []byte, preHash bool) {
215214
if len(ctx) > ContextMaxSize {
216-
panic(fmt.Errorf("ed448: bad context length: " + strconv.Itoa(len(ctx))))
215+
panic(fmt.Errorf("ed448: bad context length: %v", len(ctx)))
217216
}
218217

219218
H := sha3.NewShake256()

0 commit comments

Comments
 (0)