diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2019-11-28 21:52:56 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2019-11-28 21:52:56 +0000 |
commit | ac2220e1028412b81f8511d90951a2db8515e001 (patch) | |
tree | 185d700c950174491f9ab73a507cfecc8236ecdd /regress/lib/libcrypto/wycheproof | |
parent | 2b5f0a37935e0f3f2833d748729effb8cbb0ec93 (diff) |
move the HKDF tests up a bit
Diffstat (limited to 'regress/lib/libcrypto/wycheproof')
-rw-r--r-- | regress/lib/libcrypto/wycheproof/wycheproof.go | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/regress/lib/libcrypto/wycheproof/wycheproof.go b/regress/lib/libcrypto/wycheproof/wycheproof.go index 955eb482204..569814c3fc1 100644 --- a/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -1,4 +1,4 @@ -/* $OpenBSD: wycheproof.go,v 1.105 2019/11/28 21:42:42 tb Exp $ */ +/* $OpenBSD: wycheproof.go,v 1.106 2019/11/28 21:52:55 tb Exp $ */ /* * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> @@ -1787,73 +1787,6 @@ func runECDSAWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDSAW return success } -func runKWTestWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { - var aesKey C.AES_KEY - - ret := C.AES_set_encrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) - if ret != 0 { - fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", - wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) - return false - } - - outLen := msgLen - out := make([]byte, outLen) - copy(out, msg) - out = append(out, make([]byte, 8)...) - ret = C.AES_wrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(msgLen)) - success := false - if ret == C.int(len(out)) && bytes.Equal(out, ct) { - if acceptableAudit && wt.Result == "acceptable" { - gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) - } - if wt.Result != "invalid" { - success = true - } - } else if wt.Result != "valid" { - success = true - } - if !success { - fmt.Printf("FAIL: Test case %d (%q) %v - msgLen = %d, AES_wrap_key() = %d, want %v\n", - wt.TCID, wt.Comment, wt.Flags, msgLen, int(ret), wt.Result) - } - return success -} - -func runKWTestUnWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { - var aesKey C.AES_KEY - - ret := C.AES_set_decrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) - if ret != 0 { - fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", - wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) - return false - } - - out := make([]byte, ctLen) - copy(out, ct) - if ctLen == 0 { - out = append(out, 0) - } - ret = C.AES_unwrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(ctLen)) - success := false - if ret == C.int(ctLen-8) && bytes.Equal(out[0:ret], msg[0:ret]) { - if acceptableAudit && wt.Result == "acceptable" { - gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) - } - if wt.Result != "invalid" { - success = true - } - } else if wt.Result != "valid" { - success = true - } - if !success { - fmt.Printf("FAIL: Test case %d (%q) %v - keyLen = %d, AES_unwrap_key() = %d, want %v\n", - wt.TCID, wt.Comment, wt.Flags, keyLen, int(ret), wt.Result) - } - return success -} - func runHkdfTest(md *C.EVP_MD, wt *wycheproofTestHkdf) bool { ikm, err := hex.DecodeString(wt.Ikm) if err != nil { @@ -1922,6 +1855,73 @@ func runHkdfTestGroup(algorithm string, wtg *wycheproofTestGroupHkdf) bool { return success } +func runKWTestWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { + var aesKey C.AES_KEY + + ret := C.AES_set_encrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) + if ret != 0 { + fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", + wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) + return false + } + + outLen := msgLen + out := make([]byte, outLen) + copy(out, msg) + out = append(out, make([]byte, 8)...) + ret = C.AES_wrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(msgLen)) + success := false + if ret == C.int(len(out)) && bytes.Equal(out, ct) { + if acceptableAudit && wt.Result == "acceptable" { + gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) + } + if wt.Result != "invalid" { + success = true + } + } else if wt.Result != "valid" { + success = true + } + if !success { + fmt.Printf("FAIL: Test case %d (%q) %v - msgLen = %d, AES_wrap_key() = %d, want %v\n", + wt.TCID, wt.Comment, wt.Flags, msgLen, int(ret), wt.Result) + } + return success +} + +func runKWTestUnWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { + var aesKey C.AES_KEY + + ret := C.AES_set_decrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) + if ret != 0 { + fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", + wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) + return false + } + + out := make([]byte, ctLen) + copy(out, ct) + if ctLen == 0 { + out = append(out, 0) + } + ret = C.AES_unwrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(ctLen)) + success := false + if ret == C.int(ctLen-8) && bytes.Equal(out[0:ret], msg[0:ret]) { + if acceptableAudit && wt.Result == "acceptable" { + gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) + } + if wt.Result != "invalid" { + success = true + } + } else if wt.Result != "valid" { + success = true + } + if !success { + fmt.Printf("FAIL: Test case %d (%q) %v - keyLen = %d, AES_unwrap_key() = %d, want %v\n", + wt.TCID, wt.Comment, wt.Flags, keyLen, int(ret), wt.Result) + } + return success +} + func runKWTest(keySize int, wt *wycheproofTestKW) bool { key, err := hex.DecodeString(wt.Key) if err != nil { |