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,99 @@
1
+ /* $OpenBSD: md5.h,v 1.25 2025/01/25 17:59:44 tb Exp $ */
2
+ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3
+ * All rights reserved.
4
+ *
5
+ * This package is an SSL implementation written
6
+ * by Eric Young (eay@cryptsoft.com).
7
+ * The implementation was written so as to conform with Netscapes SSL.
8
+ *
9
+ * This library is free for commercial and non-commercial use as long as
10
+ * the following conditions are aheared to. The following conditions
11
+ * apply to all code found in this distribution, be it the RC4, RSA,
12
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13
+ * included with this distribution is covered by the same copyright terms
14
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15
+ *
16
+ * Copyright remains Eric Young's, and as such any Copyright notices in
17
+ * the code are not to be removed.
18
+ * If this package is used in a product, Eric Young should be given attribution
19
+ * as the author of the parts of the library used.
20
+ * This can be in the form of a textual message at program startup or
21
+ * in documentation (online or textual) provided with the package.
22
+ *
23
+ * Redistribution and use in source and binary forms, with or without
24
+ * modification, are permitted provided that the following conditions
25
+ * are met:
26
+ * 1. Redistributions of source code must retain the copyright
27
+ * notice, this list of conditions and the following disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ * 3. All advertising materials mentioning features or use of this software
32
+ * must display the following acknowledgement:
33
+ * "This product includes cryptographic software written by
34
+ * Eric Young (eay@cryptsoft.com)"
35
+ * The word 'cryptographic' can be left out if the rouines from the library
36
+ * being used are not cryptographic related :-).
37
+ * 4. If you include any Windows specific code (or a derivative thereof) from
38
+ * the apps directory (application code) you must include an acknowledgement:
39
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40
+ *
41
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51
+ * SUCH DAMAGE.
52
+ *
53
+ * The licence and distribution terms for any publically available version or
54
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
55
+ * copied and put under another distribution licence
56
+ * [including the GNU Public Licence.]
57
+ */
58
+
59
+ #include <stddef.h>
60
+
61
+ #ifndef HEADER_MD5_H
62
+ #define HEADER_MD5_H
63
+
64
+ #include <openssl/opensslconf.h>
65
+
66
+ #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__OpenBSD__)
67
+ #define __bounded__(x, y, z)
68
+ #endif
69
+
70
+ #ifdef __cplusplus
71
+ extern "C" {
72
+ #endif
73
+
74
+ #define MD5_LONG unsigned int
75
+
76
+ #define MD5_CBLOCK 64
77
+ #define MD5_LBLOCK (MD5_CBLOCK/4)
78
+ #define MD5_DIGEST_LENGTH 16
79
+
80
+ typedef struct MD5state_st {
81
+ MD5_LONG A, B,C, D;
82
+ MD5_LONG Nl, Nh;
83
+ MD5_LONG data[MD5_LBLOCK];
84
+ unsigned int num;
85
+ } MD5_CTX;
86
+
87
+ int MD5_Init(MD5_CTX *c);
88
+ int MD5_Update(MD5_CTX *c, const void *data, size_t len)
89
+ __attribute__ ((__bounded__(__buffer__, 2, 3)));
90
+ int MD5_Final(unsigned char *md, MD5_CTX *c);
91
+ unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
92
+ __attribute__ ((__bounded__(__buffer__, 1, 2)))
93
+ __attribute__ ((__nonnull__(3)));
94
+ void MD5_Transform(MD5_CTX *c, const unsigned char *b);
95
+ #ifdef __cplusplus
96
+ }
97
+ #endif
98
+
99
+ #endif
@@ -0,0 +1,236 @@
1
+ /* $OpenBSD: mlkem.h,v 1.10 2026/01/16 18:28:04 tb Exp $ */
2
+ /*
3
+ * Copyright (c) 2025 Bob Beck <beck@obtuse.com>
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ #ifndef OPENSSL_HEADER_MLKEM_H
19
+ #define OPENSSL_HEADER_MLKEM_H
20
+
21
+ #include <sys/types.h>
22
+ #include <stdint.h>
23
+
24
+ #if defined(__cplusplus)
25
+ extern "C" {
26
+ #endif
27
+
28
+ /*
29
+ * ML-KEM constants
30
+ */
31
+
32
+ #define MLKEM768_RANK 3
33
+ #define MLKEM1024_RANK 4
34
+
35
+ /*
36
+ * ML-KEM keys
37
+ */
38
+
39
+ typedef struct MLKEM_private_key_st MLKEM_private_key;
40
+ typedef struct MLKEM_public_key_st MLKEM_public_key;
41
+
42
+ /*
43
+ * MLKEM_private_key_new allocates a new uninitialized ML-KEM private key for
44
+ * |rank|, which must be MLKEM768_RANK or MLKEM1024_RANK. It returns a pointer
45
+ * to an allocated structure suitable for holding a generated private key of the
46
+ * corresponding rank on success, NULL is returned on failure. The caller is
47
+ * responsible for deallocating the resulting key with |MLKEM_private_key_free|.
48
+ */
49
+ MLKEM_private_key *MLKEM_private_key_new(int rank);
50
+
51
+ /*
52
+ * MLKEM_private_key_free zeroes and frees all memory for |key| if |key| is
53
+ * non NULL. If |key| is NULL it does nothing and returns.
54
+ */
55
+ void MLKEM_private_key_free(MLKEM_private_key *key);
56
+
57
+ /*
58
+ * MLKEM_private_key_encoded_length the number of bytes used by the encoded form
59
+ * of |key|. This corresponds to the length of the buffer allocated for the
60
+ * encoded_public_key from |MLKEM_marshal_private_key|. Zero is returned if
61
+ * |key| is NULL or has an invalid rank.
62
+ */
63
+ size_t MLKEM_private_key_encoded_length(const MLKEM_private_key *key);
64
+
65
+ /*
66
+ * MLKEM_private_key_ciphertext_length returns the number of bytes of ciphertext
67
+ * required to decrypt a shared secret with |key| using |MLKEM_decap|. Zero is
68
+ * returned if |key| is NULL or has an invalid rank.
69
+ */
70
+ size_t MLKEM_private_key_ciphertext_length(const MLKEM_private_key *key);
71
+
72
+ /*
73
+ * MLKEM_public_key_new allocates a new uninitialized ML-KEM public key for
74
+ * |rank|, which must be MLKEM768_RANK or MLKEM1024_RANK. It returns a pointer
75
+ * to an allocated structure suitable for holding a generated public key of the
76
+ * corresponding rank on success, NULL is returned on failure. The caller is
77
+ * responsible for deallocating the resulting key with |MLKEM_public_key_free|.
78
+ */
79
+ MLKEM_public_key *MLKEM_public_key_new(int rank);
80
+
81
+ /*
82
+ * MLKEM_public_key_free zeros and deallocates all memory for |key| if |key| is
83
+ * non NULL. If |key| is NULL it does nothing and returns.
84
+ */
85
+ void MLKEM_public_key_free(MLKEM_public_key *key);
86
+
87
+ /*
88
+ * MLKEM_public_key_encoded_length the number of bytes used by the encoded form
89
+ * of |key|. This corresponds to the length of the buffer allocated for the
90
+ * encoded_public_key from |MLKEM_generate_key| or |MLKEM_marshal_public_key|.
91
+ * Zero is returned if |key| is NULL or has an invalid rank.
92
+ */
93
+ size_t MLKEM_public_key_encoded_length(const MLKEM_public_key *key);
94
+
95
+ /*
96
+ * MLKEM_public_key_cipertext_length returns the number of bytes produced as the
97
+ * ciphertext when encrypting a shared secret with |key| using |MLKEM_encap|.
98
+ * Zero is returned if |key| is NULL or has an invalid rank.
99
+ */
100
+ size_t MLKEM_public_key_ciphertext_length(const MLKEM_public_key *key);
101
+
102
+ /*
103
+ * ML-KEM operations
104
+ */
105
+
106
+ /*
107
+ * MLKEM_generate_key generates a random private/public key pair, initializing
108
+ * |private_key|. It returns one on success, and zero on failure or error.
109
+ * |private_key| must be a new uninitialized key. |*out_encoded_public_key| and
110
+ * |*out_optional_seed|, if provided, must have the value of NULL. On success, a
111
+ * pointer to the encoded public key of the correct size for |key| is returned
112
+ * in |out_encoded_public_key|, and the length in bytes of
113
+ * |*out_encoded_public_key| is returned in |out_encoded_public_key_len|. If
114
+ * |out_optional_seed| is not NULL, a pointer to the seed used to generate the
115
+ * private key is returned in |*out_optional_seed| and the length in bytes of
116
+ * the seed is returned in |*out_optional_seed_len|. The caller is responsible
117
+ * for freeing the values returned in |out_encoded_public_key|, and
118
+ * |out_optional_seed|.
119
+ *
120
+ * In the event a private key needs to be saved, The normal best practice is to
121
+ * save |out_optional_seed| as the private key, along with the ML-KEM rank value.
122
+ * An MLKEM_private_key of the correct rank can then be constructed using
123
+ * |MLKEM_private_key_from_seed|.
124
+ */
125
+ int MLKEM_generate_key(MLKEM_private_key *private_key,
126
+ uint8_t **out_encoded_public_key, size_t *out_encoded_public_key_len,
127
+ uint8_t **out_optional_seed, size_t *out_optional_seed_len);
128
+
129
+ /*
130
+ * MLKEM_private_key_from_seed derives a private key from a seed that was
131
+ * generated by |MLKEM_generate_key| initializing |private_key|. It returns one
132
+ * on success, and zero on failure or error. |private_key| must be a new
133
+ * uninitialized key. |seed_len| must be MLKEM_SEED_LENGTH.
134
+ *
135
+ * For |private_key| to match the key generated by |MLKEM_generate_key|,
136
+ * |private_key| must have been created with the same rank as used when generating
137
+ * the key.
138
+ */
139
+ int MLKEM_private_key_from_seed(MLKEM_private_key *private_key,
140
+ const uint8_t *seed, size_t seed_len);
141
+
142
+ /*
143
+ * MLKEM_public_from_private initializes |public_key| with the public key that
144
+ * corresponds to |private_key|. It returns one on success and zero on
145
+ * error. This is faster than parsing the output of |MLKEM_generate_key| if, for
146
+ * some reason, you need to encapsulate to a key that was just
147
+ * generated. |private key| must be a new uninitialized key, of the same rank as
148
+ * |public_key|.
149
+ */
150
+ int MLKEM_public_from_private(const MLKEM_private_key *private_key,
151
+ MLKEM_public_key *public_key);
152
+
153
+ /*
154
+ * MLKEM_encap encrypts a random shared secret for an initialized
155
+ * |public_key|. It returns one on success, and zero on failure or error. |*out
156
+ * ciphertext| and |*out_shared_secret| must have the value NULL. On success, a
157
+ * pointer to the ciphertext of the correct size for |key| is returned in
158
+ * |out_ciphertext|, the length in bytes of |*out_ciphertext| is returned in
159
+ * |*out_ciphertext_len|, a pointer to the random shared secret is returned in
160
+ * |out_shared_secret|, and the length in bytes of |*out_shared_secret| is
161
+ * returned in |*out_ciphtertext_len|. The caller is responsible for zeroing and
162
+ * freeing the values returned in |out_ciphertext| and |out_shared_secret|
163
+ */
164
+ int MLKEM_encap(const MLKEM_public_key *public_key,
165
+ uint8_t **out_ciphertext, size_t *out_ciphertext_len,
166
+ uint8_t **out_shared_secret, size_t *out_shared_secret_len);
167
+
168
+ /*
169
+ * MLKEM_decap decrypts a shared secret from |ciphertext| using an initialized
170
+ * |private_key|. It returns a pointer to the shared secret|out_shared_secret|
171
+ * and the length in bytes of |*out_shared_secret| in |*out_shared_secret_len|.
172
+ *
173
+ * If |ciphertext_len| is incorrect for |private_key|, |*out_shared_secret| is
174
+ * not NULL, or memory can not be allocated, it returns zero, otherwise it
175
+ * returns one. If |ciphertext| is invalid, a pointer is returned in
176
+ * |out_shared_secret| pointing to a key that will always be the same for the
177
+ * same |ciphertext| and |private_key|, but which appears to be random unless
178
+ * one has access to |private_key|. These alternatives occur in constant time.
179
+ * Any subsequent symmetric encryption using |out_shared_secret| must use an
180
+ * authenticated encryption scheme in order to discover the decapsulation
181
+ * failure. The caller is responsible for zeroing and freeing the value returned
182
+ * in |out_shared_secret|.
183
+ */
184
+ int MLKEM_decap(const MLKEM_private_key *private_key,
185
+ const uint8_t *ciphertext, size_t ciphertext_len,
186
+ uint8_t **out_shared_secret, size_t *out_shared_secret_len);
187
+
188
+ /* Serialization of ML-KEM keys. */
189
+
190
+ /*
191
+ * MLKEM_marshal_public_key serializes an initialized |public_key| in the
192
+ * standard format for ML-KEM public keys. It returns one on success or zero on
193
+ * allocation error or failure. |*out| must have the value NULL. On success a
194
+ * pointer is returned in |out| to the encoded public key matching |public_key|,
195
+ * and a pointer to the length in bytes of the encoded public key is stored in
196
+ * |out_len|. The caller is responsible for freeing the values returned in
197
+ * |out|.
198
+ */
199
+ int MLKEM_marshal_public_key(const MLKEM_public_key *public_key, uint8_t **out,
200
+ size_t *out_len);
201
+
202
+ /*
203
+ * MLKEM_parse_public_key parses a public key, in the format generated by
204
+ * |MLKEM_marshal_public_key|, from |in|. It returns one on success or zero on
205
+ * error or failure. |public_key| must be a new uninitialized key. |in_len| must
206
+ * be the correct length for the encoded format of |public_key. On success
207
+ * |public_key| is initialized to the value parsed from |in|.
208
+ */
209
+ int MLKEM_parse_public_key(MLKEM_public_key *public_key, const uint8_t *in,
210
+ size_t in_len);
211
+
212
+ /*
213
+ * Marshals a private key to encoded format, used for NIST tests.
214
+ */
215
+ int MLKEM_marshal_private_key(const MLKEM_private_key *private_key,
216
+ uint8_t **out, size_t *out_len);
217
+
218
+ /*
219
+ * MLKEM_parse_private_key parses a private key, in the format generated by
220
+ * |MLKEM_marshal_private_key|, from |in|. It returns one on success or zero on
221
+ * error or failure. |private_key| must be a new uninitialized key. |in_len|
222
+ * must be the correct length for the encoded format of |private_key. On success
223
+ * |private_key| is initialized to the value parsed from |in|.
224
+ *
225
+ * This format is wastefully verbose and should be avoided. Private keys should
226
+ * be stored as seeds from |MLKEM_generate_key|, and then parsed using
227
+ * |MLKEM_private_key_from_seed|.
228
+ */
229
+ int MLKEM_parse_private_key(MLKEM_private_key *private_key, const uint8_t *in,
230
+ size_t in_len);
231
+
232
+ #if defined(__cplusplus)
233
+ }
234
+ #endif
235
+
236
+ #endif /* OPENSSL_HEADER_MLKEM_H */
@@ -0,0 +1,118 @@
1
+ /* $OpenBSD: modes.h,v 1.6 2023/07/08 14:55:36 beck Exp $ */
2
+ /* ====================================================================
3
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
4
+ *
5
+ * Rights for redistribution and usage in source and binary
6
+ * forms are granted according to the OpenSSL license.
7
+ */
8
+
9
+ #include <stddef.h>
10
+
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
15
+ typedef void (*block128_f)(const unsigned char in[16],
16
+ unsigned char out[16],
17
+ const void *key);
18
+
19
+ typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out,
20
+ size_t len, const void *key,
21
+ unsigned char ivec[16], int enc);
22
+
23
+ typedef void (*ctr128_f)(const unsigned char *in, unsigned char *out,
24
+ size_t blocks, const void *key,
25
+ const unsigned char ivec[16]);
26
+
27
+ typedef void (*ccm128_f)(const unsigned char *in, unsigned char *out,
28
+ size_t blocks, const void *key,
29
+ const unsigned char ivec[16], unsigned char cmac[16]);
30
+
31
+ void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
32
+ size_t len, const void *key,
33
+ unsigned char ivec[16], block128_f block);
34
+ void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
35
+ size_t len, const void *key,
36
+ unsigned char ivec[16], block128_f block);
37
+
38
+ void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
39
+ size_t len, const void *key,
40
+ unsigned char ivec[16], unsigned char ecount_buf[16],
41
+ unsigned int *num, block128_f block);
42
+
43
+ void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
44
+ size_t len, const void *key,
45
+ unsigned char ivec[16], unsigned char ecount_buf[16],
46
+ unsigned int *num, ctr128_f ctr);
47
+
48
+ void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
49
+ size_t len, const void *key,
50
+ unsigned char ivec[16], int *num,
51
+ block128_f block);
52
+
53
+ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
54
+ size_t len, const void *key,
55
+ unsigned char ivec[16], int *num,
56
+ int enc, block128_f block);
57
+ void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
58
+ size_t length, const void *key,
59
+ unsigned char ivec[16], int *num,
60
+ int enc, block128_f block);
61
+ void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
62
+ size_t bits, const void *key,
63
+ unsigned char ivec[16], int *num,
64
+ int enc, block128_f block);
65
+
66
+ typedef struct gcm128_context GCM128_CONTEXT;
67
+
68
+ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
69
+ void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
70
+ void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
71
+ size_t len);
72
+ int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
73
+ size_t len);
74
+ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
75
+ const unsigned char *in, unsigned char *out,
76
+ size_t len);
77
+ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
78
+ const unsigned char *in, unsigned char *out,
79
+ size_t len);
80
+ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
81
+ const unsigned char *in, unsigned char *out,
82
+ size_t len, ctr128_f stream);
83
+ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
84
+ const unsigned char *in, unsigned char *out,
85
+ size_t len, ctr128_f stream);
86
+ int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,
87
+ size_t len);
88
+ void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
89
+ void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
90
+
91
+ typedef struct ccm128_context CCM128_CONTEXT;
92
+
93
+ void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx,
94
+ unsigned int M, unsigned int L, void *key, block128_f block);
95
+ int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx,
96
+ const unsigned char *nonce, size_t nlen, size_t mlen);
97
+ void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx,
98
+ const unsigned char *aad, size_t alen);
99
+ int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx,
100
+ const unsigned char *inp, unsigned char *out, size_t len);
101
+ int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx,
102
+ const unsigned char *inp, unsigned char *out, size_t len);
103
+ int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx,
104
+ const unsigned char *inp, unsigned char *out, size_t len,
105
+ ccm128_f stream);
106
+ int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx,
107
+ const unsigned char *inp, unsigned char *out, size_t len,
108
+ ccm128_f stream);
109
+ size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
110
+
111
+ typedef struct xts128_context XTS128_CONTEXT;
112
+
113
+ int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
114
+ const unsigned char *inp, unsigned char *out, size_t len, int enc);
115
+
116
+ #ifdef __cplusplus
117
+ }
118
+ #endif