-/* $OpenBSD: wycheproof.go,v 1.155 2023/11/07 16:46:12 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.156 2023/11/07 16:54:43 tb Exp $ */
/*
* Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2018,2019,2022 Theo Buehler <tb@openbsd.org>
return out, outLen
}
-func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int,
- iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int,
- wt *wycheproofTestAesCbcPkcs5) bool {
+func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int, wt *wycheproofTestAesCbcPkcs5) bool {
var action string
if doEncrypt == 1 {
action = "encrypting"
action = "decrypting"
}
- ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])),
- (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt))
+ ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt))
if ret != 1 {
log.Fatalf("EVP_CipherInit_ex failed: %d", ret)
}
cipherOut := make([]byte, inLen+C.EVP_MAX_BLOCK_LENGTH)
var cipherOutLen C.int
- ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen,
- (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen))
+ ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen))
if ret != 1 {
if wt.Result == "invalid" {
fmt.Printf("INFO: %s [%v] - EVP_CipherUpdate() = %d\n", wt, action, ret)
}
func (wtg *wycheproofTestGroupAesCbcPkcs5) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with IV size %d and key size %d...\n",
- algorithm, wtg.Type, wtg.IVSize, wtg.KeySize)
+ fmt.Printf("Running %v test group %v with IV size %d and key size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize)
cipher, err := cipherAes("AES-CBC", wtg.KeySize)
if err != nil {
return success
}
-func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int,
- key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int,
- in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int,
- wt *wycheproofTestAead) bool {
+func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool {
var ctrlSetIVLen C.int
var ctrlSetTag C.int
var ctrlGetTag C.int
}
}
- ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])),
- (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt))
+ ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt))
if ret != 1 {
fmt.Printf("FAIL: %s [%v] - setting key and IV failed: %d.\n", wt, action, ret)
return false
cipherOut = append(cipherOut, 0)
}
- ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen,
- (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen))
+ ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen))
if ret != 1 {
if wt.Result == "invalid" {
return true
}
func (wtg *wycheproofTestGroupAesAead) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n",
- algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize)
+ fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize)
cipher, err := cipherAes(algorithm, wtg.KeySize)
if err != nil {
}
func (wtg *wycheproofTestGroupAesCmac) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n",
- algorithm, wtg.Type, wtg.KeySize, wtg.TagSize)
+ fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", algorithm, wtg.Type, wtg.KeySize, wtg.TagSize)
cipher, err := cipherAes("AES-CBC", wtg.KeySize)
if err != nil {
return success
}
-func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int,
- ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool {
+func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool {
maxOutLen := ctLen + tagLen
opened := make([]byte, maxOutLen)
if catCtTagLen == 0 {
catCtTag = append(catCtTag, 0)
}
- openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])),
- (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen),
- (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen),
- (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(catCtTagLen),
- (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen))
+ openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])), (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen), (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(catCtTagLen), (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen))
if openRet != 1 {
if wt.Result == "invalid" {
return success
}
-func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte,
- msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool {
+func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool {
maxOutLen := msgLen + tagLen
sealed := make([]byte, maxOutLen)
}
var sealedLen C.size_t
- sealRet := C.EVP_AEAD_CTX_seal(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))
+ sealRet := C.EVP_AEAD_CTX_seal(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))
if sealRet != 1 {
success := (wt.Result == "invalid")
return true
}
- fmt.Printf("Running %v test group %v with IV size %d, key size %d, tag size %d...\n",
- algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize)
+ fmt.Printf("Running %v test group %v with IV size %d, key size %d, tag size %d...\n", algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize)
success := true
for _, wt := range wtg.Tests {
}
defer C.free(unsafe.Pointer(cDer))
- ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen),
- (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), dsa)
+ ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), dsa)
} else {
sig, sigLen := mustDecodeHexString(wt.Sig, "sig")
- ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen),
- (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa)
+ ret = C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa)
}
success := true
}
func (wtg *wycheproofTestGroupDSA) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v, key size %d and %v...\n",
- algorithm, wtg.Type, wtg.Key.KeySize, wtg.SHA)
+ fmt.Printf("Running %v test group %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.KeySize, wtg.SHA)
dsa := C.DSA_new()
if dsa == nil {
}
func (wtg *wycheproofTestGroupECDH) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n",
- algorithm, wtg.Type, wtg.Curve, wtg.Encoding)
+ fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding)
nid, err := nidFromString(wtg.Curve)
if err != nil {
}
func (wtg *wycheproofTestGroupECDHWebCrypto) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n",
- algorithm, wtg.Type, wtg.Curve, wtg.Encoding)
+ fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", algorithm, wtg.Type, wtg.Curve, wtg.Encoding)
nid, err := nidFromString(wtg.Curve)
if err != nil {
}
defer C.free(unsafe.Pointer(cDer))
- ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen),
- (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), ecKey)
+ ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), ecKey)
} else {
sig, sigLen := mustDecodeHexString(wt.Sig, "sig")
- ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen),
- (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), ecKey)
+ ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), ecKey)
}
// XXX audit acceptable cases...
}
func (wtg *wycheproofTestGroupECDSA) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n",
- algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA)
+ fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA)
nid, err := nidFromString(wtg.Key.Curve)
if err != nil {
}
func (wtg *wycheproofTestGroupECDSAWebCrypto) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n",
- algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA)
+ fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA)
nid, err := nidFromString(wtg.JWK.Crv)
if err != nil {
}
func (wtg *wycheproofTestGroupKW) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with key size %d...\n",
- algorithm, wtg.Type, wtg.KeySize)
+ fmt.Printf("Running %v test group %v with key size %d...\n", algorithm, wtg.Type, wtg.KeySize)
success := true
for _, wt := range wtg.Tests {
}
func (wtg *wycheproofTestGroupRsaesOaep) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with key size %d MGF %v and %v...\n",
- algorithm, wtg.Type, wtg.KeySize, wtg.MGFSHA, wtg.SHA)
+ fmt.Printf("Running %v test group %v with key size %d MGF %v and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.MGFSHA, wtg.SHA)
rsa := C.RSA_new()
if rsa == nil {
sigOut = append(sigOut, 0)
}
- ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])),
- (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING)
+ ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])), (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING)
if ret == -1 {
if wt.Result == "invalid" {
return true
return false
}
- ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha,
- (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen))
+ ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha, (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen))
success := false
if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") {
}
func (wtg *wycheproofTestGroupRsassa) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with key size %d and %v...\n",
- algorithm, wtg.Type, wtg.KeySize, wtg.SHA)
+ fmt.Printf("Running %v test group %v with key size %d and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.SHA)
rsa := C.RSA_new()
if rsa == nil {
log.Fatal("RSA_new failed")
msg, msgLen := mustHashHexMessage(md, wt.Msg)
sig, sigLen := mustDecodeHexString(wt.Sig, "sig")
- ret := C.RSA_verify(C.int(nid), (*C.uchar)(unsafe.Pointer(&msg[0])), C.uint(msgLen),
- (*C.uchar)(unsafe.Pointer(&sig[0])), C.uint(sigLen), rsa)
+ ret := C.RSA_verify(C.int(nid), (*C.uchar)(unsafe.Pointer(&msg[0])), C.uint(msgLen), (*C.uchar)(unsafe.Pointer(&sig[0])), C.uint(sigLen), rsa)
// XXX audit acceptable cases...
success := true
}
func (wtg *wycheproofTestGroupRSA) run(algorithm string, variant testVariant) bool {
- fmt.Printf("Running %v test group %v with key size %d and %v...\n",
- algorithm, wtg.Type, wtg.KeySize, wtg.SHA)
+ fmt.Printf("Running %v test group %v with key size %d and %v...\n", algorithm, wtg.Type, wtg.KeySize, wtg.SHA)
rsa := C.RSA_new()
if rsa == nil {
if err := json.Unmarshal(b, wtv); err != nil {
log.Fatalf("Failed to unmarshal JSON: %v", err)
}
- fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n",
- wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path))
+ fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path))
success := true
for _, tg := range wtv.TestGroups {