diff --git a/lib/crypto/ecdsa/ecdsa_p256_private.go b/lib/crypto/ecdsa/ecdsa_p256_private.go index dced1f5..741d979 100644 --- a/lib/crypto/ecdsa/ecdsa_p256_private.go +++ b/lib/crypto/ecdsa/ecdsa_p256_private.go @@ -17,7 +17,7 @@ type ( // Len implements types.SigningPrivateKey. func (e *ECP256PrivateKey) Len() int { - panic("unimplemented") + return 32 } // Sign implements types.Signer. diff --git a/lib/crypto/ecdsa/ecdsa_p256_public.go b/lib/crypto/ecdsa/ecdsa_p256_public.go index 57df3ca..92943a5 100644 --- a/lib/crypto/ecdsa/ecdsa_p256_public.go +++ b/lib/crypto/ecdsa/ecdsa_p256_public.go @@ -5,6 +5,7 @@ import ( "crypto/elliptic" "github.com/go-i2p/go-i2p/lib/crypto/types" + "github.com/samber/oops" ) type ( @@ -13,17 +14,30 @@ type ( // Verify implements types.Verifier. func (k ECP256PublicKey) Verify(data []byte, sig []byte) error { - panic("unimplemented") + log.WithField("data_length", len(data)).Debug("Verifying data with ECDSA-P256") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.Verify(data, sig) } // VerifyHash implements types.Verifier. func (k ECP256PublicKey) VerifyHash(h []byte, sig []byte) error { - panic("unimplemented") + log.WithField("hash_length", len(h)).Debug("Verifying hash with ECDSA-P256") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.VerifyHash(h, sig) } // Encrypt implements types.Encrypter. func (k *ECP256PublicKey) Encrypt(data []byte) (enc []byte, err error) { - panic("unimplemented") + log.Error("Encryption not supported with ECDSA keys") + return nil, oops.Errorf("encryption not supported with ECDSA keys; ECDSA is for signing/verification only") } func (k ECP256PublicKey) Len() int { diff --git a/lib/crypto/ecdsa/ecdsa_p384_public.go b/lib/crypto/ecdsa/ecdsa_p384_public.go index 99151e3..55b4448 100644 --- a/lib/crypto/ecdsa/ecdsa_p384_public.go +++ b/lib/crypto/ecdsa/ecdsa_p384_public.go @@ -13,12 +13,24 @@ type ( // Verify implements types.Verifier. func (k ECP384PublicKey) Verify(data []byte, sig []byte) error { - panic("unimplemented") + log.WithField("data_length", len(data)).Debug("Verifying data with ECDSA-P384") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.Verify(data, sig) } // VerifyHash implements types.Verifier. func (k ECP384PublicKey) VerifyHash(h []byte, sig []byte) error { - panic("unimplemented") + log.WithField("hash_length", len(h)).Debug("Verifying hash with ECDSA-P384") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.VerifyHash(h, sig) } func (k ECP384PublicKey) Bytes() []byte { diff --git a/lib/crypto/ecdsa/ecdsa_p521_public.go b/lib/crypto/ecdsa/ecdsa_p521_public.go index 646f763..bfaa13e 100644 --- a/lib/crypto/ecdsa/ecdsa_p521_public.go +++ b/lib/crypto/ecdsa/ecdsa_p521_public.go @@ -13,12 +13,24 @@ type ( // Verify implements types.Verifier. func (k ECP521PublicKey) Verify(data []byte, sig []byte) error { - panic("unimplemented") + log.WithField("data_length", len(data)).Debug("Verifying data with ECDSA-P521") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.Verify(data, sig) } // VerifyHash implements types.Verifier. func (k ECP521PublicKey) VerifyHash(h []byte, sig []byte) error { - panic("unimplemented") + log.WithField("hash_length", len(h)).Debug("Verifying hash with ECDSA-P521") + verifier, err := k.NewVerifier() + if err != nil { + log.WithError(err).Error("Failed to create verifier") + return err + } + return verifier.VerifyHash(h, sig) } func (k ECP521PublicKey) Bytes() []byte { diff --git a/template.md b/template.md index 7dcc429..8b801ee 100644 --- a/template.md +++ b/template.md @@ -11,3 +11,5 @@ {{ .Name }} {{ .ImportPath }} + +[go-i2p template file](/template.md) \ No newline at end of file