mirror of
https://github.com/libp2p/go-openssl.git
synced 2025-04-25 17:50:23 +08:00
skip ed25519 tests if not supported
This commit is contained in:
parent
8ea58d1789
commit
0ffbced908
21
key.go
21
key.go
@ -24,6 +24,10 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var ( // some (effectively) constants for tests to refer to
|
||||
ed25519_support = C.X_ED25519_SUPPORT != 0
|
||||
)
|
||||
|
||||
type Method *C.EVP_MD
|
||||
|
||||
var (
|
||||
@ -133,10 +137,10 @@ func (key *pKey) SignPKCS1v15(method Method, data []byte) ([]byte, error) {
|
||||
sig := make([]byte, 64, 64)
|
||||
var sigblen C.ulong = 64
|
||||
if 1 != C.X_EVP_DigestSign(ctx,
|
||||
((*C.uchar)(unsafe.Pointer(&sig[0]))),
|
||||
&sigblen,
|
||||
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||
C.ulong(len(data))) {
|
||||
((*C.uchar)(unsafe.Pointer(&sig[0]))),
|
||||
&sigblen,
|
||||
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||
C.ulong(len(data))) {
|
||||
return nil, errors.New("signpkcs1v15: failed to do one-shot signature")
|
||||
}
|
||||
|
||||
@ -177,10 +181,10 @@ func (key *pKey) VerifyPKCS1v15(method Method, data, sig []byte) error {
|
||||
}
|
||||
|
||||
if 1 != C.X_EVP_DigestVerify(ctx,
|
||||
((*C.uchar)(unsafe.Pointer(&sig[0]))),
|
||||
C.ulong(len(sig)),
|
||||
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||
C.ulong(len(data))) {
|
||||
((*C.uchar)(unsafe.Pointer(&sig[0]))),
|
||||
C.ulong(len(sig)),
|
||||
(*C.uchar)(unsafe.Pointer(&data[0])),
|
||||
C.ulong(len(data))) {
|
||||
return errors.New("verifypkcs1v15: failed to do one-shot verify")
|
||||
}
|
||||
|
||||
@ -476,7 +480,6 @@ func GenerateECKey(curve EllipticCurve) (PrivateKey, error) {
|
||||
|
||||
// GenerateED25519Key generates a Ed25519 key
|
||||
func GenerateED25519Key() (PrivateKey, error) {
|
||||
|
||||
// Key context
|
||||
keyCtx := C.EVP_PKEY_CTX_new_id(C.X_EVP_PKEY_ED25519, nil)
|
||||
if keyCtx == nil {
|
||||
|
12
key_test.go
12
key_test.go
@ -175,6 +175,10 @@ func TestGenerateEC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerateEd25519(t *testing.T) {
|
||||
if !ed25519_support {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
key, err := GenerateED25519Key()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -253,6 +257,10 @@ func TestSignEC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSignED25519(t *testing.T) {
|
||||
if !ed25519_support {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
t.Parallel()
|
||||
|
||||
key, err := GenerateED25519Key()
|
||||
@ -394,6 +402,10 @@ func TestMarshalEC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMarshalEd25519(t *testing.T) {
|
||||
if !ed25519_support {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
key, err := LoadPrivateKeyFromPEM(ed25519KeyBytes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
10
shim.c
10
shim.c
@ -44,6 +44,8 @@ static int go_write_bio_puts(BIO *b, const char *str) {
|
||||
************************************************
|
||||
*/
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
||||
|
||||
const int X_ED25519_SUPPORT = 1;
|
||||
int X_EVP_PKEY_ED25519 = EVP_PKEY_ED25519;
|
||||
|
||||
int X_EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
@ -66,7 +68,10 @@ int X_EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
|
||||
size_t siglen, const unsigned char *tbs, size_t tbslen){
|
||||
return EVP_DigestVerify(ctx, sigret, siglen, tbs, tbslen);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
const int X_ED25519_SUPPORT = 0;
|
||||
int X_EVP_PKEY_ED25519 = EVP_PKEY_NONE;
|
||||
|
||||
int X_EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
@ -89,6 +94,7 @@ int X_EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
|
||||
size_t siglen, const unsigned char *tbs, size_t tbslen){
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -216,8 +222,6 @@ int X_PEM_write_bio_PrivateKey_traditional(BIO *bio, EVP_PKEY *key, const EVP_CI
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
************************************************
|
||||
* v1.0.X implementation
|
||||
@ -362,8 +366,6 @@ int X_PEM_write_bio_PrivateKey_traditional(BIO *bio, EVP_PKEY *key, const EVP_CI
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
************************************************
|
||||
* common implementation
|
||||
|
Loading…
Reference in New Issue
Block a user