Commit 0ffbced9 authored by Jeff Wendling's avatar Jeff Wendling

skip ed25519 tests if not supported

parent 8ea58d17
......@@ -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 {
......
......@@ -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)
......
......@@ -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
......
......@@ -102,6 +102,7 @@ extern BIO *X_BIO_new_write_bio();
extern BIO *X_BIO_new_read_bio();
/* EVP methods */
extern const int X_ED25519_SUPPORT;
extern int X_EVP_PKEY_ED25519;
extern const EVP_MD *X_EVP_get_digestbyname(const char *name);
extern EVP_MD_CTX *X_EVP_MD_CTX_new();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment