1 1.1 riastrad 2 1.1 riastrad #define TEST_NAME "misuse" 3 1.1 riastrad #include "cmptest.h" 4 1.1 riastrad 5 1.1 riastrad #ifdef HAVE_CATCHABLE_ABRT 6 1.1 riastrad # include <signal.h> 7 1.1 riastrad 8 1.1 riastrad static void 9 1.1 riastrad sigabrt_handler_15(int sig) 10 1.1 riastrad { 11 1.1 riastrad (void) sig; 12 1.1 riastrad exit(0); 13 1.1 riastrad } 14 1.1 riastrad 15 1.1 riastrad # ifndef SODIUM_LIBRARY_MINIMAL 16 1.1 riastrad static void 17 1.1 riastrad sigabrt_handler_14(int sig) 18 1.1 riastrad { 19 1.1 riastrad (void) sig; 20 1.1 riastrad signal(SIGABRT, sigabrt_handler_15); 21 1.1 riastrad assert(crypto_box_curve25519xchacha20poly1305_easy 22 1.1 riastrad (NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1, 23 1.1 riastrad NULL, NULL, NULL) == -1); 24 1.1 riastrad exit(1); 25 1.1 riastrad } 26 1.1 riastrad 27 1.1 riastrad static void 28 1.1 riastrad sigabrt_handler_13(int sig) 29 1.1 riastrad { 30 1.1 riastrad (void) sig; 31 1.1 riastrad signal(SIGABRT, sigabrt_handler_14); 32 1.1 riastrad assert(crypto_box_curve25519xchacha20poly1305_easy_afternm 33 1.1 riastrad (NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1, 34 1.1 riastrad NULL, NULL) == -1); 35 1.1 riastrad exit(1); 36 1.1 riastrad } 37 1.1 riastrad # endif 38 1.1 riastrad 39 1.1 riastrad static void 40 1.1 riastrad sigabrt_handler_12(int sig) 41 1.1 riastrad { 42 1.1 riastrad (void) sig; 43 1.1 riastrad # ifdef SODIUM_LIBRARY_MINIMAL 44 1.1 riastrad signal(SIGABRT, sigabrt_handler_15); 45 1.1 riastrad # else 46 1.1 riastrad signal(SIGABRT, sigabrt_handler_13); 47 1.1 riastrad # endif 48 1.1 riastrad assert(crypto_pwhash_str_alg(NULL, "", 0U, 1U, 1U, -1) == -1); 49 1.1 riastrad exit(1); 50 1.1 riastrad } 51 1.1 riastrad 52 1.1 riastrad static void 53 1.1 riastrad sigabrt_handler_11(int sig) 54 1.1 riastrad { 55 1.1 riastrad (void) sig; 56 1.1 riastrad signal(SIGABRT, sigabrt_handler_12); 57 1.1 riastrad assert(crypto_box_easy(NULL, NULL, crypto_stream_xsalsa20_MESSAGEBYTES_MAX, 58 1.1 riastrad NULL, NULL, NULL) == -1); 59 1.1 riastrad exit(1); 60 1.1 riastrad } 61 1.1 riastrad 62 1.1 riastrad static void 63 1.1 riastrad sigabrt_handler_10(int sig) 64 1.1 riastrad { 65 1.1 riastrad (void) sig; 66 1.1 riastrad signal(SIGABRT, sigabrt_handler_11); 67 1.1 riastrad assert(crypto_box_easy_afternm(NULL, NULL, crypto_stream_xsalsa20_MESSAGEBYTES_MAX, 68 1.1 riastrad NULL, NULL) == -1); 69 1.1 riastrad exit(1); 70 1.1 riastrad } 71 1.1 riastrad 72 1.1 riastrad static void 73 1.1 riastrad sigabrt_handler_9(int sig) 74 1.1 riastrad { 75 1.1 riastrad (void) sig; 76 1.1 riastrad signal(SIGABRT, sigabrt_handler_10); 77 1.1 riastrad assert(sodium_base642bin(NULL, 1, NULL, 1, NULL, NULL, NULL, -1) == -1); 78 1.1 riastrad exit(1); 79 1.1 riastrad } 80 1.1 riastrad 81 1.1 riastrad static void 82 1.1 riastrad sigabrt_handler_8(int sig) 83 1.1 riastrad { 84 1.1 riastrad (void) sig; 85 1.1 riastrad signal(SIGABRT, sigabrt_handler_9); 86 1.1 riastrad assert(sodium_bin2base64(NULL, 1, NULL, 1, sodium_base64_VARIANT_ORIGINAL) == NULL); 87 1.1 riastrad exit(1); 88 1.1 riastrad } 89 1.1 riastrad 90 1.1 riastrad static void 91 1.1 riastrad sigabrt_handler_7(int sig) 92 1.1 riastrad { 93 1.1 riastrad (void) sig; 94 1.1 riastrad signal(SIGABRT, sigabrt_handler_8); 95 1.1 riastrad assert(sodium_bin2base64(NULL, 1, NULL, 1, -1) == NULL); 96 1.1 riastrad exit(1); 97 1.1 riastrad } 98 1.1 riastrad 99 1.1 riastrad static void 100 1.1 riastrad sigabrt_handler_6(int sig) 101 1.1 riastrad { 102 1.1 riastrad (void) sig; 103 1.1 riastrad signal(SIGABRT, sigabrt_handler_7); 104 1.1 riastrad assert(sodium_pad(NULL, NULL, SIZE_MAX, 16, 1) == -1); 105 1.1 riastrad exit(1); 106 1.1 riastrad } 107 1.1 riastrad 108 1.1 riastrad static void 109 1.1 riastrad sigabrt_handler_5(int sig) 110 1.1 riastrad { 111 1.1 riastrad (void) sig; 112 1.1 riastrad signal(SIGABRT, sigabrt_handler_6); 113 1.1 riastrad assert(crypto_aead_xchacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX, 114 1.1 riastrad NULL, 0, NULL, NULL, NULL) == -1); 115 1.1 riastrad exit(1); 116 1.1 riastrad } 117 1.1 riastrad 118 1.1 riastrad static void 119 1.1 riastrad sigabrt_handler_4(int sig) 120 1.1 riastrad { 121 1.1 riastrad (void) sig; 122 1.1 riastrad signal(SIGABRT, sigabrt_handler_5); 123 1.1 riastrad assert(crypto_aead_chacha20poly1305_ietf_encrypt(NULL, NULL, NULL, UINT64_MAX, 124 1.1 riastrad NULL, 0, NULL, NULL, NULL) == -1); 125 1.1 riastrad exit(1); 126 1.1 riastrad } 127 1.1 riastrad 128 1.1 riastrad static void 129 1.1 riastrad sigabrt_handler_3(int sig) 130 1.1 riastrad { 131 1.1 riastrad (void) sig; 132 1.1 riastrad signal(SIGABRT, sigabrt_handler_4); 133 1.1 riastrad assert(crypto_aead_chacha20poly1305_encrypt(NULL, NULL, NULL, UINT64_MAX, 134 1.1 riastrad NULL, 0, NULL, NULL, NULL) == -1); 135 1.1 riastrad exit(1); 136 1.1 riastrad } 137 1.1 riastrad 138 1.1 riastrad static void 139 1.1 riastrad sigabrt_handler_2(int sig) 140 1.1 riastrad { 141 1.1 riastrad (void) sig; 142 1.1 riastrad signal(SIGABRT, sigabrt_handler_3); 143 1.1 riastrad #if SIZE_MAX > 0x4000000000ULL 144 1.1 riastrad randombytes_buf_deterministic(NULL, 0x4000000001ULL, NULL); 145 1.1 riastrad #else 146 1.1 riastrad abort(); 147 1.1 riastrad #endif 148 1.1 riastrad exit(1); 149 1.1 riastrad } 150 1.1 riastrad 151 1.1 riastrad static void 152 1.1 riastrad sigabrt_handler_1(int sig) 153 1.1 riastrad { 154 1.1 riastrad (void) sig; 155 1.1 riastrad signal(SIGABRT, sigabrt_handler_2); 156 1.1 riastrad assert(crypto_kx_server_session_keys(NULL, NULL, NULL, NULL, NULL) == -1); 157 1.1 riastrad exit(1); 158 1.1 riastrad } 159 1.1 riastrad 160 1.1 riastrad int 161 1.1 riastrad main(void) 162 1.1 riastrad { 163 1.1 riastrad signal(SIGABRT, sigabrt_handler_1); 164 1.1 riastrad assert(crypto_kx_client_session_keys(NULL, NULL, NULL, NULL, NULL) == -1); 165 1.1 riastrad return 1; 166 1.1 riastrad } 167 1.1 riastrad #else 168 1.1 riastrad int 169 1.1 riastrad main(void) 170 1.1 riastrad { 171 1.1 riastrad return 0; 172 1.1 riastrad } 173 1.1 riastrad #endif 174