Merge pull request #1397 from JacobBarthelmeh/Optimizations

Optimizations
This commit is contained in:
toddouska 2018-02-26 08:43:22 -08:00 committed by GitHub
commit b527f6fb81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 57 deletions

View File

@ -15941,10 +15941,17 @@ const char* GetCipherNameInternal(const char* cipherName, int cipherSuite)
return NULL; return NULL;
} }
first = (XSTRSTR(cipherName, "CHACHA")) ? "CHACHA" first =
: (XSTRSTR(cipherName, "EC")) ? "EC" #ifdef HAVE_CHACHA
: (XSTRSTR(cipherName, "CCM")) ? "CCM" (XSTRSTR(cipherName, "CHACHA")) ? "CHACHA" :
: NULL; /* normal */ #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++) { for (i = 0; i < (int)(sizeof(cipher_name_idx)/sizeof(int)); i++) {
if (cipher_name_idx[i] == cipherSuite) { if (cipher_name_idx[i] == cipherSuite) {

View File

@ -8374,15 +8374,21 @@ int wc_AesGetKeySize(Aes* aes, word32* keySize)
} }
switch (aes->rounds) { switch (aes->rounds) {
#ifdef WOLFSSL_AES_128
case 10: case 10:
*keySize = 16; *keySize = 16;
break; break;
#endif
#ifdef WOLFSSL_AES_192
case 12: case 12:
*keySize = 24; *keySize = 24;
break; break;
#endif
#ifdef WOLFSSL_AES_256
case 14: case 14:
*keySize = 32; *keySize = 32;
break; break;
#endif
default: default:
*keySize = 0; *keySize = 0;
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;

View File

@ -4164,9 +4164,9 @@ static int GetName(DecodedCert* cert, int nameType)
/* v1 name types */ /* v1 name types */
if (joint[0] == 0x55 && joint[1] == 0x04) { if (joint[0] == 0x55 && joint[1] == 0x04) {
byte id; const char* copy = NULL;
byte copy = FALSE;
int strLen; int strLen;
byte id;
cert->srcIdx += 2; cert->srcIdx += 2;
id = cert->source[cert->srcIdx++]; id = cert->source[cert->srcIdx++];
@ -4189,22 +4189,14 @@ static int GetName(DecodedCert* cert, int nameType)
cert->subjectCNEnc = b; cert->subjectCNEnc = b;
} }
if (!tooBig) { copy = WOLFSSL_COMMON_NAME;
XMEMCPY(&full[idx], "/CN=", 4);
idx += 4;
copy = TRUE;
}
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
dName->cnIdx = cert->srcIdx; dName->cnIdx = cert->srcIdx;
dName->cnLen = strLen; dName->cnLen = strLen;
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_SUR_NAME) { else if (id == ASN_SUR_NAME) {
if (!tooBig) { copy = WOLFSSL_SUR_NAME;
XMEMCPY(&full[idx], "/SN=", 4);
idx += 4;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectSN = (char*)&cert->source[cert->srcIdx]; cert->subjectSN = (char*)&cert->source[cert->srcIdx];
@ -4218,11 +4210,7 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_COUNTRY_NAME) { else if (id == ASN_COUNTRY_NAME) {
if (!tooBig) { copy = WOLFSSL_COUNTRY_NAME;
XMEMCPY(&full[idx], "/C=", 3);
idx += 3;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectC = (char*)&cert->source[cert->srcIdx]; cert->subjectC = (char*)&cert->source[cert->srcIdx];
@ -4236,11 +4224,7 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_LOCALITY_NAME) { else if (id == ASN_LOCALITY_NAME) {
if (!tooBig) { copy = WOLFSSL_LOCALITY_NAME;
XMEMCPY(&full[idx], "/L=", 3);
idx += 3;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectL = (char*)&cert->source[cert->srcIdx]; cert->subjectL = (char*)&cert->source[cert->srcIdx];
@ -4254,11 +4238,7 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_STATE_NAME) { else if (id == ASN_STATE_NAME) {
if (!tooBig) { copy = WOLFSSL_STATE_NAME;
XMEMCPY(&full[idx], "/ST=", 4);
idx += 4;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectST = (char*)&cert->source[cert->srcIdx]; cert->subjectST = (char*)&cert->source[cert->srcIdx];
@ -4272,11 +4252,7 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_ORG_NAME) { else if (id == ASN_ORG_NAME) {
if (!tooBig) { copy = WOLFSSL_ORG_NAME;
XMEMCPY(&full[idx], "/O=", 3);
idx += 3;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectO = (char*)&cert->source[cert->srcIdx]; cert->subjectO = (char*)&cert->source[cert->srcIdx];
@ -4290,11 +4266,7 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_ORGUNIT_NAME) { else if (id == ASN_ORGUNIT_NAME) {
if (!tooBig) { copy = WOLFSSL_ORGUNIT_NAME;
XMEMCPY(&full[idx], "/OU=", 4);
idx += 4;
copy = TRUE;
}
#ifdef WOLFSSL_CERT_GEN #ifdef WOLFSSL_CERT_GEN
if (nameType == SUBJECT) { if (nameType == SUBJECT) {
cert->subjectOU = (char*)&cert->source[cert->srcIdx]; cert->subjectOU = (char*)&cert->source[cert->srcIdx];
@ -4308,17 +4280,15 @@ static int GetName(DecodedCert* cert, int nameType)
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
else if (id == ASN_SERIAL_NUMBER) { else if (id == ASN_SERIAL_NUMBER) {
if (!tooBig) { copy = WOLFSSL_SERIAL_NUMBER;
XMEMCPY(&full[idx], "/serialNumber=", 14);
idx += 14;
copy = TRUE;
}
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
dName->snIdx = cert->srcIdx; dName->snIdx = cert->srcIdx;
dName->snLen = strLen; dName->snLen = strLen;
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
} }
if (copy && !tooBig) { if (copy && !tooBig) {
XMEMCPY(&full[idx], copy, XSTRLEN(copy));
idx += (word32)XSTRLEN(copy);
XMEMCPY(&full[idx], &cert->source[cert->srcIdx], strLen); XMEMCPY(&full[idx], &cert->source[cert->srcIdx], strLen);
idx += strLen; idx += strLen;
} }

View File

@ -33,15 +33,9 @@
#pragma warning(disable: 4996) #pragma warning(disable: 4996)
#endif #endif
#ifndef NO_ERROR_STRINGS
const char* wc_GetErrorString(int error) const char* wc_GetErrorString(int error)
{ {
#ifdef NO_ERROR_STRINGS
(void)error;
return "no support for error strings built in";
#else
switch (error) { switch (error) {
case OPEN_RAN_E : case OPEN_RAN_E :
@ -456,12 +450,11 @@ const char* wc_GetErrorString(int error)
return "unknown error number"; return "unknown error number";
} }
#endif /* NO_ERROR_STRINGS */
} }
void wc_ErrorString(int error, char* buffer) void wc_ErrorString(int error, char* buffer)
{ {
XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ); XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
} }
#endif /* !NO_ERROR_STRINGS */

View File

@ -115,6 +115,17 @@ enum DN_Tags {
ASN_DOMAIN_COMPONENT = 0x19 /* DC */ 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 { enum PBES {
PBE_MD5_DES = 0, PBE_MD5_DES = 0,
PBE_SHA1_RC4_128 = 1, PBE_SHA1_RC4_128 = 1,

View File

@ -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 void wc_ErrorString(int err, char* buff);
WOLFSSL_API const char* wc_GetErrorString(int error); WOLFSSL_API const char* wc_GetErrorString(int error);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */