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->cipherType = AES_128_XTS_TYPE;
ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE;
ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE;
ctx->keyLen = 16; ctx->keyLen = 32;
ctx->block_size = 1; ctx->block_size = 1;
if (enc == 0 || enc == 1) if (enc == 0 || enc == 1)
ctx->enc = enc ? 1 : 0; ctx->enc = enc ? 1 : 0;
if (key) { if (iv) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, ctx->cipher.tweak = iv;
AES_ENCRYPTION, 0); ctx->cipher.tweakSz = 16;
if (ret != 0)
return ret;
} }
if (iv && key == NULL) { if (key) {
ret = wc_AesSetIV(&ctx->cipher.aes, iv); ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen,
if (ret != 0) AES_ENCRYPTION, NULL, 0);
if (ret != 0) {
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
return ret; return ret;
}
} }
} }
#endif /* WOLFSSL_AES_128 */ #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->cipherType = AES_256_XTS_TYPE;
ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE;
ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE;
ctx->keyLen = 32; ctx->keyLen = 64;
ctx->block_size = 1; ctx->block_size = 1;
if (enc == 0 || enc == 1) if (enc == 0 || enc == 1)
ctx->enc = enc ? 1 : 0; ctx->enc = enc ? 1 : 0;
if (key) { if (iv) {
ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, ctx->cipher.tweak = iv;
AES_ENCRYPTION, 0); ctx->cipher.tweakSz = 16;
if (ret != 0){
WOLFSSL_MSG("AesSetKey() failed");
return ret;
}
} }
if (iv && key == NULL) { if (key) {
ret = wc_AesSetIV(&ctx->cipher.aes, iv); ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen,
if (ret != 0){ AES_ENCRYPTION, NULL, 0);
WOLFSSL_MSG("wc_AesSetIV() failed"); if (ret != 0) {
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
return ret; return ret;
} }
} }

View File

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