summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-14 09:35:18 +0000
committertb <>2022-01-14 09:35:18 +0000
commitd976af16afece80aad931c280f7d3ed7fb3f275f (patch)
tree86b78d5d433b6cbfc78b63b75a9e4883bf50aa80
parentd6621223b7dc417fc0691a0d498791f6125d59c0 (diff)
downloadopenbsd-d976af16afece80aad931c280f7d3ed7fb3f275f.tar.gz
openbsd-d976af16afece80aad931c280f7d3ed7fb3f275f.tar.bz2
openbsd-d976af16afece80aad931c280f7d3ed7fb3f275f.zip
Convert wycheproof.go for opaque EVP_AEAD_CTX
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go
index e23b100bf7..8d01b5d8b0 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.124 2021/11/21 11:55:00 tb Exp $ */ 1/* $OpenBSD: wycheproof.go,v 1.125 2022/01/14 09:35:18 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>
@@ -908,19 +908,23 @@ func runAesAeadTest(algorithm string, ctx *C.EVP_CIPHER_CTX, aead *C.EVP_AEAD, w
908 908
909 openAead, sealAead := true, true 909 openAead, sealAead := true, true
910 if aead != nil { 910 if aead != nil {
911 var ctx C.EVP_AEAD_CTX 911 ctx := C.EVP_AEAD_CTX_new()
912 if C.EVP_AEAD_CTX_init(&ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 { 912 if ctx == nil {
913 log.Fatal("EVP_AEAD_CTX_new() failed")
914 }
915 defer C.EVP_AEAD_CTX_free(ctx)
916
917 if C.EVP_AEAD_CTX_init(ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 {
913 log.Fatal("Failed to initialize AEAD context") 918 log.Fatal("Failed to initialize AEAD context")
914 } 919 }
915 defer C.EVP_AEAD_CTX_cleanup(&ctx)
916 920
917 // Make sure we don't accidentally prepend or compare against a 0. 921 // Make sure we don't accidentally prepend or compare against a 0.
918 if ctLen == 0 { 922 if ctLen == 0 {
919 ct = nil 923 ct = nil
920 } 924 }
921 925
922 openAead = checkAeadOpen(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) 926 openAead = checkAeadOpen(ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt)
923 sealAead = checkAeadSeal(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) 927 sealAead = checkAeadSeal(ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt)
924 } 928 }
925 929
926 return openEvp && sealEvp && openAead && sealAead 930 return openEvp && sealEvp && openAead && sealAead
@@ -1227,14 +1231,17 @@ func runChaCha20Poly1305Test(algorithm string, wt *wycheproofTestAead) bool {
1227 msg = append(tag, 0) 1231 msg = append(tag, 0)
1228 } 1232 }
1229 1233
1230 var ctx C.EVP_AEAD_CTX 1234 ctx := C.EVP_AEAD_CTX_new()
1231 if C.EVP_AEAD_CTX_init(&ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 { 1235 if ctx == nil {
1236 log.Fatal("EVP_AEAD_CTX_new() failed")
1237 }
1238 defer C.EVP_AEAD_CTX_free(ctx)
1239 if C.EVP_AEAD_CTX_init(ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 {
1232 log.Fatal("Failed to initialize AEAD context") 1240 log.Fatal("Failed to initialize AEAD context")
1233 } 1241 }
1234 defer C.EVP_AEAD_CTX_cleanup(&ctx)
1235 1242
1236 openSuccess := checkAeadOpen(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) 1243 openSuccess := checkAeadOpen(ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt)
1237 sealSuccess := checkAeadSeal(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) 1244 sealSuccess := checkAeadSeal(ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt)
1238 1245
1239 return openSuccess && sealSuccess 1246 return openSuccess && sealSuccess
1240} 1247}