diff options
| author | tb <> | 2018-08-20 20:46:51 +0000 |
|---|---|---|
| committer | tb <> | 2018-08-20 20:46:51 +0000 |
| commit | 482e734c2daa07e5c21361527e0e52167cebb2c4 (patch) | |
| tree | 7afe5f0feebed5988998e5930e98f555630e62d2 /src | |
| parent | bbb92d9c768afa455c7322b4b45434897a1fbe03 (diff) | |
| download | openbsd-482e734c2daa07e5c21361527e0e52167cebb2c4.tar.gz openbsd-482e734c2daa07e5c21361527e0e52167cebb2c4.tar.bz2 openbsd-482e734c2daa07e5c21361527e0e52167cebb2c4.zip | |
Test EVP_AEAD_CTX_open() at the same time as EVP_AEAD_CTX_seal()
Suggested by jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index dc1a4f0b97..3fa08ba636 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.9 2018/08/20 18:47:20 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.10 2018/08/20 20:46:51 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -249,6 +249,9 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 249 | sealed := make([]byte, maxOutLen) | 249 | sealed := make([]byte, maxOutLen) |
| 250 | var sealedLen C.size_t | 250 | var sealedLen C.size_t |
| 251 | 251 | ||
| 252 | opened := make([]byte, maxOutLen) | ||
| 253 | var openedLen C.size_t | ||
| 254 | |||
| 252 | var ctx C.EVP_AEAD_CTX | 255 | var ctx C.EVP_AEAD_CTX |
| 253 | if C.EVP_AEAD_CTX_init((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(key_len), C.size_t(tag_len), nil) != 1 { | 256 | if C.EVP_AEAD_CTX_init((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(key_len), C.size_t(tag_len), nil) != 1 { |
| 254 | log.Fatalf("Failed to initialize AEAD context") | 257 | log.Fatalf("Failed to initialize AEAD context") |
| @@ -256,26 +259,41 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 256 | 259 | ||
| 257 | sealRet := C.EVP_AEAD_CTX_seal((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), (*C.uint8_t)(unsafe.Pointer(&sealed[0])), (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | 260 | sealRet := C.EVP_AEAD_CTX_seal((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), (*C.uint8_t)(unsafe.Pointer(&sealed[0])), (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) |
| 258 | 261 | ||
| 262 | concat := append(ct, tag...) | ||
| 263 | openRet := C.EVP_AEAD_CTX_open((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), (*C.uint8_t)(unsafe.Pointer(&opened[0])), (*C.size_t)(unsafe.Pointer(&openedLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&concat[0])), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
| 264 | |||
| 259 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) | 265 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) |
| 260 | 266 | ||
| 261 | if sealRet != 1 && wt.Result == "invalid" { | 267 | if sealRet != 1 && wt.Result == "invalid" { |
| 262 | fmt.Printf("INFO: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, want %v\n", wt.TCID, wt.Comment, int(sealRet), wt.Result) | 268 | fmt.Printf("INFO: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, EVP_AEAD_CTX_open() = %d, want %v\n", wt.TCID, wt.Comment, int(sealRet), int(openRet), wt.Result) |
| 269 | return true | ||
| 270 | } | ||
| 271 | if openRet != 1 && wt.Result == "invalid" { | ||
| 263 | return true | 272 | return true |
| 264 | } | 273 | } |
| 265 | 274 | ||
| 266 | if (sealedLen != C.size_t(maxOutLen)) { | 275 | if (sealedLen != C.size_t(maxOutLen)) { |
| 267 | fmt.Printf("FAIL: Test case %d (%q) - ChaCha output length mismatch: got %d, want %d", wt.TCID, wt.Comment, sealedLen, maxOutLen) | 276 | fmt.Printf("FAIL: Test case %d (%q) - seal length mismatch: got %d, want %d", wt.TCID, wt.Comment, sealedLen, maxOutLen) |
| 277 | return false | ||
| 278 | } | ||
| 279 | if (openedLen != C.size_t(msgLen)) { | ||
| 280 | fmt.Printf("FAIL: Test case %d (%q) - open length mismatch: got %d, want %d", wt.TCID, wt.Comment, openedLen, msgLen) | ||
| 268 | return false | 281 | return false |
| 269 | } | 282 | } |
| 270 | 283 | ||
| 271 | sealedCt := sealed[0:msgLen] | 284 | sealedCt := sealed[0:msgLen] |
| 272 | sealedTag := sealed[msgLen: maxOutLen] | 285 | sealedTag := sealed[msgLen: maxOutLen] |
| 273 | 286 | ||
| 287 | openedMsg := opened[0:openedLen] | ||
| 288 | if (msgLen == 0) { | ||
| 289 | msg = nil | ||
| 290 | } | ||
| 291 | |||
| 274 | success := false | 292 | success := false |
| 275 | if (bytes.Equal(sealedCt, ct) && bytes.Equal(sealedTag, tag)) || wt.Result == "invalid" { | 293 | if (bytes.Equal(sealedCt, ct) && bytes.Equal(sealedTag, tag) && bytes.Equal(openedMsg, msg)) || wt.Result == "invalid" { |
| 276 | success = true | 294 | success = true |
| 277 | } else { | 295 | } else { |
| 278 | fmt.Printf("FAIL: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, ct match: %t, tag match: %t; want %v\n", wt.TCID, wt.Comment, int(sealRet), bytes.Equal(sealedCt, ct), bytes.Equal(sealedTag, tag), wt.Result) | 296 | fmt.Printf("FAIL: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, ct match: %t, tag match: %t; msg match: %t; want %v\n", wt.TCID, wt.Comment, int(sealRet), bytes.Equal(sealedCt, ct), bytes.Equal(sealedTag, tag), bytes.Equal(openedMsg, msg), wt.Result) |
| 279 | } | 297 | } |
| 280 | 298 | ||
| 281 | return success | 299 | return success |
