tangled
alpha
login
or
join now
sachy.dev
/
sachy-embed-core
0
fork
atom
Repo of no-std crates for my personal embedded projects
0
fork
atom
overview
issues
pulls
pipelines
Sachy's crypto scheme lmao
sachy.dev
2 days ago
0b6253d8
ee60e727
2/2
miri.yml
success
1m 32s
test.yml
success
1m 17s
+739
-59
4 changed files
expand all
collapse all
unified
split
Cargo.lock
Cargo.toml
sachy-crypto
Cargo.toml
src
lib.rs
+404
-59
Cargo.lock
···
18
18
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
19
19
20
20
[[package]]
21
21
+
name = "aead"
22
22
+
version = "0.6.0-rc.10"
23
23
+
source = "registry+https://github.com/rust-lang/crates.io-index"
24
24
+
checksum = "6b657e772794c6b04730ea897b66a058ccd866c16d1967da05eeeecec39043fe"
25
25
+
dependencies = [
26
26
+
"crypto-common 0.2.1",
27
27
+
"inout",
28
28
+
]
29
29
+
30
30
+
[[package]]
21
31
name = "aho-corasick"
22
32
version = "1.1.4"
23
33
source = "registry+https://github.com/rust-lang/crates.io-index"
···
63
73
]
64
74
65
75
[[package]]
76
76
+
name = "base16ct"
77
77
+
version = "1.0.0"
78
78
+
source = "registry+https://github.com/rust-lang/crates.io-index"
79
79
+
checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6"
80
80
+
81
81
+
[[package]]
66
82
name = "base64ct"
67
83
version = "1.8.3"
68
84
source = "registry+https://github.com/rust-lang/crates.io-index"
···
90
106
]
91
107
92
108
[[package]]
109
109
+
name = "block-buffer"
110
110
+
version = "0.12.0"
111
111
+
source = "registry+https://github.com/rust-lang/crates.io-index"
112
112
+
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
113
113
+
dependencies = [
114
114
+
"hybrid-array",
115
115
+
]
116
116
+
117
117
+
[[package]]
93
118
name = "byteorder"
94
119
version = "1.5.0"
95
120
source = "registry+https://github.com/rust-lang/crates.io-index"
···
112
137
113
138
[[package]]
114
139
name = "cc"
115
115
-
version = "1.2.56"
140
140
+
version = "1.2.57"
116
141
source = "registry+https://github.com/rust-lang/crates.io-index"
117
117
-
checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
142
142
+
checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423"
118
143
dependencies = [
119
144
"find-msvc-tools",
120
145
"shlex",
···
127
152
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
128
153
129
154
[[package]]
155
155
+
name = "chacha20"
156
156
+
version = "0.10.0"
157
157
+
source = "registry+https://github.com/rust-lang/crates.io-index"
158
158
+
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
159
159
+
dependencies = [
160
160
+
"cfg-if",
161
161
+
"cipher",
162
162
+
"cpufeatures 0.3.0",
163
163
+
]
164
164
+
165
165
+
[[package]]
166
166
+
name = "chacha20poly1305"
167
167
+
version = "0.11.0-rc.3"
168
168
+
source = "registry+https://github.com/rust-lang/crates.io-index"
169
169
+
checksum = "1c9ed179664f12fd6f155f6dd632edf5f3806d48c228c67ff78366f2a0eb6b5e"
170
170
+
dependencies = [
171
171
+
"aead",
172
172
+
"chacha20",
173
173
+
"cipher",
174
174
+
"poly1305",
175
175
+
]
176
176
+
177
177
+
[[package]]
178
178
+
name = "cipher"
179
179
+
version = "0.5.1"
180
180
+
source = "registry+https://github.com/rust-lang/crates.io-index"
181
181
+
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
182
182
+
dependencies = [
183
183
+
"block-buffer 0.12.0",
184
184
+
"crypto-common 0.2.1",
185
185
+
"inout",
186
186
+
]
187
187
+
188
188
+
[[package]]
189
189
+
name = "cmov"
190
190
+
version = "0.5.2"
191
191
+
source = "registry+https://github.com/rust-lang/crates.io-index"
192
192
+
checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3"
193
193
+
194
194
+
[[package]]
195
195
+
name = "const-oid"
196
196
+
version = "0.10.2"
197
197
+
source = "registry+https://github.com/rust-lang/crates.io-index"
198
198
+
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
199
199
+
200
200
+
[[package]]
130
201
name = "core-foundation"
131
202
version = "0.10.1"
132
203
source = "registry+https://github.com/rust-lang/crates.io-index"
···
143
214
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
144
215
145
216
[[package]]
217
217
+
name = "cpubits"
218
218
+
version = "0.1.0"
219
219
+
source = "registry+https://github.com/rust-lang/crates.io-index"
220
220
+
checksum = "5ef0c543070d296ea414df2dd7625d1b24866ce206709d8a4a424f28377f5861"
221
221
+
222
222
+
[[package]]
146
223
name = "cpufeatures"
147
224
version = "0.2.17"
148
225
source = "registry+https://github.com/rust-lang/crates.io-index"
···
152
229
]
153
230
154
231
[[package]]
232
232
+
name = "cpufeatures"
233
233
+
version = "0.3.0"
234
234
+
source = "registry+https://github.com/rust-lang/crates.io-index"
235
235
+
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
236
236
+
dependencies = [
237
237
+
"libc",
238
238
+
]
239
239
+
240
240
+
[[package]]
155
241
name = "critical-section"
156
242
version = "1.2.0"
157
243
source = "registry+https://github.com/rust-lang/crates.io-index"
158
244
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
159
245
160
246
[[package]]
247
247
+
name = "crypto-bigint"
248
248
+
version = "0.7.2"
249
249
+
source = "registry+https://github.com/rust-lang/crates.io-index"
250
250
+
checksum = "e9b6a7421484856c90cb2e996b91068d608539bb4e6f0a111b16d70678824d09"
251
251
+
dependencies = [
252
252
+
"cpubits",
253
253
+
"ctutils",
254
254
+
"getrandom",
255
255
+
"hybrid-array",
256
256
+
"num-traits",
257
257
+
"rand_core",
258
258
+
"subtle",
259
259
+
"zeroize",
260
260
+
]
261
261
+
262
262
+
[[package]]
161
263
name = "crypto-common"
162
264
version = "0.1.7"
163
265
source = "registry+https://github.com/rust-lang/crates.io-index"
···
168
270
]
169
271
170
272
[[package]]
273
273
+
name = "crypto-common"
274
274
+
version = "0.2.1"
275
275
+
source = "registry+https://github.com/rust-lang/crates.io-index"
276
276
+
checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710"
277
277
+
dependencies = [
278
278
+
"getrandom",
279
279
+
"hybrid-array",
280
280
+
"rand_core",
281
281
+
]
282
282
+
283
283
+
[[package]]
284
284
+
name = "ctutils"
285
285
+
version = "0.4.0"
286
286
+
source = "registry+https://github.com/rust-lang/crates.io-index"
287
287
+
checksum = "1005a6d4446f5120ef475ad3d2af2b30c49c2c9c6904258e3bb30219bebed5e4"
288
288
+
dependencies = [
289
289
+
"cmov",
290
290
+
"subtle",
291
291
+
]
292
292
+
293
293
+
[[package]]
171
294
name = "darling"
172
295
version = "0.20.11"
173
296
source = "registry+https://github.com/rust-lang/crates.io-index"
···
244
367
]
245
368
246
369
[[package]]
370
370
+
name = "der"
371
371
+
version = "0.8.0"
372
372
+
source = "registry+https://github.com/rust-lang/crates.io-index"
373
373
+
checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b"
374
374
+
dependencies = [
375
375
+
"const-oid",
376
376
+
"zeroize",
377
377
+
]
378
378
+
379
379
+
[[package]]
247
380
name = "derive_builder"
248
381
version = "0.20.2"
249
382
source = "registry+https://github.com/rust-lang/crates.io-index"
···
275
408
]
276
409
277
410
[[package]]
411
411
+
name = "dhkem"
412
412
+
version = "0.1.0-rc.0"
413
413
+
source = "git+https://github.com/RustCrypto/KEMs?rev=2d277162e0c5ed1c53bb315d0c0dace394cba70a#2d277162e0c5ed1c53bb315d0c0dace394cba70a"
414
414
+
dependencies = [
415
415
+
"elliptic-curve",
416
416
+
"hkdf",
417
417
+
"k256",
418
418
+
"kem",
419
419
+
"rand_core",
420
420
+
"zeroize",
421
421
+
]
422
422
+
423
423
+
[[package]]
278
424
name = "digest"
279
425
version = "0.10.7"
280
426
source = "registry+https://github.com/rust-lang/crates.io-index"
281
427
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
282
428
dependencies = [
283
283
-
"block-buffer",
284
284
-
"crypto-common",
429
429
+
"block-buffer 0.10.4",
430
430
+
"crypto-common 0.1.7",
431
431
+
]
432
432
+
433
433
+
[[package]]
434
434
+
name = "digest"
435
435
+
version = "0.11.2"
436
436
+
source = "registry+https://github.com/rust-lang/crates.io-index"
437
437
+
checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c"
438
438
+
dependencies = [
439
439
+
"block-buffer 0.12.0",
440
440
+
"crypto-common 0.2.1",
441
441
+
"ctutils",
285
442
]
286
443
287
444
[[package]]
···
294
451
]
295
452
296
453
[[package]]
454
454
+
name = "ecdsa"
455
455
+
version = "0.17.0-rc.16"
456
456
+
source = "registry+https://github.com/rust-lang/crates.io-index"
457
457
+
checksum = "91bbdd377139884fafcad8dc43a760a3e1e681aa26db910257fa6535b70e1829"
458
458
+
dependencies = [
459
459
+
"der",
460
460
+
"elliptic-curve",
461
461
+
"signature",
462
462
+
"zeroize",
463
463
+
]
464
464
+
465
465
+
[[package]]
297
466
name = "either"
298
467
version = "1.15.0"
299
468
source = "registry+https://github.com/rust-lang/crates.io-index"
300
469
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
301
470
302
471
[[package]]
472
472
+
name = "elliptic-curve"
473
473
+
version = "0.14.0-rc.29"
474
474
+
source = "registry+https://github.com/rust-lang/crates.io-index"
475
475
+
checksum = "e84043d573efd4ac9d2d125817979a379204bf7e328b25a4a30487e8d100e618"
476
476
+
dependencies = [
477
477
+
"base16ct",
478
478
+
"crypto-bigint",
479
479
+
"crypto-common 0.2.1",
480
480
+
"digest 0.11.2",
481
481
+
"hkdf",
482
482
+
"hybrid-array",
483
483
+
"rand_core",
484
484
+
"rustcrypto-ff",
485
485
+
"rustcrypto-group",
486
486
+
"sec1",
487
487
+
"subtle",
488
488
+
"zeroize",
489
489
+
]
490
490
+
491
491
+
[[package]]
303
492
name = "embassy-net"
304
493
version = "0.7.1"
305
494
source = "registry+https://github.com/rust-lang/crates.io-index"
···
338
527
339
528
[[package]]
340
529
name = "embassy-time"
341
341
-
version = "0.5.0"
530
530
+
version = "0.5.1"
342
531
source = "registry+https://github.com/rust-lang/crates.io-index"
343
343
-
checksum = "f4fa65b9284d974dad7a23bb72835c4ec85c0b540d86af7fc4098c88cff51d65"
532
532
+
checksum = "592b0c143ec626e821d4d90da51a2bd91d559d6c442b7c74a47d368c9e23d97a"
344
533
dependencies = [
345
534
"cfg-if",
346
535
"critical-section",
···
355
544
356
545
[[package]]
357
546
name = "embassy-time-driver"
358
358
-
version = "0.2.1"
547
547
+
version = "0.2.2"
359
548
source = "registry+https://github.com/rust-lang/crates.io-index"
360
360
-
checksum = "a0a244c7dc22c8d0289379c8d8830cae06bb93d8f990194d0de5efb3b5ae7ba6"
549
549
+
checksum = "6ee71af1b3a0deaa53eaf2d39252f83504c853646e472400b763060389b9fcc9"
361
550
dependencies = [
362
551
"document-features",
363
552
]
···
521
710
"cfg-if",
522
711
"libc",
523
712
"r-efi",
713
713
+
"rand_core",
524
714
"wasip2",
525
715
"wasip3",
526
716
]
···
610
800
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
611
801
612
802
[[package]]
803
803
+
name = "hkdf"
804
804
+
version = "0.13.0-rc.5"
805
805
+
source = "registry+https://github.com/rust-lang/crates.io-index"
806
806
+
checksum = "cbb55385998ae66b8d2d5143c05c94b9025ab863966f0c94ce7a5fde30105092"
807
807
+
dependencies = [
808
808
+
"hmac",
809
809
+
]
810
810
+
811
811
+
[[package]]
812
812
+
name = "hmac"
813
813
+
version = "0.13.0-rc.6"
814
814
+
source = "registry+https://github.com/rust-lang/crates.io-index"
815
815
+
checksum = "60017b071c523c9e5a55dd1253582bff6150c5e96a7e8511e419de1ab5ee97f9"
816
816
+
dependencies = [
817
817
+
"digest 0.11.2",
818
818
+
]
819
819
+
820
820
+
[[package]]
613
821
name = "home"
614
822
version = "0.5.12"
615
823
source = "registry+https://github.com/rust-lang/crates.io-index"
···
619
827
]
620
828
621
829
[[package]]
830
830
+
name = "hybrid-array"
831
831
+
version = "0.4.8"
832
832
+
source = "registry+https://github.com/rust-lang/crates.io-index"
833
833
+
checksum = "8655f91cd07f2b9d0c24137bd650fe69617773435ee5ec83022377777ce65ef1"
834
834
+
dependencies = [
835
835
+
"subtle",
836
836
+
"typenum",
837
837
+
"zeroize",
838
838
+
]
839
839
+
840
840
+
[[package]]
622
841
name = "i2cdev"
623
842
version = "0.6.2"
624
843
source = "registry+https://github.com/rust-lang/crates.io-index"
···
655
874
]
656
875
657
876
[[package]]
877
877
+
name = "inout"
878
878
+
version = "0.2.2"
879
879
+
source = "registry+https://github.com/rust-lang/crates.io-index"
880
880
+
checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7"
881
881
+
dependencies = [
882
882
+
"hybrid-array",
883
883
+
]
884
884
+
885
885
+
[[package]]
658
886
name = "io-kit-sys"
659
887
version = "0.4.1"
660
888
source = "registry+https://github.com/rust-lang/crates.io-index"
···
681
909
682
910
[[package]]
683
911
name = "itoa"
684
684
-
version = "1.0.17"
912
912
+
version = "1.0.18"
685
913
source = "registry+https://github.com/rust-lang/crates.io-index"
686
686
-
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
914
914
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
687
915
688
916
[[package]]
689
917
name = "jiff"
···
708
936
]
709
937
710
938
[[package]]
939
939
+
name = "k256"
940
940
+
version = "0.14.0-rc.8"
941
941
+
source = "registry+https://github.com/rust-lang/crates.io-index"
942
942
+
checksum = "f7d2c6c227649d5ec80eaae541f1736232641a0bcdb3062a52b34edb42054158"
943
943
+
dependencies = [
944
944
+
"cpubits",
945
945
+
"ecdsa",
946
946
+
"elliptic-curve",
947
947
+
]
948
948
+
949
949
+
[[package]]
950
950
+
name = "kem"
951
951
+
version = "0.3.0-rc.6"
952
952
+
source = "registry+https://github.com/rust-lang/crates.io-index"
953
953
+
checksum = "e3ae2c3347ff4a7af4f679a9e397c2c7e6034a00b773dd2dd3c001d7f40897c9"
954
954
+
dependencies = [
955
955
+
"crypto-common 0.2.1",
956
956
+
"rand_core",
957
957
+
]
958
958
+
959
959
+
[[package]]
711
960
name = "leb128fmt"
712
961
version = "0.1.0"
713
962
source = "registry+https://github.com/rust-lang/crates.io-index"
···
715
964
716
965
[[package]]
717
966
name = "libc"
718
718
-
version = "0.2.182"
967
967
+
version = "0.2.183"
719
968
source = "registry+https://github.com/rust-lang/crates.io-index"
720
720
-
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
969
969
+
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
721
970
722
971
[[package]]
723
972
name = "libm"
···
949
1198
950
1199
[[package]]
951
1200
name = "once_cell"
952
952
-
version = "1.21.3"
1201
1201
+
version = "1.21.4"
953
1202
source = "registry+https://github.com/rust-lang/crates.io-index"
954
954
-
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
1203
1203
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
955
1204
956
1205
[[package]]
957
1206
name = "owo-colors"
···
999
1248
checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220"
1000
1249
dependencies = [
1001
1250
"pest",
1002
1002
-
"sha2",
1251
1251
+
"sha2 0.10.9",
1003
1252
]
1004
1253
1005
1254
[[package]]
···
1020
1269
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
1021
1270
1022
1271
[[package]]
1272
1272
+
name = "poly1305"
1273
1273
+
version = "0.9.0-rc.6"
1274
1274
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1275
1275
+
checksum = "19feddcbdf17fad33f40041c7f9e768faf19455f32a6d52ba1b8b65ffc7b1cae"
1276
1276
+
dependencies = [
1277
1277
+
"cpufeatures 0.3.0",
1278
1278
+
"universal-hash",
1279
1279
+
]
1280
1280
+
1281
1281
+
[[package]]
1023
1282
name = "portable-atomic"
1024
1283
version = "1.13.1"
1025
1284
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1027
1286
1028
1287
[[package]]
1029
1288
name = "portable-atomic-util"
1030
1030
-
version = "0.2.5"
1289
1289
+
version = "0.2.6"
1031
1290
source = "registry+https://github.com/rust-lang/crates.io-index"
1032
1032
-
checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5"
1291
1291
+
checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3"
1033
1292
dependencies = [
1034
1293
"portable-atomic",
1035
1294
]
···
1178
1437
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
1179
1438
1180
1439
[[package]]
1440
1440
+
name = "rand_core"
1441
1441
+
version = "0.10.0"
1442
1442
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1443
1443
+
checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba"
1444
1444
+
1445
1445
+
[[package]]
1181
1446
name = "regex"
1182
1447
version = "1.12.3"
1183
1448
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1213
1478
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
1214
1479
1215
1480
[[package]]
1481
1481
+
name = "rustcrypto-ff"
1482
1482
+
version = "0.14.0-rc.0"
1483
1483
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1484
1484
+
checksum = "c5db129183b2c139d7d87d08be57cba626c715789db17aec65c8866bfd767d1f"
1485
1485
+
dependencies = [
1486
1486
+
"rand_core",
1487
1487
+
"subtle",
1488
1488
+
]
1489
1489
+
1490
1490
+
[[package]]
1491
1491
+
name = "rustcrypto-group"
1492
1492
+
version = "0.14.0-rc.0"
1493
1493
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1494
1494
+
checksum = "57c4b1463f274a3ff6fb2f44da43e576cb9424367bd96f185ead87b52fe00523"
1495
1495
+
dependencies = [
1496
1496
+
"rand_core",
1497
1497
+
"rustcrypto-ff",
1498
1498
+
"subtle",
1499
1499
+
]
1500
1500
+
1501
1501
+
[[package]]
1216
1502
name = "rustix"
1217
1503
version = "0.38.44"
1218
1504
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1261
1547
]
1262
1548
1263
1549
[[package]]
1550
1550
+
name = "sachy-crypto"
1551
1551
+
version = "0.1.0"
1552
1552
+
dependencies = [
1553
1553
+
"chacha20poly1305",
1554
1554
+
"dhkem",
1555
1555
+
"k256",
1556
1556
+
"sha2 0.11.0-rc.5",
1557
1557
+
]
1558
1558
+
1559
1559
+
[[package]]
1264
1560
name = "sachy-esphome"
1265
1561
version = "0.1.0"
1266
1562
dependencies = [
···
1299
1595
"defmt 1.0.1",
1300
1596
"embassy-time",
1301
1597
"sachy-fmt",
1302
1302
-
"winnow",
1598
1598
+
"winnow 0.7.15",
1303
1599
]
1304
1600
1305
1601
[[package]]
···
1331
1627
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
1332
1628
1333
1629
[[package]]
1630
1630
+
name = "sec1"
1631
1631
+
version = "0.8.0"
1632
1632
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1633
1633
+
checksum = "f46b9a5ab87780a3189a1d704766579517a04ad59de653b7aad7d38e8a15f7dc"
1634
1634
+
dependencies = [
1635
1635
+
"base16ct",
1636
1636
+
"ctutils",
1637
1637
+
"der",
1638
1638
+
"hybrid-array",
1639
1639
+
"subtle",
1640
1640
+
"zeroize",
1641
1641
+
]
1642
1642
+
1643
1643
+
[[package]]
1334
1644
name = "semver"
1335
1645
version = "1.0.27"
1336
1646
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1381
1691
1382
1692
[[package]]
1383
1693
name = "serialport"
1384
1384
-
version = "4.7.3"
1694
1694
+
version = "4.9.0"
1385
1695
source = "registry+https://github.com/rust-lang/crates.io-index"
1386
1386
-
checksum = "2acaf3f973e8616d7ceac415f53fc60e190b2a686fbcf8d27d0256c741c5007b"
1696
1696
+
checksum = "a4d91116f97173694f1642263b2ff837f80d933aa837e2314969f6728f661df3"
1387
1697
dependencies = [
1388
1698
"bitflags 2.11.0",
1389
1699
"cfg-if",
···
1394
1704
"nix 0.26.4",
1395
1705
"scopeguard",
1396
1706
"unescaper",
1397
1397
-
"winapi",
1707
1707
+
"windows-sys 0.52.0",
1398
1708
]
1399
1709
1400
1710
[[package]]
···
1404
1714
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
1405
1715
dependencies = [
1406
1716
"cfg-if",
1407
1407
-
"cpufeatures",
1408
1408
-
"digest",
1717
1717
+
"cpufeatures 0.2.17",
1718
1718
+
"digest 0.10.7",
1719
1719
+
]
1720
1720
+
1721
1721
+
[[package]]
1722
1722
+
name = "sha2"
1723
1723
+
version = "0.11.0-rc.5"
1724
1724
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1725
1725
+
checksum = "7c5f3b1e2dc8aad28310d8410bd4d7e180eca65fca176c52ab00d364475d0024"
1726
1726
+
dependencies = [
1727
1727
+
"cfg-if",
1728
1728
+
"cpufeatures 0.2.17",
1729
1729
+
"digest 0.11.2",
1409
1730
]
1410
1731
1411
1732
[[package]]
···
1413
1734
version = "1.3.0"
1414
1735
source = "registry+https://github.com/rust-lang/crates.io-index"
1415
1736
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
1737
1737
+
1738
1738
+
[[package]]
1739
1739
+
name = "signature"
1740
1740
+
version = "3.0.0-rc.10"
1741
1741
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1742
1742
+
checksum = "7f1880df446116126965eeec169136b2e0251dba37c6223bcc819569550edea3"
1743
1743
+
dependencies = [
1744
1744
+
"rand_core",
1745
1745
+
]
1416
1746
1417
1747
[[package]]
1418
1748
name = "smoltcp"
···
1451
1781
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
1452
1782
1453
1783
[[package]]
1784
1784
+
name = "subtle"
1785
1785
+
version = "2.6.1"
1786
1786
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1787
1787
+
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
1788
1788
+
1789
1789
+
[[package]]
1454
1790
name = "supports-color"
1455
1791
version = "3.0.2"
1456
1792
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1493
1829
1494
1830
[[package]]
1495
1831
name = "tempfile"
1496
1496
-
version = "3.26.0"
1832
1832
+
version = "3.27.0"
1497
1833
source = "registry+https://github.com/rust-lang/crates.io-index"
1498
1498
-
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
1834
1834
+
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
1499
1835
dependencies = [
1500
1836
"fastrand",
1501
1837
"getrandom",
···
1566
1902
1567
1903
[[package]]
1568
1904
name = "toml_datetime"
1569
1569
-
version = "1.0.0+spec-1.1.0"
1905
1905
+
version = "1.0.1+spec-1.1.0"
1570
1906
source = "registry+https://github.com/rust-lang/crates.io-index"
1571
1571
-
checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e"
1907
1907
+
checksum = "9b320e741db58cac564e26c607d3cc1fdc4a88fd36c879568c07856ed83ff3e9"
1572
1908
dependencies = [
1573
1909
"serde_core",
1574
1910
]
1575
1911
1576
1912
[[package]]
1577
1913
name = "toml_edit"
1578
1578
-
version = "0.25.4+spec-1.1.0"
1914
1914
+
version = "0.25.5+spec-1.1.0"
1579
1915
source = "registry+https://github.com/rust-lang/crates.io-index"
1580
1580
-
checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2"
1916
1916
+
checksum = "8ca1a40644a28bce036923f6a431df0b34236949d111cc07cb6dca830c9ef2e1"
1581
1917
dependencies = [
1582
1918
"indexmap",
1583
1919
"toml_datetime",
1584
1920
"toml_parser",
1585
1921
"toml_writer",
1586
1586
-
"winnow",
1922
1922
+
"winnow 1.0.0",
1587
1923
]
1588
1924
1589
1925
[[package]]
1590
1926
name = "toml_parser"
1591
1591
-
version = "1.0.9+spec-1.1.0"
1927
1927
+
version = "1.0.10+spec-1.1.0"
1592
1928
source = "registry+https://github.com/rust-lang/crates.io-index"
1593
1593
-
checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4"
1929
1929
+
checksum = "7df25b4befd31c4816df190124375d5a20c6b6921e2cad937316de3fccd63420"
1594
1930
dependencies = [
1595
1595
-
"winnow",
1931
1931
+
"winnow 1.0.0",
1596
1932
]
1597
1933
1598
1934
[[package]]
1599
1935
name = "toml_writer"
1600
1600
-
version = "1.0.6+spec-1.1.0"
1936
1936
+
version = "1.0.7+spec-1.1.0"
1601
1937
source = "registry+https://github.com/rust-lang/crates.io-index"
1602
1602
-
checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
1938
1938
+
checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d"
1603
1939
1604
1940
[[package]]
1605
1941
name = "typenum"
···
1653
1989
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
1654
1990
1655
1991
[[package]]
1992
1992
+
name = "universal-hash"
1993
1993
+
version = "0.6.1"
1994
1994
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1995
1995
+
checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96"
1996
1996
+
dependencies = [
1997
1997
+
"crypto-common 0.2.1",
1998
1998
+
"ctutils",
1999
1999
+
]
2000
2000
+
2001
2001
+
[[package]]
1656
2002
name = "version_check"
1657
2003
version = "0.9.5"
1658
2004
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1729
2075
]
1730
2076
1731
2077
[[package]]
1732
1732
-
name = "winapi"
1733
1733
-
version = "0.3.9"
2078
2078
+
name = "windows-link"
2079
2079
+
version = "0.2.1"
1734
2080
source = "registry+https://github.com/rust-lang/crates.io-index"
1735
1735
-
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
1736
1736
-
dependencies = [
1737
1737
-
"winapi-i686-pc-windows-gnu",
1738
1738
-
"winapi-x86_64-pc-windows-gnu",
1739
1739
-
]
2081
2081
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
1740
2082
1741
2083
[[package]]
1742
1742
-
name = "winapi-i686-pc-windows-gnu"
1743
1743
-
version = "0.4.0"
2084
2084
+
name = "windows-sys"
2085
2085
+
version = "0.52.0"
1744
2086
source = "registry+https://github.com/rust-lang/crates.io-index"
1745
1745
-
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1746
1746
-
1747
1747
-
[[package]]
1748
1748
-
name = "winapi-x86_64-pc-windows-gnu"
1749
1749
-
version = "0.4.0"
1750
1750
-
source = "registry+https://github.com/rust-lang/crates.io-index"
1751
1751
-
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1752
1752
-
1753
1753
-
[[package]]
1754
1754
-
name = "windows-link"
1755
1755
-
version = "0.2.1"
1756
1756
-
source = "registry+https://github.com/rust-lang/crates.io-index"
1757
1757
-
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
2087
2087
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
2088
2088
+
dependencies = [
2089
2089
+
"windows-targets 0.52.6",
2090
2090
+
]
1758
2091
1759
2092
[[package]]
1760
2093
name = "windows-sys"
···
1914
2247
1915
2248
[[package]]
1916
2249
name = "winnow"
1917
1917
-
version = "0.7.14"
2250
2250
+
version = "0.7.15"
1918
2251
source = "registry+https://github.com/rust-lang/crates.io-index"
1919
1919
-
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
2252
2252
+
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
2253
2253
+
2254
2254
+
[[package]]
2255
2255
+
name = "winnow"
2256
2256
+
version = "1.0.0"
2257
2257
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2258
2258
+
checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8"
1920
2259
dependencies = [
1921
2260
"memchr",
1922
2261
]
···
2008
2347
"unicode-xid",
2009
2348
"wasmparser",
2010
2349
]
2350
2350
+
2351
2351
+
[[package]]
2352
2352
+
name = "zeroize"
2353
2353
+
version = "1.8.2"
2354
2354
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2355
2355
+
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
2011
2356
2012
2357
[[package]]
2013
2358
name = "zmij"
+4
Cargo.toml
···
4
4
"sachy-battery",
5
5
"sachy-bthome",
6
6
"sachy-config",
7
7
+
"sachy-crypto",
7
8
"sachy-esphome",
8
9
"sachy-fmt",
9
10
"sachy-fnv",
···
26
27
embassy-sync = { version = "0.7" }
27
28
embassy-net = { version = "0.7" }
28
29
defmt = { version = "1" }
30
30
+
31
31
+
[patch.crates-io]
32
32
+
dhkem = { git = "https://github.com/RustCrypto/KEMs", rev = "2d277162e0c5ed1c53bb315d0c0dace394cba70a" }
+14
sachy-crypto/Cargo.toml
···
1
1
+
[package]
2
2
+
name = "sachy-crypto"
3
3
+
authors.workspace = true
4
4
+
edition.workspace = true
5
5
+
repository.workspace = true
6
6
+
license.workspace = true
7
7
+
version.workspace = true
8
8
+
rust-version.workspace = true
9
9
+
10
10
+
[dependencies]
11
11
+
chacha20poly1305 = { version = "=0.11.0-rc.3", default-features = false, features = ["getrandom", "alloc"] }
12
12
+
k256 = { version = "=0.14.0-rc.8", default-features = false, features = ["ecdh", "getrandom"] }
13
13
+
sha2 = { version = "=0.11.0-rc.5", default-features = false, features = [] }
14
14
+
dhkem = { version = "0.1.0-rc.0", features = ["getrandom", "k256"] }
+317
sachy-crypto/src/lib.rs
···
1
1
+
#![no_std]
2
2
+
3
3
+
use core::ops::{AddAssign, Sub};
4
4
+
5
5
+
use chacha20poly1305::{
6
6
+
AeadCore, AeadInOut, ChaCha20Poly1305, KeyInit,
7
7
+
aead::{
8
8
+
self, Buffer,
9
9
+
array::{Array, ArraySize},
10
10
+
common::array::typenum::Unsigned,
11
11
+
},
12
12
+
consts::U8,
13
13
+
};
14
14
+
use dhkem::{
15
15
+
Encapsulate, Kem, Secp256k1DecapsulationKey, Secp256k1EncapsulationKey, Secp256k1Kem,
16
16
+
TryDecapsulate,
17
17
+
kem::{Ciphertext, SharedKey, TryKeyInit},
18
18
+
};
19
19
+
use k256::{ecdh::SharedSecret, elliptic_curve::subtle::ConstantTimeEq};
20
20
+
21
21
+
extern crate alloc;
22
22
+
23
23
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24
24
+
pub struct HandshakeError;
25
25
+
26
26
+
pub struct ClientHandshake(Secp256k1DecapsulationKey);
27
27
+
28
28
+
impl ClientHandshake {
29
29
+
pub fn send() -> (Secp256k1EncapsulationKey, Self) {
30
30
+
let (decap, encap) = Secp256k1Kem::generate_keypair();
31
31
+
32
32
+
(encap, Self(decap))
33
33
+
}
34
34
+
35
35
+
pub fn finish(
36
36
+
self,
37
37
+
ciphertext: &[u8],
38
38
+
psk: &[u8; 32],
39
39
+
) -> Result<TransportState, HandshakeError> {
40
40
+
let shared = self
41
41
+
.0
42
42
+
.try_decapsulate_slice(ciphertext)
43
43
+
.map_err(|_| HandshakeError)?;
44
44
+
45
45
+
TransportState::init(psk, shared)
46
46
+
}
47
47
+
}
48
48
+
49
49
+
pub struct ServerHandshake(SharedKey<Secp256k1Kem>);
50
50
+
51
51
+
impl ServerHandshake {
52
52
+
pub fn receive(buf: &[u8]) -> Result<(Ciphertext<Secp256k1Kem>, Self), HandshakeError> {
53
53
+
let encap = Secp256k1EncapsulationKey::new_from_slice(buf).map_err(|_| HandshakeError)?;
54
54
+
55
55
+
let (ciphertext, sk) = encap.encapsulate();
56
56
+
57
57
+
Ok((ciphertext, Self(sk)))
58
58
+
}
59
59
+
60
60
+
pub fn finish(self, psk: &[u8; 32]) -> Result<TransportState, HandshakeError> {
61
61
+
TransportState::init(psk, self.0)
62
62
+
}
63
63
+
}
64
64
+
65
65
+
/// Error type.
66
66
+
///
67
67
+
/// This type is deliberately opaque as to avoid potential side-channel
68
68
+
/// leakage (e.g. padding oracle).
69
69
+
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
70
70
+
pub struct AeadError;
71
71
+
72
72
+
impl core::fmt::Display for AeadError {
73
73
+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74
74
+
f.write_str("aead::Error")
75
75
+
}
76
76
+
}
77
77
+
78
78
+
impl core::error::Error for AeadError {}
79
79
+
80
80
+
impl From<chacha20poly1305::Error> for AeadError {
81
81
+
fn from(_value: chacha20poly1305::Error) -> Self {
82
82
+
AeadError
83
83
+
}
84
84
+
}
85
85
+
86
86
+
/// Nonce as used by a given AEAD construction and STREAM primitive.
87
87
+
pub type Nonce<A, S> = chacha20poly1305::aead::array::Array<u8, NonceSize<A, S>>;
88
88
+
89
89
+
/// Size of a nonce as used by a STREAM construction, sans the overhead of
90
90
+
/// the STREAM protocol itself.
91
91
+
pub type NonceSize<A, S> =
92
92
+
<<A as AeadCore>::NonceSize as Sub<<S as StreamPrimitive<A>>::NonceOverhead>>::Output;
93
93
+
94
94
+
/// Low-level STREAM implementation.
95
95
+
///
96
96
+
/// This trait provides a particular "flavor" of STREAM, as there are
97
97
+
/// different ways the specifics of the construction can be implemented.
98
98
+
///
99
99
+
/// Deliberately immutable and stateless to permit parallel operation.
100
100
+
pub trait StreamPrimitive<A>
101
101
+
where
102
102
+
A: AeadInOut,
103
103
+
A::NonceSize: Sub<Self::NonceOverhead>,
104
104
+
NonceSize<A, Self>: ArraySize,
105
105
+
{
106
106
+
/// Number of bytes this STREAM primitive requires from the nonce.
107
107
+
type NonceOverhead: ArraySize;
108
108
+
109
109
+
/// Type used as the STREAM counter.
110
110
+
type Counter: AddAssign + Copy + Default + Eq;
111
111
+
112
112
+
/// Value to use when incrementing the STREAM counter (i.e. one)
113
113
+
const COUNTER_INCR: Self::Counter;
114
114
+
115
115
+
/// Maximum value of the STREAM counter.
116
116
+
const COUNTER_MAX: Self::Counter;
117
117
+
118
118
+
/// Encrypt an AEAD message in-place at the given position in the STREAM.
119
119
+
fn encrypt_in_place(
120
120
+
&self,
121
121
+
position: Self::Counter,
122
122
+
associated_data: &[u8],
123
123
+
buffer: &mut dyn Buffer,
124
124
+
) -> Result<(), AeadError>;
125
125
+
126
126
+
/// Decrypt an AEAD message in-place at the given position in the STREAM.
127
127
+
fn decrypt_in_place(
128
128
+
&self,
129
129
+
position: Self::Counter,
130
130
+
associated_data: &[u8],
131
131
+
buffer: &mut dyn Buffer,
132
132
+
) -> Result<(), AeadError>;
133
133
+
}
134
134
+
135
135
+
pub struct TransportState {
136
136
+
aead: ChaCha20Poly1305,
137
137
+
epstein: Nonce<ChaCha20Poly1305, Self>,
138
138
+
counter: u64,
139
139
+
}
140
140
+
141
141
+
impl StreamPrimitive<ChaCha20Poly1305> for TransportState {
142
142
+
type NonceOverhead = U8;
143
143
+
144
144
+
type Counter = u64;
145
145
+
146
146
+
const COUNTER_INCR: Self::Counter = 1;
147
147
+
148
148
+
const COUNTER_MAX: Self::Counter = u64::MAX;
149
149
+
150
150
+
fn encrypt_in_place(
151
151
+
&self,
152
152
+
position: Self::Counter,
153
153
+
associated_data: &[u8],
154
154
+
buffer: &mut dyn Buffer,
155
155
+
) -> Result<(), AeadError> {
156
156
+
let epstein = self.aead_nonce(position);
157
157
+
self.aead
158
158
+
.encrypt_in_place(&epstein, associated_data, buffer)?;
159
159
+
Ok(())
160
160
+
}
161
161
+
162
162
+
fn decrypt_in_place(
163
163
+
&self,
164
164
+
position: Self::Counter,
165
165
+
associated_data: &[u8],
166
166
+
buffer: &mut dyn Buffer,
167
167
+
) -> Result<(), AeadError> {
168
168
+
let epstein = self.aead_nonce(position);
169
169
+
self.aead
170
170
+
.decrypt_in_place(&epstein, associated_data, buffer)?;
171
171
+
Ok(())
172
172
+
}
173
173
+
}
174
174
+
175
175
+
impl TransportState {
176
176
+
fn aead_nonce(&self, position: u64) -> aead::Nonce<ChaCha20Poly1305> {
177
177
+
let mut result = Array::default();
178
178
+
179
179
+
let (prefix, tail) = result.split_at_mut(NonceSize::<ChaCha20Poly1305, Self>::to_usize());
180
180
+
181
181
+
prefix.copy_from_slice(&self.epstein);
182
182
+
183
183
+
tail[..8].copy_from_slice(&position.to_be_bytes());
184
184
+
185
185
+
result
186
186
+
}
187
187
+
188
188
+
pub fn init(psk: &[u8; 32], shared: impl Into<SharedSecret>) -> Result<Self, HandshakeError> {
189
189
+
let kdf = shared.into().extract::<sha2::Sha256>(Some(psk));
190
190
+
191
191
+
let mut key = [0u8; 32];
192
192
+
193
193
+
kdf.expand(b"sachy-crypto", &mut key)
194
194
+
.map_err(|_| HandshakeError)?;
195
195
+
196
196
+
let mut epstein = Nonce::<ChaCha20Poly1305, Self>::default();
197
197
+
198
198
+
kdf.expand(b"noncer", &mut epstein)
199
199
+
.map_err(|_| HandshakeError)?;
200
200
+
201
201
+
Ok(Self {
202
202
+
aead: ChaCha20Poly1305::new(&key.into()),
203
203
+
epstein,
204
204
+
counter: 0,
205
205
+
})
206
206
+
}
207
207
+
208
208
+
pub fn encrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), AeadError> {
209
209
+
let counter_data = self.counter.to_be_bytes();
210
210
+
211
211
+
self.encrypt_in_place(self.counter, &counter_data, msg)?;
212
212
+
213
213
+
self.counter += Self::COUNTER_INCR;
214
214
+
215
215
+
if self.counter.ct_eq(&Self::COUNTER_MAX).into() {
216
216
+
Err(AeadError)
217
217
+
} else {
218
218
+
Ok(())
219
219
+
}
220
220
+
}
221
221
+
222
222
+
pub fn decrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), AeadError> {
223
223
+
let counter_data = self.counter.to_be_bytes();
224
224
+
225
225
+
self.decrypt_in_place(self.counter, &counter_data, msg)?;
226
226
+
227
227
+
self.counter += Self::COUNTER_INCR;
228
228
+
229
229
+
if self.counter.ct_eq(&Self::COUNTER_MAX).into() {
230
230
+
Err(AeadError)
231
231
+
} else {
232
232
+
Ok(())
233
233
+
}
234
234
+
}
235
235
+
}
236
236
+
237
237
+
#[cfg(test)]
238
238
+
mod tests {
239
239
+
use dhkem::kem::KeyExport;
240
240
+
241
241
+
use super::*;
242
242
+
243
243
+
#[test]
244
244
+
fn handshake_protocol_works() -> Result<(), HandshakeError> {
245
245
+
let psk: [u8; 32] = [
246
246
+
31, 48, 29, 177, 88, 236, 186, 84, 65, 51, 214, 243, 174, 24, 45, 101, 229, 129, 62,
247
247
+
132, 45, 174, 183, 65, 89, 73, 107, 177, 77, 90, 164, 251,
248
248
+
];
249
249
+
250
250
+
let (ek, client) = ClientHandshake::send();
251
251
+
252
252
+
let (ciphertext, server) = ServerHandshake::receive(&ek.to_bytes())?;
253
253
+
254
254
+
let client_transport = client.finish(&ciphertext, &psk)?;
255
255
+
let server_transport = server.finish(&psk)?;
256
256
+
257
257
+
// If the nonces match, then we can assume the rest of the internal state is correct
258
258
+
assert_eq!(
259
259
+
client_transport.epstein.as_slice(),
260
260
+
server_transport.epstein.as_slice()
261
261
+
);
262
262
+
263
263
+
Ok(())
264
264
+
}
265
265
+
266
266
+
#[test]
267
267
+
fn two_way_transport_sync_works() -> Result<(), AeadError> {
268
268
+
let shared_secret = [
269
269
+
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
270
270
+
0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
271
271
+
0x9c, 0x9d, 0x9e, 0x9f,
272
272
+
];
273
273
+
274
274
+
let psk: [u8; 32] = [
275
275
+
31, 48, 29, 177, 88, 236, 186, 84, 65, 51, 214, 243, 174, 24, 45, 101, 229, 129, 62,
276
276
+
132, 45, 174, 183, 65, 89, 73, 107, 177, 77, 90, 164, 251,
277
277
+
];
278
278
+
279
279
+
let mut alice = TransportState::init(&psk, Array(shared_secret)).map_err(|_| AeadError)?;
280
280
+
let mut bob = TransportState::init(&psk, Array(shared_secret)).map_err(|_| AeadError)?;
281
281
+
282
282
+
let orig = b"Test Message, Please ignore.".to_vec();
283
283
+
284
284
+
let mut msg = orig.clone();
285
285
+
286
286
+
// a -> b
287
287
+
alice.encrypt(&mut msg)?;
288
288
+
289
289
+
assert_ne!(orig.as_slice(), msg.as_slice());
290
290
+
let a1 = msg.clone();
291
291
+
292
292
+
bob.decrypt(&mut msg)?;
293
293
+
294
294
+
// a -> b
295
295
+
alice.encrypt(&mut msg)?;
296
296
+
297
297
+
assert_ne!(msg.as_slice(), a1.as_slice());
298
298
+
let a2 = msg.clone();
299
299
+
300
300
+
bob.decrypt(&mut msg)?;
301
301
+
302
302
+
// b -> a
303
303
+
bob.encrypt(&mut msg)?;
304
304
+
305
305
+
// None of the ciphertexts should match each other
306
306
+
assert_ne!(msg.as_slice(), a1.as_slice());
307
307
+
assert_ne!(msg.as_slice(), a2.as_slice());
308
308
+
assert_ne!(a1.as_slice(), a2.as_slice());
309
309
+
310
310
+
alice.decrypt(&mut msg)?;
311
311
+
312
312
+
assert_eq!(orig.as_slice(), msg.as_slice());
313
313
+
assert_eq!(alice.counter, bob.counter);
314
314
+
315
315
+
Ok(())
316
316
+
}
317
317
+
}