File: misuse.c

package info (click to toggle)
libsodium 1.0.18-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,480 kB
  • sloc: ansic: 45,158; asm: 4,264; makefile: 870; sh: 640; python: 405; xml: 30; pascal: 11
file content (184 lines) | stat: -rw-r--r-- 4,472 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

#define TEST_NAME "misuse"
#include "cmptest.h"

#ifdef HAVE_CATCHABLE_ABRT
# include <signal.h>

static void
sigabrt_handler_15(int sig)
{
    (void) sig;
    exit(0);
}

# ifndef SODIUM_LIBRARY_MINIMAL
static void
sigabrt_handler_14(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_15);
    assert(crypto_box_curve25519xchacha20poly1305_easy
           (guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
            guard_page, guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_13(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_14);
    assert(crypto_box_curve25519xchacha20poly1305_easy_afternm
           (guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
            guard_page, guard_page) == -1);
    exit(1);
}
# endif

static void
sigabrt_handler_12(int sig)
{
    (void) sig;
# ifdef SODIUM_LIBRARY_MINIMAL
    signal(SIGABRT, sigabrt_handler_15);
# else
    signal(SIGABRT, sigabrt_handler_13);
# endif
    assert(crypto_pwhash_str_alg((char *) guard_page,
                                 "", 0U, 1U, 1U, -1) == -1);
    exit(1);
}

static void
sigabrt_handler_11(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_12);
    assert(crypto_box_easy(guard_page, guard_page,
                           crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
                           guard_page, guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_10(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_11);
    assert(crypto_box_easy_afternm(guard_page, guard_page,
                                   crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
                                   guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_9(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_10);
    assert(sodium_base642bin(guard_page, 1, (const char *) guard_page, 1,
                             NULL, NULL, NULL, -1) == -1);
    exit(1);
}

static void
sigabrt_handler_8(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_9);
    assert(sodium_bin2base64((char *) guard_page, 1, guard_page, 1,
                             sodium_base64_VARIANT_ORIGINAL) == NULL);
    exit(1);
}

static void
sigabrt_handler_7(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_8);
    assert(sodium_bin2base64((char *) guard_page, 1,
                             guard_page, 1, -1) == NULL);
    exit(1);
}

static void
sigabrt_handler_6(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_7);
    assert(sodium_pad(NULL, guard_page, SIZE_MAX, 16, 1) == -1);
    exit(1);
}

static void
sigabrt_handler_5(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_6);
    assert(crypto_aead_xchacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
                                                      NULL, 0, NULL,
                                                      guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_4(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_5);
    assert(crypto_aead_chacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
                                                     NULL, 0, NULL,
                                                     guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_3(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_4);
    assert(crypto_aead_chacha20poly1305_encrypt(guard_page, NULL, NULL, UINT64_MAX,
                                                NULL, 0, NULL,
                                                guard_page, guard_page) == -1);
    exit(1);
}

static void
sigabrt_handler_2(int sig)
{
    (void) sig;
    signal(SIGABRT, sigabrt_handler_3);
#if SIZE_MAX > 0x4000000000ULL
    randombytes_buf_deterministic(guard_page, 0x4000000001ULL, guard_page);
#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, guard_page, guard_page,
                                         guard_page) == -1);
    exit(1);
}

int
main(void)
{
    signal(SIGABRT, sigabrt_handler_1);
    assert(crypto_kx_client_session_keys(NULL, NULL, guard_page, guard_page,
                                         guard_page) == -1);
    return 1;
}
#else
int
main(void)
{
    return 0;
}
#endif