diff options
author | tb <> | 2021-04-03 13:34:45 +0000 |
---|---|---|
committer | tb <> | 2021-04-03 13:34:45 +0000 |
commit | e947814ce6eb46cc48b27b041f76414b97773ee1 (patch) | |
tree | 9a610f97df3ae77375c1319441613c330bf0b6aa | |
parent | 6ff89a0a45c68b86e20818023df4407e1d524e2f (diff) | |
download | openbsd-e947814ce6eb46cc48b27b041f76414b97773ee1.tar.gz openbsd-e947814ce6eb46cc48b27b041f76414b97773ee1.tar.bz2 openbsd-e947814ce6eb46cc48b27b041f76414b97773ee1.zip |
Run the CMAC tests through EVP_PKEY_new_CMAC_key().
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 3c96dd009d..4e465a8410 100644 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: wycheproof.go,v 1.120 2020/05/14 18:11:45 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.121 2021/04/03 13:34:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> |
@@ -39,6 +39,12 @@ package main | |||
39 | #include <openssl/pem.h> | 39 | #include <openssl/pem.h> |
40 | #include <openssl/x509.h> | 40 | #include <openssl/x509.h> |
41 | #include <openssl/rsa.h> | 41 | #include <openssl/rsa.h> |
42 | |||
43 | int | ||
44 | evpDigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt) | ||
45 | { | ||
46 | return EVP_DigestSignUpdate(ctx, d, cnt); | ||
47 | } | ||
42 | */ | 48 | */ |
43 | import "C" | 49 | import "C" |
44 | 50 | ||
@@ -1008,22 +1014,28 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
1008 | tag = append(tag, 0) | 1014 | tag = append(tag, 0) |
1009 | } | 1015 | } |
1010 | 1016 | ||
1011 | ctx := C.CMAC_CTX_new() | 1017 | mdctx := C.EVP_MD_CTX_new() |
1012 | if ctx == nil { | 1018 | if mdctx == nil { |
1019 | log.Fatal("EVP_MD_CTX_new failed") | ||
1020 | } | ||
1021 | defer C.EVP_MD_CTX_free(mdctx) | ||
1022 | |||
1023 | pkey := C.EVP_PKEY_new_CMAC_key(nil, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), cipher) | ||
1024 | if pkey == nil { | ||
1013 | log.Fatal("CMAC_CTX_new failed") | 1025 | log.Fatal("CMAC_CTX_new failed") |
1014 | } | 1026 | } |
1015 | defer C.CMAC_CTX_free(ctx) | 1027 | defer C.EVP_PKEY_free(pkey) |
1016 | 1028 | ||
1017 | ret := C.CMAC_Init(ctx, unsafe.Pointer(&key[0]), C.size_t(keyLen), cipher, nil) | 1029 | ret := C.EVP_DigestSignInit(mdctx, nil, nil, nil, pkey) |
1018 | if ret != 1 { | 1030 | if ret != 1 { |
1019 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Init() = %d, want %v\n", | 1031 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_DigestSignInit() = %d, want %v\n", |
1020 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 1032 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
1021 | return false | 1033 | return false |
1022 | } | 1034 | } |
1023 | 1035 | ||
1024 | ret = C.CMAC_Update(ctx, unsafe.Pointer(&msg[0]), C.size_t(msgLen)) | 1036 | ret = C.evpDigestSignUpdate(mdctx, unsafe.Pointer(&msg[0]), C.size_t(msgLen)) |
1025 | if ret != 1 { | 1037 | if ret != 1 { |
1026 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Update() = %d, want %v\n", | 1038 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_DigestSignUpdate() = %d, want %v\n", |
1027 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 1039 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
1028 | return false | 1040 | return false |
1029 | } | 1041 | } |
@@ -1031,9 +1043,9 @@ func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | |||
1031 | var outLen C.size_t | 1043 | var outLen C.size_t |
1032 | outTag := make([]byte, 16) | 1044 | outTag := make([]byte, 16) |
1033 | 1045 | ||
1034 | ret = C.CMAC_Final(ctx, (*C.uchar)(unsafe.Pointer(&outTag[0])), &outLen) | 1046 | ret = C.EVP_DigestSignFinal(mdctx, (*C.uchar)(unsafe.Pointer(&outTag[0])), &outLen) |
1035 | if ret != 1 { | 1047 | if ret != 1 { |
1036 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Final() = %d, want %v\n", | 1048 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_DigestSignFinal() = %d, want %v\n", |
1037 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | 1049 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) |
1038 | return false | 1050 | return false |
1039 | } | 1051 | } |