diff options
| author | tb <> | 2018-08-20 18:26:35 +0000 |
|---|---|---|
| committer | tb <> | 2018-08-20 18:26:35 +0000 |
| commit | c6e00c017a856485cae72f681a0c081050aabd50 (patch) | |
| tree | 57a5f9956671d9e084027e665bf5e0c2f9bfae43 /src | |
| parent | 23fb349fe56f25227dca8f3fcac4cd1f3e30b803 (diff) | |
| download | openbsd-c6e00c017a856485cae72f681a0c081050aabd50.tar.gz openbsd-c6e00c017a856485cae72f681a0c081050aabd50.tar.bz2 openbsd-c6e00c017a856485cae72f681a0c081050aabd50.zip | |
Use sealed instead of out in a couple of places in preparation of
testing EVP_AEAD_CTX_open()
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 740a388152..d648ee5adb 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.7 2018/08/20 18:17:52 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.8 2018/08/20 18:26:35 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -245,30 +245,31 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | maxOutLen := msgLen + tag_len | 247 | maxOutLen := msgLen + tag_len |
| 248 | out := make([]byte, maxOutLen) | 248 | |
| 249 | var outLen C.size_t | 249 | sealed := make([]byte, maxOutLen) |
| 250 | var sealedLen C.size_t | ||
| 250 | 251 | ||
| 251 | var ctx C.EVP_AEAD_CTX | 252 | var ctx C.EVP_AEAD_CTX |
| 252 | 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 { | 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 { |
| 253 | log.Fatalf("Failed to initialize AEAD context") | 254 | log.Fatalf("Failed to initialize AEAD context") |
| 254 | } | 255 | } |
| 255 | 256 | ||
| 256 | ret := C.EVP_AEAD_CTX_seal((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx)), (*C.uint8_t)(unsafe.Pointer(&out[0])), (*C.size_t)(unsafe.Pointer(&outLen)), 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)) | 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)) |
| 257 | 258 | ||
| 258 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) | 259 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) |
| 259 | 260 | ||
| 260 | if ret != 1 && wt.Result == "invalid" { | 261 | if sealRet != 1 && wt.Result == "invalid" { |
| 261 | fmt.Printf("INFO: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, want %v\n", wt.TCID, wt.Comment, int(ret), wt.Result) | 262 | fmt.Printf("INFO: Test case %d (%q) - EVP_AEAD_CTX_seal() = %d, want %v\n", wt.TCID, wt.Comment, int(sealRet), wt.Result) |
| 262 | return true | 263 | return true |
| 263 | } | 264 | } |
| 264 | 265 | ||
| 265 | if (outLen != C.size_t(maxOutLen)) { | 266 | if (sealedLen != C.size_t(maxOutLen)) { |
| 266 | fmt.Printf("FAIL: Test case %d (%q) - ChaCha output length mismatch: got %d, want %d", wt.TCID, wt.Comment, outLen, maxOutLen) | 267 | fmt.Printf("FAIL: Test case %d (%q) - ChaCha output length mismatch: got %d, want %d", wt.TCID, wt.Comment, sealedLen, maxOutLen) |
| 267 | return false | 268 | return false |
| 268 | } | 269 | } |
| 269 | 270 | ||
| 270 | outCt := out[0:msgLen] | 271 | sealedCt := sealed[0:msgLen] |
| 271 | outTag := out[msgLen: maxOutLen] | 272 | sealedTag := sealed[msgLen: maxOutLen] |
| 272 | 273 | ||
| 273 | if len(ct) != msgLen { | 274 | if len(ct) != msgLen { |
| 274 | fmt.Printf("FAIL: Test case %d (%q) - msg length %d doesn't match ct length %d", wt.TCID, wt.Comment, msgLen, len(ct)) | 275 | fmt.Printf("FAIL: Test case %d (%q) - msg length %d doesn't match ct length %d", wt.TCID, wt.Comment, msgLen, len(ct)) |
| @@ -280,10 +281,10 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 280 | } | 281 | } |
| 281 | 282 | ||
| 282 | success := false | 283 | success := false |
| 283 | if (bytes.Equal(outCt, ct) && bytes.Equal(outTag, tag)) || wt.Result == "invalid" { | 284 | if (bytes.Equal(sealedCt, ct) && bytes.Equal(sealedTag, tag)) || wt.Result == "invalid" { |
| 284 | success = true | 285 | success = true |
| 285 | } else { | 286 | } else { |
| 286 | 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(ret), bytes.Equal(outCt, ct), bytes.Equal(outTag, tag), wt.Result) | 287 | 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) |
| 287 | } | 288 | } |
| 288 | 289 | ||
| 289 | return success | 290 | return success |
