Skip to content

Commit 5fa65a5

Browse files
authored
Merge pull request #181 from ColtonWilley/wp_fips_gcm_fix
Modify FIPS build and fix AES-GCM stream handling for FIPS
2 parents b1a102e + 9ad53bd commit 5fa65a5

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

scripts/utils-wolfssl.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ WOLFSSL_TAG=${WOLFSSL_TAG:-"v5.8.0-stable"}
2626
WOLFSSL_SOURCE_DIR=${SCRIPT_DIR}/../wolfssl-source
2727
WOLFSSL_INSTALL_DIR=${SCRIPT_DIR}/../wolfssl-install
2828
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0}
29+
WOLFSSL_FIPS_CONFIG_OPTS=${WOLFSSL_CONFIG_OPTS:-'--enable-opensslcoexist '}
30+
WOLFSSL_FIPS_CONFIG_CFLAGS=${WOLFSSL_CONFIG_CFLAGS:-"-I${OPENSSL_INSTALL_DIR}/include"}
2931
WOLFSSL_CONFIG_OPTS=${WOLFSSL_CONFIG_OPTS:-'--enable-all-crypto --with-eccminsz=192 --with-max-ecc-bits=1024 --enable-opensslcoexist --enable-sha'}
30-
WOLFSSL_CONFIG_CFLAGS=${WOLFSSL_CONFIG_CFLAGS:-"-I${OPENSSL_INSTALL_DIR}/include -DWC_RSA_NO_PADDING -DWOLFSSL_PUBLIC_MP -DHAVE_PUBLIC_FFDHE -DHAVE_FFDHE_6144 -DHAVE_FFDHE_8192 -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_PSS_SALT_LEN_DISCOVER -DRSA_MIN_SIZE=1024 -DWOLFSSL_OLD_OID_SUM -DWOLFSSL_BIND "}
32+
WOLFSSL_CONFIG_CFLAGS=${WOLFSSL_CONFIG_CFLAGS:-"-I${OPENSSL_INSTALL_DIR}/include -DWC_RSA_NO_PADDING -DWOLFSSL_PUBLIC_MP -DHAVE_PUBLIC_FFDHE -DHAVE_FFDHE_6144 -DHAVE_FFDHE_8192 -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_PSS_SALT_LEN_DISCOVER -DRSA_MIN_SIZE=1024 -DWOLFSSL_OLD_OID_SUM "}
3133

3234
WOLFPROV_DEBUG=${WOLFPROV_DEBUG:-0}
3335
USE_CUR_TAG=${USE_CUR_TAG:-0}
@@ -96,12 +98,16 @@ install_wolfssl() {
9698
fi
9799
printf "using FIPS bundle ... "
98100
CONF_ARGS+=" --enable-fips=$WOLFSSL_FIPS_VERSION"
101+
WOLFSSL_CONFIG_OPTS=$WOLFSSL_FIPS_CONFIG_OPTS
102+
WOLFSSL_CONFIG_CFLAGS=$WOLFSSL_FIPS_CONFIG_CFLAGS
99103
elif [ "$WOLFSSL_ISFIPS" = "1" ]; then
100104
printf "with FIPS ... "
101105
CONF_ARGS+=" --enable-fips=v5"
106+
WOLFSSL_CONFIG_OPTS=$WOLFSSL_FIPS_CONFIG_OPTS
107+
WOLFSSL_CONFIG_CFLAGS=$WOLFSSL_FIPS_CONFIG_CFLAGS
102108
if [ ! -e "XXX-fips-test" ]; then
103109
# Sometimes the system OpenSSL is different than the one we're using. So for the 'git' commands, we'll just use whatever the system comes with
104-
LD_LIBRARY_PATH="" ./fips-check.sh keep nomakecheck linuxv5 >>$LOG_FILE 2>&1
110+
LD_LIBRARY_PATH="" ./fips-check.sh linuxv5.2.1 keep nomakecheck >>$LOG_FILE 2>&1
105111
if [ $? != 0 ]; then
106112
printf "ERROR checking out FIPS\n"
107113
rm -rf ${WOLFSSL_INSTALL_DIR}

src/wp_aes_aead.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,17 +1395,32 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen,
13951395
}
13961396
}
13971397
else {
1398-
/* Only the most recent auth err matters */
1399-
ctx->authErr = 0;
1400-
rc = wc_AesGcmDecrypt(&ctx->aes, tmp, ctx->in, (word32)ctx->inLen,
1401-
iv, (word32)ctx->ivLen, ctx->buf, (word32)ctx->tagLen,
1402-
ctx->aad, (word32)ctx->aadLen);
1403-
if (rc == AES_GCM_AUTH_E) {
1404-
ctx->authErr = 1;
1405-
rc = 0;
1398+
if (done) {
1399+
/* Only the most recent auth err matters */
1400+
ctx->authErr = 0;
1401+
rc = wc_AesGcmDecrypt(&ctx->aes, tmp, ctx->in, (word32)ctx->inLen,
1402+
iv, (word32)ctx->ivLen, ctx->buf, (word32)ctx->tagLen,
1403+
ctx->aad, (word32)ctx->aadLen);
1404+
if (rc == AES_GCM_AUTH_E) {
1405+
ctx->authErr = 1;
1406+
rc = 0;
1407+
}
1408+
if (rc != 0) {
1409+
ok = 0;
1410+
}
14061411
}
1407-
if (rc != 0) {
1408-
ok = 0;
1412+
else {
1413+
byte tmpTag[16];
1414+
1415+
/* wc_AesGcmDecrypt does not yield plaintext on auth tag error.
1416+
* For all calls except final we use encrypt instead to yield
1417+
* the proper plaintext */
1418+
rc = wc_AesGcmEncrypt_ex(&ctx->aes, tmp, ctx->in,
1419+
(word32)ctx->inLen, iv, (word32)ctx->ivLen, (byte*)tmpTag,
1420+
(word32)ctx->tagLen, ctx->aad, (word32)ctx->aadLen);
1421+
if (rc != 0) {
1422+
ok = 0;
1423+
}
14091424
}
14101425
}
14111426
/* Copy out relevant portion of output */
@@ -1424,6 +1439,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen,
14241439
ctx->aadLen = 0;
14251440
ctx->aadSet = 0;
14261441
OPENSSL_free(ctx->in);
1442+
ctx->bufSize = 0;
14271443
ctx->in = NULL;
14281444
ctx->inLen = 0;
14291445
}

src/wp_rsa_kmgmt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,8 @@ static int wp_rsa_decode_pki(wp_Rsa* rsa, unsigned char* data, word32 len)
21842184
return ok;
21852185
}
21862186

2187+
#ifdef WOLFSSL_ENCRYPTED_KEYS
2188+
21872189
/** PBKDF2 OPID. */
21882190
unsigned char pbkdf2_oid[] = {
21892191
42, 134, 72, 134, 247, 13, 1, 5, 12
@@ -2261,6 +2263,8 @@ static int wp_rsa_decode_enc_pki(wp_Rsa* rsa, unsigned char* data, word32 len,
22612263
return ok;
22622264
}
22632265

2266+
#endif
2267+
22642268
/**
22652269
* Construct parameters from RSA key and pass off to callback.
22662270
*

0 commit comments

Comments
 (0)