From a4caa42793dee81925269c2a66d099b544f57b9d Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 24 Apr 2020 11:17:54 -0700 Subject: [PATCH] Improve the Base64 line size for `NO_ASN` case. Fix report of unread `ret`. --- wolfcrypt/src/asn.c | 3 +-- wolfcrypt/src/coding.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 11e58a7cb..2c7facc55 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -15573,10 +15573,9 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx, /* get curve id */ if ((ret = CheckCurve(oidSum)) < 0) - ret = ECC_CURVE_OID_E; + return ECC_CURVE_OID_E; else { curve_id = ret; - ret = 0; } } diff --git a/wolfcrypt/src/coding.c b/wolfcrypt/src/coding.c index c94efb03e..2a8dcb418 100644 --- a/wolfcrypt/src/coding.c +++ b/wolfcrypt/src/coding.c @@ -29,10 +29,11 @@ #ifndef NO_CODING #include -#include /* For PEM_LINE_SZ */ #include #include - +#ifndef NO_ASN + #include /* For PEM_LINE_SZ */ +#endif enum { BAD = 0xFF, /* invalid encoding */ @@ -42,6 +43,14 @@ enum { }; +#ifndef BASE64_LINE_SZ + #ifdef NO_ASN + #define BASE64_LINE_SZ 64 + #else + #define BASE64_LINE_SZ PEM_LINE_SZ + #endif +#endif + #ifdef WOLFSSL_BASE64_DECODE static @@ -91,7 +100,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) { word32 i = 0; word32 j = 0; - word32 plainSz = inLen - ((inLen + (PEM_LINE_SZ - 1)) / PEM_LINE_SZ ); + word32 plainSz = inLen - ((inLen + (BASE64_LINE_SZ - 1)) / BASE64_LINE_SZ ); int ret; const byte maxIdx = (byte)sizeof(base64Decode) + BASE64_MIN - 1; @@ -291,7 +300,7 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out, int getSzOnly = (out == NULL); word32 outSz = (inLen + 3 - 1) / 3 * 4; - word32 addSz = (outSz + PEM_LINE_SZ - 1) / PEM_LINE_SZ; /* new lines */ + word32 addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */ if (escaped == WC_ESC_NL_ENC) addSz *= 3; /* instead of just \n, we're doing %0A triplet */ @@ -328,8 +337,8 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out, inLen -= 3; - /* Insert newline after PEM_LINE_SZ, unless no \n requested */ - if (escaped != WC_NO_NL_ENC && (++n % (PEM_LINE_SZ/4)) == 0 && inLen) { + /* Insert newline after BASE64_LINE_SZ, unless no \n requested */ + if (escaped != WC_NO_NL_ENC && (++n % (BASE64_LINE_SZ/4)) == 0 && inLen) { ret = CEscape(escaped, '\n', out, &i, *outLen, 1, getSzOnly); if (ret != 0) break; }