demos: Silence warnings on Win64 builds
Reviewed-by: Saša Nedvědický <sashan@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/27806)
This commit is contained in:
parent
9f08f30f1d
commit
8067e713a1
@ -83,7 +83,7 @@ int main(int argc, char *argv[])
|
||||
out = BIO_push(ssl_bio, out);
|
||||
|
||||
p = "GET / HTTP/1.0\r\n\r\n";
|
||||
len = strlen(p);
|
||||
len = (int)strlen(p);
|
||||
|
||||
off = 0;
|
||||
for (;;) {
|
||||
|
@ -142,7 +142,7 @@ static int aes_ccm_encrypt(void)
|
||||
|
||||
/* Output tag */
|
||||
printf("Tag:\n");
|
||||
BIO_dump_fp(stdout, outtag, ccm_tag_len);
|
||||
BIO_dump_fp(stdout, outtag, (int)ccm_tag_len);
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
|
@ -27,6 +27,10 @@
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#ifdef OPENSSL_SYS_WINDOWS
|
||||
# define fileno _fileno
|
||||
#endif
|
||||
|
||||
/*-
|
||||
* This demonstration will show how to digest data using
|
||||
* a BIO configured with a message digest
|
||||
|
@ -139,7 +139,7 @@ static int do_encrypt(OSSL_LIB_CTX *libctx,
|
||||
*out_len = buf_len;
|
||||
*out = buf;
|
||||
fprintf(stdout, "Encrypted:\n");
|
||||
BIO_dump_indent_fp(stdout, buf, buf_len, 2);
|
||||
BIO_dump_indent_fp(stdout, buf, (int)buf_len, 2);
|
||||
fprintf(stdout, "\n");
|
||||
ret = 1;
|
||||
|
||||
@ -198,7 +198,7 @@ static int do_decrypt(OSSL_LIB_CTX *libctx, const unsigned char *in, size_t in_l
|
||||
*out_len = buf_len;
|
||||
*out = buf;
|
||||
fprintf(stdout, "Decrypted:\n");
|
||||
BIO_dump_indent_fp(stdout, buf, buf_len, 2);
|
||||
BIO_dump_indent_fp(stdout, buf, (int)buf_len, 2);
|
||||
fprintf(stdout, "\n");
|
||||
ret = 1;
|
||||
|
||||
|
@ -160,7 +160,7 @@ static int create_socket(uint16_t port)
|
||||
struct sockaddr_in sa = {0};
|
||||
|
||||
/* Retrieve the file descriptor for a new UDP socket */
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
if ((fd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
fprintf(stderr, "cannot create socket");
|
||||
goto err;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ static int create_socket(uint16_t port)
|
||||
struct sockaddr_in sa = {0};
|
||||
|
||||
/* Retrieve the file descriptor for a new UDP socket */
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
if ((fd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
fprintf(stderr, "cannot create socket");
|
||||
return -1;
|
||||
}
|
||||
@ -423,7 +423,7 @@ static int run_quic_server(SSL_CTX *ctx, int fd)
|
||||
}
|
||||
|
||||
if (total_read != total_written)
|
||||
fprintf(stderr, "Failed to echo data [read: %lu, written: %lu]\n",
|
||||
fprintf(stderr, "Failed to echo data [read: %zu, written: %zu]\n",
|
||||
total_read, total_written);
|
||||
|
||||
/*
|
||||
|
@ -113,7 +113,7 @@ int main(int argc, char **argv)
|
||||
if (max_threads == 0)
|
||||
threads = 1;
|
||||
else if (max_threads < parallel_cost)
|
||||
threads = max_threads;
|
||||
threads = (unsigned int)max_threads;
|
||||
}
|
||||
|
||||
/* Set password */
|
||||
|
@ -185,7 +185,7 @@ static int keyexch_x25519_after(
|
||||
}
|
||||
|
||||
printf("Shared secret (%s):\n", local_peer->name);
|
||||
BIO_dump_indent_fp(stdout, local_peer->secret, local_peer->secret_len, 2);
|
||||
BIO_dump_indent_fp(stdout, local_peer->secret, (int)local_peer->secret_len, 2);
|
||||
putchar('\n');
|
||||
|
||||
ret = 1;
|
||||
|
@ -128,7 +128,7 @@ int main(void)
|
||||
}
|
||||
|
||||
printf("Generated MAC:\n");
|
||||
BIO_dump_indent_fp(stdout, out, out_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out, (int)out_len, 2);
|
||||
putchar('\n');
|
||||
|
||||
if (out_len != sizeof(expected_output)) {
|
||||
|
@ -121,7 +121,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
printf("Generated MAC:\n");
|
||||
BIO_dump_indent_fp(stdout, out, out_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out, (int)out_len, 2);
|
||||
putchar('\n');
|
||||
|
||||
if (out_len != sizeof(expected_output)) {
|
||||
|
@ -139,7 +139,7 @@ int main(void)
|
||||
}
|
||||
|
||||
printf("Generated MAC:\n");
|
||||
BIO_dump_indent_fp(stdout, out, out_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out, (int)out_len, 2);
|
||||
putchar('\n');
|
||||
|
||||
if (out_len != sizeof(expected_output)) {
|
||||
|
@ -183,7 +183,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
printf("Generated MAC:\n");
|
||||
BIO_dump_indent_fp(stdout, out, out_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out, (int)out_len, 2);
|
||||
putchar('\n');
|
||||
|
||||
if (out_len != sizeof(expected_output)) {
|
||||
|
@ -120,7 +120,7 @@ int main(int argc, char **argv)
|
||||
* This example loads the PEM data from a memory buffer
|
||||
* Use BIO_new_fp() to load a PEM file instead
|
||||
*/
|
||||
in = BIO_new_mem_buf(dsapem, strlen(dsapem));
|
||||
in = BIO_new_mem_buf(dsapem, (int)strlen(dsapem));
|
||||
if (in == NULL) {
|
||||
fprintf(stderr, "BIO_new_mem_buf() failed\n");
|
||||
goto cleanup;
|
||||
|
@ -118,9 +118,9 @@ static int get_key_values(EVP_PKEY *pkey)
|
||||
|
||||
fprintf(stdout, "Curve name: %s\n", out_curvename);
|
||||
fprintf(stdout, "Public key:\n");
|
||||
BIO_dump_indent_fp(stdout, out_pubkey, out_pubkey_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out_pubkey, (int)out_pubkey_len, 2);
|
||||
fprintf(stdout, "Private Key:\n");
|
||||
BIO_dump_indent_fp(stdout, out_privkey, out_privkey_len, 2);
|
||||
BIO_dump_indent_fp(stdout, out_privkey, (int)out_privkey_len, 2);
|
||||
|
||||
ret = 1;
|
||||
cleanup:
|
||||
|
@ -129,7 +129,7 @@ static int dsa_print_key(const EVP_PKEY *pkey, int keypair,
|
||||
if (EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_FFC_SEED, seed,
|
||||
sizeof(seed), &seedlen) > 0) {
|
||||
BIO_printf(bio, " %s\n", OSSL_PKEY_PARAM_FFC_SEED);
|
||||
BIO_dump(bio, seed, seedlen);
|
||||
BIO_dump(bio, seed, (int)seedlen);
|
||||
}
|
||||
if (EVP_PKEY_get_int_param(pkey, OSSL_PKEY_PARAM_FFC_GINDEX, &gindex) > 0) {
|
||||
if (gindex != -1)
|
||||
|
@ -508,11 +508,11 @@ new_txt_simple_respoonse(const char *fill_pattern, unsigned int fsize)
|
||||
if (rts == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((rts->rts_pattern = strdup(fill_pattern)) == NULL) {
|
||||
if ((rts->rts_pattern = OPENSSL_strdup(fill_pattern)) == NULL) {
|
||||
OPENSSL_free(rts);
|
||||
return NULL;
|
||||
}
|
||||
rts->rts_pattern_len = strlen(fill_pattern);
|
||||
rts->rts_pattern_len = (unsigned int)strlen(fill_pattern);
|
||||
rts->rts_len = fsize;
|
||||
|
||||
rb = (struct response_buffer *)rts;
|
||||
@ -603,11 +603,11 @@ new_txt_full_respoonse(const char *fill_pattern, unsigned int fsize)
|
||||
if (rtf == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((rtf->rtf_pattern = strdup(fill_pattern)) == NULL) {
|
||||
if ((rtf->rtf_pattern = OPENSSL_strdup(fill_pattern)) == NULL) {
|
||||
OPENSSL_free(rtf);
|
||||
return NULL;
|
||||
}
|
||||
rtf->rtf_pattern_len = strlen(fill_pattern);
|
||||
rtf->rtf_pattern_len = (unsigned int)strlen(fill_pattern);
|
||||
|
||||
t = time(&t);
|
||||
ctime_r(&t, date_str);
|
||||
@ -1037,7 +1037,7 @@ rebuild_poll_set(struct poll_manager *pm)
|
||||
POLL_PRINTA(pe->pe_poll_item.events),
|
||||
POLL_PRINTA(~pe->pe_want_mask));
|
||||
}
|
||||
pm->pm_event_count = i;
|
||||
pm->pm_event_count = (unsigned int)i;
|
||||
pm->pm_need_rebuild = 0;
|
||||
|
||||
return 0;
|
||||
@ -1456,7 +1456,7 @@ app_read_cb(struct poll_event *pe)
|
||||
return rv;
|
||||
}
|
||||
pes->pes_wpos += read_len;
|
||||
pes->pes_wpos_sz -= read_len;
|
||||
pes->pes_wpos_sz -= (unsigned int)read_len;
|
||||
|
||||
rv = parse_request(pes);
|
||||
|
||||
@ -1869,7 +1869,7 @@ create_socket(uint16_t port)
|
||||
struct sockaddr_in sa = {0};
|
||||
|
||||
/* Retrieve the file descriptor for a new UDP socket */
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
if ((fd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
DPRINTF(stderr, "cannot create socket");
|
||||
return -1;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ static int create_socket(uint16_t port)
|
||||
int fd = -1;
|
||||
struct sockaddr_in sa = {0};
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
if ((fd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
fprintf(stderr, "cannot create socket");
|
||||
goto err;
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ end:
|
||||
EVP_PKEY_CTX_free(pkey_ctx);
|
||||
|
||||
fprintf(stdout, "Generating signature:\n");
|
||||
BIO_dump_indent_fp(stdout, sig_value, sig_len, 2);
|
||||
BIO_dump_indent_fp(stdout, sig_value, (int)sig_len, 2);
|
||||
fprintf(stdout, "\n");
|
||||
return ret;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ static int demo_sign(OSSL_LIB_CTX *libctx, const char *sig_name,
|
||||
*sig_out_len = sig_len;
|
||||
*sig_out_value = sig_value;
|
||||
fprintf(stdout, "Generating signature:\n");
|
||||
BIO_dump_indent_fp(stdout, sig_value, sig_len, 2);
|
||||
BIO_dump_indent_fp(stdout, sig_value, (int)sig_len, 2);
|
||||
fprintf(stdout, "\n");
|
||||
ret = 1;
|
||||
|
||||
|
@ -73,7 +73,7 @@ static int demo_sign(EVP_PKEY *priv,
|
||||
}
|
||||
*sig_out_len = sig_len;
|
||||
*sig_out_value = sig_value;
|
||||
BIO_dump_indent_fp(stdout, sig_value, sig_len, 2);
|
||||
BIO_dump_indent_fp(stdout, sig_value, (int)sig_len, 2);
|
||||
fprintf(stdout, "\n");
|
||||
ret = 1;
|
||||
|
||||
|
@ -17,8 +17,13 @@
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define SOCKET int
|
||||
#define closesocket(s) close(s)
|
||||
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
static const int server_port = 4433;
|
||||
@ -33,9 +38,9 @@ typedef unsigned char flag;
|
||||
*/
|
||||
static volatile flag server_running = true;
|
||||
|
||||
static int create_socket(flag isServer)
|
||||
static SOCKET create_socket(flag isServer)
|
||||
{
|
||||
int s;
|
||||
SOCKET s;
|
||||
int optval = 1;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
@ -51,7 +56,7 @@ static int create_socket(flag isServer)
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
/* Reuse the address; good for quick restarts */
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(optval))
|
||||
< 0) {
|
||||
perror("setsockopt(SO_REUSEADDR) failed");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -141,8 +146,8 @@ int main(int argc, char **argv)
|
||||
SSL_CTX *ssl_ctx = NULL;
|
||||
SSL *ssl = NULL;
|
||||
|
||||
int server_skt = -1;
|
||||
int client_skt = -1;
|
||||
SOCKET server_skt = -1;
|
||||
SOCKET client_skt = -1;
|
||||
|
||||
/* used by fgets */
|
||||
char buffer[BUFFERSIZE];
|
||||
@ -207,7 +212,7 @@ int main(int argc, char **argv)
|
||||
while (server_running) {
|
||||
/* Wait for TCP connection from client */
|
||||
client_skt = accept(server_skt, (struct sockaddr*) &addr,
|
||||
&addr_len);
|
||||
&addr_len);
|
||||
if (client_skt < 0) {
|
||||
perror("Unable to accept");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -217,7 +222,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Create server SSL structure using newly accepted client socket */
|
||||
ssl = SSL_new(ssl_ctx);
|
||||
if (!SSL_set_fd(ssl, client_skt)) {
|
||||
if (!SSL_set_fd(ssl, (int)client_skt)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -233,7 +238,7 @@ int main(int argc, char **argv)
|
||||
/* Echo loop */
|
||||
while (true) {
|
||||
/* Get message from client; will fail if client closes connection */
|
||||
if ((rxlen = SSL_read(ssl, rxbuf, rxcap)) <= 0) {
|
||||
if ((rxlen = SSL_read(ssl, rxbuf, (int)rxcap)) <= 0) {
|
||||
if (rxlen == 0) {
|
||||
printf("Client closed connection\n");
|
||||
} else {
|
||||
@ -263,7 +268,7 @@ int main(int argc, char **argv)
|
||||
/* Cleanup for next client */
|
||||
SSL_shutdown(ssl);
|
||||
SSL_free(ssl);
|
||||
close(client_skt);
|
||||
closesocket(client_skt);
|
||||
/*
|
||||
* Set client_skt to -1 to avoid double close when
|
||||
* server_running become false before next accept
|
||||
@ -297,7 +302,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Create client SSL structure using dedicated client socket */
|
||||
ssl = SSL_new(ssl_ctx);
|
||||
if (!SSL_set_fd(ssl, client_skt)) {
|
||||
if (!SSL_set_fd(ssl, (int)client_skt)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto exit;
|
||||
}
|
||||
@ -329,14 +334,14 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
/* Send it to the server */
|
||||
if ((result = SSL_write(ssl, txbuf, strlen(txbuf))) <= 0) {
|
||||
if ((result = SSL_write(ssl, txbuf, (int)strlen(txbuf))) <= 0) {
|
||||
printf("Server closed connection\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Wait for the echo */
|
||||
rxlen = SSL_read(ssl, rxbuf, rxcap);
|
||||
rxlen = SSL_read(ssl, rxbuf, (int)rxcap);
|
||||
if (rxlen <= 0) {
|
||||
printf("Server closed connection\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
@ -364,9 +369,9 @@ exit:
|
||||
SSL_CTX_free(ssl_ctx);
|
||||
|
||||
if (client_skt != -1)
|
||||
close(client_skt);
|
||||
closesocket(client_skt);
|
||||
if (server_skt != -1)
|
||||
close(server_skt);
|
||||
closesocket(server_skt);
|
||||
|
||||
printf("sslecho exiting\n");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user