Fix in evp_aes_xts init

This commit is contained in:
Eric Blankenhorn
2020-01-29 15:30:45 -06:00
parent d7c1b9561f
commit e421d9f52c
2 changed files with 20 additions and 22 deletions

View File

@ -17766,20 +17766,21 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ctx->cipherType = AES_128_XTS_TYPE;
ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE;
ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE;
ctx->keyLen = 16;
ctx->keyLen = 32;
ctx->block_size = 1;
if (enc == 0 || enc == 1)
ctx->enc = enc ? 1 : 0;
if (iv) {
ctx->cipher.tweak = iv;
ctx->cipher.tweakSz = 16;
}
if (key) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv,
AES_ENCRYPTION, 0);
if (ret != 0)
ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen,
AES_ENCRYPTION, NULL, 0);
if (ret != 0) {
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
return ret;
}
if (iv && key == NULL) {
ret = wc_AesSetIV(&ctx->cipher.aes, iv);
if (ret != 0)
return ret;
}
}
#endif /* WOLFSSL_AES_128 */
@ -17790,22 +17791,19 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ctx->cipherType = AES_256_XTS_TYPE;
ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE;
ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE;
ctx->keyLen = 32;
ctx->keyLen = 64;
ctx->block_size = 1;
if (enc == 0 || enc == 1)
ctx->enc = enc ? 1 : 0;
if (iv) {
ctx->cipher.tweak = iv;
ctx->cipher.tweakSz = 16;
}
if (key) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv,
AES_ENCRYPTION, 0);
ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen,
AES_ENCRYPTION, NULL, 0);
if (ret != 0) {
WOLFSSL_MSG("AesSetKey() failed");
return ret;
}
}
if (iv && key == NULL) {
ret = wc_AesSetIV(&ctx->cipher.aes, iv);
if (ret != 0){
WOLFSSL_MSG("wc_AesSetIV() failed");
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
return ret;
}
}

View File

@ -178,7 +178,7 @@ typedef union {
Aes aes;
#ifdef WOLFSSL_AES_XTS
XtsAes xts;
byte* tweak;
const byte* tweak;
word32 tweakSz;
#endif
#endif