diff options
| author | tb <> | 2018-08-20 18:17:52 +0000 |
|---|---|---|
| committer | tb <> | 2018-08-20 18:17:52 +0000 |
| commit | 23fb349fe56f25227dca8f3fcac4cd1f3e30b803 (patch) | |
| tree | 16175c1d6dfb7031755c34781fc0b41ffb7c3e7c /src | |
| parent | 5009d6df2ed67bbfa38248a80b501d5bfc1fa884 (diff) | |
| download | openbsd-23fb349fe56f25227dca8f3fcac4cd1f3e30b803.tar.gz openbsd-23fb349fe56f25227dca8f3fcac4cd1f3e30b803.tar.bz2 openbsd-23fb349fe56f25227dca8f3fcac4cd1f3e30b803.zip | |
Shuffle the decoding of the hex strings to the top and group all length
tests together. Make failure of the length tests non-fatal, as these are
failures of test cases, not of the program.
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index c00a869f6f..740a388152 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.6 2018/08/20 17:06:18 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.7 2018/08/20 18:17:52 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -201,22 +201,10 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 201 | if err != nil { | 201 | if err != nil { |
| 202 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | 202 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) |
| 203 | } | 203 | } |
| 204 | if key_len != len(key) { | ||
| 205 | log.Fatalf("Key length mismatch: got %d, want %d", len(key), key_len) | ||
| 206 | } | ||
| 207 | |||
| 208 | var ctx C.EVP_AEAD_CTX | ||
| 209 | 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 { | ||
| 210 | log.Fatalf("Failed to initialize AEAD context") | ||
| 211 | } | ||
| 212 | |||
| 213 | iv, err := hex.DecodeString(wt.IV) | 204 | iv, err := hex.DecodeString(wt.IV) |
| 214 | if err != nil { | 205 | if err != nil { |
| 215 | log.Fatalf("Failed to decode key %q: %v", wt.IV, err) | 206 | log.Fatalf("Failed to decode key %q: %v", wt.IV, err) |
| 216 | } | 207 | } |
| 217 | if iv_len != len(iv) { | ||
| 218 | log.Fatalf("IV length mismatch: got %d, want %d", len(iv), iv_len) | ||
| 219 | } | ||
| 220 | aad, err := hex.DecodeString(wt.AAD) | 208 | aad, err := hex.DecodeString(wt.AAD) |
| 221 | if err != nil { | 209 | if err != nil { |
| 222 | log.Fatalf("Failed to decode AAD %q: %v", wt.AAD, err) | 210 | log.Fatalf("Failed to decode AAD %q: %v", wt.AAD, err) |
| @@ -225,8 +213,27 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 225 | if err != nil { | 213 | if err != nil { |
| 226 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) | 214 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) |
| 227 | } | 215 | } |
| 216 | ct, err := hex.DecodeString(wt.CT) | ||
| 217 | if err != nil { | ||
| 218 | log.Fatalf("Failed to decode ct %q: %v", wt.CT, err) | ||
| 219 | } | ||
| 220 | tag, err := hex.DecodeString(wt.Tag) | ||
| 221 | if err != nil { | ||
| 222 | log.Fatalf("Failed to decode tag %q: %v", wt.Tag, err) | ||
| 223 | } | ||
| 224 | |||
| 225 | keyLen, ivLen, aadLen, tagLen := len(key), len(iv), len(aad), len(tag) | ||
| 226 | if key_len != keyLen || iv_len != ivLen || tag_len != tagLen { | ||
| 227 | fmt.Printf("FAIL: Test case %d (%q) - length mismatch; key: got %d, want %d; IV: got %d, want %d; tag: got %d, want %d\n", wt.TCID, wt.Comment, keyLen, key_len, ivLen, iv_len, tagLen, tag_len) | ||
| 228 | return false | ||
| 229 | } | ||
| 230 | |||
| 231 | msgLen, ctLen := len(msg), len(ct) | ||
| 232 | if msgLen != ctLen { | ||
| 233 | fmt.Printf("FAIL: Test case %d (%q) - length mismatch: msgLen = %d, ctLen = %d\n", wt.TCID, wt.Comment, msgLen, ctLen) | ||
| 234 | return false | ||
| 235 | } | ||
| 228 | 236 | ||
| 229 | ivLen, aadLen, msgLen := len(iv), len(aad), len(msg) | ||
| 230 | if ivLen == 0 { | 237 | if ivLen == 0 { |
| 231 | iv = append(iv, 0) | 238 | iv = append(iv, 0) |
| 232 | } | 239 | } |
| @@ -241,6 +248,11 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 241 | out := make([]byte, maxOutLen) | 248 | out := make([]byte, maxOutLen) |
| 242 | var outLen C.size_t | 249 | var outLen C.size_t |
| 243 | 250 | ||
| 251 | 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 | log.Fatalf("Failed to initialize AEAD context") | ||
| 254 | } | ||
| 255 | |||
| 244 | 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)) | 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)) |
| 245 | 257 | ||
| 246 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) | 258 | C.EVP_AEAD_CTX_cleanup((*C.EVP_AEAD_CTX)(unsafe.Pointer(&ctx))) |
| @@ -258,18 +270,10 @@ func runChaCha20Poly1305Test(iv_len int, key_len int, tag_len int, wt *wycheproo | |||
| 258 | outCt := out[0:msgLen] | 270 | outCt := out[0:msgLen] |
| 259 | outTag := out[msgLen: maxOutLen] | 271 | outTag := out[msgLen: maxOutLen] |
| 260 | 272 | ||
| 261 | ct, err := hex.DecodeString(wt.CT) | ||
| 262 | if err != nil { | ||
| 263 | log.Fatalf("Failed to decode ct %q: %v", wt.CT, err) | ||
| 264 | } | ||
| 265 | if len(ct) != msgLen { | 273 | if len(ct) != msgLen { |
| 266 | fmt.Printf("FAIL: Test case %d (%q) - msg length %d doesn't match ct length %d", wt.TCID, wt.Comment, msgLen, len(ct)) | 274 | fmt.Printf("FAIL: Test case %d (%q) - msg length %d doesn't match ct length %d", wt.TCID, wt.Comment, msgLen, len(ct)) |
| 267 | return false | 275 | return false |
| 268 | } | 276 | } |
| 269 | tag, err := hex.DecodeString(wt.Tag) | ||
| 270 | if err != nil { | ||
| 271 | log.Fatalf("Failed to decode tag %q: %v", wt.Tag, err) | ||
| 272 | } | ||
| 273 | if len(tag) != tag_len { | 277 | if len(tag) != tag_len { |
| 274 | fmt.Printf("FAIL: Test case %d (%q) tag length: got %d, want %d", wt.TCID, wt.Comment, len(tag), tag_len) | 278 | fmt.Printf("FAIL: Test case %d (%q) tag length: got %d, want %d", wt.TCID, wt.Comment, len(tag), tag_len) |
| 275 | return false | 279 | return false |
