Skip to content

Commit a497cf3

Browse files
committed
add more test vec
1 parent b2f1196 commit a497cf3

File tree

5 files changed

+687
-18
lines changed

5 files changed

+687
-18
lines changed

elliptic/ed521/ed521.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// https://eprint.iacr.org/2013/647
1111

1212
var (
13-
// Ed-521 curve oid
13+
// Ed521 curve oid
1414
OIDED521 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 44588, 2, 1}
1515
)
1616

elliptic/ed521/params.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,6 @@ func UnmarshalPoint(curve elliptic.Curve, data []byte) (*big.Int, *big.Int) {
364364
return nil, nil
365365
}
366366

367-
func panicIfNotOnCurve(curve elliptic.Curve, x, y *big.Int) {
368-
// (0, 0) is the point at infinity by convention. It's ok to operate on it,
369-
// although IsOnCurve is documented to return false for it. See Issue 37294.
370-
if x.Sign() == 0 && y.Sign() == 0 {
371-
return
372-
}
373-
374-
if !curve.IsOnCurve(x, y) {
375-
panic("go-cryptobin/ed521: attempted operation on invalid point")
376-
}
377-
}
378-
379367
func GetPrivateScalar(buffer []byte) []byte {
380368
a := pruningBuffer(buffer)
381369
s := Reverse(a)
@@ -405,3 +393,15 @@ func Reverse(b []byte) []byte {
405393

406394
return d
407395
}
396+
397+
func panicIfNotOnCurve(curve elliptic.Curve, x, y *big.Int) {
398+
// (0, 0) is the point at infinity by convention. It's ok to operate on it,
399+
// although IsOnCurve is documented to return false for it. See Issue 37294.
400+
if x.Sign() == 0 && y.Sign() == 0 {
401+
return
402+
}
403+
404+
if !curve.IsOnCurve(x, y) {
405+
panic("go-cryptobin/ed521: attempted operation on invalid point")
406+
}
407+
}

pubkey/ed521/ed521.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func sign(privateKey *PrivateKey, message []byte, domPre, context string) ([]byt
262262
byteLen := (params.BitSize + 7) / 8
263263

264264
seed := privateKey.Seed()
265-
publicKeyBytes := ed521.MarshalPoint(privateKey.Curve, privateKey.X, privateKey.Y)
265+
eA := ed521.MarshalPoint(privateKey.Curve, privateKey.X, privateKey.Y)
266266

267267
h := make([]byte, 132)
268268
sha3.ShakeSum256(h, seed)
@@ -295,7 +295,7 @@ func sign(privateKey *PrivateKey, message []byte, domPre, context string) ([]byt
295295
kh.Write([]byte{byte(len(context))})
296296
kh.Write([]byte(context))
297297
kh.Write(R)
298-
kh.Write(publicKeyBytes)
298+
kh.Write(eA)
299299
kh.Write(PHM)
300300
hramDigest := make([]byte, 132)
301301
kh.Read(hramDigest)
@@ -388,14 +388,14 @@ func verify(publicKey *PublicKey, message, sig []byte, domPre, context string) b
388388
SBytes := ed521.Reverse(sig[byteLen:])
389389
S := new(big.Int).SetBytes(SBytes)
390390

391-
publicKeyBytes := ed521.MarshalPoint(publicKey.Curve, publicKey.X, publicKey.Y)
391+
eA := ed521.MarshalPoint(publicKey.Curve, publicKey.X, publicKey.Y)
392392

393393
kh := sha3.NewShake256()
394394
kh.Write([]byte(domPre))
395395
kh.Write([]byte{byte(len(context))})
396396
kh.Write([]byte(context))
397397
kh.Write(R)
398-
kh.Write(publicKeyBytes)
398+
kh.Write(eA)
399399
kh.Write(PHM)
400400
hramDigest := make([]byte, 132)
401401
kh.Read(hramDigest)

0 commit comments

Comments
 (0)