mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 04:04:39 +02:00
ZD16445
- Use unions for type punning in xor API - Initialise potentially uninitialised variables - Use `LL` suffix to specify a larger integer type - Don't use `max` as it can shadow other definitions
This commit is contained in:
10
tests/api.c
10
tests/api.c
@@ -3728,7 +3728,7 @@ static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
|
|||||||
WOLFSSL_CTX* ctx;
|
WOLFSSL_CTX* ctx;
|
||||||
const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
|
const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
|
||||||
byte ca_expired_cert[TWOK_BUF];
|
byte ca_expired_cert[TWOK_BUF];
|
||||||
word32 sizeof_ca_expired_cert;
|
word32 sizeof_ca_expired_cert = 0;
|
||||||
XFILE fp = XBADFILE;
|
XFILE fp = XBADFILE;
|
||||||
|
|
||||||
#ifndef NO_WOLFSSL_CLIENT
|
#ifndef NO_WOLFSSL_CLIENT
|
||||||
@@ -11337,7 +11337,7 @@ static int test_wolfSSL_no_password_cb(void)
|
|||||||
const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
|
const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
|
||||||
const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
|
const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
|
||||||
XFILE f = XBADFILE;
|
XFILE f = XBADFILE;
|
||||||
int bytes;
|
int bytes = 0;
|
||||||
|
|
||||||
#ifndef NO_WOLFSSL_CLIENT
|
#ifndef NO_WOLFSSL_CLIENT
|
||||||
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
|
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
|
||||||
@@ -19788,7 +19788,7 @@ static int test_wc_DsaKeyToPublicDer(void)
|
|||||||
DsaKey key;
|
DsaKey key;
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
byte* der = NULL;
|
byte* der = NULL;
|
||||||
word32 sz;
|
word32 sz = 0;
|
||||||
word32 idx = 0;
|
word32 idx = 0;
|
||||||
|
|
||||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||||
@@ -26113,7 +26113,7 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
|
|||||||
#if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
|
#if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
|
||||||
/* test of decrypt callback with KEKRI enveloped data */
|
/* test of decrypt callback with KEKRI enveloped data */
|
||||||
{
|
{
|
||||||
int envelopedSz;
|
int envelopedSz = 0;
|
||||||
const byte keyId[] = { 0x00 };
|
const byte keyId[] = { 0x00 };
|
||||||
|
|
||||||
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
||||||
@@ -26638,7 +26638,7 @@ static int test_wc_PKCS7_BER(void)
|
|||||||
#ifndef NO_DES3
|
#ifndef NO_DES3
|
||||||
byte decoded[2048];
|
byte decoded[2048];
|
||||||
#endif
|
#endif
|
||||||
word32 derSz;
|
word32 derSz = 0;
|
||||||
|
|
||||||
ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
|
ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
|
||||||
ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
|
ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
|
||||||
|
@@ -41,7 +41,7 @@ int w64wrapper_test(void)
|
|||||||
|
|
||||||
a = w64From32(0x01020304, 0x05060708);
|
a = w64From32(0x01020304, 0x05060708);
|
||||||
#if defined(WORD64_AVAILABLE) && !defined(WOLFSSL_W64_WRAPPER_TEST)
|
#if defined(WORD64_AVAILABLE) && !defined(WOLFSSL_W64_WRAPPER_TEST)
|
||||||
if (a.n != 0x0102030405060708)
|
if (a.n != 0x0102030405060708LL)
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
if (a.n[0] != 0x01020304 || a.n[1] != 0x05060708)
|
if (a.n[0] != 0x01020304 || a.n[1] != 0x05060708)
|
||||||
|
@@ -639,13 +639,13 @@ static word32 SizeASN_Num(word32 n, int bits, byte tag)
|
|||||||
* @param [in] idx Index of item working on.
|
* @param [in] idx Index of item working on.
|
||||||
*/
|
*/
|
||||||
static void SizeASN_CalcDataLength(const ASNItem* asn, ASNSetData *data,
|
static void SizeASN_CalcDataLength(const ASNItem* asn, ASNSetData *data,
|
||||||
int idx, int max)
|
int idx, int maxIdx)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
data[idx].data.buffer.length = 0;
|
data[idx].data.buffer.length = 0;
|
||||||
/* Sum the item length of all items underneath. */
|
/* Sum the item length of all items underneath. */
|
||||||
for (j = idx + 1; j < max; j++) {
|
for (j = idx + 1; j < maxIdx; j++) {
|
||||||
/* Stop looking if the next ASN.1 is same level or higher. */
|
/* Stop looking if the next ASN.1 is same level or higher. */
|
||||||
if (asn[j].depth <= asn[idx].depth)
|
if (asn[j].depth <= asn[idx].depth)
|
||||||
break;
|
break;
|
||||||
|
@@ -273,11 +273,11 @@ WC_MISC_STATIC WC_INLINE void xorbufout(void* out, const void* buf,
|
|||||||
{
|
{
|
||||||
word32 i;
|
word32 i;
|
||||||
byte* o;
|
byte* o;
|
||||||
byte* b;
|
const byte* b;
|
||||||
const byte* m;
|
const byte* m;
|
||||||
|
|
||||||
o = (byte*)out;
|
o = (byte*)out;
|
||||||
b = (byte*)buf;
|
b = (const byte*)buf;
|
||||||
m = (const byte*)mask;
|
m = (const byte*)mask;
|
||||||
|
|
||||||
|
|
||||||
@@ -285,6 +285,15 @@ WC_MISC_STATIC WC_INLINE void xorbufout(void* out, const void* buf,
|
|||||||
((wc_ptr_t)b) % WOLFSSL_WORD_SIZE &&
|
((wc_ptr_t)b) % WOLFSSL_WORD_SIZE &&
|
||||||
((wc_ptr_t)b) % WOLFSSL_WORD_SIZE ==
|
((wc_ptr_t)b) % WOLFSSL_WORD_SIZE ==
|
||||||
((wc_ptr_t)m) % WOLFSSL_WORD_SIZE) {
|
((wc_ptr_t)m) % WOLFSSL_WORD_SIZE) {
|
||||||
|
/* type-punning helpers */
|
||||||
|
union {
|
||||||
|
byte* bp;
|
||||||
|
wolfssl_word* wp;
|
||||||
|
} tpo;
|
||||||
|
union {
|
||||||
|
const byte* bp;
|
||||||
|
const wolfssl_word* wp;
|
||||||
|
} tpb, tpm;
|
||||||
/* Alignment checks out. Possible to XOR words. */
|
/* Alignment checks out. Possible to XOR words. */
|
||||||
/* Move alignment so that it lines up with a
|
/* Move alignment so that it lines up with a
|
||||||
* WOLFSSL_WORD_SIZE boundary */
|
* WOLFSSL_WORD_SIZE boundary */
|
||||||
@@ -292,8 +301,13 @@ WC_MISC_STATIC WC_INLINE void xorbufout(void* out, const void* buf,
|
|||||||
*(o++) = (byte)(*(b++) ^ *(m++));
|
*(o++) = (byte)(*(b++) ^ *(m++));
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
XorWordsOut( (wolfssl_word**)&o, (const wolfssl_word**)&b,
|
tpo.bp = o;
|
||||||
(const wolfssl_word**)&m, count / WOLFSSL_WORD_SIZE);
|
tpb.bp = b;
|
||||||
|
tpm.bp = m;
|
||||||
|
XorWordsOut( &tpo.wp, &tpb.wp, &tpm.wp, count / WOLFSSL_WORD_SIZE);
|
||||||
|
o = tpo.bp;
|
||||||
|
b = tpb.bp;
|
||||||
|
m = tpm.bp;
|
||||||
count %= WOLFSSL_WORD_SIZE;
|
count %= WOLFSSL_WORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +340,15 @@ WC_MISC_STATIC WC_INLINE void xorbuf(void* buf, const void* mask, word32 count)
|
|||||||
|
|
||||||
if (((wc_ptr_t)b) % WOLFSSL_WORD_SIZE ==
|
if (((wc_ptr_t)b) % WOLFSSL_WORD_SIZE ==
|
||||||
((wc_ptr_t)m) % WOLFSSL_WORD_SIZE) {
|
((wc_ptr_t)m) % WOLFSSL_WORD_SIZE) {
|
||||||
|
/* type-punning helpers */
|
||||||
|
union {
|
||||||
|
byte* bp;
|
||||||
|
wolfssl_word* wp;
|
||||||
|
} tpb;
|
||||||
|
union {
|
||||||
|
const byte* bp;
|
||||||
|
const wolfssl_word* wp;
|
||||||
|
} tpm;
|
||||||
/* Alignment checks out. Possible to XOR words. */
|
/* Alignment checks out. Possible to XOR words. */
|
||||||
/* Move alignment so that it lines up with a
|
/* Move alignment so that it lines up with a
|
||||||
* WOLFSSL_WORD_SIZE boundary */
|
* WOLFSSL_WORD_SIZE boundary */
|
||||||
@@ -333,8 +356,11 @@ WC_MISC_STATIC WC_INLINE void xorbuf(void* buf, const void* mask, word32 count)
|
|||||||
*(b++) ^= *(m++);
|
*(b++) ^= *(m++);
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
XorWords( (wolfssl_word**)&b,
|
tpb.bp = b;
|
||||||
(const wolfssl_word**)&m, count / WOLFSSL_WORD_SIZE);
|
tpm.bp = m;
|
||||||
|
XorWords( &tpb.wp, &tpm.wp, count / WOLFSSL_WORD_SIZE);
|
||||||
|
b = tpb.bp;
|
||||||
|
m = tpm.bp;
|
||||||
count %= WOLFSSL_WORD_SIZE;
|
count %= WOLFSSL_WORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user