Skip to content

Commit

Permalink
Rebasing on top of master.
Browse files Browse the repository at this point in the history
  • Loading branch information
armfazh committed Aug 26, 2020
1 parent 4456729 commit 3f3c87b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 9 additions & 0 deletions sign/ed25519/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import (
"github.com/cloudflare/circl/sign/ed25519"
)

type zeroReader struct{}

func (zeroReader) Read(buf []byte) (int, error) {
for i := range buf {
buf[i] = 0
}
return len(buf), nil
}

func TestMalleability(t *testing.T) {
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
// that s be in [0, order). This prevents someone from adding a multiple of
Expand Down
21 changes: 10 additions & 11 deletions sign/ed448/ed448.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import (
"crypto"
cryptoRand "crypto/rand"
"crypto/subtle"
"errors"
"fmt"
"io"
"strconv"

"github.com/cloudflare/circl/ecc/goldilocks"
sha3 "github.com/cloudflare/circl/internal/shake"
"github.com/cloudflare/circl/sign"
"github.com/cloudflare/circl/sign/ed448/internal/goldilocks"
)

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

// Scheme is an identifier for choosing a signature scheme.
// Scheme is an identifier for choosing a signature scheme. The zero value
// is ED448.
Scheme SchemeID
}

Expand Down Expand Up @@ -154,7 +153,7 @@ func (priv PrivateKey) Sign(
case scheme == ED448Ph && opts.HashFunc() == crypto.Hash(0):
return SignPh(priv, message, ctx), nil
default:
return nil, errors.New("ed448: bad hash algorithm")
return nil, fmt.Errorf("ed448: bad hash algorithm")
}
}

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

privateKey := NewKeyFromSeed(seed)
publicKey := make([]byte, PublicKeySize)
copy(publicKey, privateKey[SeedSize:])
privateKey := make(PrivateKey, PrivateKeySize)
publicKey := make(PublicKey, PublicKeySize)
newKeyFromSeed(privateKey, publicKey, seed)

return publicKey, privateKey, nil
}
Expand All @@ -187,9 +186,9 @@ func NewKeyFromSeed(seed []byte) PrivateKey {
return privateKey
}

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

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

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

H := sha3.NewShake256()
Expand Down

0 comments on commit 3f3c87b

Please sign in to comment.