licentivo-launch 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +35 -0
  4. data/ext/launch_native/extconf.rb +28 -0
  5. data/lib/licentivo_launch/vendor/licentivo.rb +262 -0
  6. data/lib/licentivo_launch.rb +352 -0
  7. data/vendor/LICENSE +21 -0
  8. data/vendor/NOTICE +17 -0
  9. data/vendor/VERSION +1 -0
  10. data/vendor/c/app.c +33 -0
  11. data/vendor/c/demo.c +77 -0
  12. data/vendor/c/feature_tasks.h +72 -0
  13. data/vendor/c/licentivo.c +382 -0
  14. data/vendor/c/licentivo.h +67 -0
  15. data/vendor/c/quickstart.c +51 -0
  16. data/vendor/c/test_vectors.c +4 -0
  17. data/vendor/c/vendor/Monocypher-LICENCE.md +173 -0
  18. data/vendor/c/vendor/cJSON-LICENSE +20 -0
  19. data/vendor/c/vendor/cJSON.c +3191 -0
  20. data/vendor/c/vendor/cJSON.h +306 -0
  21. data/vendor/c/vendor/monocypher-ed25519.c +500 -0
  22. data/vendor/c/vendor/monocypher-ed25519.h +140 -0
  23. data/vendor/c/vendor/monocypher.c +2956 -0
  24. data/vendor/c/vendor/monocypher.h +321 -0
  25. data/vendor/curl/COPYING.txt +22 -0
  26. data/vendor/curl/bin/libcurl-x64.dll +0 -0
  27. data/vendor/curl/include/brotli/decode.h +409 -0
  28. data/vendor/curl/include/brotli/encode.h +505 -0
  29. data/vendor/curl/include/brotli/port.h +302 -0
  30. data/vendor/curl/include/brotli/shared_dictionary.h +100 -0
  31. data/vendor/curl/include/brotli/types.h +83 -0
  32. data/vendor/curl/include/curl/curl.h +3374 -0
  33. data/vendor/curl/include/curl/curlver.h +77 -0
  34. data/vendor/curl/include/curl/easy.h +123 -0
  35. data/vendor/curl/include/curl/header.h +74 -0
  36. data/vendor/curl/include/curl/mprintf.h +85 -0
  37. data/vendor/curl/include/curl/multi.h +561 -0
  38. data/vendor/curl/include/curl/options.h +70 -0
  39. data/vendor/curl/include/curl/stdcheaders.h +35 -0
  40. data/vendor/curl/include/curl/system.h +399 -0
  41. data/vendor/curl/include/curl/typecheck-gcc.h +964 -0
  42. data/vendor/curl/include/curl/urlapi.h +156 -0
  43. data/vendor/curl/include/curl/websockets.h +98 -0
  44. data/vendor/curl/include/libpsl.h +207 -0
  45. data/vendor/curl/include/libssh2.h +1516 -0
  46. data/vendor/curl/include/libssh2_publickey.h +128 -0
  47. data/vendor/curl/include/libssh2_sftp.h +382 -0
  48. data/vendor/curl/include/nghttp2/nghttp2.h +6878 -0
  49. data/vendor/curl/include/nghttp2/nghttp2ver.h +42 -0
  50. data/vendor/curl/include/nghttp3/nghttp3.h +3704 -0
  51. data/vendor/curl/include/nghttp3/version.h +46 -0
  52. data/vendor/curl/include/ngtcp2/ngtcp2.h +7485 -0
  53. data/vendor/curl/include/ngtcp2/ngtcp2_crypto.h +1071 -0
  54. data/vendor/curl/include/ngtcp2/ngtcp2_crypto_quictls.h +147 -0
  55. data/vendor/curl/include/ngtcp2/version.h +51 -0
  56. data/vendor/curl/include/openssl/aes.h +120 -0
  57. data/vendor/curl/include/openssl/asn1.h +1121 -0
  58. data/vendor/curl/include/openssl/asn1t.h +996 -0
  59. data/vendor/curl/include/openssl/bio.h +716 -0
  60. data/vendor/curl/include/openssl/blowfish.h +106 -0
  61. data/vendor/curl/include/openssl/bn.h +480 -0
  62. data/vendor/curl/include/openssl/buffer.h +102 -0
  63. data/vendor/curl/include/openssl/camellia.h +121 -0
  64. data/vendor/curl/include/openssl/cast.h +99 -0
  65. data/vendor/curl/include/openssl/chacha.h +54 -0
  66. data/vendor/curl/include/openssl/cmac.h +81 -0
  67. data/vendor/curl/include/openssl/cms.h +541 -0
  68. data/vendor/curl/include/openssl/comp.h +7 -0
  69. data/vendor/curl/include/openssl/conf.h +189 -0
  70. data/vendor/curl/include/openssl/crypto.h +458 -0
  71. data/vendor/curl/include/openssl/ct.h +567 -0
  72. data/vendor/curl/include/openssl/curve25519.h +104 -0
  73. data/vendor/curl/include/openssl/des.h +215 -0
  74. data/vendor/curl/include/openssl/dh.h +245 -0
  75. data/vendor/curl/include/openssl/dsa.h +263 -0
  76. data/vendor/curl/include/openssl/dtls1.h +107 -0
  77. data/vendor/curl/include/openssl/ec.h +675 -0
  78. data/vendor/curl/include/openssl/ecdh.h +6 -0
  79. data/vendor/curl/include/openssl/ecdsa.h +6 -0
  80. data/vendor/curl/include/openssl/engine.h +215 -0
  81. data/vendor/curl/include/openssl/err.h +325 -0
  82. data/vendor/curl/include/openssl/evp.h +1288 -0
  83. data/vendor/curl/include/openssl/hkdf.h +65 -0
  84. data/vendor/curl/include/openssl/hmac.h +101 -0
  85. data/vendor/curl/include/openssl/idea.h +99 -0
  86. data/vendor/curl/include/openssl/kdf.h +137 -0
  87. data/vendor/curl/include/openssl/lhash.h +179 -0
  88. data/vendor/curl/include/openssl/md4.h +105 -0
  89. data/vendor/curl/include/openssl/md5.h +99 -0
  90. data/vendor/curl/include/openssl/mlkem.h +236 -0
  91. data/vendor/curl/include/openssl/modes.h +118 -0
  92. data/vendor/curl/include/openssl/obj_mac.h +4646 -0
  93. data/vendor/curl/include/openssl/objects.h +137 -0
  94. data/vendor/curl/include/openssl/ocsp.h +484 -0
  95. data/vendor/curl/include/openssl/opensslconf.h +16 -0
  96. data/vendor/curl/include/openssl/opensslfeatures.h +153 -0
  97. data/vendor/curl/include/openssl/opensslv.h +18 -0
  98. data/vendor/curl/include/openssl/ossl_typ.h +196 -0
  99. data/vendor/curl/include/openssl/pem.h +542 -0
  100. data/vendor/curl/include/openssl/pkcs12.h +284 -0
  101. data/vendor/curl/include/openssl/pkcs7.h +523 -0
  102. data/vendor/curl/include/openssl/poly1305.h +45 -0
  103. data/vendor/curl/include/openssl/posix_time.h +54 -0
  104. data/vendor/curl/include/openssl/rand.h +118 -0
  105. data/vendor/curl/include/openssl/rc2.h +101 -0
  106. data/vendor/curl/include/openssl/rc4.h +88 -0
  107. data/vendor/curl/include/openssl/ripemd.h +107 -0
  108. data/vendor/curl/include/openssl/rsa.h +603 -0
  109. data/vendor/curl/include/openssl/safestack.h +1739 -0
  110. data/vendor/curl/include/openssl/sha.h +190 -0
  111. data/vendor/curl/include/openssl/sm3.h +49 -0
  112. data/vendor/curl/include/openssl/sm4.h +47 -0
  113. data/vendor/curl/include/openssl/srtp.h +148 -0
  114. data/vendor/curl/include/openssl/ssl.h +2336 -0
  115. data/vendor/curl/include/openssl/ssl3.h +441 -0
  116. data/vendor/curl/include/openssl/stack.h +99 -0
  117. data/vendor/curl/include/openssl/tls1.h +764 -0
  118. data/vendor/curl/include/openssl/ts.h +660 -0
  119. data/vendor/curl/include/openssl/txt_db.h +112 -0
  120. data/vendor/curl/include/openssl/ui.h +397 -0
  121. data/vendor/curl/include/openssl/x509.h +1037 -0
  122. data/vendor/curl/include/openssl/x509_vfy.h +464 -0
  123. data/vendor/curl/include/openssl/x509v3.h +1039 -0
  124. data/vendor/curl/include/zconf.h +206 -0
  125. data/vendor/curl/include/zdict.h +481 -0
  126. data/vendor/curl/include/zlib.h +1859 -0
  127. data/vendor/curl/include/zlib_name_mangling.h +8 -0
  128. data/vendor/curl/include/zstd.h +3198 -0
  129. data/vendor/curl/include/zstd_errors.h +107 -0
  130. data/vendor/curl/lib/libcurl.dll.a +0 -0
  131. data/vendor/curl/licenses/brotli/LICENSE.txt +19 -0
  132. data/vendor/curl/licenses/certdata/LICENSE.url +2 -0
  133. data/vendor/curl/licenses/libpsl/COPYING.txt +20 -0
  134. data/vendor/curl/licenses/libressl/COPYING.txt +133 -0
  135. data/vendor/curl/licenses/libssh2/COPYING.txt +43 -0
  136. data/vendor/curl/licenses/nghttp2/COPYING.txt +23 -0
  137. data/vendor/curl/licenses/nghttp3/COPYING.txt +22 -0
  138. data/vendor/curl/licenses/ngtcp2/COPYING.txt +22 -0
  139. data/vendor/curl/licenses/psl/LICENSE.txt +373 -0
  140. data/vendor/curl/licenses/trurl/COPYING.txt +22 -0
  141. data/vendor/curl/licenses/zlibng/LICENSE.md +19 -0
  142. data/vendor/curl/licenses/zstd/LICENSE.txt +30 -0
  143. metadata +205 -0
@@ -0,0 +1,1071 @@
1
+ /*
2
+ * ngtcp2
3
+ *
4
+ * Copyright (c) 2019 ngtcp2 contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * "Software"), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+ #ifndef NGTCP2_CRYPTO_H
26
+ #define NGTCP2_CRYPTO_H
27
+
28
+ #include <ngtcp2/ngtcp2.h>
29
+
30
+ #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif /* defined(__cplusplus) */
33
+
34
+ #ifdef WIN32
35
+ # ifndef WIN32_LEAN_AND_MEAN
36
+ # define WIN32_LEAN_AND_MEAN
37
+ # endif /* !defined(WIN32_LEAN_AND_MEAN) */
38
+ # include <ws2tcpip.h>
39
+ #endif /* defined(WIN32) */
40
+
41
+ /**
42
+ * @macrosection
43
+ *
44
+ * ngtcp2 crypto library error codes
45
+ */
46
+
47
+ /**
48
+ * @macro
49
+ *
50
+ * :macro:`NGTCP2_CRYPTO_ERR_INTERNAL` indicates an internal error.
51
+ */
52
+ #define NGTCP2_CRYPTO_ERR_INTERNAL -201
53
+
54
+ /**
55
+ * @macro
56
+ *
57
+ * :macro:`NGTCP2_CRYPTO_ERR_UNREADABLE_TOKEN` indicates that a token
58
+ * is unreadable because it is not correctly formatted; or verifying
59
+ * the integrity protection failed.
60
+ */
61
+ #define NGTCP2_CRYPTO_ERR_UNREADABLE_TOKEN -202
62
+
63
+ /**
64
+ * @macro
65
+ *
66
+ * :macro:`NGTCP2_CRYPTO_ERR_VERIFY_TOKEN` indicates that a token does
67
+ * not probe the client address; or the token validity has expired; or
68
+ * it contains invalid Connection ID.
69
+ */
70
+ #define NGTCP2_CRYPTO_ERR_VERIFY_TOKEN -203
71
+
72
+ /**
73
+ * @macro
74
+ *
75
+ * :macro:`NGTCP2_CRYPTO_ERR_NOMEM` indicates out of memory.
76
+ */
77
+ #define NGTCP2_CRYPTO_ERR_NOMEM -501
78
+
79
+ /**
80
+ * @function
81
+ *
82
+ * `ngtcp2_crypto_ctx_tls` initializes |ctx| by extracting negotiated
83
+ * ciphers and message digests from native TLS session
84
+ * |tls_native_handle|. This is used for encrypting/decrypting
85
+ * Handshake and 1-RTT packets. If it is unable to obtain necessary
86
+ * data from |tls_native_handle|, this function returns NULL.
87
+ *
88
+ * If libngtcp2_crypto_quictls is linked, |tls_native_handle| must be
89
+ * a pointer to SSL object.
90
+ */
91
+ NGTCP2_EXTERN ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx,
92
+ void *tls_native_handle);
93
+
94
+ /**
95
+ * @function
96
+ *
97
+ * `ngtcp2_crypto_ctx_tls_early` initializes |ctx| by extracting early
98
+ * ciphers and message digests from native TLS session
99
+ * |tls_native_handle|. This is used for encrypting/decrypting 0-RTT
100
+ * packets. If it is unable to obtain necessary data from
101
+ * |tls_native_handle|, this function returns NULL.
102
+ *
103
+ * If libngtcp2_crypto_quictls is linked, |tls_native_handle| must be
104
+ * a pointer to SSL object.
105
+ */
106
+ NGTCP2_EXTERN ngtcp2_crypto_ctx *
107
+ ngtcp2_crypto_ctx_tls_early(ngtcp2_crypto_ctx *ctx, void *tls_native_handle);
108
+
109
+ /**
110
+ * @function
111
+ *
112
+ * `ngtcp2_crypto_md_init` initializes |md| with the provided
113
+ * |md_native_handle| which is an underlying message digest object.
114
+ *
115
+ * If libngtcp2_crypto_quictls is linked, |md_native_handle| must be a
116
+ * pointer to EVP_MD.
117
+ *
118
+ * If libngtcp2_crypto_gnutls is linked, |md_native_handle| must be
119
+ * gnutls_mac_algorithm_t casted to ``void *``.
120
+ *
121
+ * If libngtcp2_crypto_boringssl is linked, |md_native_handle| must be
122
+ * a pointer to EVP_MD.
123
+ */
124
+ NGTCP2_EXTERN ngtcp2_crypto_md *ngtcp2_crypto_md_init(ngtcp2_crypto_md *md,
125
+ void *md_native_handle);
126
+
127
+ /**
128
+ * @function
129
+ *
130
+ * `ngtcp2_crypto_md_hashlen` returns the length of |md| output.
131
+ */
132
+ NGTCP2_EXTERN size_t ngtcp2_crypto_md_hashlen(const ngtcp2_crypto_md *md);
133
+
134
+ /**
135
+ * @function
136
+ *
137
+ * `ngtcp2_crypto_aead_keylen` returns the length of key for |aead|.
138
+ */
139
+ NGTCP2_EXTERN size_t ngtcp2_crypto_aead_keylen(const ngtcp2_crypto_aead *aead);
140
+
141
+ /**
142
+ * @function
143
+ *
144
+ * `ngtcp2_crypto_aead_noncelen` returns the length of nonce for
145
+ * |aead|.
146
+ */
147
+ NGTCP2_EXTERN size_t
148
+ ngtcp2_crypto_aead_noncelen(const ngtcp2_crypto_aead *aead);
149
+
150
+ /**
151
+ * @function
152
+ *
153
+ * `ngtcp2_crypto_hkdf_extract` performs HKDF extract operation.
154
+ *
155
+ * The length of output is `ngtcp2_crypto_md_hashlen(md)
156
+ * <ngtcp2_crypto_md_hashlen>`. The output is stored in the buffer
157
+ * pointed by |dest|. The caller is responsible to specify the buffer
158
+ * that has enough capacity to store the output.
159
+ *
160
+ * This function returns 0 if it succeeds, or -1.
161
+ */
162
+ NGTCP2_EXTERN int
163
+ ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
164
+ const uint8_t *secret, size_t secretlen,
165
+ const uint8_t *salt, size_t saltlen);
166
+
167
+ /**
168
+ * @function
169
+ *
170
+ * `ngtcp2_crypto_hkdf_expand` performs HKDF expand operation. The
171
+ * result is |destlen| bytes long, and is stored in the buffer pointed
172
+ * by |dest|.
173
+ *
174
+ * This function returns 0 if it succeeds, or -1.
175
+ */
176
+ NGTCP2_EXTERN int ngtcp2_crypto_hkdf_expand(
177
+ uint8_t *dest, size_t destlen, const ngtcp2_crypto_md *md,
178
+ const uint8_t *secret, size_t secretlen, const uint8_t *info, size_t infolen);
179
+
180
+ /**
181
+ * @function
182
+ *
183
+ * `ngtcp2_crypto_hkdf` performs HKDF operation. The result is
184
+ * |destlen| bytes long, and is stored in the buffer pointed by
185
+ * |dest|.
186
+ *
187
+ * This function returns 0 if it succeeds, or -1.
188
+ */
189
+ NGTCP2_EXTERN int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
190
+ const ngtcp2_crypto_md *md,
191
+ const uint8_t *secret, size_t secretlen,
192
+ const uint8_t *salt, size_t saltlen,
193
+ const uint8_t *info, size_t infolen);
194
+
195
+ /**
196
+ * @function
197
+ *
198
+ * `ngtcp2_crypto_packet_protection_ivlen` returns the length of IV
199
+ * used to encrypt QUIC packet.
200
+ */
201
+ NGTCP2_EXTERN size_t
202
+ ngtcp2_crypto_packet_protection_ivlen(const ngtcp2_crypto_aead *aead);
203
+
204
+ /**
205
+ * @function
206
+ *
207
+ * `ngtcp2_crypto_encrypt` encrypts |plaintext| of length
208
+ * |plaintextlen| and writes the ciphertext into the buffer pointed by
209
+ * |dest|. The length of ciphertext is |plaintextlen| +
210
+ * :member:`aead->max_overhead <ngtcp2_crypto_aead.max_overhead>`
211
+ * bytes long. |dest| must have enough capacity to store the
212
+ * ciphertext. |dest| and |plaintext| may point to the same buffer.
213
+ *
214
+ * This function returns 0 if it succeeds, or -1.
215
+ */
216
+ NGTCP2_EXTERN int ngtcp2_crypto_encrypt(uint8_t *dest,
217
+ const ngtcp2_crypto_aead *aead,
218
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
219
+ const uint8_t *plaintext,
220
+ size_t plaintextlen,
221
+ const uint8_t *nonce, size_t noncelen,
222
+ const uint8_t *aad, size_t aadlen);
223
+
224
+ /**
225
+ * @function
226
+ *
227
+ * `ngtcp2_crypto_encrypt_cb` is a wrapper function around
228
+ * `ngtcp2_crypto_encrypt`. It can be directly passed to
229
+ * :member:`ngtcp2_callbacks.encrypt` field.
230
+ *
231
+ * This function returns 0 if it succeeds, or
232
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
233
+ */
234
+ NGTCP2_EXTERN int
235
+ ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
236
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
237
+ const uint8_t *plaintext, size_t plaintextlen,
238
+ const uint8_t *nonce, size_t noncelen,
239
+ const uint8_t *aad, size_t aadlen);
240
+
241
+ /**
242
+ * @function
243
+ *
244
+ * `ngtcp2_crypto_decrypt` decrypts |ciphertext| of length
245
+ * |ciphertextlen| and writes the plaintext into the buffer pointed by
246
+ * |dest|. The length of plaintext is |ciphertextlen| -
247
+ * :member:`aead->max_overhead <ngtcp2_crypto_aead.max_overhead>`
248
+ * bytes long. |dest| must have enough capacity to store the
249
+ * plaintext. |dest| and |ciphertext| may point to the same buffer.
250
+ *
251
+ * This function returns 0 if it succeeds, or -1.
252
+ */
253
+ NGTCP2_EXTERN int ngtcp2_crypto_decrypt(uint8_t *dest,
254
+ const ngtcp2_crypto_aead *aead,
255
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
256
+ const uint8_t *ciphertext,
257
+ size_t ciphertextlen,
258
+ const uint8_t *nonce, size_t noncelen,
259
+ const uint8_t *aad, size_t aadlen);
260
+
261
+ /**
262
+ * @function
263
+ *
264
+ * `ngtcp2_crypto_decrypt_cb` is a wrapper function around
265
+ * `ngtcp2_crypto_decrypt`. It can be directly passed to
266
+ * :member:`ngtcp2_callbacks.decrypt` field.
267
+ *
268
+ * This function returns 0 if it succeeds, or
269
+ * :macro:`NGTCP2_ERR_TLS_DECRYPT`.
270
+ */
271
+ NGTCP2_EXTERN int
272
+ ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
273
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
274
+ const uint8_t *ciphertext, size_t ciphertextlen,
275
+ const uint8_t *nonce, size_t noncelen,
276
+ const uint8_t *aad, size_t aadlen);
277
+
278
+ /**
279
+ * @function
280
+ *
281
+ * `ngtcp2_crypto_hp_mask` generates a mask which is used in packet
282
+ * header encryption. The mask is written to the buffer pointed by
283
+ * |dest|. The sample is passed as |sample| which is
284
+ * :macro:`NGTCP2_HP_SAMPLELEN` bytes long. The length of mask must
285
+ * be at least :macro:`NGTCP2_HP_MASKLEN`. The library only uses the
286
+ * first :macro:`NGTCP2_HP_MASKLEN` bytes of the produced mask. The
287
+ * buffer pointed by |dest| must have at least
288
+ * :macro:`NGTCP2_HP_SAMPLELEN` bytes available.
289
+ *
290
+ * This function returns 0 if it succeeds, or -1.
291
+ */
292
+ NGTCP2_EXTERN int ngtcp2_crypto_hp_mask(uint8_t *dest,
293
+ const ngtcp2_crypto_cipher *hp,
294
+ const ngtcp2_crypto_cipher_ctx *hp_ctx,
295
+ const uint8_t *sample);
296
+
297
+ /**
298
+ * @function
299
+ *
300
+ * `ngtcp2_crypto_hp_mask_cb` is a wrapper function around
301
+ * `ngtcp2_crypto_hp_mask`. It can be directly passed to
302
+ * :member:`ngtcp2_callbacks.hp_mask` field.
303
+ *
304
+ * This function returns 0 if it succeeds, or
305
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
306
+ */
307
+ NGTCP2_EXTERN int
308
+ ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
309
+ const ngtcp2_crypto_cipher_ctx *hp_ctx,
310
+ const uint8_t *sample);
311
+
312
+ /**
313
+ * @function
314
+ *
315
+ * `ngtcp2_crypto_derive_and_install_rx_key` derives the decryption
316
+ * keying materials from |secret|, and installs them to |conn|.
317
+ *
318
+ * If |key| is not NULL, the derived packet protection key is written
319
+ * to the buffer pointed by |key|. If |iv| is not NULL, the derived
320
+ * packet protection IV is written to the buffer pointed by |iv|. If
321
+ * |hp| is not NULL, the derived header protection key is written to
322
+ * the buffer pointed by |hp|.
323
+ *
324
+ * |secretlen| specifies the length of |secret|.
325
+ *
326
+ * The length of packet protection key and header protection key is
327
+ * `ngtcp2_crypto_aead_keylen(ctx->aead) <ngtcp2_crypto_aead_keylen>`,
328
+ * and the length of packet protection IV is
329
+ * `ngtcp2_crypto_packet_protection_ivlen(ctx->aead)
330
+ * <ngtcp2_crypto_packet_protection_ivlen>` where ctx is obtained by
331
+ * `ngtcp2_crypto_ctx_tls` (or `ngtcp2_crypto_ctx_tls_early` if
332
+ * |level| ==
333
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`).
334
+ *
335
+ * In the first call of this function, it calls
336
+ * `ngtcp2_conn_set_crypto_ctx` (or `ngtcp2_conn_set_early_crypto_ctx`
337
+ * if |level| ==
338
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
339
+ * set negotiated AEAD and message digest algorithm. After the
340
+ * successful call of this function, application can use
341
+ * `ngtcp2_conn_get_crypto_ctx2` (or
342
+ * `ngtcp2_conn_get_0rtt_crypto_ctx2` if |level| ==
343
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
344
+ * get :type:`ngtcp2_crypto_ctx`.
345
+ *
346
+ * If |conn| is initialized as client, and |level| is
347
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_1RTT`, this
348
+ * function retrieves a remote QUIC transport parameters extension
349
+ * from an object obtained by `ngtcp2_conn_get_tls_native_handle2`,
350
+ * and sets it to |conn| by calling
351
+ * `ngtcp2_conn_decode_and_set_remote_transport_params`.
352
+ *
353
+ * This function returns 0 if it succeeds, or -1.
354
+ */
355
+ NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_rx_key(
356
+ ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp,
357
+ ngtcp2_encryption_level level, const uint8_t *secret, size_t secretlen);
358
+
359
+ /**
360
+ * @function
361
+ *
362
+ * `ngtcp2_crypto_derive_and_install_tx_key` derives the encryption
363
+ * keying materials from |secret|, and installs new keys to |conn|.
364
+ *
365
+ * If |key| is not NULL, the derived packet protection key is written
366
+ * to the buffer pointed by |key|. If |iv| is not NULL, the derived
367
+ * packet protection IV is written to the buffer pointed by |iv|. If
368
+ * |hp| is not NULL, the derived header protection key is written to
369
+ * the buffer pointed by |hp|.
370
+ *
371
+ * |secretlen| specifies the length of |secret|.
372
+ *
373
+ * The length of packet protection key and header protection key is
374
+ * `ngtcp2_crypto_aead_keylen(ctx->aead) <ngtcp2_crypto_aead_keylen>`,
375
+ * and the length of packet protection IV is
376
+ * `ngtcp2_crypto_packet_protection_ivlen(ctx->aead)
377
+ * <ngtcp2_crypto_packet_protection_ivlen>` where ctx is obtained by
378
+ * `ngtcp2_crypto_ctx_tls` (or `ngtcp2_crypto_ctx_tls_early` if
379
+ * |level| ==
380
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`).
381
+ *
382
+ * In the first call of this function, it calls
383
+ * `ngtcp2_conn_set_crypto_ctx` (or `ngtcp2_conn_set_early_crypto_ctx`
384
+ * if |level| ==
385
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
386
+ * set negotiated AEAD and message digest algorithm. After the
387
+ * successful call of this function, application can use
388
+ * `ngtcp2_conn_get_crypto_ctx2` (or
389
+ * `ngtcp2_conn_get_0rtt_crypto_ctx2` if |level| ==
390
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_0RTT`) to
391
+ * get :type:`ngtcp2_crypto_ctx`.
392
+ *
393
+ * If |conn| is initialized as server, and |level| is
394
+ * :enum:`ngtcp2_encryption_level.NGTCP2_ENCRYPTION_LEVEL_1RTT`, this
395
+ * function retrieves a remote QUIC transport parameters extension
396
+ * from an object obtained by `ngtcp2_conn_get_tls_native_handle2`,
397
+ * and sets it to |conn| by calling
398
+ * `ngtcp2_conn_decode_and_set_remote_transport_params`.
399
+ *
400
+ * This function returns 0 if it succeeds, or -1.
401
+ */
402
+ NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_tx_key(
403
+ ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp,
404
+ ngtcp2_encryption_level level, const uint8_t *secret, size_t secretlen);
405
+
406
+ /**
407
+ * @function
408
+ *
409
+ * `ngtcp2_crypto_update_key` updates traffic keying materials.
410
+ *
411
+ * The new decryption traffic secret is written to the buffer pointed
412
+ * by |rx_secret|. The length of secret is |secretlen| bytes, and
413
+ * |rx_secret| must point to the buffer which has enough capacity.
414
+ *
415
+ * The new encryption traffic secret is written to the buffer pointed
416
+ * by |tx_secret|. The length of secret is |secretlen| bytes, and
417
+ * |tx_secret| must point to the buffer which has enough capacity.
418
+ *
419
+ * The derived decryption packet protection key is written to the
420
+ * buffer pointed by |rx_key|. The derived decryption packet
421
+ * protection IV is written to the buffer pointed by |rx_iv|.
422
+ * |rx_aead_ctx| is initialized with the derived key and IV.
423
+ *
424
+ * The derived encryption packet protection key is written to the
425
+ * buffer pointed by |tx_key|. The derived encryption packet
426
+ * protection IV is written to the buffer pointed by |tx_iv|.
427
+ * |tx_aead_ctx| is initialized with the derived key and IV.
428
+ *
429
+ * |current_rx_secret| and |current_tx_secret| are the current
430
+ * decryption and encryption traffic secrets respectively. They share
431
+ * the same length with |rx_secret| and |tx_secret|.
432
+ *
433
+ * The length of packet protection key and header protection key is
434
+ * `ngtcp2_crypto_aead_keylen(ctx->aead) <ngtcp2_crypto_aead_keylen>`,
435
+ * and the length of packet protection IV is
436
+ * `ngtcp2_crypto_packet_protection_ivlen(ctx->aead)
437
+ * <ngtcp2_crypto_packet_protection_ivlen>` where ctx is obtained by
438
+ * `ngtcp2_crypto_ctx_tls`.
439
+ *
440
+ * This function returns 0 if it succeeds, or -1.
441
+ */
442
+ NGTCP2_EXTERN int ngtcp2_crypto_update_key(
443
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
444
+ ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_key, uint8_t *rx_iv,
445
+ ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_key, uint8_t *tx_iv,
446
+ const uint8_t *current_rx_secret, const uint8_t *current_tx_secret,
447
+ size_t secretlen);
448
+
449
+ /**
450
+ * @function
451
+ *
452
+ * `ngtcp2_crypto_update_key_cb` is a wrapper function around
453
+ * `ngtcp2_crypto_update_key`. It can be directly passed to
454
+ * :member:`ngtcp2_callbacks.update_key` field.
455
+ *
456
+ * This function returns 0 if it succeeds, or
457
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
458
+ */
459
+ NGTCP2_EXTERN int ngtcp2_crypto_update_key_cb(
460
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
461
+ ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_iv,
462
+ ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_iv,
463
+ const uint8_t *current_rx_secret, const uint8_t *current_tx_secret,
464
+ size_t secretlen, void *user_data);
465
+
466
+ /**
467
+ * @function
468
+ *
469
+ * `ngtcp2_crypto_client_initial_cb` installs initial secrets and
470
+ * encryption keys, and sets QUIC transport parameters.
471
+ *
472
+ * This function can be directly passed to
473
+ * :member:`ngtcp2_callbacks.client_initial` field. It is only used
474
+ * by client.
475
+ *
476
+ * This function returns 0 if it succeeds, or
477
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
478
+ */
479
+ NGTCP2_EXTERN int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn,
480
+ void *user_data);
481
+
482
+ /**
483
+ * @function
484
+ *
485
+ * `ngtcp2_crypto_recv_retry_cb` re-installs initial secrets in
486
+ * response to incoming Retry packet.
487
+ *
488
+ * This function can be directly passed to
489
+ * :member:`ngtcp2_callbacks.recv_retry` field. It is only used by
490
+ * client.
491
+ *
492
+ * This function returns 0 if it succeeds, or
493
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
494
+ */
495
+ NGTCP2_EXTERN int ngtcp2_crypto_recv_retry_cb(ngtcp2_conn *conn,
496
+ const ngtcp2_pkt_hd *hd,
497
+ void *user_data);
498
+
499
+ /**
500
+ * @function
501
+ *
502
+ * `ngtcp2_crypto_recv_client_initial_cb` installs initial secrets in
503
+ * response to an incoming Initial packet from client, and sets QUIC
504
+ * transport parameters.
505
+ *
506
+ * This function can be directly passed to
507
+ * :member:`ngtcp2_callbacks.recv_client_initial` field. It is only
508
+ * used by server.
509
+ *
510
+ * This function returns 0 if it succeeds, or
511
+ * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`.
512
+ */
513
+ NGTCP2_EXTERN int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn,
514
+ const ngtcp2_cid *dcid,
515
+ void *user_data);
516
+
517
+ /**
518
+ * @function
519
+ *
520
+ * `ngtcp2_crypto_read_write_crypto_data` reads CRYPTO data |data| of
521
+ * length |datalen| in an encryption level |encryption_level|, and may
522
+ * feed outgoing CRYPTO data to |conn|. This function can drive
523
+ * handshake. This function can be also used after handshake
524
+ * completes. It is allowed to call this function with |datalen| ==
525
+ * 0. In this case, no additional read operation is done.
526
+ *
527
+ * This function is implemented per TLS backend. See
528
+ * :ref:`tls-integration` for more details.
529
+ *
530
+ * This function returns 0 if it succeeds, or a negative error code.
531
+ * The generic error code is -1 if a specific error code is not
532
+ * suitable. The error codes less than -10000 are specific to
533
+ * underlying TLS implementation. Refer to the implementation
534
+ * specific header files for error codes.
535
+ */
536
+ NGTCP2_EXTERN int
537
+ ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
538
+ ngtcp2_encryption_level encryption_level,
539
+ const uint8_t *data, size_t datalen);
540
+
541
+ /**
542
+ * @function
543
+ *
544
+ * `ngtcp2_crypto_recv_crypto_data_cb` is a wrapper function around
545
+ * `ngtcp2_crypto_read_write_crypto_data`. It can be directly passed
546
+ * to :member:`ngtcp2_callbacks.recv_crypto_data` field.
547
+ *
548
+ * For quictls and OpenSSL, the following error codes are treated as
549
+ * success:
550
+ *
551
+ * - -10001 (e.g., :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP`)
552
+ * - -10002 (e.g., :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB`)
553
+ *
554
+ * To continue the interrupted handshake, call
555
+ * `ngtcp2_conn_continue_handshake`.
556
+ *
557
+ * See :ref:`tls-integration` for more details.
558
+ *
559
+ * If this function is used, the TLS implementation specific error
560
+ * codes described in `ngtcp2_crypto_read_write_crypto_data` are
561
+ * treated as if it returns -1 except for those that are listed above.
562
+ * Do not use this function if an application wishes to use the TLS
563
+ * implementation specific error codes.
564
+ */
565
+ NGTCP2_EXTERN int ngtcp2_crypto_recv_crypto_data_cb(
566
+ ngtcp2_conn *conn, ngtcp2_encryption_level encryption_level, uint64_t offset,
567
+ const uint8_t *data, size_t datalen, void *user_data);
568
+
569
+ /**
570
+ * @function
571
+ *
572
+ * `ngtcp2_crypto_generate_stateless_reset_token` generates a
573
+ * stateless reset token using HKDF extraction using the given |cid|
574
+ * and |secret| as input. The token will be written to the buffer
575
+ * pointed by |token|, and it must have a capacity of at least
576
+ * :macro:`NGTCP2_STATELESS_RESET_TOKENLEN` bytes.
577
+ *
578
+ * This function returns 0 if it succeeds, or -1.
579
+ */
580
+ NGTCP2_EXTERN int ngtcp2_crypto_generate_stateless_reset_token(
581
+ uint8_t *token, const uint8_t *secret, size_t secretlen,
582
+ const ngtcp2_cid *cid);
583
+
584
+ /**
585
+ * @macro
586
+ *
587
+ * :macro:`NGTCP2_CRYPTO_TOKEN_RAND_DATALEN` is the length of random
588
+ * data added to a token generated by
589
+ * `ngtcp2_crypto_generate_retry_token` or
590
+ * `ngtcp2_crypto_generate_regular_token`.
591
+ */
592
+ #define NGTCP2_CRYPTO_TOKEN_RAND_DATALEN 16
593
+
594
+ /**
595
+ * @macro
596
+ *
597
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY` is the magic byte for
598
+ * Retry token generated by `ngtcp2_crypto_generate_retry_token`.
599
+ */
600
+ #define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY 0xB6
601
+
602
+ /**
603
+ * @macro
604
+ *
605
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2` is the magic byte for
606
+ * Retry token generated by `ngtcp2_crypto_generate_retry_token2`.
607
+ */
608
+ #define NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2 0xB7
609
+
610
+ /**
611
+ * @macro
612
+ *
613
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR` is the magic byte for a
614
+ * token generated by `ngtcp2_crypto_generate_regular_token`.
615
+ */
616
+ #define NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR 0x36
617
+
618
+ /**
619
+ * @macro
620
+ *
621
+ * :macro:`NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN` is the maximum length of
622
+ * a token generated by `ngtcp2_crypto_generate_retry_token`.
623
+ */
624
+ #define NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN \
625
+ (/* magic = */ 1 + /* cid len = */ 1 + NGTCP2_MAX_CIDLEN + \
626
+ sizeof(ngtcp2_tstamp) + /* aead tag = */ 16 + \
627
+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN)
628
+
629
+ /**
630
+ * @macro
631
+ *
632
+ * :macro:`NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN2` is the maximum length of
633
+ * a token generated by `ngtcp2_crypto_generate_retry_token2`.
634
+ */
635
+ #define NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN2 \
636
+ (/* magic = */ 1 + sizeof(ngtcp2_sockaddr_union) + /* cid len = */ 1 + \
637
+ NGTCP2_MAX_CIDLEN + sizeof(ngtcp2_tstamp) + /* aead tag = */ 16 + \
638
+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN)
639
+
640
+ /**
641
+ * @macro
642
+ *
643
+ * :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN` is the maximum length
644
+ * of a token generated by `ngtcp2_crypto_generate_regular_token`.
645
+ * `ngtcp2_crypto_generate_regular_token2` generates a token of length
646
+ * at most :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN` bytes + the
647
+ * length of the provided opaque data.
648
+ */
649
+ #define NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN \
650
+ (/* magic = */ 1 + sizeof(ngtcp2_tstamp) + /* aead tag = */ 16 + \
651
+ NGTCP2_CRYPTO_TOKEN_RAND_DATALEN)
652
+
653
+ /**
654
+ * @function
655
+ *
656
+ * `ngtcp2_crypto_generate_retry_token` generates a token in the
657
+ * buffer pointed by |token| that is sent with Retry packet. The
658
+ * buffer pointed by |token| must have at least
659
+ * :macro:`NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN` bytes long. The
660
+ * successfully generated token starts with
661
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY`. |secret| of length
662
+ * |secretlen| is a keying material to generate keys to encrypt the
663
+ * token. |version| is QUIC version. |remote_addr| of length
664
+ * |remote_addrlen| is an address of client. |retry_scid| is a Source
665
+ * Connection ID chosen by server, and set in Retry packet. |odcid|
666
+ * is a Destination Connection ID in Initial packet sent by client.
667
+ * |ts| is the timestamp when the token is generated.
668
+ *
669
+ * See also `ngtcp2_crypto_generate_retry_token2`.
670
+ *
671
+ * This function returns the length of generated token if it succeeds,
672
+ * or -1.
673
+ */
674
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_retry_token(
675
+ uint8_t *token, const uint8_t *secret, size_t secretlen, uint32_t version,
676
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
677
+ const ngtcp2_cid *retry_scid, const ngtcp2_cid *odcid, ngtcp2_tstamp ts);
678
+
679
+ /**
680
+ * @function
681
+ *
682
+ * `ngtcp2_crypto_verify_retry_token` verifies Retry token stored in
683
+ * the buffer pointed by |token| of length |tokenlen|. |secret| of
684
+ * length |secretlen| is a keying material to generate keys to decrypt
685
+ * the token. |version| is QUIC version of the Initial packet that
686
+ * contains this token. |remote_addr| of length |remote_addrlen| is
687
+ * an address of client. |dcid| is a Destination Connection ID in
688
+ * Initial packet sent by client. |timeout| is the period during
689
+ * which the token is valid. |ts| is the current timestamp. When
690
+ * validation succeeds, the extracted Destination Connection ID (which
691
+ * is the Destination Connection ID in Initial packet sent by client
692
+ * that triggered Retry packet) is stored in the buffer pointed by
693
+ * |odcid|.
694
+ *
695
+ * This function returns 0 if it succeeds, or -1.
696
+ */
697
+ NGTCP2_EXTERN int ngtcp2_crypto_verify_retry_token(
698
+ ngtcp2_cid *odcid, const uint8_t *token, size_t tokenlen,
699
+ const uint8_t *secret, size_t secretlen, uint32_t version,
700
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
701
+ const ngtcp2_cid *dcid, ngtcp2_duration timeout, ngtcp2_tstamp ts);
702
+
703
+ /**
704
+ * @function
705
+ *
706
+ * `ngtcp2_crypto_generate_retry_token2` generates a token in the
707
+ * buffer pointed by |token| that is sent with Retry packet. The
708
+ * buffer pointed by |token| must have at least
709
+ * :macro:`NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN2` bytes long. The
710
+ * successfully generated token starts with
711
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY2`. |secret| of length
712
+ * |secretlen| is a keying material to generate keys to encrypt the
713
+ * token. |version| is QUIC version. |remote_addr| of length
714
+ * |remote_addrlen| is an address of client. |retry_scid| is a Source
715
+ * Connection ID chosen by server, and set in Retry packet. |odcid|
716
+ * is a Destination Connection ID in Initial packet sent by client.
717
+ * |ts| is the timestamp when the token is generated.
718
+ *
719
+ * Use this function instead of `ngtcp2_crypto_generate_retry_token`
720
+ * if more detailed error handling is required when verifying the
721
+ * token. `ngtcp2_crypto_verify_retry_token2` must be used to verify
722
+ * the token.
723
+ *
724
+ * This function returns the length of generated token if it succeeds,
725
+ * or -1.
726
+ */
727
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_retry_token2(
728
+ uint8_t *token, const uint8_t *secret, size_t secretlen, uint32_t version,
729
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
730
+ const ngtcp2_cid *retry_scid, const ngtcp2_cid *odcid, ngtcp2_tstamp ts);
731
+
732
+ /**
733
+ * @function
734
+ *
735
+ * `ngtcp2_crypto_verify_retry_token2` verifies Retry token stored in
736
+ * the buffer pointed by |token| of length |tokenlen|. |secret| of
737
+ * length |secretlen| is a keying material to generate keys to decrypt
738
+ * the token. |version| is QUIC version of the Initial packet that
739
+ * contains this token. |remote_addr| of length |remote_addrlen| is
740
+ * an address of client. |dcid| is a Destination Connection ID in
741
+ * Initial packet sent by client. |timeout| is the period during
742
+ * which the token is valid. |ts| is the current timestamp. When
743
+ * validation succeeds, the extracted Destination Connection ID (which
744
+ * is the Destination Connection ID in Initial packet sent by client
745
+ * that triggered Retry packet) is stored in the buffer pointed by
746
+ * |odcid|.
747
+ *
748
+ * The token must be generated by
749
+ * `ngtcp2_crypto_generate_retry_token2`.
750
+ *
751
+ * This function returns 0 if it succeeds, or one of the following
752
+ * negative error codes:
753
+ *
754
+ * :macro:`NGTCP2_CRYPTO_ERR_UNREADABLE_TOKEN`
755
+ * A token is badly formatted; or verifying the integrity
756
+ * protection failed.
757
+ * :macro:`NGTCP2_CRYPTO_ERR_VERIFY_TOKEN`
758
+ * A token does not probe the client address; or the token
759
+ * validity has expired; or it contains invalid Connection ID.
760
+ * :macro:`NGTCP2_CRYPTO_ERR_INTERNAL`
761
+ * Internal error occurred.
762
+ */
763
+ NGTCP2_EXTERN int ngtcp2_crypto_verify_retry_token2(
764
+ ngtcp2_cid *odcid, const uint8_t *token, size_t tokenlen,
765
+ const uint8_t *secret, size_t secretlen, uint32_t version,
766
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
767
+ const ngtcp2_cid *dcid, ngtcp2_duration timeout, ngtcp2_tstamp ts);
768
+
769
+ /**
770
+ * @function
771
+ *
772
+ * `ngtcp2_crypto_generate_regular_token` generates a token in the
773
+ * buffer pointed by |token| that is sent with NEW_TOKEN frame. The
774
+ * buffer pointed by |token| must have at least
775
+ * :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN` bytes long. The
776
+ * successfully generated token starts with
777
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR`. |secret| of length
778
+ * |secretlen| is a keying material to generate keys to encrypt the
779
+ * token. |remote_addr| of length |remote_addrlen| is an address of
780
+ * client. |ts| is the timestamp when the token is generated.
781
+ *
782
+ * This function returns the length of generated token if it succeeds,
783
+ * or -1.
784
+ */
785
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_regular_token(
786
+ uint8_t *token, const uint8_t *secret, size_t secretlen,
787
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
788
+ ngtcp2_tstamp ts);
789
+
790
+ /**
791
+ * @function
792
+ *
793
+ * `ngtcp2_crypto_verify_regular_token` verifies a regular token
794
+ * stored in the buffer pointed by |token| of length |tokenlen|.
795
+ * |secret| of length |secretlen| is a keying material to generate
796
+ * keys to decrypt the token. |remote_addr| of length
797
+ * |remote_addrlen| is an address of client. |timeout| is the period
798
+ * during which the token is valid. |ts| is the current timestamp.
799
+ *
800
+ * This function returns 0 if it succeeds, or -1.
801
+ */
802
+ NGTCP2_EXTERN int ngtcp2_crypto_verify_regular_token(
803
+ const uint8_t *token, size_t tokenlen, const uint8_t *secret,
804
+ size_t secretlen, const ngtcp2_sockaddr *remote_addr,
805
+ ngtcp2_socklen remote_addrlen, ngtcp2_duration timeout, ngtcp2_tstamp ts);
806
+
807
+ /**
808
+ * @function
809
+ *
810
+ * `ngtcp2_crypto_generate_regular_token2` generates a token in the
811
+ * buffer pointed by |token| that is sent with NEW_TOKEN frame. The
812
+ * buffer pointed by |token| must have at least
813
+ * :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN` + |datalen| bytes long.
814
+ * The successfully generated token starts with
815
+ * :macro:`NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR`. |secret| of length
816
+ * |secretlen| is a keying material to generate keys to encrypt the
817
+ * token. |remote_addr| of length |remote_addrlen| is an address of
818
+ * client. |ts| is the timestamp when the token is generated. |data|
819
+ * of length |datalen| is an opaque data embedded in the token.
820
+ * |datalen| must be less than or equal to 256.
821
+ *
822
+ * Calling this function with |datalen| = 0 is equivalent to calling
823
+ * `ngtcp2_crypto_generate_regular_token`.
824
+ *
825
+ * To get the opaque data after successful verification, use
826
+ * `ngtcp2_crypto_verify_regular_token2`.
827
+ * `ngtcp2_crypto_verify_regular_token` can verify the token with
828
+ * |datalen| > 0, but it discards the opaque data.
829
+ *
830
+ * This function returns the length of generated token if it succeeds,
831
+ * or -1.
832
+ */
833
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_generate_regular_token2(
834
+ uint8_t *token, const uint8_t *secret, size_t secretlen,
835
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
836
+ const void *data, size_t datalen, ngtcp2_tstamp ts);
837
+
838
+ /**
839
+ * @function
840
+ *
841
+ * `ngtcp2_crypto_verify_regular_token2` verifies a regular token
842
+ * stored in the buffer pointed by |token| of length |tokenlen|.
843
+ * |secret| of length |secretlen| is a keying material to generate
844
+ * keys to decrypt the token. |remote_addr| of length
845
+ * |remote_addrlen| is an address of client. |timeout| is the period
846
+ * during which the token is valid. |ts| is the current timestamp.
847
+ * |data| is the pointer to the buffer of length at least
848
+ * |max_datalen| bytes. If the token is verified successfully, the
849
+ * opaque data embedded in the token is copied to the buffer pointed
850
+ * by |data|.
851
+ *
852
+ * If |tokenlen| is less than
853
+ * :macro:`NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN`, this function returns
854
+ * :macro:`NGTCP2_CRYPTO_ERR_UNREADABLE_TOKEN`.
855
+ *
856
+ * If the length of opaque data is larger than |max_datalen|, the
857
+ * verification still succeeds, but nothing is written to the buffer
858
+ * pointed by |data|, and this function returns 0. In other words,
859
+ * the opaque data is discarded.
860
+ *
861
+ * This function returns the number of the opaque data written to the
862
+ * buffer pointed by |data| if it succeeds, or one of the following
863
+ * negative error codes:
864
+ *
865
+ * :macro:`NGTCP2_CRYPTO_ERR_UNREADABLE_TOKEN`
866
+ * A token is badly formatted; or verifying the integrity
867
+ * protection failed.
868
+ * :macro:`NGTCP2_CRYPTO_ERR_VERIFY_TOKEN`
869
+ * A token validity has expired.
870
+ * :macro:`NGTCP2_CRYPTO_ERR_INTERNAL`
871
+ * Internal error occurred.
872
+ */
873
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_verify_regular_token2(
874
+ void *data, size_t max_datalen, const uint8_t *token, size_t tokenlen,
875
+ const uint8_t *secret, size_t secretlen, const ngtcp2_sockaddr *remote_addr,
876
+ ngtcp2_socklen remote_addrlen, ngtcp2_duration timeout, ngtcp2_tstamp ts);
877
+
878
+ /**
879
+ * @function
880
+ *
881
+ * `ngtcp2_crypto_write_connection_close` writes Initial packet
882
+ * containing CONNECTION_CLOSE with the given |error_code| and the
883
+ * optional |reason| of length |reasonlen| to the buffer pointed by
884
+ * |dest| of length |destlen|. This function is designed for server
885
+ * to close connection without committing the state when validating
886
+ * Retry token fails. This function must not be used by client. The
887
+ * |dcid| must be the Source Connection ID in Initial packet from
888
+ * client. The |scid| must be the Destination Connection ID in
889
+ * Initial packet from client. |scid| is used to derive initial
890
+ * keying materials.
891
+ *
892
+ * This function wraps around `ngtcp2_pkt_write_connection_close` for
893
+ * easier use.
894
+ *
895
+ * This function returns 0 if it succeeds, or -1.
896
+ */
897
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_write_connection_close(
898
+ uint8_t *dest, size_t destlen, uint32_t version, const ngtcp2_cid *dcid,
899
+ const ngtcp2_cid *scid, uint64_t error_code, const uint8_t *reason,
900
+ size_t reasonlen);
901
+
902
+ /**
903
+ * @function
904
+ *
905
+ * `ngtcp2_crypto_write_retry` writes Retry packet to the buffer
906
+ * pointed by |dest| of length |destlen|. |dcid| is the Connection ID
907
+ * which appeared in a packet as a Source Connection ID sent by
908
+ * client. |scid| is a server chosen Source Connection ID. |odcid|
909
+ * specifies Original Destination Connection ID which appeared in a
910
+ * packet as a Destination Connection ID sent by client. |token|
911
+ * specifies Retry Token, and |tokenlen| specifies its length.
912
+ *
913
+ * This function wraps around `ngtcp2_pkt_write_retry` for easier use.
914
+ *
915
+ * This function returns 0 if it succeeds, or -1.
916
+ */
917
+ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_write_retry(
918
+ uint8_t *dest, size_t destlen, uint32_t version, const ngtcp2_cid *dcid,
919
+ const ngtcp2_cid *scid, const ngtcp2_cid *odcid, const uint8_t *token,
920
+ size_t tokenlen);
921
+
922
+ /**
923
+ * @function
924
+ *
925
+ * `ngtcp2_crypto_aead_ctx_encrypt_init` initializes |aead_ctx| with
926
+ * new AEAD cipher context object for encryption which is constructed
927
+ * to use |key| as encryption key. |aead| specifies AEAD cipher to
928
+ * use. |noncelen| is the length of nonce.
929
+ *
930
+ * This function returns 0 if it succeeds, or -1.
931
+ */
932
+ NGTCP2_EXTERN int
933
+ ngtcp2_crypto_aead_ctx_encrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx,
934
+ const ngtcp2_crypto_aead *aead,
935
+ const uint8_t *key, size_t noncelen);
936
+
937
+ /**
938
+ * @function
939
+ *
940
+ * `ngtcp2_crypto_aead_ctx_decrypt_init` initializes |aead_ctx| with
941
+ * new AEAD cipher context object for decryption which is constructed
942
+ * to use |key| as decryption key. |aead| specifies AEAD cipher to
943
+ * use. |noncelen| is the length of nonce.
944
+ *
945
+ * This function returns 0 if it succeeds, or -1.
946
+ */
947
+ NGTCP2_EXTERN int
948
+ ngtcp2_crypto_aead_ctx_decrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx,
949
+ const ngtcp2_crypto_aead *aead,
950
+ const uint8_t *key, size_t noncelen);
951
+
952
+ /**
953
+ * @function
954
+ *
955
+ * `ngtcp2_crypto_aead_ctx_free` frees up resources used by
956
+ * |aead_ctx|. This function does not free the memory pointed by
957
+ * |aead_ctx| itself.
958
+ */
959
+ NGTCP2_EXTERN void
960
+ ngtcp2_crypto_aead_ctx_free(ngtcp2_crypto_aead_ctx *aead_ctx);
961
+
962
+ /**
963
+ * @function
964
+ *
965
+ * `ngtcp2_crypto_delete_crypto_aead_ctx_cb` deletes the given
966
+ * |aead_ctx|.
967
+ *
968
+ * This function can be directly passed to
969
+ * :member:`ngtcp2_callbacks.delete_crypto_aead_ctx` field.
970
+ */
971
+ NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_aead_ctx_cb(
972
+ ngtcp2_conn *conn, ngtcp2_crypto_aead_ctx *aead_ctx, void *user_data);
973
+
974
+ /**
975
+ * @function
976
+ *
977
+ * `ngtcp2_crypto_delete_crypto_cipher_ctx_cb` deletes the given
978
+ * |cipher_ctx|.
979
+ *
980
+ * This function can be directly passed to
981
+ * :member:`ngtcp2_callbacks.delete_crypto_cipher_ctx` field.
982
+ */
983
+ NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_cipher_ctx_cb(
984
+ ngtcp2_conn *conn, ngtcp2_crypto_cipher_ctx *cipher_ctx, void *user_data);
985
+
986
+ /**
987
+ * @function
988
+ *
989
+ * .. warning::
990
+ *
991
+ * .. version-deprecated:: 1.22.0
992
+ * Use `ngtcp2_crypto_get_path_challenge_data2_cb` instead.
993
+ *
994
+ * `ngtcp2_crypto_get_path_challenge_data_cb` writes unpredictable
995
+ * sequence of :macro:`NGTCP2_PATH_CHALLENGE_DATALEN` bytes to |data|
996
+ * which is sent with PATH_CHALLENGE frame.
997
+ *
998
+ * This function can be directly passed to
999
+ * :member:`ngtcp2_callbacks.get_path_challenge_data` field.
1000
+ */
1001
+ NGTCP2_EXTERN int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn,
1002
+ uint8_t *data,
1003
+ void *user_data);
1004
+
1005
+ /**
1006
+ * @function
1007
+ *
1008
+ * `ngtcp2_crypto_get_path_challenge_data2_cb` writes unpredictable
1009
+ * sequence of :macro:`NGTCP2_PATH_CHALLENGE_DATALEN` bytes to |data|
1010
+ * which is sent with PATH_CHALLENGE frame.
1011
+ *
1012
+ * This function can be directly passed to
1013
+ * :member:`ngtcp2_callbacks.get_path_challenge_data2` field.
1014
+ *
1015
+ * .. version-added:: 1.22.0
1016
+ */
1017
+ NGTCP2_EXTERN int ngtcp2_crypto_get_path_challenge_data2_cb(
1018
+ ngtcp2_conn *conn, ngtcp2_path_challenge_data *data, void *user_data);
1019
+
1020
+ /**
1021
+ * @function
1022
+ *
1023
+ * `ngtcp2_crypto_version_negotiation_cb` installs Initial keys for
1024
+ * |version| which is negotiated or being negotiated. |client_dcid|
1025
+ * is the destination connection ID in first Initial packet from
1026
+ * client.
1027
+ *
1028
+ * This function can be directly passed to
1029
+ * :member:`ngtcp2_callbacks.version_negotiation` field.
1030
+ */
1031
+ NGTCP2_EXTERN int
1032
+ ngtcp2_crypto_version_negotiation_cb(ngtcp2_conn *conn, uint32_t version,
1033
+ const ngtcp2_cid *client_dcid,
1034
+ void *user_data);
1035
+
1036
+ typedef struct ngtcp2_crypto_conn_ref ngtcp2_crypto_conn_ref;
1037
+
1038
+ /**
1039
+ * @functypedef
1040
+ *
1041
+ * :type:`ngtcp2_crypto_get_conn` is a callback function to get a
1042
+ * pointer to :type:`ngtcp2_conn` from |conn_ref|. The implementation
1043
+ * must return non-NULL :type:`ngtcp2_conn` object.
1044
+ */
1045
+ typedef ngtcp2_conn *(*ngtcp2_crypto_get_conn)(
1046
+ ngtcp2_crypto_conn_ref *conn_ref);
1047
+
1048
+ /**
1049
+ * @struct
1050
+ *
1051
+ * :type:`ngtcp2_crypto_conn_ref` is a structure to get a pointer to
1052
+ * :type:`ngtcp2_conn`. It is meant to be set to TLS native handle as
1053
+ * an application specific data (e.g. SSL_set_app_data in quictls).
1054
+ */
1055
+ typedef struct ngtcp2_crypto_conn_ref {
1056
+ /**
1057
+ * :member:`get_conn` is a callback function to get a pointer to
1058
+ * :type:`ngtcp2_conn` object.
1059
+ */
1060
+ ngtcp2_crypto_get_conn get_conn;
1061
+ /**
1062
+ * :member:`user_data` is a pointer to arbitrary user data.
1063
+ */
1064
+ void *user_data;
1065
+ } ngtcp2_crypto_conn_ref;
1066
+
1067
+ #ifdef __cplusplus
1068
+ }
1069
+ #endif /* defined(__cplusplus) */
1070
+
1071
+ #endif /* !defined(NGTCP2_CRYPTO_H) */