github.com/cloudflare/circl@v1.5.0/sign/ed448/signapi.go (about) 1 package ed448 2 3 import ( 4 "crypto/rand" 5 "encoding/asn1" 6 7 "github.com/cloudflare/circl/sign" 8 ) 9 10 var sch sign.Scheme = &scheme{} 11 12 // Scheme returns a signature interface. 13 func Scheme() sign.Scheme { return sch } 14 15 type scheme struct{} 16 17 func (*scheme) Name() string { return "Ed448" } 18 func (*scheme) PublicKeySize() int { return PublicKeySize } 19 func (*scheme) PrivateKeySize() int { return PrivateKeySize } 20 func (*scheme) SignatureSize() int { return SignatureSize } 21 func (*scheme) SeedSize() int { return SeedSize } 22 func (*scheme) TLSIdentifier() uint { return 0x0808 } 23 func (*scheme) SupportsContext() bool { return true } 24 func (*scheme) Oid() asn1.ObjectIdentifier { 25 return asn1.ObjectIdentifier{1, 3, 101, 113} 26 } 27 28 func (*scheme) GenerateKey() (sign.PublicKey, sign.PrivateKey, error) { 29 return GenerateKey(rand.Reader) 30 } 31 32 func (*scheme) Sign( 33 sk sign.PrivateKey, 34 message []byte, 35 opts *sign.SignatureOpts, 36 ) []byte { 37 priv, ok := sk.(PrivateKey) 38 if !ok { 39 panic(sign.ErrTypeMismatch) 40 } 41 ctx := "" 42 if opts != nil { 43 ctx = opts.Context 44 } 45 return Sign(priv, message, ctx) 46 } 47 48 func (*scheme) Verify( 49 pk sign.PublicKey, 50 message, signature []byte, 51 opts *sign.SignatureOpts, 52 ) bool { 53 pub, ok := pk.(PublicKey) 54 if !ok { 55 panic(sign.ErrTypeMismatch) 56 } 57 ctx := "" 58 if opts != nil { 59 ctx = opts.Context 60 } 61 return Verify(pub, message, signature, ctx) 62 } 63 64 func (*scheme) DeriveKey(seed []byte) (sign.PublicKey, sign.PrivateKey) { 65 privateKey := NewKeyFromSeed(seed) 66 publicKey := make(PublicKey, PublicKeySize) 67 copy(publicKey, privateKey[SeedSize:]) 68 return publicKey, privateKey 69 } 70 71 func (*scheme) UnmarshalBinaryPublicKey(buf []byte) (sign.PublicKey, error) { 72 if len(buf) < PublicKeySize { 73 return nil, sign.ErrPubKeySize 74 } 75 pub := make(PublicKey, PublicKeySize) 76 copy(pub, buf[:PublicKeySize]) 77 return pub, nil 78 } 79 80 func (*scheme) UnmarshalBinaryPrivateKey(buf []byte) (sign.PrivateKey, error) { 81 if len(buf) < PrivateKeySize { 82 return nil, sign.ErrPrivKeySize 83 } 84 priv := make(PrivateKey, PrivateKeySize) 85 copy(priv, buf[:PrivateKeySize]) 86 return priv, nil 87 }