diff --git a/src/pk.c b/src/pk.c index b4515783c..718e75adb 100644 --- a/src/pk.c +++ b/src/pk.c @@ -12659,7 +12659,7 @@ point_conversion_form_t wolfSSL_EC_KEY_get_conv_form(const WOLFSSL_EC_KEY* key) int ret = -1; if (key != NULL) { - ret = (int)(unsigned char)key->form; + ret = key->form; } return ret; diff --git a/src/ssl.c b/src/ssl.c index d9859b840..4c8bfe68c 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -22959,7 +22959,7 @@ int wolfSSL_i2d_PublicKey(const WOLFSSL_EVP_PKEY *key, unsigned char **der) unsigned char *local_der = NULL; word32 local_derSz = 0; unsigned char *pub_der = NULL; - ecc_key eccKey; + ecc_key *eccKey = NULL; word32 inOutIdx = 0; #endif word32 pub_derSz = 0; @@ -22996,15 +22996,23 @@ int wolfSSL_i2d_PublicKey(const WOLFSSL_EVP_PKEY *key, unsigned char **der) } if (ret == 0) { - ret = wc_ecc_init(&eccKey); + eccKey = (ecc_key *)XMALLOC(sizeof(*eccKey), NULL, DYNAMIC_TYPE_ECC); + if (eccKey == NULL) { + WOLFSSL_MSG("Failed to allocate key buffer."); + ret = WOLFSSL_FATAL_ERROR; + } } if (ret == 0) { - ret = wc_EccPublicKeyDecode(local_der, &inOutIdx, &eccKey, local_derSz); + ret = wc_ecc_init(eccKey); } if (ret == 0) { - pub_derSz = wc_EccPublicKeyDerSize(&eccKey, 0); + ret = wc_EccPublicKeyDecode(local_der, &inOutIdx, eccKey, local_derSz); + } + + if (ret == 0) { + pub_derSz = wc_EccPublicKeyDerSize(eccKey, 0); if (pub_derSz <= 0) { ret = WOLFSSL_FAILURE; } @@ -23020,7 +23028,7 @@ int wolfSSL_i2d_PublicKey(const WOLFSSL_EVP_PKEY *key, unsigned char **der) } if (ret == 0) { - pub_derSz = wc_EccPublicKeyToDer(&eccKey, pub_der, pub_derSz, 0); + pub_derSz = wc_EccPublicKeyToDer(eccKey, pub_der, pub_derSz, 0); if (pub_derSz <= 0) { ret = WOLFSSL_FATAL_ERROR; } @@ -23049,7 +23057,9 @@ int wolfSSL_i2d_PublicKey(const WOLFSSL_EVP_PKEY *key, unsigned char **der) XFREE(pub_der, NULL, DYNAMIC_TYPE_PUBLIC_KEY); XFREE(local_der, NULL, DYNAMIC_TYPE_PUBLIC_KEY); - wc_ecc_free(&eccKey); + wc_ecc_free(eccKey); + XFREE(eccKey, NULL, DYNAMIC_TYPE_ECC); + #else ret = WOLFSSL_FATAL_ERROR; #endif /* HAVE_ECC */ diff --git a/wolfcrypt/src/pwdbased.c b/wolfcrypt/src/pwdbased.c index 4d7434557..5d177d476 100644 --- a/wolfcrypt/src/pwdbased.c +++ b/wolfcrypt/src/pwdbased.c @@ -581,8 +581,7 @@ static void scryptSalsa(word32* out, word32* in) word32 x[16]; #ifdef LITTLE_ENDIAN_ORDER - for (i = 0; i < 16; ++i) - x[i] = in[i]; + XMEMCPY(x, in, sizeof(x)); #else for (i = 0; i < 16; i++) x[i] = ByteReverseWord32(in[i]); @@ -623,15 +622,14 @@ static void scryptSalsa(word32* out, word32* in) */ static void scryptBlockMix(byte* b, byte* y, int r) { - byte x[64]; #ifdef WORD64_AVAILABLE + word64 x[8]; word64* b64 = (word64*)b; word64* y64 = (word64*)y; - word64* x64 = (word64*)x; #else + word32 x[16]; word32* b32 = (word32*)b; word32* y32 = (word32*)y; - word32* x32 = (word32*)x; #endif int i; int j; @@ -643,10 +641,11 @@ static void scryptBlockMix(byte* b, byte* y, int r) { #ifdef WORD64_AVAILABLE for (j = 0; j < 8; j++) - x64[j] ^= b64[i * 8 + j]; + x[j] ^= b64[i * 8 + j]; + #else for (j = 0; j < 16; j++) - x32[j] ^= b32[i * 16 + j]; + x[j] ^= b32[i * 16 + j]; #endif scryptSalsa((word32*)x, (word32*)x); XMEMCPY(y + i * 64, x, sizeof(x)); diff --git a/wolfssl/openssl/ec.h b/wolfssl/openssl/ec.h index 3fb5270f5..065c63ceb 100644 --- a/wolfssl/openssl/ec.h +++ b/wolfssl/openssl/ec.h @@ -116,7 +116,7 @@ struct WOLFSSL_EC_KEY { void* internal; /* our ECC Key */ void* heap; - char form; /* Either POINT_CONVERSION_UNCOMPRESSED or + unsigned char form; /* Either POINT_CONVERSION_UNCOMPRESSED or * POINT_CONVERSION_COMPRESSED */ word16 pkcs8HeaderSz;