kychacha_gem 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 28626174e9e96beb3f0eb45a42fddec45bd5bad0c6d901d20df1ce41f6555c03
4
+ data.tar.gz: b49a0dbd56886f941c854753173a86db259ea2e00e30b8c6dc5a83490f31b165
5
+ SHA512:
6
+ metadata.gz: f306c2fd23c96f0586600c5e06128d7aafa921448f5a78414cdfdd04480d1abca6add3f176bd559137f42460cf18278dd7d6a2c80654ef39c82ad9637575fed5
7
+ data.tar.gz: bac35a60f395f6c7ccbec1d21e3040a866675425136a6cefbb0c60395dc674c71d9ca1b32ba7ac3007d1c951203cc05d2479f2564010ef0e107be9b485df055d
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle" />
12
+ </content>
13
+ <orderEntry type="jdk" jdkName="ruby-3.4.3-p32 (2)" jdkType="RUBY_SDK" />
14
+ <orderEntry type="sourceFolder" forTests="false" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.8, ruby-3.4.3-p32 (2)) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.1, ruby-3.4.3-p32 (2)) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="irb (v1.14.3, ruby-3.4.3-p32 (2)) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.2.1, ruby-3.4.3-p32 (2)) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.0, ruby-3.4.3-p32 (2)) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.3, ruby-3.4.3-p32 (2)) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.4, ruby-3.4.3-p32 (2)) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.4, ruby-3.4.3-p32 (2)) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.3, ruby-3.4.3-p32 (2)) [gem]" level="application" />
24
+ </component>
25
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-3.4.3-p32" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-05-09
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Cargo.lock ADDED
@@ -0,0 +1,660 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aead"
7
+ version = "0.5.2"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
10
+ dependencies = [
11
+ "crypto-common",
12
+ "generic-array",
13
+ ]
14
+
15
+ [[package]]
16
+ name = "anyhow"
17
+ version = "1.0.98"
18
+ source = "registry+https://github.com/rust-lang/crates.io-index"
19
+ checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
20
+
21
+ [[package]]
22
+ name = "autocfg"
23
+ version = "1.4.0"
24
+ source = "registry+https://github.com/rust-lang/crates.io-index"
25
+ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
26
+
27
+ [[package]]
28
+ name = "bincode"
29
+ version = "2.0.1"
30
+ source = "registry+https://github.com/rust-lang/crates.io-index"
31
+ checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
32
+ dependencies = [
33
+ "bincode_derive",
34
+ "serde",
35
+ "unty",
36
+ ]
37
+
38
+ [[package]]
39
+ name = "bincode_derive"
40
+ version = "2.0.1"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
43
+ dependencies = [
44
+ "virtue",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "bitflags"
49
+ version = "2.9.0"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
52
+
53
+ [[package]]
54
+ name = "block-buffer"
55
+ version = "0.10.4"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
58
+ dependencies = [
59
+ "generic-array",
60
+ ]
61
+
62
+ [[package]]
63
+ name = "cfg-if"
64
+ version = "1.0.0"
65
+ source = "registry+https://github.com/rust-lang/crates.io-index"
66
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
67
+
68
+ [[package]]
69
+ name = "chacha20"
70
+ version = "0.9.1"
71
+ source = "registry+https://github.com/rust-lang/crates.io-index"
72
+ checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
73
+ dependencies = [
74
+ "cfg-if",
75
+ "cipher",
76
+ "cpufeatures",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "chacha20poly1305"
81
+ version = "0.10.1"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35"
84
+ dependencies = [
85
+ "aead",
86
+ "chacha20",
87
+ "cipher",
88
+ "poly1305",
89
+ "zeroize",
90
+ ]
91
+
92
+ [[package]]
93
+ name = "cipher"
94
+ version = "0.4.4"
95
+ source = "registry+https://github.com/rust-lang/crates.io-index"
96
+ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
97
+ dependencies = [
98
+ "crypto-common",
99
+ "inout",
100
+ "zeroize",
101
+ ]
102
+
103
+ [[package]]
104
+ name = "cpufeatures"
105
+ version = "0.2.17"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
108
+ dependencies = [
109
+ "libc",
110
+ ]
111
+
112
+ [[package]]
113
+ name = "crypto-common"
114
+ version = "0.1.6"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
117
+ dependencies = [
118
+ "generic-array",
119
+ "rand_core 0.6.4",
120
+ "typenum",
121
+ ]
122
+
123
+ [[package]]
124
+ name = "digest"
125
+ version = "0.10.7"
126
+ source = "registry+https://github.com/rust-lang/crates.io-index"
127
+ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
128
+ dependencies = [
129
+ "block-buffer",
130
+ "crypto-common",
131
+ "subtle",
132
+ ]
133
+
134
+ [[package]]
135
+ name = "generic-array"
136
+ version = "0.14.7"
137
+ source = "registry+https://github.com/rust-lang/crates.io-index"
138
+ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
139
+ dependencies = [
140
+ "typenum",
141
+ "version_check",
142
+ ]
143
+
144
+ [[package]]
145
+ name = "getrandom"
146
+ version = "0.2.16"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
149
+ dependencies = [
150
+ "cfg-if",
151
+ "libc",
152
+ "wasi 0.11.0+wasi-snapshot-preview1",
153
+ ]
154
+
155
+ [[package]]
156
+ name = "getrandom"
157
+ version = "0.3.3"
158
+ source = "registry+https://github.com/rust-lang/crates.io-index"
159
+ checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
160
+ dependencies = [
161
+ "cfg-if",
162
+ "libc",
163
+ "r-efi",
164
+ "wasi 0.14.2+wasi-0.2.4",
165
+ ]
166
+
167
+ [[package]]
168
+ name = "hax-lib"
169
+ version = "0.2.0"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "61933dbb676f11311378720e1ee97a511813edb7044255381ba0d625cac6be7b"
172
+ dependencies = [
173
+ "hax-lib-macros",
174
+ "num-bigint",
175
+ "num-traits",
176
+ ]
177
+
178
+ [[package]]
179
+ name = "hax-lib-macros"
180
+ version = "0.2.0"
181
+ source = "registry+https://github.com/rust-lang/crates.io-index"
182
+ checksum = "7ba3a8d32921c3f535e973f72053d20bc8c7f74028911a269748440952157807"
183
+ dependencies = [
184
+ "hax-lib-macros-types",
185
+ "paste",
186
+ "proc-macro-error",
187
+ "proc-macro2",
188
+ "quote",
189
+ "syn 2.0.101",
190
+ ]
191
+
192
+ [[package]]
193
+ name = "hax-lib-macros-types"
194
+ version = "0.2.0"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "d5a22f64cb35f8363892df6285e7edbe96885cd660d85bfd6765c95886647b77"
197
+ dependencies = [
198
+ "proc-macro2",
199
+ "quote",
200
+ "serde",
201
+ "serde_json",
202
+ "uuid",
203
+ ]
204
+
205
+ [[package]]
206
+ name = "hex"
207
+ version = "0.4.3"
208
+ source = "registry+https://github.com/rust-lang/crates.io-index"
209
+ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
210
+
211
+ [[package]]
212
+ name = "hkdf"
213
+ version = "0.12.4"
214
+ source = "registry+https://github.com/rust-lang/crates.io-index"
215
+ checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
216
+ dependencies = [
217
+ "hmac",
218
+ ]
219
+
220
+ [[package]]
221
+ name = "hmac"
222
+ version = "0.12.1"
223
+ source = "registry+https://github.com/rust-lang/crates.io-index"
224
+ checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
225
+ dependencies = [
226
+ "digest",
227
+ ]
228
+
229
+ [[package]]
230
+ name = "inout"
231
+ version = "0.1.4"
232
+ source = "registry+https://github.com/rust-lang/crates.io-index"
233
+ checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
234
+ dependencies = [
235
+ "generic-array",
236
+ ]
237
+
238
+ [[package]]
239
+ name = "itoa"
240
+ version = "1.0.15"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
243
+
244
+ [[package]]
245
+ name = "kychacha_crypto"
246
+ version = "3.1.0"
247
+ source = "registry+https://github.com/rust-lang/crates.io-index"
248
+ checksum = "c210f2450a6b62a42e2e2792309acc39a99b5e6ffd0de8e7927cfe2ddc9f67c3"
249
+ dependencies = [
250
+ "anyhow",
251
+ "bincode",
252
+ "chacha20poly1305",
253
+ "hkdf",
254
+ "libcrux-ml-kem",
255
+ "rand_chacha",
256
+ "serde",
257
+ "serde_bytes",
258
+ "sha2",
259
+ "zerocopy",
260
+ ]
261
+
262
+ [[package]]
263
+ name = "libc"
264
+ version = "0.2.172"
265
+ source = "registry+https://github.com/rust-lang/crates.io-index"
266
+ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
267
+
268
+ [[package]]
269
+ name = "libcrux-intrinsics"
270
+ version = "0.0.2"
271
+ source = "registry+https://github.com/rust-lang/crates.io-index"
272
+ checksum = "f4f764ef781467a75b92f4df575911f1cdcf77a7beb316d8054a233fed53a7ab"
273
+ dependencies = [
274
+ "hax-lib",
275
+ ]
276
+
277
+ [[package]]
278
+ name = "libcrux-ml-kem"
279
+ version = "0.0.2"
280
+ source = "registry+https://github.com/rust-lang/crates.io-index"
281
+ checksum = "34075e62474b4531bd02647a59190b9d4982b5ecca5d9775fc3d35dd70d9cff1"
282
+ dependencies = [
283
+ "hax-lib",
284
+ "libcrux-intrinsics",
285
+ "libcrux-platform",
286
+ "libcrux-sha3",
287
+ "rand",
288
+ ]
289
+
290
+ [[package]]
291
+ name = "libcrux-platform"
292
+ version = "0.0.2"
293
+ source = "registry+https://github.com/rust-lang/crates.io-index"
294
+ checksum = "db82d058aa76ea315a3b2092f69dfbd67ddb0e462038a206e1dcd73f058c0778"
295
+ dependencies = [
296
+ "libc",
297
+ ]
298
+
299
+ [[package]]
300
+ name = "libcrux-sha3"
301
+ version = "0.0.2"
302
+ source = "registry+https://github.com/rust-lang/crates.io-index"
303
+ checksum = "3678ede46c5b5e7d5c0035065f8b9575fb67b6df405a88778ddb89cfb71d8fed"
304
+ dependencies = [
305
+ "hax-lib",
306
+ "libcrux-intrinsics",
307
+ "libcrux-platform",
308
+ ]
309
+
310
+ [[package]]
311
+ name = "log"
312
+ version = "0.4.27"
313
+ source = "registry+https://github.com/rust-lang/crates.io-index"
314
+ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
315
+
316
+ [[package]]
317
+ name = "memchr"
318
+ version = "2.7.4"
319
+ source = "registry+https://github.com/rust-lang/crates.io-index"
320
+ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
321
+
322
+ [[package]]
323
+ name = "num-bigint"
324
+ version = "0.4.6"
325
+ source = "registry+https://github.com/rust-lang/crates.io-index"
326
+ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
327
+ dependencies = [
328
+ "num-integer",
329
+ "num-traits",
330
+ ]
331
+
332
+ [[package]]
333
+ name = "num-integer"
334
+ version = "0.1.46"
335
+ source = "registry+https://github.com/rust-lang/crates.io-index"
336
+ checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
337
+ dependencies = [
338
+ "num-traits",
339
+ ]
340
+
341
+ [[package]]
342
+ name = "num-traits"
343
+ version = "0.2.19"
344
+ source = "registry+https://github.com/rust-lang/crates.io-index"
345
+ checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
346
+ dependencies = [
347
+ "autocfg",
348
+ ]
349
+
350
+ [[package]]
351
+ name = "opaque-debug"
352
+ version = "0.3.1"
353
+ source = "registry+https://github.com/rust-lang/crates.io-index"
354
+ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
355
+
356
+ [[package]]
357
+ name = "paste"
358
+ version = "1.0.15"
359
+ source = "registry+https://github.com/rust-lang/crates.io-index"
360
+ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
361
+
362
+ [[package]]
363
+ name = "poly1305"
364
+ version = "0.8.0"
365
+ source = "registry+https://github.com/rust-lang/crates.io-index"
366
+ checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
367
+ dependencies = [
368
+ "cpufeatures",
369
+ "opaque-debug",
370
+ "universal-hash",
371
+ ]
372
+
373
+ [[package]]
374
+ name = "ppv-lite86"
375
+ version = "0.2.21"
376
+ source = "registry+https://github.com/rust-lang/crates.io-index"
377
+ checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
378
+ dependencies = [
379
+ "zerocopy",
380
+ ]
381
+
382
+ [[package]]
383
+ name = "proc-macro-error"
384
+ version = "1.0.4"
385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
386
+ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
387
+ dependencies = [
388
+ "proc-macro-error-attr",
389
+ "proc-macro2",
390
+ "quote",
391
+ "syn 1.0.109",
392
+ "version_check",
393
+ ]
394
+
395
+ [[package]]
396
+ name = "proc-macro-error-attr"
397
+ version = "1.0.4"
398
+ source = "registry+https://github.com/rust-lang/crates.io-index"
399
+ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
400
+ dependencies = [
401
+ "proc-macro2",
402
+ "quote",
403
+ "version_check",
404
+ ]
405
+
406
+ [[package]]
407
+ name = "proc-macro2"
408
+ version = "1.0.95"
409
+ source = "registry+https://github.com/rust-lang/crates.io-index"
410
+ checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
411
+ dependencies = [
412
+ "unicode-ident",
413
+ ]
414
+
415
+ [[package]]
416
+ name = "quote"
417
+ version = "1.0.40"
418
+ source = "registry+https://github.com/rust-lang/crates.io-index"
419
+ checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
420
+ dependencies = [
421
+ "proc-macro2",
422
+ ]
423
+
424
+ [[package]]
425
+ name = "r-efi"
426
+ version = "5.2.0"
427
+ source = "registry+https://github.com/rust-lang/crates.io-index"
428
+ checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
429
+
430
+ [[package]]
431
+ name = "rand"
432
+ version = "0.9.1"
433
+ source = "registry+https://github.com/rust-lang/crates.io-index"
434
+ checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
435
+ dependencies = [
436
+ "rand_chacha",
437
+ "rand_core 0.9.3",
438
+ ]
439
+
440
+ [[package]]
441
+ name = "rand_chacha"
442
+ version = "0.9.0"
443
+ source = "registry+https://github.com/rust-lang/crates.io-index"
444
+ checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
445
+ dependencies = [
446
+ "ppv-lite86",
447
+ "rand_core 0.9.3",
448
+ ]
449
+
450
+ [[package]]
451
+ name = "rand_core"
452
+ version = "0.6.4"
453
+ source = "registry+https://github.com/rust-lang/crates.io-index"
454
+ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
455
+ dependencies = [
456
+ "getrandom 0.2.16",
457
+ ]
458
+
459
+ [[package]]
460
+ name = "rand_core"
461
+ version = "0.9.3"
462
+ source = "registry+https://github.com/rust-lang/crates.io-index"
463
+ checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
464
+ dependencies = [
465
+ "getrandom 0.3.3",
466
+ ]
467
+
468
+ [[package]]
469
+ name = "rs_kychacha_gem"
470
+ version = "0.1.0"
471
+ dependencies = [
472
+ "hex",
473
+ "kychacha_crypto",
474
+ "libc",
475
+ "log",
476
+ ]
477
+
478
+ [[package]]
479
+ name = "ryu"
480
+ version = "1.0.20"
481
+ source = "registry+https://github.com/rust-lang/crates.io-index"
482
+ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
483
+
484
+ [[package]]
485
+ name = "serde"
486
+ version = "1.0.219"
487
+ source = "registry+https://github.com/rust-lang/crates.io-index"
488
+ checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
489
+ dependencies = [
490
+ "serde_derive",
491
+ ]
492
+
493
+ [[package]]
494
+ name = "serde_bytes"
495
+ version = "0.11.17"
496
+ source = "registry+https://github.com/rust-lang/crates.io-index"
497
+ checksum = "8437fd221bde2d4ca316d61b90e337e9e702b3820b87d63caa9ba6c02bd06d96"
498
+ dependencies = [
499
+ "serde",
500
+ ]
501
+
502
+ [[package]]
503
+ name = "serde_derive"
504
+ version = "1.0.219"
505
+ source = "registry+https://github.com/rust-lang/crates.io-index"
506
+ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
507
+ dependencies = [
508
+ "proc-macro2",
509
+ "quote",
510
+ "syn 2.0.101",
511
+ ]
512
+
513
+ [[package]]
514
+ name = "serde_json"
515
+ version = "1.0.140"
516
+ source = "registry+https://github.com/rust-lang/crates.io-index"
517
+ checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
518
+ dependencies = [
519
+ "itoa",
520
+ "memchr",
521
+ "ryu",
522
+ "serde",
523
+ ]
524
+
525
+ [[package]]
526
+ name = "sha2"
527
+ version = "0.10.9"
528
+ source = "registry+https://github.com/rust-lang/crates.io-index"
529
+ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
530
+ dependencies = [
531
+ "cfg-if",
532
+ "cpufeatures",
533
+ "digest",
534
+ ]
535
+
536
+ [[package]]
537
+ name = "subtle"
538
+ version = "2.6.1"
539
+ source = "registry+https://github.com/rust-lang/crates.io-index"
540
+ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
541
+
542
+ [[package]]
543
+ name = "syn"
544
+ version = "1.0.109"
545
+ source = "registry+https://github.com/rust-lang/crates.io-index"
546
+ checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
547
+ dependencies = [
548
+ "proc-macro2",
549
+ "unicode-ident",
550
+ ]
551
+
552
+ [[package]]
553
+ name = "syn"
554
+ version = "2.0.101"
555
+ source = "registry+https://github.com/rust-lang/crates.io-index"
556
+ checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
557
+ dependencies = [
558
+ "proc-macro2",
559
+ "quote",
560
+ "unicode-ident",
561
+ ]
562
+
563
+ [[package]]
564
+ name = "typenum"
565
+ version = "1.18.0"
566
+ source = "registry+https://github.com/rust-lang/crates.io-index"
567
+ checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
568
+
569
+ [[package]]
570
+ name = "unicode-ident"
571
+ version = "1.0.18"
572
+ source = "registry+https://github.com/rust-lang/crates.io-index"
573
+ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
574
+
575
+ [[package]]
576
+ name = "universal-hash"
577
+ version = "0.5.1"
578
+ source = "registry+https://github.com/rust-lang/crates.io-index"
579
+ checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
580
+ dependencies = [
581
+ "crypto-common",
582
+ "subtle",
583
+ ]
584
+
585
+ [[package]]
586
+ name = "unty"
587
+ version = "0.0.4"
588
+ source = "registry+https://github.com/rust-lang/crates.io-index"
589
+ checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
590
+
591
+ [[package]]
592
+ name = "uuid"
593
+ version = "1.16.0"
594
+ source = "registry+https://github.com/rust-lang/crates.io-index"
595
+ checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9"
596
+ dependencies = [
597
+ "getrandom 0.3.3",
598
+ ]
599
+
600
+ [[package]]
601
+ name = "version_check"
602
+ version = "0.9.5"
603
+ source = "registry+https://github.com/rust-lang/crates.io-index"
604
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
605
+
606
+ [[package]]
607
+ name = "virtue"
608
+ version = "0.0.18"
609
+ source = "registry+https://github.com/rust-lang/crates.io-index"
610
+ checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
611
+
612
+ [[package]]
613
+ name = "wasi"
614
+ version = "0.11.0+wasi-snapshot-preview1"
615
+ source = "registry+https://github.com/rust-lang/crates.io-index"
616
+ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
617
+
618
+ [[package]]
619
+ name = "wasi"
620
+ version = "0.14.2+wasi-0.2.4"
621
+ source = "registry+https://github.com/rust-lang/crates.io-index"
622
+ checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
623
+ dependencies = [
624
+ "wit-bindgen-rt",
625
+ ]
626
+
627
+ [[package]]
628
+ name = "wit-bindgen-rt"
629
+ version = "0.39.0"
630
+ source = "registry+https://github.com/rust-lang/crates.io-index"
631
+ checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
632
+ dependencies = [
633
+ "bitflags",
634
+ ]
635
+
636
+ [[package]]
637
+ name = "zerocopy"
638
+ version = "0.8.25"
639
+ source = "registry+https://github.com/rust-lang/crates.io-index"
640
+ checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb"
641
+ dependencies = [
642
+ "zerocopy-derive",
643
+ ]
644
+
645
+ [[package]]
646
+ name = "zerocopy-derive"
647
+ version = "0.8.25"
648
+ source = "registry+https://github.com/rust-lang/crates.io-index"
649
+ checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef"
650
+ dependencies = [
651
+ "proc-macro2",
652
+ "quote",
653
+ "syn 2.0.101",
654
+ ]
655
+
656
+ [[package]]
657
+ name = "zeroize"
658
+ version = "1.8.1"
659
+ source = "registry+https://github.com/rust-lang/crates.io-index"
660
+ checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
data/Cargo.toml ADDED
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "rs_kychacha_gem"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+
9
+ [dependencies]
10
+ hex = "0.4.3"
11
+ kychacha_crypto = "3.1.0"
12
+ libc = "0.2.172"
13
+ log = "0.4.27"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Nicolás Rodríguez Álvarez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # KychachaGem
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kychacha_gem`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kychacha_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/kychacha_gem/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the KychachaGem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kychacha_gem/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rake/testtask"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
data/ext/extconf.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+
3
+ RUST_DIR = File.expand_path('../', __FILE__)
4
+
5
+ # Build the Rust library
6
+ puts "Building Rust library with cargo..."
7
+ Dir.chdir(RUST_DIR) do
8
+ system('cargo build --release') || raise("Failed to build Rust library")
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KychachaGem
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,73 @@
1
+ require_relative "kychacha_gem/version"
2
+ require 'ffi'
3
+
4
+ module KychachaGem
5
+ class Error < StandardError; end
6
+
7
+ class FFIBindings
8
+ extend FFI::Library
9
+ # Load rust library
10
+ ffi_lib File.expand_path("../target/release/librs_kychacha_gem.#{FFI::Platform::LIBSUFFIX}", __dir__)
11
+
12
+ # Declare extern functions
13
+ attach_function :generate_keypair, [], :pointer
14
+ attach_function :get_priv_key, [:pointer], :pointer
15
+ attach_function :get_pub_key, [:pointer], :pointer
16
+ attach_function :encrypt, [:string, :string], :pointer
17
+ attach_function :decrypt, [:string, :string], :pointer
18
+ attach_function :free_string, [:pointer], :void
19
+
20
+ private_class_method :new
21
+ end
22
+
23
+ # Create a custom memory pointer with automatic cleanup
24
+ class ManagedPointer < FFI::AutoPointer
25
+ def self.release(pointer)
26
+ FFIBindings.free_string(pointer) unless pointer.null?
27
+ end
28
+
29
+ def to_s
30
+ return "" if self.null?
31
+ self.read_string.force_encoding("UTF-8")
32
+ end
33
+ end
34
+
35
+ class KeyPair
36
+ def initialize(pointer)
37
+ @pointer = ManagedPointer.new(pointer)
38
+ end
39
+
40
+ def to_s
41
+ @pointer.to_s
42
+ end
43
+
44
+ def private_key
45
+ ptr = FFIBindings.get_priv_key(@pointer)
46
+ ManagedPointer.new(ptr)
47
+ end
48
+
49
+ def public_key
50
+ ptr = FFIBindings.get_pub_key(@pointer)
51
+ ManagedPointer.new(ptr)
52
+ end
53
+ end
54
+
55
+ def self.generate_keypair
56
+ ptr = FFIBindings.generate_keypair
57
+ KeyPair.new(ptr)
58
+ end
59
+
60
+ def self.encrypt(public_key, message)
61
+ key_str = public_key.to_s
62
+ msg_str = message.to_s
63
+ ptr = FFIBindings.encrypt(key_str, msg_str)
64
+ ManagedPointer.new(ptr)
65
+ end
66
+
67
+ def self.decrypt(private_key, encrypted_data)
68
+ key_str = private_key.to_s
69
+ enc_str = encrypted_data.to_s
70
+ ptr = FFIBindings.decrypt(key_str, enc_str)
71
+ ManagedPointer.new(ptr)
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ module KychachaGem
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/src/lib.rs ADDED
@@ -0,0 +1,164 @@
1
+ use std::ffi::{c_char, CStr, CString};
2
+ use kychacha_crypto::{bytes_to_public_key, bytes_to_secret_key, generate_keypair as kgk, public_key_to_bytes, secret_key_to_bytes, encrypt as kencrypt, decrypt as kdecript, MlKem768PublicKey, MlKem768PrivateKey};
3
+ use libc::CS;
4
+ use log::error;
5
+
6
+ #[unsafe(no_mangle)]
7
+ pub extern "C" fn generate_keypair() -> *mut c_char {
8
+ let keypair = kgk();
9
+ let hex = hex::encode([public_key_to_bytes(keypair.public_key()).as_ref(),secret_key_to_bytes(keypair.private_key()).as_ref()].concat());
10
+ CString::new(hex).unwrap_or_default().into_raw()
11
+ }
12
+
13
+ #[unsafe(no_mangle)]
14
+ pub extern "C" fn get_pub_key(keypair:*mut c_char) -> *mut c_char {
15
+ unsafe {
16
+ // Early returns for validation checks
17
+ if keypair.is_null() {
18
+ return error_msg("Error: Null pointer provided");
19
+ }
20
+
21
+ let hex_s = match CStr::from_ptr(keypair).to_str() {
22
+ Ok(s) => s,
23
+ Err(_) => return error_msg("Error: Invalid UTF-8 in keypair string"),
24
+ };
25
+
26
+ let comb = match hex::decode(hex_s) {
27
+ Ok(bytes) => bytes,
28
+ Err(_) => return error_msg("Error: Invalid hex format in keypair"),
29
+ };
30
+
31
+ if comb.len() <= 1184 {
32
+ return error_msg("Failed to reassemble keys: Invalid keypair");
33
+ }
34
+ match <&[u8; 1184]>::try_from(&comb[..1184]) {
35
+ Ok(pub_key_bytes) => CString::new(hex::encode(pub_key_bytes))
36
+ .unwrap_or_default()
37
+ .into_raw(),
38
+ Err(_) => error_msg("Error: Private key has incorrect length"),
39
+ }
40
+ }
41
+ }
42
+
43
+ #[unsafe(no_mangle)]
44
+ pub extern "C" fn get_priv_key(keypair: *mut c_char) -> *mut c_char {
45
+ unsafe {
46
+ // Early returns for validation checks
47
+ if keypair.is_null() {
48
+ return error_msg("Error: Null pointer provided");
49
+ }
50
+
51
+ // Chain operations with early return on errors
52
+ let hex_s = match CStr::from_ptr(keypair).to_str() {
53
+ Ok(s) => s,
54
+ Err(_) => return error_msg("Error: Invalid UTF-8 in keypair string"),
55
+ };
56
+
57
+ let comb = match hex::decode(hex_s) {
58
+ Ok(bytes) => bytes,
59
+ Err(_) => return error_msg("Error: Invalid hex format in keypair"),
60
+ };
61
+
62
+ if comb.len() <= 1184 {
63
+ return error_msg("Failed to reassemble keys: Invalid keypair");
64
+ }
65
+
66
+ match <&[u8; 2400]>::try_from(&comb[1184..]) {
67
+ Ok(priv_key_bytes) => CString::new(hex::encode(priv_key_bytes))
68
+ .unwrap_or_default()
69
+ .into_raw(),
70
+ Err(_) => error_msg("Error: Private key has incorrect length"),
71
+ }
72
+ }
73
+ }
74
+
75
+ #[unsafe(no_mangle)]
76
+ pub extern "C" fn encrypt(pubkey: *mut c_char, message: *mut c_char) -> *mut c_char {
77
+ unsafe {
78
+ // Check for null pointer
79
+ if pubkey.is_null() || message.is_null(){
80
+ return error_msg("Error: Null pointer provided");
81
+ }
82
+
83
+ let (hex_s, msg_s) = match (
84
+ CStr::from_ptr(pubkey).to_str(),
85
+ CStr::from_ptr(message).to_str()
86
+ ) {
87
+ (Ok(p), Ok(m)) => (p, m),
88
+ (Err(_), _) => return error_msg("Error: Invalid UTF-8 in pubkey string"),
89
+ (_, Err(_)) => return error_msg("Error: Invalid UTF-8 in message string")
90
+ };
91
+
92
+ let pubkey_bytes = match hex::decode(hex_s) {
93
+ Ok(p) => p,
94
+ Err(_) => return error_msg("Error: Failed to decode the message")
95
+ };
96
+
97
+ let pubkey_array: [u8; 1184] = match pubkey_bytes.try_into() {
98
+ Ok(a) => a,
99
+ Err(_) => return error_msg("Invalid public key format"),
100
+ };
101
+
102
+ let pubkey = match bytes_to_public_key(&pubkey_array) {
103
+ Ok(pk) => pk,
104
+ Err(_) => return error_msg("Failed to create public key from bytes"),
105
+ };
106
+
107
+ CString::new(hex::encode(kencrypt(&pubkey, msg_s.as_bytes()).unwrap())).unwrap_or_default().into_raw()
108
+ }
109
+ }
110
+
111
+ #[unsafe(no_mangle)]
112
+ pub extern "C" fn decrypt(cprivkey: *mut c_char,encrypted_data: *mut c_char) -> *mut c_char {
113
+ unsafe {
114
+ // Check for null pointer
115
+ if cprivkey.is_null() || encrypted_data.is_null(){
116
+ return error_msg("Error: Null pointer provided");
117
+ }
118
+ let (privatekey_cs,data_cs) = match (
119
+ CStr::from_ptr(cprivkey).to_str(),
120
+ CStr::from_ptr(encrypted_data).to_str()
121
+ ){
122
+ (Ok(p),Ok(ed)) => (p,ed),
123
+ (Err(_),_) => return error_msg("Error: Invalid UTF-8 in private key"),
124
+ (_,Err(_)) => return error_msg("Error: Invalid UTF-8 in encrypted data")
125
+ };
126
+
127
+ let (privatekey_bytes,data_vec) = match (
128
+ hex::decode(privatekey_cs),
129
+ hex::decode(data_cs)
130
+ ) {
131
+ (Ok(p),Ok(ed)) => (p,ed),
132
+ (Err(_),_) => return error_msg("Error: Invalid Hex in private key"),
133
+ (_,Err(_)) => return error_msg("Error: Invalid Hex in encrypted data")
134
+ };
135
+
136
+ let private_key_array: [u8; 2400] = match privatekey_bytes.try_into(){
137
+ Ok(pk) => pk,
138
+ Err(_) => return error_msg("Error while reconstructing the private key to a array")
139
+ };
140
+
141
+ let private_key: MlKem768PrivateKey = match bytes_to_secret_key(&private_key_array) {
142
+ Ok(pk) => pk,
143
+ Err(_) => return error_msg("Error: Invalid private key")
144
+ };
145
+
146
+ CString::new(kdecript(data_vec.as_slice(), &private_key).unwrap()).unwrap_or_default().into_raw()
147
+ }
148
+ }
149
+
150
+ fn error_msg(msg:&str) -> *mut c_char {
151
+ return CString::new(format!("*/üuüuüu/-/ {msg} /-/üuüuüu/*"))
152
+ .unwrap_or_default()
153
+ .into_raw();
154
+ }
155
+
156
+
157
+ #[unsafe(no_mangle)]
158
+ pub extern "C" fn free_string(ptr: *mut c_char) {
159
+ if !ptr.is_null() {
160
+ unsafe {
161
+ drop(CString::from_raw(ptr));
162
+ }
163
+ }
164
+ }
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kychacha_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - nichokas
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - nicolasralv@gmail.com
14
+ executables: []
15
+ extensions:
16
+ - ext/extconf.rb
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".idea/.gitignore"
20
+ - ".idea/kychacha_gem.iml"
21
+ - ".idea/misc.xml"
22
+ - ".idea/vcs.xml"
23
+ - ".rspec"
24
+ - CHANGELOG.md
25
+ - CODE_OF_CONDUCT.md
26
+ - Cargo.lock
27
+ - Cargo.toml
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - ext/extconf.rb
32
+ - lib/kychacha_gem.rb
33
+ - lib/kychacha_gem/version.rb
34
+ - sig/kychacha_gem.rbs
35
+ - src/lib.rs
36
+ homepage: https://github.com/Nichokas/kychacha_gem
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/Nichokas/kychacha_gem
41
+ source_code_uri: https://github.com/Nichokas/kychacha_gem
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.1.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.6.8
57
+ specification_version: 4
58
+ summary: Gem for using the kychacha_crypto post-quantum protocol (Kyber with ChaCha20)
59
+ from ruby
60
+ test_files: []