libsodium/test/default/misuse.c

81 lines
1.6 KiB
C
Raw Normal View History

#define TEST_NAME "misuse"
#include "cmptest.h"
2017-09-15 04:19:34 -04:00
#if defined(SIGABRT) && (defined(__APPLE__) || defined(__OpenBSD__))
# include <signal.h>
static void
2017-07-24 09:16:22 -04:00
sigabrt_handler_6(int sig)
{
(void) sig;
exit(0);
}
2017-07-24 09:16:22 -04:00
static void
sigabrt_handler_5(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_6);
assert(crypto_aead_xchacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX,
NULL, 0, NULL, NULL, NULL) == -1);
exit(1);
}
2017-07-21 10:52:01 -04:00
static void
sigabrt_handler_4(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_5);
assert(crypto_aead_chacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX,
NULL, 0, NULL, NULL, NULL) == -1);
exit(1);
}
static void
sigabrt_handler_3(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_4);
assert(crypto_aead_chacha20poly1305_encrypt(NULL, NULL, NULL, UINT64_MAX,
NULL, 0, NULL, NULL, NULL) == -1);
exit(1);
}
static void
sigabrt_handler_2(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_3);
#if SIZE_MAX > 0x4000000000ULL
randombytes_buf_deterministic(NULL, 0x4000000001ULL, NULL);
#else
abort();
#endif
exit(1);
}
static void
sigabrt_handler_1(int sig)
{
(void) sig;
signal(SIGABRT, sigabrt_handler_2);
assert(crypto_kx_server_session_keys(NULL, NULL, NULL, NULL, NULL) == -1);
exit(1);
}
int
main(void)
{
signal(SIGABRT, sigabrt_handler_1);
assert(crypto_kx_client_session_keys(NULL, NULL, NULL, NULL, NULL) == -1);
return 1;
}
#else
int
main(void)
{
return 0;
}
#endif