mirror of https://github.com/wolfSSL/wolfssl
Fix for Fedora 32/64
This commit is contained in:
parent
03b571cde4
commit
f438e7ac65
|
@ -45,7 +45,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#ifdef SO_NOSIGPIPE
|
||||
#ifndef SO_NOSIGPIPE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#endif /* USE_WINDOWS_API */
|
||||
|
@ -271,8 +271,9 @@ int wc_BioRead(WOLFCRYPT_BIO *bio, void *data, int size)
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_READ | BIO_CB_RETURN,
|
||||
data, size, 0, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioRead", (int)ret);
|
||||
|
@ -323,8 +324,9 @@ int wc_BioWrite(WOLFCRYPT_BIO *bio, const void *data, int size)
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_WRITE | BIO_CB_RETURN,
|
||||
data, size, 0, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioWrite", (int)ret);
|
||||
|
@ -369,8 +371,9 @@ int wc_BioPuts(WOLFCRYPT_BIO *bio, const char *data)
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_PUTS | BIO_CB_RETURN,
|
||||
data, 0, 0, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioPuts", (int)ret);
|
||||
|
@ -414,8 +417,9 @@ int wc_BioGets(WOLFCRYPT_BIO *bio, char *data, int size)
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_GETS | BIO_CB_RETURN,
|
||||
data, size, 0, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioGets", (int)ret);
|
||||
|
@ -457,8 +461,9 @@ long wc_BioCtrl(WOLFCRYPT_BIO *bio, int cmd, long larg, void *parg)
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_CTRL | BIO_CB_RETURN,
|
||||
parg, cmd, larg, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioCtrl", (int)ret);
|
||||
|
@ -501,8 +506,9 @@ long wc_BioCallbackCtrl(WOLFCRYPT_BIO *bio, int cmd,
|
|||
if (bio->callback != NULL) {
|
||||
ret = bio->callback(bio, BIO_CB_CTRL | BIO_CB_RETURN,
|
||||
(void *)&fp, cmd, 0, ret);
|
||||
if (ret <= 0)
|
||||
if (ret <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
WOLFSSL_LEAVE("wc_BioCallbackCtrl", (int)ret);
|
||||
|
@ -2096,8 +2102,9 @@ void wc_BioSetCipher(WOLFCRYPT_BIO *bio, const WOLFCRYPT_EVP_CIPHER *cipher,
|
|||
|
||||
if ((bio->callback != NULL) &&
|
||||
bio->callback(bio, BIO_CB_CTRL, (const char *)cipher,
|
||||
BIO_CTRL_SET, enc, 1) <= 0)
|
||||
BIO_CTRL_SET, enc, 1) <= 0) {
|
||||
WOLFSSL_ERROR(BIO_CALLBACK_E);
|
||||
}
|
||||
}
|
||||
|
||||
static int wc_BioCipher_new(WOLFCRYPT_BIO *bio)
|
||||
|
@ -2631,8 +2638,9 @@ static long wc_BioDigest_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
ret = wc_EVP_DigestInit(ctx, (WOLFCRYPT_EVP_MD *)ptr);
|
||||
if (ret > 0)
|
||||
bio->init = 1;
|
||||
else
|
||||
else {
|
||||
WOLFSSL_ERROR(BIO_DGST_INIT_E);
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_CTRL_DUP:
|
||||
|
@ -3209,22 +3217,22 @@ static int wc_BioAccept_new(WOLFCRYPT_BIO *bio)
|
|||
|
||||
static void wc_BioAccept_close_socket(WOLFCRYPT_BIO *bio)
|
||||
{
|
||||
WOLFCRYPT_BIO_ACCEPT *accept;
|
||||
WOLFCRYPT_BIO_ACCEPT *baccept;
|
||||
|
||||
if (bio == NULL) {
|
||||
WOLFSSL_ERROR(BAD_FUNC_ARG);
|
||||
return;
|
||||
}
|
||||
|
||||
accept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
if (accept->accept_sock != WOLFSSL_SOCKET_INVALID) {
|
||||
shutdown(accept->accept_sock, SHUT_RDWR);
|
||||
baccept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
if (baccept->accept_sock != WOLFSSL_SOCKET_INVALID) {
|
||||
shutdown(baccept->accept_sock, SHUT_RDWR);
|
||||
#ifdef USE_WINDOWS_API
|
||||
closesocket(accept->accept_sock);
|
||||
closesocket(baccept->accept_sock);
|
||||
#else
|
||||
close(accept->accept_sock);
|
||||
close(baccept->accept_sock);
|
||||
#endif
|
||||
accept->accept_sock = WOLFSSL_SOCKET_INVALID;
|
||||
baccept->accept_sock = WOLFSSL_SOCKET_INVALID;
|
||||
bio->num = WOLFSSL_SOCKET_INVALID;
|
||||
}
|
||||
}
|
||||
|
@ -3244,14 +3252,14 @@ static int wc_BioAccept_free(WOLFCRYPT_BIO *bio)
|
|||
wc_BioAccept_close_socket(bio);
|
||||
|
||||
if (bio->ptr != NULL) {
|
||||
WOLFCRYPT_BIO_ACCEPT *accept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
WOLFCRYPT_BIO_ACCEPT *baccept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
|
||||
if (accept->param_addr != NULL)
|
||||
XFREE(accept->param_addr, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
if (accept->ip_port != NULL)
|
||||
XFREE(accept->ip_port, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
if (accept->bio_chain != NULL)
|
||||
wc_BioFree(accept->bio_chain);
|
||||
if (baccept->param_addr != NULL)
|
||||
XFREE(baccept->param_addr, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
if (baccept->ip_port != NULL)
|
||||
XFREE(baccept->ip_port, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
if (baccept->bio_chain != NULL)
|
||||
wc_BioFree(baccept->bio_chain);
|
||||
|
||||
XFREE(bio->ptr, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
bio->ptr = NULL;
|
||||
|
@ -3263,30 +3271,30 @@ static int wc_BioAccept_free(WOLFCRYPT_BIO *bio)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int wc_BioAccept_state(WOLFCRYPT_BIO *bio, WOLFCRYPT_BIO_ACCEPT *accept)
|
||||
static int wc_BioAccept_state(WOLFCRYPT_BIO *bio, WOLFCRYPT_BIO_ACCEPT *baccept)
|
||||
{
|
||||
WOLFCRYPT_BIO *nbio = NULL;
|
||||
int s = -1;
|
||||
int dsock;
|
||||
|
||||
if (bio == NULL || accept == NULL) {
|
||||
if (bio == NULL || baccept == NULL) {
|
||||
WOLFSSL_ERROR(BAD_FUNC_ARG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
again:
|
||||
switch (accept->state) {
|
||||
switch (baccept->state) {
|
||||
case ACPT_S_BEFORE:
|
||||
if (accept->param_addr == NULL) {
|
||||
if (baccept->param_addr == NULL) {
|
||||
WOLFSSL_ERROR(BIO_NO_PORT_E);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s = wc_BioGetAcceptSocket(accept->param_addr, accept->bind_mode);
|
||||
s = wc_BioGetAcceptSocket(baccept->param_addr, baccept->bind_mode);
|
||||
if (s == WOLFSSL_SOCKET_INVALID)
|
||||
return -1;
|
||||
|
||||
if (accept->accept_nbio) {
|
||||
if (baccept->accept_nbio) {
|
||||
if (!wc_BioSocketNbio(s, 1)) {
|
||||
#ifdef USE_WINDOWS_API
|
||||
closesocket(s);
|
||||
|
@ -3299,7 +3307,7 @@ again:
|
|||
}
|
||||
|
||||
/* TCP NO DELAY */
|
||||
if (accept->options & 1) {
|
||||
if (baccept->options & 1) {
|
||||
if (!wc_BioSetTcpNdelay(s, 1)) {
|
||||
#ifdef USE_WINDOWS_API
|
||||
closesocket(s);
|
||||
|
@ -3312,7 +3320,7 @@ again:
|
|||
}
|
||||
|
||||
/* IGNORE SIGPIPE */
|
||||
if (accept->options & 2) {
|
||||
if (baccept->options & 2) {
|
||||
if (!wc_BioSetTcpNsigpipe(s, 1)) {
|
||||
#ifdef USE_WINDOWS_API
|
||||
closesocket(s);
|
||||
|
@ -3324,21 +3332,21 @@ again:
|
|||
}
|
||||
}
|
||||
|
||||
accept->accept_sock = s;
|
||||
baccept->accept_sock = s;
|
||||
bio->num = s;
|
||||
accept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
baccept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case ACPT_S_GET_ACCEPT_SOCKET:
|
||||
if (bio->next_bio != NULL) {
|
||||
accept->state = ACPT_S_OK;
|
||||
baccept->state = ACPT_S_OK;
|
||||
goto again;
|
||||
}
|
||||
|
||||
wc_BioClearRetryFlags(bio);
|
||||
bio->retry_reason = 0;
|
||||
dsock = wc_BioAccept(accept->accept_sock, &accept->ip_port);
|
||||
dsock = wc_BioAccept(baccept->accept_sock, &baccept->ip_port);
|
||||
|
||||
/* retry case */
|
||||
if (dsock == -2) {
|
||||
|
@ -3357,7 +3365,7 @@ again:
|
|||
wc_BioSetCallback(nbio, wc_BioGetCallback(bio));
|
||||
wc_BioSetCallbackArg(nbio, wc_BioGetCallbackArg(bio));
|
||||
|
||||
if (accept->nbio) {
|
||||
if (baccept->nbio) {
|
||||
if (!wc_BioSocketNbio(dsock, 1)) {
|
||||
WOLFSSL_ERROR(BIO_NBIO_E);
|
||||
goto err;
|
||||
|
@ -3368,8 +3376,8 @@ again:
|
|||
* If the accept BIO has an bio_chain, we dup it and put the new
|
||||
* socket at the end.
|
||||
*/
|
||||
if (accept->bio_chain != NULL) {
|
||||
WOLFCRYPT_BIO *dbio = wc_BioDupChain(accept->bio_chain);
|
||||
if (baccept->bio_chain != NULL) {
|
||||
WOLFCRYPT_BIO *dbio = wc_BioDupChain(baccept->bio_chain);
|
||||
if (dbio == NULL)
|
||||
goto err;
|
||||
if (!wc_BioPush(dbio, nbio))
|
||||
|
@ -3380,7 +3388,7 @@ again:
|
|||
if (wc_BioPush(bio, nbio) == NULL)
|
||||
goto err;
|
||||
|
||||
accept->state = ACPT_S_OK;
|
||||
baccept->state = ACPT_S_OK;
|
||||
return 1;
|
||||
err:
|
||||
if (nbio != NULL)
|
||||
|
@ -3395,7 +3403,7 @@ again:
|
|||
|
||||
case ACPT_S_OK:
|
||||
if (bio->next_bio == NULL) {
|
||||
accept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
baccept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
goto again;
|
||||
}
|
||||
return 1;
|
||||
|
@ -3411,7 +3419,7 @@ again:
|
|||
static int wc_BioAccept_read(WOLFCRYPT_BIO *bio, char *data, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
WOLFCRYPT_BIO_ACCEPT *accept;
|
||||
WOLFCRYPT_BIO_ACCEPT *baccept;
|
||||
|
||||
if (bio == NULL || data == NULL) {
|
||||
WOLFSSL_ERROR(BAD_FUNC_ARG);
|
||||
|
@ -3419,10 +3427,10 @@ static int wc_BioAccept_read(WOLFCRYPT_BIO *bio, char *data, int size)
|
|||
}
|
||||
|
||||
wc_BioClearRetryFlags(bio);
|
||||
accept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
baccept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
|
||||
while (bio->next_bio == NULL) {
|
||||
ret = wc_BioAccept_state(bio, accept);
|
||||
ret = wc_BioAccept_state(bio, baccept);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
|
@ -3436,7 +3444,7 @@ static int wc_BioAccept_read(WOLFCRYPT_BIO *bio, char *data, int size)
|
|||
static int wc_BioAccept_write(WOLFCRYPT_BIO *bio, const char *data, int size)
|
||||
{
|
||||
int ret = 0;
|
||||
WOLFCRYPT_BIO_ACCEPT *accept;
|
||||
WOLFCRYPT_BIO_ACCEPT *baccept;
|
||||
|
||||
if (bio == NULL || data == NULL) {
|
||||
WOLFSSL_ERROR(BAD_FUNC_ARG);
|
||||
|
@ -3444,10 +3452,10 @@ static int wc_BioAccept_write(WOLFCRYPT_BIO *bio, const char *data, int size)
|
|||
}
|
||||
|
||||
wc_BioClearRetryFlags(bio);
|
||||
accept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
baccept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
|
||||
while (bio->next_bio == NULL) {
|
||||
ret = wc_BioAccept_state(bio, accept);
|
||||
ret = wc_BioAccept_state(bio, baccept);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
|
@ -3462,7 +3470,7 @@ static long wc_BioAccept_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
{
|
||||
int *ip;
|
||||
long ret = 1;
|
||||
WOLFCRYPT_BIO_ACCEPT *accept;
|
||||
WOLFCRYPT_BIO_ACCEPT *baccept;
|
||||
char **pp;
|
||||
|
||||
if (bio == NULL) {
|
||||
|
@ -3470,49 +3478,49 @@ static long wc_BioAccept_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
accept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
baccept = (WOLFCRYPT_BIO_ACCEPT *)bio->ptr;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
ret = 0;
|
||||
accept->state = ACPT_S_BEFORE;
|
||||
baccept->state = ACPT_S_BEFORE;
|
||||
wc_BioAccept_close_socket(bio);
|
||||
bio->flags = 0;
|
||||
break;
|
||||
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
/* use this one to start the connection */
|
||||
ret = (long)wc_BioAccept_state(bio, accept);
|
||||
ret = (long)wc_BioAccept_state(bio, baccept);
|
||||
break;
|
||||
|
||||
case BIO_C_SET_ACCEPT:
|
||||
if (ptr != NULL) {
|
||||
if (num == 0) {
|
||||
bio->init = 1;
|
||||
if (accept->param_addr != NULL)
|
||||
XFREE(accept->param_addr, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
accept->param_addr = strdup(ptr);
|
||||
if (baccept->param_addr != NULL)
|
||||
XFREE(baccept->param_addr, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
baccept->param_addr = strdup(ptr);
|
||||
}
|
||||
else if (num == 1) {
|
||||
accept->accept_nbio = (ptr != NULL);
|
||||
baccept->accept_nbio = (ptr != NULL);
|
||||
}
|
||||
else if (num == 2) {
|
||||
if (accept->bio_chain != NULL)
|
||||
wc_BioFree(accept->bio_chain);
|
||||
accept->bio_chain = (WOLFCRYPT_BIO *)ptr;
|
||||
if (baccept->bio_chain != NULL)
|
||||
wc_BioFree(baccept->bio_chain);
|
||||
baccept->bio_chain = (WOLFCRYPT_BIO *)ptr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BIO_C_SET_NBIO:
|
||||
accept->nbio = (int)num;
|
||||
baccept->nbio = (int)num;
|
||||
break;
|
||||
|
||||
case BIO_C_SET_FD:
|
||||
bio->init = 1;
|
||||
bio->num = *((int *)ptr);
|
||||
accept->accept_sock = bio->num;
|
||||
accept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
baccept->accept_sock = bio->num;
|
||||
baccept->state = ACPT_S_GET_ACCEPT_SOCKET;
|
||||
bio->shutdown = (int)num;
|
||||
bio->init = 1;
|
||||
break;
|
||||
|
@ -3521,8 +3529,8 @@ static long wc_BioAccept_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
if (bio->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL)
|
||||
*ip = accept->accept_sock;
|
||||
ret = accept->accept_sock;
|
||||
*ip = baccept->accept_sock;
|
||||
ret = baccept->accept_sock;
|
||||
}
|
||||
else
|
||||
ret = -1;
|
||||
|
@ -3532,7 +3540,7 @@ static long wc_BioAccept_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
if (bio->init) {
|
||||
if (ptr != NULL) {
|
||||
pp = (char **)ptr;
|
||||
*pp = accept->param_addr;
|
||||
*pp = baccept->param_addr;
|
||||
}
|
||||
else
|
||||
ret = -1;
|
||||
|
@ -3559,15 +3567,15 @@ static long wc_BioAccept_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
break;
|
||||
|
||||
case BIO_C_SET_BIND_MODE:
|
||||
accept->bind_mode = (int)num;
|
||||
baccept->bind_mode = (int)num;
|
||||
break;
|
||||
|
||||
case BIO_C_GET_BIND_MODE:
|
||||
ret = (long)accept->bind_mode;
|
||||
ret = (long)baccept->bind_mode;
|
||||
break;
|
||||
|
||||
case BIO_C_SET_EX_ARG:
|
||||
accept->options = (int)num;
|
||||
baccept->options = (int)num;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -3783,8 +3791,9 @@ static int wc_BioConn_state(WOLFCRYPT_BIO *bio, WOLFCRYPT_BIO_CONNECT *conn)
|
|||
conn->state = BIO_CONN_S_BLOCKED_CONNECT;
|
||||
bio->retry_reason = BIO_RR_CONNECT;
|
||||
}
|
||||
else
|
||||
else {
|
||||
WOLFSSL_ERROR(BIO_CONNECT_E);
|
||||
}
|
||||
goto exit_loop;
|
||||
}
|
||||
else
|
||||
|
@ -4150,7 +4159,7 @@ static long wc_BioConn_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
|
||||
wc_BioSetNbio(dbio, conn->nbio);
|
||||
|
||||
wc_BioSetInfoCallback(dbio,
|
||||
(void)wc_BioSetInfoCallback(dbio,
|
||||
(WOLFCRYPT_BIO_info_cb *)conn->info_callback);
|
||||
}
|
||||
break;
|
||||
|
@ -5263,7 +5272,9 @@ static long wc_BioFile_ctrl(WOLFCRYPT_BIO *bio, int cmd, long num, void *ptr)
|
|||
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = (long)XFTELL((FILE *)bio->ptr);
|
||||
XFSEEK((FILE *)bio->ptr, 0, XSEEK_END);
|
||||
ret = XFTELL((FILE *)bio->ptr);
|
||||
XREWIND((FILE *)bio->ptr);
|
||||
break;
|
||||
|
||||
case BIO_C_SET_FILE_PTR:
|
||||
|
|
|
@ -6013,7 +6013,7 @@ static int evp_enc_test(const WOLFCRYPT_EVP_CIPHER* type)
|
|||
WOLFCRYPT_EVP_CIPHER_CTX ctx;
|
||||
int i, ret, len = 0, loop, outLen, rand_size, witLen;
|
||||
|
||||
byte random[4500], wit[5000], out[5000];
|
||||
byte brandom[4500], wit[5000], out[5000];
|
||||
|
||||
byte key[] = {0x9d, 0xbf, 0xe2, 0x11, 0xf9, 0xea, 0x19, 0xf3,
|
||||
0x44, 0x2e, 0xae, 0x19, 0x54, 0x80, 0x87, 0x4c,
|
||||
|
@ -6028,7 +6028,7 @@ static int evp_enc_test(const WOLFCRYPT_EVP_CIPHER* type)
|
|||
if (i != 0)
|
||||
return -1198;
|
||||
|
||||
i = wc_RNG_GenerateBlock(&rng, random, sizeof(random));
|
||||
i = wc_RNG_GenerateBlock(&rng, brandom, sizeof(brandom));
|
||||
if (i != 0)
|
||||
return -1199;
|
||||
|
||||
|
@ -6036,8 +6036,8 @@ static int evp_enc_test(const WOLFCRYPT_EVP_CIPHER* type)
|
|||
|
||||
|
||||
/* Encrypt/Decrypt with round bytes block Update */
|
||||
for (rand_size = sizeof(random), loop = 1; loop < 1000; loop++) {
|
||||
rand_size = sizeof(random) - loop;
|
||||
for (rand_size = sizeof(brandom), loop = 1; loop < 1000; loop++) {
|
||||
rand_size = sizeof(brandom) - loop;
|
||||
|
||||
/* Encrypt */
|
||||
wc_EVP_CIPHER_CTX_init(&ctx);
|
||||
|
@ -6050,7 +6050,7 @@ static int evp_enc_test(const WOLFCRYPT_EVP_CIPHER* type)
|
|||
return -1200;
|
||||
|
||||
ret = wc_EVP_CipherUpdate(&ctx, out+len, &outLen,
|
||||
random, rand_size);
|
||||
brandom, rand_size);
|
||||
if (ret != SSL_SUCCESS)
|
||||
return -1201;
|
||||
|
||||
|
@ -6095,7 +6095,7 @@ static int evp_enc_test(const WOLFCRYPT_EVP_CIPHER* type)
|
|||
if (witLen != rand_size)
|
||||
return -1206;
|
||||
|
||||
if (XMEMCMP(random, wit, witLen))
|
||||
if (XMEMCMP(brandom, wit, witLen))
|
||||
return -1207;
|
||||
}
|
||||
|
||||
|
@ -6264,20 +6264,21 @@ int bio_md_test(void)
|
|||
return -1068;
|
||||
|
||||
/* Ensure all of our data is pushed all the way to the BIO */
|
||||
wc_BioFlush(bmd);
|
||||
if (wc_BioFlush(bmd) < 0)
|
||||
return -1069;
|
||||
|
||||
/* get the digest */
|
||||
XMEMSET(digest, 0, sizeof(digest));
|
||||
size = wc_BioGets(bmd, digest, sizeof(digest));
|
||||
if (size <= 0)
|
||||
return -1069;
|
||||
|
||||
if (size != wc_EVP_MD_size(hash_list[i].type))
|
||||
return -1070;
|
||||
|
||||
if (XMEMCMP(digest, hash_list[i].digest, size))
|
||||
if (size != wc_EVP_MD_size(hash_list[i].type))
|
||||
return -1071;
|
||||
|
||||
if (XMEMCMP(digest, hash_list[i].digest, size))
|
||||
return -1072;
|
||||
|
||||
/* free BIO */
|
||||
wc_BioFreeAll(bmd);
|
||||
|
||||
|
@ -6292,22 +6293,22 @@ int bio_b64_test(void)
|
|||
WOLFCRYPT_BIO *b64, *file;
|
||||
int i, loop, rand_size;
|
||||
int total, w;
|
||||
byte random[9000], wit[9000];
|
||||
byte brandom[9000], wit[9000];
|
||||
WC_RNG rng;
|
||||
|
||||
i = wc_InitRng(&rng);
|
||||
if (i != 0)
|
||||
return -1198;
|
||||
|
||||
i = wc_RNG_GenerateBlock(&rng, random, sizeof(random));
|
||||
i = wc_RNG_GenerateBlock(&rng, brandom, sizeof(brandom));
|
||||
if (i != 0)
|
||||
return -1199;
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
|
||||
/* Encode/Decode random data */
|
||||
for (rand_size = sizeof(random), loop = 1; loop < 1000; loop++) {
|
||||
rand_size = sizeof(random) - loop;
|
||||
/* Encode/Decode brandom data */
|
||||
for (rand_size = sizeof(brandom), loop = 1; loop < 1000; loop++) {
|
||||
rand_size = sizeof(brandom) - loop;
|
||||
|
||||
/* Create a buffered file BIO for writing */
|
||||
if (loop & 1)
|
||||
|
@ -6329,7 +6330,7 @@ int bio_b64_test(void)
|
|||
* It checks for errors as if the underlying file were non-blocking */
|
||||
for (total = 0; total < rand_size; total += w)
|
||||
{
|
||||
w = wc_BioWrite(b64, random + total,
|
||||
w = wc_BioWrite(b64, brandom + total,
|
||||
rand_size - (int)total);
|
||||
if (w <= 0) {
|
||||
if (wc_BioShouldRetry(b64)) {
|
||||
|
@ -6341,7 +6342,8 @@ int bio_b64_test(void)
|
|||
}
|
||||
|
||||
/* Ensure all of our data is pushed all the way to the file */
|
||||
wc_BioFlush(b64);
|
||||
if (wc_BioFlush(b64) < 0)
|
||||
return -1070;
|
||||
|
||||
/* free BIO chain cipher-file */
|
||||
wc_BioFreeAll(b64);
|
||||
|
@ -6354,7 +6356,7 @@ int bio_b64_test(void)
|
|||
else
|
||||
file = wc_BioNewFile("test_b64_nonl", "r");
|
||||
if (file == NULL)
|
||||
return -1070;
|
||||
return -1071;
|
||||
|
||||
/* Create a base64 encoding filter BIO */
|
||||
b64 = wc_BioNew(wc_Bio_f_base64());
|
||||
|
@ -6385,7 +6387,7 @@ int bio_b64_test(void)
|
|||
if (total != rand_size)
|
||||
return -1079;
|
||||
|
||||
if (XMEMCMP(random, wit, total))
|
||||
if (XMEMCMP(brandom, wit, total))
|
||||
return -1080;
|
||||
}
|
||||
|
||||
|
@ -6397,13 +6399,13 @@ int bio_b64_test(void)
|
|||
static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
||||
{
|
||||
int total, i, w, rand_size;
|
||||
WOLFCRYPT_BIO *cipher, *buffer, *file, *b64;
|
||||
WOLFCRYPT_BIO *cipher, *buff, *file, *b64;
|
||||
byte key[] = { 0x63, 0x21, 0x5f, 0x9b, 0xdc, 0x74, 0xcc, 0x90,
|
||||
0x96, 0x43, 0xd1, 0xcc, 0x7a, 0xb2, 0x27, 0xc5 };
|
||||
byte iv[] = { 0x1a, 0x4a, 0xf8, 0xd5, 0xd0, 0x09, 0xff, 0x09,
|
||||
0xd6, 0xb3, 0x72, 0x3d, 0xc4, 0xed, 0x9c, 0x8e };
|
||||
|
||||
byte random[4200], wit[4200];
|
||||
byte brandom[4200], wit[4200];
|
||||
|
||||
WC_RNG rng;
|
||||
|
||||
|
@ -6411,15 +6413,15 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
if (w != 0)
|
||||
return 1060;
|
||||
|
||||
w = wc_RNG_GenerateBlock(&rng, random, sizeof(random));
|
||||
w = wc_RNG_GenerateBlock(&rng, brandom, sizeof(brandom));
|
||||
if (w != 0)
|
||||
return 1061;
|
||||
|
||||
wc_FreeRng(&rng);
|
||||
|
||||
for (rand_size = sizeof(random), i = 1; i < 300; i++) {
|
||||
for (rand_size = sizeof(brandom), i = 1; i < 300; i++) {
|
||||
|
||||
rand_size = sizeof(random) - i;
|
||||
rand_size = sizeof(brandom) - i;
|
||||
|
||||
/* Create a buffered file BIO for writing */
|
||||
if (i & 1)
|
||||
|
@ -6430,8 +6432,8 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
return -1062;
|
||||
|
||||
/* Create a buffering filter BIO to buffer writes to the file */
|
||||
buffer = wc_BioNew(wc_Bio_f_buffer());
|
||||
if (buffer == NULL)
|
||||
buff = wc_BioNew(wc_Bio_f_buffer());
|
||||
if (buff == NULL)
|
||||
return -1063;
|
||||
|
||||
/* Create a cipher filter BIO */
|
||||
|
@ -6457,10 +6459,10 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
if (wc_BioPush(cipher, b64) == NULL)
|
||||
return -1066;
|
||||
|
||||
if (wc_BioPush(b64, buffer) == NULL)
|
||||
if (wc_BioPush(b64, buff) == NULL)
|
||||
return -1067;
|
||||
|
||||
if (wc_BioPush(buffer, file) == NULL)
|
||||
if (wc_BioPush(buff, file) == NULL)
|
||||
return -1068;
|
||||
|
||||
|
||||
|
@ -6468,7 +6470,7 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
* It checks for errors as if the underlying file were non-blocking */
|
||||
for (total = 0; total < rand_size; total += w)
|
||||
{
|
||||
w = wc_BioWrite(cipher, random + total,
|
||||
w = wc_BioWrite(cipher, brandom + total,
|
||||
rand_size - (int)total);
|
||||
if (w <= 0) {
|
||||
if (wc_BioShouldRetry(cipher)) {
|
||||
|
@ -6480,7 +6482,8 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
}
|
||||
|
||||
/* Ensure all of our data is pushed all the way to the file */
|
||||
wc_BioFlush(cipher);
|
||||
if (wc_BioFlush(cipher) < 0)
|
||||
return - 1069;
|
||||
|
||||
/* get b64 BIO to free it only at first (test purpose) */
|
||||
wc_BioPop(b64);
|
||||
|
@ -6502,8 +6505,8 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
return -1070;
|
||||
|
||||
/* Create a buffering filter BIO to buffer writes to the file */
|
||||
buffer = wc_BioNew(wc_Bio_f_buffer());
|
||||
if (buffer == NULL)
|
||||
buff = wc_BioNew(wc_Bio_f_buffer());
|
||||
if (buff == NULL)
|
||||
return -1071;
|
||||
|
||||
/* Create a cipher filter BIO */
|
||||
|
@ -6525,10 +6528,10 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
if (wc_BioPush(cipher, b64) == NULL)
|
||||
return -1074;
|
||||
|
||||
if (wc_BioPush(b64, buffer) == NULL)
|
||||
if (wc_BioPush(b64, buff) == NULL)
|
||||
return -1075;
|
||||
|
||||
if (wc_BioPush(buffer, file) == NULL)
|
||||
if (wc_BioPush(buff, file) == NULL)
|
||||
return -1077;
|
||||
|
||||
/* This loop read the data from the file.
|
||||
|
@ -6564,7 +6567,7 @@ static int bio_filter_test(const WOLFCRYPT_EVP_CIPHER* cipher_type)
|
|||
if (total != rand_size)
|
||||
return -1079;
|
||||
|
||||
if (XMEMCMP(random, wit, total))
|
||||
if (XMEMCMP(brandom, wit, total))
|
||||
return -1080;
|
||||
}
|
||||
|
||||
|
@ -6938,7 +6941,8 @@ int bio_accept_ssl_test(void)
|
|||
|
||||
if (buf[0] == '\r' || buf[0] == '\n') {
|
||||
wc_BioPuts(b_rw, "CLOSE\n");
|
||||
wc_BioFlush(b_rw);
|
||||
if (wc_BioFlush(b_rw) < 0)
|
||||
return -3015;
|
||||
printf("Done -> close\n");
|
||||
break;
|
||||
}
|
||||
|
@ -6946,7 +6950,8 @@ int bio_accept_ssl_test(void)
|
|||
/* Send response */
|
||||
wc_BioPuts(b_rw, "ACK: ");
|
||||
wc_BioPuts(b_rw, buf);
|
||||
wc_BioFlush(b_rw);
|
||||
if (wc_BioFlush(b_rw) < 0)
|
||||
return -3016;
|
||||
}
|
||||
|
||||
/* close connection */
|
||||
|
@ -7015,13 +7020,8 @@ int bio_test(void)
|
|||
return -1006;
|
||||
|
||||
ret = wc_BioTell(bio);
|
||||
#ifdef USE_WINDOWS_API
|
||||
if (ret != 0)
|
||||
return -1007;
|
||||
#else
|
||||
if (ret != (int)strlen(buf)+1)
|
||||
return -1007;
|
||||
#endif
|
||||
|
||||
/* write */
|
||||
ret = wc_BioPrintf(bio, "%s\n", buf);
|
||||
|
@ -7034,7 +7034,7 @@ int bio_test(void)
|
|||
|
||||
/* reset, before reading */
|
||||
ret = wc_BioReset(bio);
|
||||
if (ret != 0)
|
||||
if (ret < 0)
|
||||
return -1010;
|
||||
|
||||
/* read */
|
||||
|
@ -7068,16 +7068,18 @@ int bio_test(void)
|
|||
if (ret != 0)
|
||||
return -1053;
|
||||
|
||||
wc_BioReset(bio);
|
||||
|
||||
ret = wc_BioWrite(bio, buf, (int)strlen(buf));
|
||||
if (ret != (int)strlen(buf))
|
||||
ret = wc_BioReset(bio);
|
||||
if (ret < 0)
|
||||
return -1054;
|
||||
|
||||
ret = wc_BioWrite(bio, buf, (int)strlen(buf));
|
||||
if (ret != (int)strlen(buf))
|
||||
return -1055;
|
||||
|
||||
ret = wc_BioWrite(bio, buf, (int)strlen(buf));
|
||||
if (ret != (int)strlen(buf))
|
||||
return -1056;
|
||||
|
||||
XMEMSET(buf_w, 0, sizeof(buf_w));
|
||||
|
||||
ret = wc_BioRead(bio, buf_w, 5);
|
||||
|
|
Loading…
Reference in New Issue