diff --git a/src/internal.c b/src/internal.c index c365168dd..e5ef65961 100644 --- a/src/internal.c +++ b/src/internal.c @@ -15941,10 +15941,17 @@ const char* GetCipherNameInternal(const char* cipherName, int cipherSuite) return NULL; } - first = (XSTRSTR(cipherName, "CHACHA")) ? "CHACHA" - : (XSTRSTR(cipherName, "EC")) ? "EC" - : (XSTRSTR(cipherName, "CCM")) ? "CCM" - : NULL; /* normal */ + first = + #ifdef HAVE_CHACHA + (XSTRSTR(cipherName, "CHACHA")) ? "CHACHA" : + #endif + #ifdef HAVE_ECC + (XSTRSTR(cipherName, "EC")) ? "EC" : + #endif + #ifdef HAVE_AESCCM + (XSTRSTR(cipherName, "CCM")) ? "CCM" : + #endif + NULL; /* normal */ for (i = 0; i < (int)(sizeof(cipher_name_idx)/sizeof(int)); i++) { if (cipher_name_idx[i] == cipherSuite) { diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 55808be98..926a9277e 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -8374,15 +8374,21 @@ int wc_AesGetKeySize(Aes* aes, word32* keySize) } switch (aes->rounds) { + #ifdef WOLFSSL_AES_128 case 10: *keySize = 16; break; + #endif + #ifdef WOLFSSL_AES_192 case 12: *keySize = 24; break; + #endif + #ifdef WOLFSSL_AES_256 case 14: *keySize = 32; break; + #endif default: *keySize = 0; ret = BAD_FUNC_ARG; diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 96253e637..c1b2f914c 100755 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -4164,9 +4164,9 @@ static int GetName(DecodedCert* cert, int nameType) /* v1 name types */ if (joint[0] == 0x55 && joint[1] == 0x04) { - byte id; - byte copy = FALSE; + const char* copy = NULL; int strLen; + byte id; cert->srcIdx += 2; id = cert->source[cert->srcIdx++]; @@ -4189,22 +4189,14 @@ static int GetName(DecodedCert* cert, int nameType) cert->subjectCNEnc = b; } - if (!tooBig) { - XMEMCPY(&full[idx], "/CN=", 4); - idx += 4; - copy = TRUE; - } + copy = WOLFSSL_COMMON_NAME; #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) dName->cnIdx = cert->srcIdx; dName->cnLen = strLen; #endif /* OPENSSL_EXTRA */ } else if (id == ASN_SUR_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/SN=", 4); - idx += 4; - copy = TRUE; - } + copy = WOLFSSL_SUR_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectSN = (char*)&cert->source[cert->srcIdx]; @@ -4218,11 +4210,7 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_COUNTRY_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/C=", 3); - idx += 3; - copy = TRUE; - } + copy = WOLFSSL_COUNTRY_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectC = (char*)&cert->source[cert->srcIdx]; @@ -4236,11 +4224,7 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_LOCALITY_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/L=", 3); - idx += 3; - copy = TRUE; - } + copy = WOLFSSL_LOCALITY_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectL = (char*)&cert->source[cert->srcIdx]; @@ -4254,11 +4238,7 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_STATE_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/ST=", 4); - idx += 4; - copy = TRUE; - } + copy = WOLFSSL_STATE_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectST = (char*)&cert->source[cert->srcIdx]; @@ -4272,11 +4252,7 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_ORG_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/O=", 3); - idx += 3; - copy = TRUE; - } + copy = WOLFSSL_ORG_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectO = (char*)&cert->source[cert->srcIdx]; @@ -4290,11 +4266,7 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_ORGUNIT_NAME) { - if (!tooBig) { - XMEMCPY(&full[idx], "/OU=", 4); - idx += 4; - copy = TRUE; - } + copy = WOLFSSL_ORGUNIT_NAME; #ifdef WOLFSSL_CERT_GEN if (nameType == SUBJECT) { cert->subjectOU = (char*)&cert->source[cert->srcIdx]; @@ -4308,17 +4280,15 @@ static int GetName(DecodedCert* cert, int nameType) #endif /* OPENSSL_EXTRA */ } else if (id == ASN_SERIAL_NUMBER) { - if (!tooBig) { - XMEMCPY(&full[idx], "/serialNumber=", 14); - idx += 14; - copy = TRUE; - } + copy = WOLFSSL_SERIAL_NUMBER; #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) dName->snIdx = cert->srcIdx; dName->snLen = strLen; #endif /* OPENSSL_EXTRA */ } if (copy && !tooBig) { + XMEMCPY(&full[idx], copy, XSTRLEN(copy)); + idx += (word32)XSTRLEN(copy); XMEMCPY(&full[idx], &cert->source[cert->srcIdx], strLen); idx += strLen; } diff --git a/wolfcrypt/src/error.c b/wolfcrypt/src/error.c index 414b77a3f..0839ed85e 100644 --- a/wolfcrypt/src/error.c +++ b/wolfcrypt/src/error.c @@ -33,15 +33,9 @@ #pragma warning(disable: 4996) #endif +#ifndef NO_ERROR_STRINGS const char* wc_GetErrorString(int error) { -#ifdef NO_ERROR_STRINGS - - (void)error; - return "no support for error strings built in"; - -#else - switch (error) { case OPEN_RAN_E : @@ -456,12 +450,11 @@ const char* wc_GetErrorString(int error) return "unknown error number"; } - -#endif /* NO_ERROR_STRINGS */ - } void wc_ErrorString(int error, char* buffer) { XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ); } +#endif /* !NO_ERROR_STRINGS */ + diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 54c2c5757..9649aa20a 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -115,6 +115,17 @@ enum DN_Tags { ASN_DOMAIN_COMPONENT = 0x19 /* DC */ }; +/* DN Tag Strings */ +#define WOLFSSL_COMMON_NAME "/CN" +#define WOLFSSL_SUR_NAME "/SN" +#define WOLFSSL_SERIAL_NUMBER "/serialNumber=" +#define WOLFSSL_COUNTRY_NAME "/C" +#define WOLFSSL_LOCALITY_NAME "/L" +#define WOLFSSL_STATE_NAME "/ST" +#define WOLFSSL_ORG_NAME "/O" +#define WOLFSSL_ORGUNIT_NAME "/OU" +#define WOLFSSL_DOMAIN_COMPONENT "/DC" + enum PBES { PBE_MD5_DES = 0, PBE_SHA1_RC4_128 = 1, diff --git a/wolfssl/wolfcrypt/error-crypt.h b/wolfssl/wolfcrypt/error-crypt.h index 6088bd9cb..92ce085ca 100644 --- a/wolfssl/wolfcrypt/error-crypt.h +++ b/wolfssl/wolfcrypt/error-crypt.h @@ -208,9 +208,15 @@ enum { }; +#ifdef NO_ERROR_STRINGS + #define wc_GetErrorString(error) "no support for error strings built in" + #define wc_ErrorString(err, buf) \ + XSTRNCPY((buf), wc_GetErrorString((err)), WOLFSSL_MAX_ERROR_SZ); + +#else WOLFSSL_API void wc_ErrorString(int err, char* buff); WOLFSSL_API const char* wc_GetErrorString(int error); - +#endif #ifdef __cplusplus } /* extern "C" */