isomorfeus-iodine 0.7.47 → 0.7.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/workflows/ruby.yml +2 -1
- data/.gitlab-ci.yml +8 -0
- data/CHANGELOG.md +1052 -1038
- data/Gemfile +10 -11
- data/Rakefile +1 -9
- data/bin/console +18 -22
- data/bitbucket-pipelines.yml +9 -0
- data/examples/etag.ru +16 -0
- data/ext/{iodine → iodine_ext}/extconf.rb +1 -1
- data/ext/{iodine → iodine_ext}/fio.c +0 -0
- data/ext/{iodine → iodine_ext}/fio.h +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.h +189 -189
- data/ext/{iodine → iodine_ext}/fio_json_parser.h +687 -687
- data/ext/{iodine → iodine_ext}/fio_siphash.c +157 -157
- data/ext/{iodine → iodine_ext}/fio_siphash.h +37 -37
- data/ext/{iodine → iodine_ext}/fio_tls.h +129 -129
- data/ext/{iodine → iodine_ext}/fio_tls_missing.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tls_openssl.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tmpfile.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj.h +44 -44
- data/ext/{iodine → iodine_ext}/fiobj4fio.h +21 -21
- data/ext/{iodine → iodine_ext}/fiobj_ary.c +333 -333
- data/ext/{iodine → iodine_ext}/fiobj_ary.h +139 -139
- data/ext/{iodine → iodine_ext}/fiobj_data.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_data.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.h +176 -176
- data/ext/{iodine → iodine_ext}/fiobj_json.c +622 -622
- data/ext/{iodine → iodine_ext}/fiobj_json.h +68 -68
- data/ext/{iodine → iodine_ext}/fiobj_mem.h +71 -71
- data/ext/{iodine → iodine_ext}/fiobj_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_mustache.h +62 -62
- data/ext/{iodine → iodine_ext}/fiobj_numbers.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_numbers.h +127 -127
- data/ext/{iodine → iodine_ext}/fiobj_str.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_str.h +172 -172
- data/ext/{iodine → iodine_ext}/fiobject.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobject.h +0 -0
- data/ext/{iodine → iodine_ext}/hpack.h +1923 -1923
- data/ext/{iodine → iodine_ext}/http.c +14 -27
- data/ext/{iodine → iodine_ext}/http.h +1002 -1002
- data/ext/{iodine → iodine_ext}/http1.c +0 -0
- data/ext/{iodine → iodine_ext}/http1.h +29 -29
- data/ext/{iodine → iodine_ext}/http1_parser.h +873 -873
- data/ext/{iodine → iodine_ext}/http_internal.c +0 -0
- data/ext/{iodine → iodine_ext}/http_internal.h +0 -0
- data/ext/{iodine → iodine_ext}/http_mime_parser.h +350 -350
- data/ext/{iodine → iodine_ext}/iodine.c +1 -1
- data/ext/{iodine → iodine_ext}/iodine.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.h +55 -55
- data/ext/{iodine → iodine_ext}/iodine_defer.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_defer.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_fiobj2rb.h +120 -120
- data/ext/{iodine → iodine_ext}/iodine_helpers.c +282 -282
- data/ext/{iodine → iodine_ext}/iodine_helpers.h +12 -12
- data/ext/{iodine → iodine_ext}/iodine_http.c +0 -2
- data/ext/{iodine → iodine_ext}/iodine_http.h +23 -23
- data/ext/{iodine → iodine_ext}/iodine_json.c +302 -302
- data/ext/{iodine → iodine_ext}/iodine_json.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_mustache.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_pubsub.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_pubsub.h +26 -26
- data/ext/{iodine → iodine_ext}/iodine_rack_io.c +0 -8
- data/ext/{iodine → iodine_ext}/iodine_rack_io.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_store.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_store.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_tcp.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tcp.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.h +13 -13
- data/ext/{iodine → iodine_ext}/mustache_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.c +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.h +0 -0
- data/ext/{iodine → iodine_ext}/resp_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/websocket_parser.h +505 -505
- data/ext/{iodine → iodine_ext}/websockets.c +0 -0
- data/ext/{iodine → iodine_ext}/websockets.h +185 -185
- data/isomorfeus-iodine.gemspec +1 -2
- data/lib/iodine/version.rb +1 -1
- data/lib/iodine.rb +1 -1
- metadata +82 -79
@@ -1,157 +1,157 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz Segev, 2017-2019
|
3
|
-
License: MIT
|
4
|
-
*/
|
5
|
-
#include <fio_siphash.h>
|
6
|
-
|
7
|
-
/* *****************************************************************************
|
8
|
-
|
9
|
-
NOTICE
|
10
|
-
|
11
|
-
This code won't be linked to the final application when using fio.h and fio.c.
|
12
|
-
|
13
|
-
The code is here only to allow the FIOBJ library to be extracted from the
|
14
|
-
facil.io framework library.
|
15
|
-
|
16
|
-
***************************************************************************** */
|
17
|
-
|
18
|
-
/* *****************************************************************************
|
19
|
-
Hashing (SipHash implementation)
|
20
|
-
***************************************************************************** */
|
21
|
-
|
22
|
-
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) && \
|
23
|
-
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
24
|
-
/* the algorithm was designed as little endian... so, byte swap 64 bit. */
|
25
|
-
#define sip_local64(i) \
|
26
|
-
(((i)&0xFFULL) << 56) | (((i)&0xFF00ULL) << 40) | \
|
27
|
-
(((i)&0xFF0000ULL) << 24) | (((i)&0xFF000000ULL) << 8) | \
|
28
|
-
(((i)&0xFF00000000ULL) >> 8) | (((i)&0xFF0000000000ULL) >> 24) | \
|
29
|
-
(((i)&0xFF000000000000ULL) >> 40) | (((i)&0xFF00000000000000ULL) >> 56)
|
30
|
-
#else
|
31
|
-
/* no need */
|
32
|
-
#define sip_local64(i) (i)
|
33
|
-
#endif
|
34
|
-
|
35
|
-
/* 64Bit left rotation, inlined. */
|
36
|
-
#define lrot64(i, bits) \
|
37
|
-
(((uint64_t)(i) << (bits)) | ((uint64_t)(i) >> (64 - (bits))))
|
38
|
-
|
39
|
-
static inline uint64_t fio_siphash_xy(const void *data, size_t len, size_t x,
|
40
|
-
size_t y, uint64_t key1, uint64_t key2) {
|
41
|
-
/* initialize the 4 words */
|
42
|
-
uint64_t v0 = (0x0706050403020100ULL ^ 0x736f6d6570736575ULL) ^ key1;
|
43
|
-
uint64_t v1 = (0x0f0e0d0c0b0a0908ULL ^ 0x646f72616e646f6dULL) ^ key2;
|
44
|
-
uint64_t v2 = (0x0706050403020100ULL ^ 0x6c7967656e657261ULL) ^ key1;
|
45
|
-
uint64_t v3 = (0x0f0e0d0c0b0a0908ULL ^ 0x7465646279746573ULL) ^ key2;
|
46
|
-
const uint64_t *w64 = data;
|
47
|
-
uint8_t len_mod = len & 255;
|
48
|
-
union {
|
49
|
-
uint64_t i;
|
50
|
-
uint8_t str[8];
|
51
|
-
} word;
|
52
|
-
|
53
|
-
#define hash_map_SipRound \
|
54
|
-
do { \
|
55
|
-
v2 += v3; \
|
56
|
-
v3 = lrot64(v3, 16) ^ v2; \
|
57
|
-
v0 += v1; \
|
58
|
-
v1 = lrot64(v1, 13) ^ v0; \
|
59
|
-
v0 = lrot64(v0, 32); \
|
60
|
-
v2 += v1; \
|
61
|
-
v0 += v3; \
|
62
|
-
v1 = lrot64(v1, 17) ^ v2; \
|
63
|
-
v3 = lrot64(v3, 21) ^ v0; \
|
64
|
-
v2 = lrot64(v2, 32); \
|
65
|
-
} while (0);
|
66
|
-
|
67
|
-
while (len >= 8) {
|
68
|
-
word.i = sip_local64(*w64);
|
69
|
-
v3 ^= word.i;
|
70
|
-
/* Sip Rounds */
|
71
|
-
for (size_t i = 0; i < x; ++i) {
|
72
|
-
hash_map_SipRound;
|
73
|
-
}
|
74
|
-
v0 ^= word.i;
|
75
|
-
w64 += 1;
|
76
|
-
len -= 8;
|
77
|
-
}
|
78
|
-
word.i = 0;
|
79
|
-
uint8_t *pos = word.str;
|
80
|
-
uint8_t *w8 = (void *)w64;
|
81
|
-
switch (len) { /* fallthrough is intentional */
|
82
|
-
case 7:
|
83
|
-
pos[6] = w8[6];
|
84
|
-
/* fallthrough */
|
85
|
-
case 6:
|
86
|
-
pos[5] = w8[5];
|
87
|
-
/* fallthrough */
|
88
|
-
case 5:
|
89
|
-
pos[4] = w8[4];
|
90
|
-
/* fallthrough */
|
91
|
-
case 4:
|
92
|
-
pos[3] = w8[3];
|
93
|
-
/* fallthrough */
|
94
|
-
case 3:
|
95
|
-
pos[2] = w8[2];
|
96
|
-
/* fallthrough */
|
97
|
-
case 2:
|
98
|
-
pos[1] = w8[1];
|
99
|
-
/* fallthrough */
|
100
|
-
case 1:
|
101
|
-
pos[0] = w8[0];
|
102
|
-
}
|
103
|
-
word.str[7] = len_mod;
|
104
|
-
|
105
|
-
/* last round */
|
106
|
-
v3 ^= word.i;
|
107
|
-
hash_map_SipRound;
|
108
|
-
hash_map_SipRound;
|
109
|
-
v0 ^= word.i;
|
110
|
-
/* Finalization */
|
111
|
-
v2 ^= 0xff;
|
112
|
-
/* d iterations of SipRound */
|
113
|
-
for (size_t i = 0; i < y; ++i) {
|
114
|
-
hash_map_SipRound;
|
115
|
-
}
|
116
|
-
hash_map_SipRound;
|
117
|
-
hash_map_SipRound;
|
118
|
-
hash_map_SipRound;
|
119
|
-
hash_map_SipRound;
|
120
|
-
/* XOR it all together */
|
121
|
-
v0 ^= v1 ^ v2 ^ v3;
|
122
|
-
#undef hash_map_SipRound
|
123
|
-
return v0;
|
124
|
-
}
|
125
|
-
|
126
|
-
#pragma weak fio_siphash24
|
127
|
-
uint64_t __attribute__((weak))
|
128
|
-
fio_siphash24(const void *data, size_t len, uint64_t key1, uint64_t key2) {
|
129
|
-
return fio_siphash_xy(data, len, 2, 4, key1, key2);
|
130
|
-
}
|
131
|
-
|
132
|
-
#pragma weak fio_siphash13
|
133
|
-
uint64_t __attribute__((weak))
|
134
|
-
fio_siphash13(const void *data, size_t len, uint64_t key1, uint64_t key2) {
|
135
|
-
return fio_siphash_xy(data, len, 1, 3, key1, key2);
|
136
|
-
}
|
137
|
-
|
138
|
-
#if DEBUG
|
139
|
-
#include <stdio.h>
|
140
|
-
#include <string.h>
|
141
|
-
#include <time.h>
|
142
|
-
|
143
|
-
void fiobj_siphash_test(void) {
|
144
|
-
fprintf(stderr, "===================================\n");
|
145
|
-
// fio_siphash_speed_test();
|
146
|
-
uint64_t result = 0;
|
147
|
-
clock_t start;
|
148
|
-
start = clock();
|
149
|
-
for (size_t i = 0; i < 100000; i++) {
|
150
|
-
char *data = "The quick brown fox jumps over the lazy dog ";
|
151
|
-
__asm__ volatile("" ::: "memory");
|
152
|
-
result += fio_siphash_xy(data, 43, 1, 3, 0, 0);
|
153
|
-
}
|
154
|
-
fprintf(stderr, "fio 100K SipHash: %lf\n",
|
155
|
-
(double)(clock() - start) / CLOCKS_PER_SEC);
|
156
|
-
}
|
157
|
-
#endif
|
1
|
+
/*
|
2
|
+
Copyright: Boaz Segev, 2017-2019
|
3
|
+
License: MIT
|
4
|
+
*/
|
5
|
+
#include <fio_siphash.h>
|
6
|
+
|
7
|
+
/* *****************************************************************************
|
8
|
+
|
9
|
+
NOTICE
|
10
|
+
|
11
|
+
This code won't be linked to the final application when using fio.h and fio.c.
|
12
|
+
|
13
|
+
The code is here only to allow the FIOBJ library to be extracted from the
|
14
|
+
facil.io framework library.
|
15
|
+
|
16
|
+
***************************************************************************** */
|
17
|
+
|
18
|
+
/* *****************************************************************************
|
19
|
+
Hashing (SipHash implementation)
|
20
|
+
***************************************************************************** */
|
21
|
+
|
22
|
+
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) && \
|
23
|
+
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
24
|
+
/* the algorithm was designed as little endian... so, byte swap 64 bit. */
|
25
|
+
#define sip_local64(i) \
|
26
|
+
(((i)&0xFFULL) << 56) | (((i)&0xFF00ULL) << 40) | \
|
27
|
+
(((i)&0xFF0000ULL) << 24) | (((i)&0xFF000000ULL) << 8) | \
|
28
|
+
(((i)&0xFF00000000ULL) >> 8) | (((i)&0xFF0000000000ULL) >> 24) | \
|
29
|
+
(((i)&0xFF000000000000ULL) >> 40) | (((i)&0xFF00000000000000ULL) >> 56)
|
30
|
+
#else
|
31
|
+
/* no need */
|
32
|
+
#define sip_local64(i) (i)
|
33
|
+
#endif
|
34
|
+
|
35
|
+
/* 64Bit left rotation, inlined. */
|
36
|
+
#define lrot64(i, bits) \
|
37
|
+
(((uint64_t)(i) << (bits)) | ((uint64_t)(i) >> (64 - (bits))))
|
38
|
+
|
39
|
+
static inline uint64_t fio_siphash_xy(const void *data, size_t len, size_t x,
|
40
|
+
size_t y, uint64_t key1, uint64_t key2) {
|
41
|
+
/* initialize the 4 words */
|
42
|
+
uint64_t v0 = (0x0706050403020100ULL ^ 0x736f6d6570736575ULL) ^ key1;
|
43
|
+
uint64_t v1 = (0x0f0e0d0c0b0a0908ULL ^ 0x646f72616e646f6dULL) ^ key2;
|
44
|
+
uint64_t v2 = (0x0706050403020100ULL ^ 0x6c7967656e657261ULL) ^ key1;
|
45
|
+
uint64_t v3 = (0x0f0e0d0c0b0a0908ULL ^ 0x7465646279746573ULL) ^ key2;
|
46
|
+
const uint64_t *w64 = data;
|
47
|
+
uint8_t len_mod = len & 255;
|
48
|
+
union {
|
49
|
+
uint64_t i;
|
50
|
+
uint8_t str[8];
|
51
|
+
} word;
|
52
|
+
|
53
|
+
#define hash_map_SipRound \
|
54
|
+
do { \
|
55
|
+
v2 += v3; \
|
56
|
+
v3 = lrot64(v3, 16) ^ v2; \
|
57
|
+
v0 += v1; \
|
58
|
+
v1 = lrot64(v1, 13) ^ v0; \
|
59
|
+
v0 = lrot64(v0, 32); \
|
60
|
+
v2 += v1; \
|
61
|
+
v0 += v3; \
|
62
|
+
v1 = lrot64(v1, 17) ^ v2; \
|
63
|
+
v3 = lrot64(v3, 21) ^ v0; \
|
64
|
+
v2 = lrot64(v2, 32); \
|
65
|
+
} while (0);
|
66
|
+
|
67
|
+
while (len >= 8) {
|
68
|
+
word.i = sip_local64(*w64);
|
69
|
+
v3 ^= word.i;
|
70
|
+
/* Sip Rounds */
|
71
|
+
for (size_t i = 0; i < x; ++i) {
|
72
|
+
hash_map_SipRound;
|
73
|
+
}
|
74
|
+
v0 ^= word.i;
|
75
|
+
w64 += 1;
|
76
|
+
len -= 8;
|
77
|
+
}
|
78
|
+
word.i = 0;
|
79
|
+
uint8_t *pos = word.str;
|
80
|
+
uint8_t *w8 = (void *)w64;
|
81
|
+
switch (len) { /* fallthrough is intentional */
|
82
|
+
case 7:
|
83
|
+
pos[6] = w8[6];
|
84
|
+
/* fallthrough */
|
85
|
+
case 6:
|
86
|
+
pos[5] = w8[5];
|
87
|
+
/* fallthrough */
|
88
|
+
case 5:
|
89
|
+
pos[4] = w8[4];
|
90
|
+
/* fallthrough */
|
91
|
+
case 4:
|
92
|
+
pos[3] = w8[3];
|
93
|
+
/* fallthrough */
|
94
|
+
case 3:
|
95
|
+
pos[2] = w8[2];
|
96
|
+
/* fallthrough */
|
97
|
+
case 2:
|
98
|
+
pos[1] = w8[1];
|
99
|
+
/* fallthrough */
|
100
|
+
case 1:
|
101
|
+
pos[0] = w8[0];
|
102
|
+
}
|
103
|
+
word.str[7] = len_mod;
|
104
|
+
|
105
|
+
/* last round */
|
106
|
+
v3 ^= word.i;
|
107
|
+
hash_map_SipRound;
|
108
|
+
hash_map_SipRound;
|
109
|
+
v0 ^= word.i;
|
110
|
+
/* Finalization */
|
111
|
+
v2 ^= 0xff;
|
112
|
+
/* d iterations of SipRound */
|
113
|
+
for (size_t i = 0; i < y; ++i) {
|
114
|
+
hash_map_SipRound;
|
115
|
+
}
|
116
|
+
hash_map_SipRound;
|
117
|
+
hash_map_SipRound;
|
118
|
+
hash_map_SipRound;
|
119
|
+
hash_map_SipRound;
|
120
|
+
/* XOR it all together */
|
121
|
+
v0 ^= v1 ^ v2 ^ v3;
|
122
|
+
#undef hash_map_SipRound
|
123
|
+
return v0;
|
124
|
+
}
|
125
|
+
|
126
|
+
#pragma weak fio_siphash24
|
127
|
+
uint64_t __attribute__((weak))
|
128
|
+
fio_siphash24(const void *data, size_t len, uint64_t key1, uint64_t key2) {
|
129
|
+
return fio_siphash_xy(data, len, 2, 4, key1, key2);
|
130
|
+
}
|
131
|
+
|
132
|
+
#pragma weak fio_siphash13
|
133
|
+
uint64_t __attribute__((weak))
|
134
|
+
fio_siphash13(const void *data, size_t len, uint64_t key1, uint64_t key2) {
|
135
|
+
return fio_siphash_xy(data, len, 1, 3, key1, key2);
|
136
|
+
}
|
137
|
+
|
138
|
+
#if DEBUG
|
139
|
+
#include <stdio.h>
|
140
|
+
#include <string.h>
|
141
|
+
#include <time.h>
|
142
|
+
|
143
|
+
void fiobj_siphash_test(void) {
|
144
|
+
fprintf(stderr, "===================================\n");
|
145
|
+
// fio_siphash_speed_test();
|
146
|
+
uint64_t result = 0;
|
147
|
+
clock_t start;
|
148
|
+
start = clock();
|
149
|
+
for (size_t i = 0; i < 100000; i++) {
|
150
|
+
char *data = "The quick brown fox jumps over the lazy dog ";
|
151
|
+
__asm__ volatile("" ::: "memory");
|
152
|
+
result += fio_siphash_xy(data, 43, 1, 3, 0, 0);
|
153
|
+
}
|
154
|
+
fprintf(stderr, "fio 100K SipHash: %lf\n",
|
155
|
+
(double)(clock() - start) / CLOCKS_PER_SEC);
|
156
|
+
}
|
157
|
+
#endif
|
@@ -1,37 +1,37 @@
|
|
1
|
-
#ifndef H_FIO_SIPHASH_H
|
2
|
-
#define H_FIO_SIPHASH_H
|
3
|
-
|
4
|
-
#ifndef _GNU_SOURCE
|
5
|
-
#define _GNU_SOURCE
|
6
|
-
#endif
|
7
|
-
|
8
|
-
#include <stdint.h>
|
9
|
-
#include <sys/types.h>
|
10
|
-
|
11
|
-
/**
|
12
|
-
* A SipHash variation (2-4).
|
13
|
-
*/
|
14
|
-
uint64_t fio_siphash24(const void *data, size_t len, uint64_t key1,
|
15
|
-
uint64_t key2);
|
16
|
-
|
17
|
-
/**
|
18
|
-
* A SipHash 1-3 variation.
|
19
|
-
*/
|
20
|
-
uint64_t fio_siphash13(const void *data, size_t len, uint64_t key1,
|
21
|
-
uint64_t key2);
|
22
|
-
|
23
|
-
/**
|
24
|
-
* The Hashing function used by dynamic facil.io objects.
|
25
|
-
*
|
26
|
-
* Currently implemented using SipHash 1-3.
|
27
|
-
*/
|
28
|
-
#define fio_siphash(data, length, k1, k2) \
|
29
|
-
fio_siphash13((data), (length), (k1), (k2))
|
30
|
-
|
31
|
-
#if DEBUG
|
32
|
-
void fiobj_siphash_test(void);
|
33
|
-
#else
|
34
|
-
#define fiobj_siphash_test()
|
35
|
-
#endif
|
36
|
-
|
37
|
-
#endif /* H_FIO_SIPHASH_H */
|
1
|
+
#ifndef H_FIO_SIPHASH_H
|
2
|
+
#define H_FIO_SIPHASH_H
|
3
|
+
|
4
|
+
#ifndef _GNU_SOURCE
|
5
|
+
#define _GNU_SOURCE
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <stdint.h>
|
9
|
+
#include <sys/types.h>
|
10
|
+
|
11
|
+
/**
|
12
|
+
* A SipHash variation (2-4).
|
13
|
+
*/
|
14
|
+
uint64_t fio_siphash24(const void *data, size_t len, uint64_t key1,
|
15
|
+
uint64_t key2);
|
16
|
+
|
17
|
+
/**
|
18
|
+
* A SipHash 1-3 variation.
|
19
|
+
*/
|
20
|
+
uint64_t fio_siphash13(const void *data, size_t len, uint64_t key1,
|
21
|
+
uint64_t key2);
|
22
|
+
|
23
|
+
/**
|
24
|
+
* The Hashing function used by dynamic facil.io objects.
|
25
|
+
*
|
26
|
+
* Currently implemented using SipHash 1-3.
|
27
|
+
*/
|
28
|
+
#define fio_siphash(data, length, k1, k2) \
|
29
|
+
fio_siphash13((data), (length), (k1), (k2))
|
30
|
+
|
31
|
+
#if DEBUG
|
32
|
+
void fiobj_siphash_test(void);
|
33
|
+
#else
|
34
|
+
#define fiobj_siphash_test()
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#endif /* H_FIO_SIPHASH_H */
|
@@ -1,129 +1,129 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz Segev, 2018-2019
|
3
|
-
License: MIT
|
4
|
-
|
5
|
-
Feel free to copy, use and enjoy according to the license provided.
|
6
|
-
*/
|
7
|
-
#ifndef H_FIO_TLS
|
8
|
-
|
9
|
-
/**
|
10
|
-
* This is an SSL/TLS extension for the facil.io library.
|
11
|
-
*/
|
12
|
-
#define H_FIO_TLS
|
13
|
-
|
14
|
-
#include <stdint.h>
|
15
|
-
|
16
|
-
#ifndef FIO_TLS_PRINT_SECRET
|
17
|
-
/* if true, the master key secret should be printed using FIO_LOG_DEBUG */
|
18
|
-
#define FIO_TLS_PRINT_SECRET 0
|
19
|
-
#endif
|
20
|
-
|
21
|
-
/** An opaque type used for the SSL/TLS functions. */
|
22
|
-
typedef struct fio_tls_s fio_tls_s;
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Creates a new SSL/TLS context / settings object with a default certificate
|
26
|
-
* (if any).
|
27
|
-
*
|
28
|
-
* If no server name is provided and no private key and public certificate are
|
29
|
-
* provided, an empty TLS object will be created, (maybe okay for clients).
|
30
|
-
*
|
31
|
-
* fio_tls_s * tls = fio_tls_new("www.example.com",
|
32
|
-
* "public_key.pem",
|
33
|
-
* "private_key.pem", NULL );
|
34
|
-
*/
|
35
|
-
fio_tls_s *fio_tls_new(const char *server_name, const char *public_cert_file,
|
36
|
-
const char *private_key_file, const char *pk_password);
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Adds a certificate a new SSL/TLS context / settings object (SNI support).
|
40
|
-
*
|
41
|
-
* fio_tls_cert_add(tls, "www.example.com",
|
42
|
-
* "public_key.pem",
|
43
|
-
* "private_key.pem", NULL );
|
44
|
-
*/
|
45
|
-
void fio_tls_cert_add(fio_tls_s *, const char *server_name,
|
46
|
-
const char *public_cert_file,
|
47
|
-
const char *private_key_file, const char *pk_password);
|
48
|
-
|
49
|
-
/**
|
50
|
-
* Adds an ALPN protocol callback to the SSL/TLS context.
|
51
|
-
*
|
52
|
-
* The first protocol added will act as the default protocol to be selected.
|
53
|
-
*
|
54
|
-
* The `on_selected` callback should accept the `uuid`, the user data pointer
|
55
|
-
* passed to either `fio_tls_accept` or `fio_tls_connect` (here:
|
56
|
-
* `udata_connetcion`) and the user data pointer passed to the
|
57
|
-
* `fio_tls_alpn_add` function (`udata_tls`).
|
58
|
-
*
|
59
|
-
* The `on_cleanup` callback will be called when the TLS object is destroyed (or
|
60
|
-
* `fio_tls_alpn_add` is called again with the same protocol name). The
|
61
|
-
* `udata_tls` argument will be passed along, as is, to the callback (if set).
|
62
|
-
*
|
63
|
-
* Except for the `tls` and `protocol_name` arguments, all arguments can be
|
64
|
-
* NULL.
|
65
|
-
*/
|
66
|
-
void fio_tls_alpn_add(fio_tls_s *tls, const char *protocol_name,
|
67
|
-
void (*on_selected)(intptr_t uuid, void *udata_connection,
|
68
|
-
void *udata_tls),
|
69
|
-
void *udata_tls, void (*on_cleanup)(void *udata_tls));
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Returns the number of registered ALPN protocol names.
|
73
|
-
*
|
74
|
-
* This could be used when deciding if protocol selection should be delegated to
|
75
|
-
* the ALPN mechanism, or whether a protocol should be immediately assigned.
|
76
|
-
*
|
77
|
-
* If no ALPN protocols are registered, zero (0) is returned.
|
78
|
-
*/
|
79
|
-
uintptr_t fio_tls_alpn_count(fio_tls_s *tls);
|
80
|
-
|
81
|
-
/**
|
82
|
-
* Adds a certificate to the "trust" list, which automatically adds a peer
|
83
|
-
* verification requirement.
|
84
|
-
*
|
85
|
-
* Note, when the fio_tls_s object is used for server connections, this will
|
86
|
-
* limit connections to clients that connect using a trusted certificate.
|
87
|
-
*
|
88
|
-
* fio_tls_trust(tls, "google-ca.pem" );
|
89
|
-
*/
|
90
|
-
void fio_tls_trust(fio_tls_s *, const char *public_cert_file);
|
91
|
-
|
92
|
-
/**
|
93
|
-
* Establishes an SSL/TLS connection as an SSL/TLS Server, using the specified
|
94
|
-
* context / settings object.
|
95
|
-
*
|
96
|
-
* The `uuid` should be a socket UUID that is already connected to a peer (i.e.,
|
97
|
-
* the result of `fio_accept`).
|
98
|
-
*
|
99
|
-
* The `udata` is an opaque user data pointer that is passed along to the
|
100
|
-
* protocol selected (if any protocols were added using `fio_tls_alpn_add`).
|
101
|
-
*/
|
102
|
-
void fio_tls_accept(intptr_t uuid, fio_tls_s *tls, void *udata);
|
103
|
-
|
104
|
-
/**
|
105
|
-
* Establishes an SSL/TLS connection as an SSL/TLS Client, using the specified
|
106
|
-
* context / settings object.
|
107
|
-
*
|
108
|
-
* The `uuid` should be a socket UUID that is already connected to a peer (i.e.,
|
109
|
-
* one received by a `fio_connect` specified callback `on_connect`).
|
110
|
-
*
|
111
|
-
* The `udata` is an opaque user data pointer that is passed along to the
|
112
|
-
* protocol selected (if any protocols were added using `fio_tls_alpn_add`).
|
113
|
-
*/
|
114
|
-
void fio_tls_connect(intptr_t uuid, fio_tls_s *tls, void *udata);
|
115
|
-
|
116
|
-
/**
|
117
|
-
* Increase the reference count for the TLS object.
|
118
|
-
*
|
119
|
-
* Decrease with `fio_tls_destroy`.
|
120
|
-
*/
|
121
|
-
void fio_tls_dup(fio_tls_s *tls);
|
122
|
-
|
123
|
-
/**
|
124
|
-
* Destroys the SSL/TLS context / settings object and frees any related
|
125
|
-
* resources / memory.
|
126
|
-
*/
|
127
|
-
void fio_tls_destroy(fio_tls_s *tls);
|
128
|
-
|
129
|
-
#endif
|
1
|
+
/*
|
2
|
+
Copyright: Boaz Segev, 2018-2019
|
3
|
+
License: MIT
|
4
|
+
|
5
|
+
Feel free to copy, use and enjoy according to the license provided.
|
6
|
+
*/
|
7
|
+
#ifndef H_FIO_TLS
|
8
|
+
|
9
|
+
/**
|
10
|
+
* This is an SSL/TLS extension for the facil.io library.
|
11
|
+
*/
|
12
|
+
#define H_FIO_TLS
|
13
|
+
|
14
|
+
#include <stdint.h>
|
15
|
+
|
16
|
+
#ifndef FIO_TLS_PRINT_SECRET
|
17
|
+
/* if true, the master key secret should be printed using FIO_LOG_DEBUG */
|
18
|
+
#define FIO_TLS_PRINT_SECRET 0
|
19
|
+
#endif
|
20
|
+
|
21
|
+
/** An opaque type used for the SSL/TLS functions. */
|
22
|
+
typedef struct fio_tls_s fio_tls_s;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Creates a new SSL/TLS context / settings object with a default certificate
|
26
|
+
* (if any).
|
27
|
+
*
|
28
|
+
* If no server name is provided and no private key and public certificate are
|
29
|
+
* provided, an empty TLS object will be created, (maybe okay for clients).
|
30
|
+
*
|
31
|
+
* fio_tls_s * tls = fio_tls_new("www.example.com",
|
32
|
+
* "public_key.pem",
|
33
|
+
* "private_key.pem", NULL );
|
34
|
+
*/
|
35
|
+
fio_tls_s *fio_tls_new(const char *server_name, const char *public_cert_file,
|
36
|
+
const char *private_key_file, const char *pk_password);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Adds a certificate a new SSL/TLS context / settings object (SNI support).
|
40
|
+
*
|
41
|
+
* fio_tls_cert_add(tls, "www.example.com",
|
42
|
+
* "public_key.pem",
|
43
|
+
* "private_key.pem", NULL );
|
44
|
+
*/
|
45
|
+
void fio_tls_cert_add(fio_tls_s *, const char *server_name,
|
46
|
+
const char *public_cert_file,
|
47
|
+
const char *private_key_file, const char *pk_password);
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Adds an ALPN protocol callback to the SSL/TLS context.
|
51
|
+
*
|
52
|
+
* The first protocol added will act as the default protocol to be selected.
|
53
|
+
*
|
54
|
+
* The `on_selected` callback should accept the `uuid`, the user data pointer
|
55
|
+
* passed to either `fio_tls_accept` or `fio_tls_connect` (here:
|
56
|
+
* `udata_connetcion`) and the user data pointer passed to the
|
57
|
+
* `fio_tls_alpn_add` function (`udata_tls`).
|
58
|
+
*
|
59
|
+
* The `on_cleanup` callback will be called when the TLS object is destroyed (or
|
60
|
+
* `fio_tls_alpn_add` is called again with the same protocol name). The
|
61
|
+
* `udata_tls` argument will be passed along, as is, to the callback (if set).
|
62
|
+
*
|
63
|
+
* Except for the `tls` and `protocol_name` arguments, all arguments can be
|
64
|
+
* NULL.
|
65
|
+
*/
|
66
|
+
void fio_tls_alpn_add(fio_tls_s *tls, const char *protocol_name,
|
67
|
+
void (*on_selected)(intptr_t uuid, void *udata_connection,
|
68
|
+
void *udata_tls),
|
69
|
+
void *udata_tls, void (*on_cleanup)(void *udata_tls));
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Returns the number of registered ALPN protocol names.
|
73
|
+
*
|
74
|
+
* This could be used when deciding if protocol selection should be delegated to
|
75
|
+
* the ALPN mechanism, or whether a protocol should be immediately assigned.
|
76
|
+
*
|
77
|
+
* If no ALPN protocols are registered, zero (0) is returned.
|
78
|
+
*/
|
79
|
+
uintptr_t fio_tls_alpn_count(fio_tls_s *tls);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Adds a certificate to the "trust" list, which automatically adds a peer
|
83
|
+
* verification requirement.
|
84
|
+
*
|
85
|
+
* Note, when the fio_tls_s object is used for server connections, this will
|
86
|
+
* limit connections to clients that connect using a trusted certificate.
|
87
|
+
*
|
88
|
+
* fio_tls_trust(tls, "google-ca.pem" );
|
89
|
+
*/
|
90
|
+
void fio_tls_trust(fio_tls_s *, const char *public_cert_file);
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Establishes an SSL/TLS connection as an SSL/TLS Server, using the specified
|
94
|
+
* context / settings object.
|
95
|
+
*
|
96
|
+
* The `uuid` should be a socket UUID that is already connected to a peer (i.e.,
|
97
|
+
* the result of `fio_accept`).
|
98
|
+
*
|
99
|
+
* The `udata` is an opaque user data pointer that is passed along to the
|
100
|
+
* protocol selected (if any protocols were added using `fio_tls_alpn_add`).
|
101
|
+
*/
|
102
|
+
void fio_tls_accept(intptr_t uuid, fio_tls_s *tls, void *udata);
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Establishes an SSL/TLS connection as an SSL/TLS Client, using the specified
|
106
|
+
* context / settings object.
|
107
|
+
*
|
108
|
+
* The `uuid` should be a socket UUID that is already connected to a peer (i.e.,
|
109
|
+
* one received by a `fio_connect` specified callback `on_connect`).
|
110
|
+
*
|
111
|
+
* The `udata` is an opaque user data pointer that is passed along to the
|
112
|
+
* protocol selected (if any protocols were added using `fio_tls_alpn_add`).
|
113
|
+
*/
|
114
|
+
void fio_tls_connect(intptr_t uuid, fio_tls_s *tls, void *udata);
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Increase the reference count for the TLS object.
|
118
|
+
*
|
119
|
+
* Decrease with `fio_tls_destroy`.
|
120
|
+
*/
|
121
|
+
void fio_tls_dup(fio_tls_s *tls);
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Destroys the SSL/TLS context / settings object and frees any related
|
125
|
+
* resources / memory.
|
126
|
+
*/
|
127
|
+
void fio_tls_destroy(fio_tls_s *tls);
|
128
|
+
|
129
|
+
#endif
|
File without changes
|
File without changes
|
File without changes
|