Repo of no-std crates for my personal embedded projects

Sachy's crypto scheme lmao #13

open opened by sachy.dev targeting main from sachy-crypto
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:usjm3ynnir6y4inkcdovrfei/sh.tangled.repo.pull/3mhklndgukc22
+760 -59
Diff #0
+380 -59
Cargo.lock
··· 17 17 source = "registry+https://github.com/rust-lang/crates.io-index" 18 18 checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" 19 19 20 + [[package]] 21 + name = "aead" 22 + version = "0.6.0-rc.10" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "6b657e772794c6b04730ea897b66a058ccd866c16d1967da05eeeecec39043fe" 25 + dependencies = [ 26 + "crypto-common 0.2.1", 27 + "inout", 28 + ] 29 + 20 30 [[package]] 21 31 name = "aho-corasick" 22 32 version = "1.1.4" ··· 62 72 "backtrace", 63 73 ] 64 74 75 + [[package]] 76 + name = "base16ct" 77 + version = "1.0.0" 78 + source = "registry+https://github.com/rust-lang/crates.io-index" 79 + checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" 80 + 65 81 [[package]] 66 82 name = "base64ct" 67 83 version = "1.8.3" ··· 89 105 "generic-array", 90 106 ] 91 107 108 + [[package]] 109 + name = "block-buffer" 110 + version = "0.12.0" 111 + source = "registry+https://github.com/rust-lang/crates.io-index" 112 + checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" 113 + dependencies = [ 114 + "hybrid-array", 115 + ] 116 + 92 117 [[package]] 93 118 name = "byteorder" 94 119 version = "1.5.0" ··· 112 137 113 138 [[package]] 114 139 name = "cc" 115 - version = "1.2.56" 140 + version = "1.2.57" 116 141 source = "registry+https://github.com/rust-lang/crates.io-index" 117 - checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" 142 + checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" 118 143 dependencies = [ 119 144 "find-msvc-tools", 120 145 "shlex", ··· 126 151 source = "registry+https://github.com/rust-lang/crates.io-index" 127 152 checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 128 153 154 + [[package]] 155 + name = "chacha20" 156 + version = "0.10.0" 157 + source = "registry+https://github.com/rust-lang/crates.io-index" 158 + checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" 159 + dependencies = [ 160 + "cfg-if", 161 + "cipher", 162 + "cpufeatures 0.3.0", 163 + ] 164 + 165 + [[package]] 166 + name = "chacha20poly1305" 167 + version = "0.11.0-rc.3" 168 + source = "registry+https://github.com/rust-lang/crates.io-index" 169 + checksum = "1c9ed179664f12fd6f155f6dd632edf5f3806d48c228c67ff78366f2a0eb6b5e" 170 + dependencies = [ 171 + "aead", 172 + "chacha20", 173 + "cipher", 174 + "poly1305", 175 + ] 176 + 177 + [[package]] 178 + name = "cipher" 179 + version = "0.5.1" 180 + source = "registry+https://github.com/rust-lang/crates.io-index" 181 + checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea" 182 + dependencies = [ 183 + "block-buffer 0.12.0", 184 + "crypto-common 0.2.1", 185 + "inout", 186 + ] 187 + 188 + [[package]] 189 + name = "cmov" 190 + version = "0.5.2" 191 + source = "registry+https://github.com/rust-lang/crates.io-index" 192 + checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3" 193 + 194 + [[package]] 195 + name = "const-oid" 196 + version = "0.10.2" 197 + source = "registry+https://github.com/rust-lang/crates.io-index" 198 + checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" 199 + 129 200 [[package]] 130 201 name = "core-foundation" 131 202 version = "0.10.1" ··· 142 213 source = "registry+https://github.com/rust-lang/crates.io-index" 143 214 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 144 215 216 + [[package]] 217 + name = "cpubits" 218 + version = "0.1.0" 219 + source = "registry+https://github.com/rust-lang/crates.io-index" 220 + checksum = "5ef0c543070d296ea414df2dd7625d1b24866ce206709d8a4a424f28377f5861" 221 + 145 222 [[package]] 146 223 name = "cpufeatures" 147 224 version = "0.2.17" ··· 151 228 "libc", 152 229 ] 153 230 231 + [[package]] 232 + name = "cpufeatures" 233 + version = "0.3.0" 234 + source = "registry+https://github.com/rust-lang/crates.io-index" 235 + checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" 236 + dependencies = [ 237 + "libc", 238 + ] 239 + 154 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 246 + [[package]] 247 + name = "crypto-bigint" 248 + version = "0.7.2" 249 + source = "registry+https://github.com/rust-lang/crates.io-index" 250 + checksum = "e9b6a7421484856c90cb2e996b91068d608539bb4e6f0a111b16d70678824d09" 251 + dependencies = [ 252 + "cpubits", 253 + "ctutils", 254 + "getrandom", 255 + "hybrid-array", 256 + "num-traits", 257 + "rand_core", 258 + "subtle", 259 + "zeroize", 260 + ] 261 + 160 262 [[package]] 161 263 name = "crypto-common" 162 264 version = "0.1.7" ··· 167 269 "typenum", 168 270 ] 169 271 272 + [[package]] 273 + name = "crypto-common" 274 + version = "0.2.1" 275 + source = "registry+https://github.com/rust-lang/crates.io-index" 276 + checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" 277 + dependencies = [ 278 + "getrandom", 279 + "hybrid-array", 280 + "rand_core", 281 + ] 282 + 283 + [[package]] 284 + name = "ctutils" 285 + version = "0.4.0" 286 + source = "registry+https://github.com/rust-lang/crates.io-index" 287 + checksum = "1005a6d4446f5120ef475ad3d2af2b30c49c2c9c6904258e3bb30219bebed5e4" 288 + dependencies = [ 289 + "cmov", 290 + "subtle", 291 + ] 292 + 170 293 [[package]] 171 294 name = "darling" 172 295 version = "0.20.11" ··· 243 366 "thiserror 2.0.18", 244 367 ] 245 368 369 + [[package]] 370 + name = "der" 371 + version = "0.8.0" 372 + source = "registry+https://github.com/rust-lang/crates.io-index" 373 + checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b" 374 + dependencies = [ 375 + "const-oid", 376 + "zeroize", 377 + ] 378 + 246 379 [[package]] 247 380 name = "derive_builder" 248 381 version = "0.20.2" ··· 280 413 source = "registry+https://github.com/rust-lang/crates.io-index" 281 414 checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 282 415 dependencies = [ 283 - "block-buffer", 284 - "crypto-common", 416 + "block-buffer 0.10.4", 417 + "crypto-common 0.1.7", 418 + ] 419 + 420 + [[package]] 421 + name = "digest" 422 + version = "0.11.2" 423 + source = "registry+https://github.com/rust-lang/crates.io-index" 424 + checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c" 425 + dependencies = [ 426 + "block-buffer 0.12.0", 427 + "crypto-common 0.2.1", 428 + "ctutils", 285 429 ] 286 430 287 431 [[package]] ··· 293 437 "litrs", 294 438 ] 295 439 440 + [[package]] 441 + name = "ecdsa" 442 + version = "0.17.0-rc.16" 443 + source = "registry+https://github.com/rust-lang/crates.io-index" 444 + checksum = "91bbdd377139884fafcad8dc43a760a3e1e681aa26db910257fa6535b70e1829" 445 + dependencies = [ 446 + "der", 447 + "elliptic-curve", 448 + "signature", 449 + "zeroize", 450 + ] 451 + 296 452 [[package]] 297 453 name = "either" 298 454 version = "1.15.0" 299 455 source = "registry+https://github.com/rust-lang/crates.io-index" 300 456 checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 301 457 458 + [[package]] 459 + name = "elliptic-curve" 460 + version = "0.14.0-rc.29" 461 + source = "registry+https://github.com/rust-lang/crates.io-index" 462 + checksum = "e84043d573efd4ac9d2d125817979a379204bf7e328b25a4a30487e8d100e618" 463 + dependencies = [ 464 + "base16ct", 465 + "crypto-bigint", 466 + "crypto-common 0.2.1", 467 + "digest 0.11.2", 468 + "hkdf", 469 + "hybrid-array", 470 + "rand_core", 471 + "rustcrypto-ff", 472 + "rustcrypto-group", 473 + "sec1", 474 + "subtle", 475 + "zeroize", 476 + ] 477 + 302 478 [[package]] 303 479 name = "embassy-net" 304 480 version = "0.7.1" ··· 338 514 339 515 [[package]] 340 516 name = "embassy-time" 341 - version = "0.5.0" 517 + version = "0.5.1" 342 518 source = "registry+https://github.com/rust-lang/crates.io-index" 343 - checksum = "f4fa65b9284d974dad7a23bb72835c4ec85c0b540d86af7fc4098c88cff51d65" 519 + checksum = "592b0c143ec626e821d4d90da51a2bd91d559d6c442b7c74a47d368c9e23d97a" 344 520 dependencies = [ 345 521 "cfg-if", 346 522 "critical-section", ··· 355 531 356 532 [[package]] 357 533 name = "embassy-time-driver" 358 - version = "0.2.1" 534 + version = "0.2.2" 359 535 source = "registry+https://github.com/rust-lang/crates.io-index" 360 - checksum = "a0a244c7dc22c8d0289379c8d8830cae06bb93d8f990194d0de5efb3b5ae7ba6" 536 + checksum = "6ee71af1b3a0deaa53eaf2d39252f83504c853646e472400b763060389b9fcc9" 361 537 dependencies = [ 362 538 "document-features", 363 539 ] ··· 521 697 "cfg-if", 522 698 "libc", 523 699 "r-efi", 700 + "rand_core", 524 701 "wasip2", 525 702 "wasip3", 526 703 ] ··· 609 786 source = "registry+https://github.com/rust-lang/crates.io-index" 610 787 checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 611 788 789 + [[package]] 790 + name = "hkdf" 791 + version = "0.13.0-rc.5" 792 + source = "registry+https://github.com/rust-lang/crates.io-index" 793 + checksum = "cbb55385998ae66b8d2d5143c05c94b9025ab863966f0c94ce7a5fde30105092" 794 + dependencies = [ 795 + "hmac", 796 + ] 797 + 798 + [[package]] 799 + name = "hmac" 800 + version = "0.13.0-rc.6" 801 + source = "registry+https://github.com/rust-lang/crates.io-index" 802 + checksum = "60017b071c523c9e5a55dd1253582bff6150c5e96a7e8511e419de1ab5ee97f9" 803 + dependencies = [ 804 + "digest 0.11.2", 805 + ] 806 + 612 807 [[package]] 613 808 name = "home" 614 809 version = "0.5.12" ··· 618 813 "windows-sys 0.61.2", 619 814 ] 620 815 816 + [[package]] 817 + name = "hybrid-array" 818 + version = "0.4.8" 819 + source = "registry+https://github.com/rust-lang/crates.io-index" 820 + checksum = "8655f91cd07f2b9d0c24137bd650fe69617773435ee5ec83022377777ce65ef1" 821 + dependencies = [ 822 + "subtle", 823 + "typenum", 824 + "zeroize", 825 + ] 826 + 621 827 [[package]] 622 828 name = "i2cdev" 623 829 version = "0.6.2" ··· 654 860 "serde_core", 655 861 ] 656 862 863 + [[package]] 864 + name = "inout" 865 + version = "0.2.2" 866 + source = "registry+https://github.com/rust-lang/crates.io-index" 867 + checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" 868 + dependencies = [ 869 + "hybrid-array", 870 + ] 871 + 657 872 [[package]] 658 873 name = "io-kit-sys" 659 874 version = "0.4.1" ··· 681 896 682 897 [[package]] 683 898 name = "itoa" 684 - version = "1.0.17" 899 + version = "1.0.18" 685 900 source = "registry+https://github.com/rust-lang/crates.io-index" 686 - checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" 901 + checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" 687 902 688 903 [[package]] 689 904 name = "jiff" ··· 707 922 "syn", 708 923 ] 709 924 925 + [[package]] 926 + name = "k256" 927 + version = "0.14.0-rc.8" 928 + source = "registry+https://github.com/rust-lang/crates.io-index" 929 + checksum = "f7d2c6c227649d5ec80eaae541f1736232641a0bcdb3062a52b34edb42054158" 930 + dependencies = [ 931 + "cpubits", 932 + "ecdsa", 933 + "elliptic-curve", 934 + ] 935 + 710 936 [[package]] 711 937 name = "leb128fmt" 712 938 version = "0.1.0" ··· 715 941 716 942 [[package]] 717 943 name = "libc" 718 - version = "0.2.182" 944 + version = "0.2.183" 719 945 source = "registry+https://github.com/rust-lang/crates.io-index" 720 - checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" 946 + checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" 721 947 722 948 [[package]] 723 949 name = "libm" ··· 949 1175 950 1176 [[package]] 951 1177 name = "once_cell" 952 - version = "1.21.3" 1178 + version = "1.21.4" 953 1179 source = "registry+https://github.com/rust-lang/crates.io-index" 954 - checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 1180 + checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" 955 1181 956 1182 [[package]] 957 1183 name = "owo-colors" ··· 999 1225 checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220" 1000 1226 dependencies = [ 1001 1227 "pest", 1002 - "sha2", 1228 + "sha2 0.10.9", 1003 1229 ] 1004 1230 1005 1231 [[package]] ··· 1019 1245 source = "registry+https://github.com/rust-lang/crates.io-index" 1020 1246 checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 1021 1247 1248 + [[package]] 1249 + name = "poly1305" 1250 + version = "0.9.0-rc.6" 1251 + source = "registry+https://github.com/rust-lang/crates.io-index" 1252 + checksum = "19feddcbdf17fad33f40041c7f9e768faf19455f32a6d52ba1b8b65ffc7b1cae" 1253 + dependencies = [ 1254 + "cpufeatures 0.3.0", 1255 + "universal-hash", 1256 + ] 1257 + 1022 1258 [[package]] 1023 1259 name = "portable-atomic" 1024 1260 version = "1.13.1" ··· 1027 1263 1028 1264 [[package]] 1029 1265 name = "portable-atomic-util" 1030 - version = "0.2.5" 1266 + version = "0.2.6" 1031 1267 source = "registry+https://github.com/rust-lang/crates.io-index" 1032 - checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5" 1268 + checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" 1033 1269 dependencies = [ 1034 1270 "portable-atomic", 1035 1271 ] ··· 1177 1413 source = "registry+https://github.com/rust-lang/crates.io-index" 1178 1414 checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" 1179 1415 1416 + [[package]] 1417 + name = "rand_core" 1418 + version = "0.10.0" 1419 + source = "registry+https://github.com/rust-lang/crates.io-index" 1420 + checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" 1421 + 1180 1422 [[package]] 1181 1423 name = "regex" 1182 1424 version = "1.12.3" ··· 1212 1454 source = "registry+https://github.com/rust-lang/crates.io-index" 1213 1455 checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" 1214 1456 1457 + [[package]] 1458 + name = "rustcrypto-ff" 1459 + version = "0.14.0-rc.0" 1460 + source = "registry+https://github.com/rust-lang/crates.io-index" 1461 + checksum = "c5db129183b2c139d7d87d08be57cba626c715789db17aec65c8866bfd767d1f" 1462 + dependencies = [ 1463 + "rand_core", 1464 + "subtle", 1465 + ] 1466 + 1467 + [[package]] 1468 + name = "rustcrypto-group" 1469 + version = "0.14.0-rc.0" 1470 + source = "registry+https://github.com/rust-lang/crates.io-index" 1471 + checksum = "57c4b1463f274a3ff6fb2f44da43e576cb9424367bd96f185ead87b52fe00523" 1472 + dependencies = [ 1473 + "rand_core", 1474 + "rustcrypto-ff", 1475 + "subtle", 1476 + ] 1477 + 1215 1478 [[package]] 1216 1479 name = "rustix" 1217 1480 version = "0.38.44" ··· 1260 1523 "toml_edit", 1261 1524 ] 1262 1525 1526 + [[package]] 1527 + name = "sachy-crypto" 1528 + version = "0.1.0" 1529 + dependencies = [ 1530 + "chacha20poly1305", 1531 + "k256", 1532 + "sha2 0.11.0-rc.5", 1533 + ] 1534 + 1263 1535 [[package]] 1264 1536 name = "sachy-esphome" 1265 1537 version = "0.1.0" ··· 1299 1571 "defmt 1.0.1", 1300 1572 "embassy-time", 1301 1573 "sachy-fmt", 1302 - "winnow", 1574 + "winnow 0.7.15", 1303 1575 ] 1304 1576 1305 1577 [[package]] ··· 1330 1602 source = "registry+https://github.com/rust-lang/crates.io-index" 1331 1603 checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 1332 1604 1605 + [[package]] 1606 + name = "sec1" 1607 + version = "0.8.0" 1608 + source = "registry+https://github.com/rust-lang/crates.io-index" 1609 + checksum = "f46b9a5ab87780a3189a1d704766579517a04ad59de653b7aad7d38e8a15f7dc" 1610 + dependencies = [ 1611 + "base16ct", 1612 + "ctutils", 1613 + "der", 1614 + "hybrid-array", 1615 + "subtle", 1616 + "zeroize", 1617 + ] 1618 + 1333 1619 [[package]] 1334 1620 name = "semver" 1335 1621 version = "1.0.27" ··· 1381 1667 1382 1668 [[package]] 1383 1669 name = "serialport" 1384 - version = "4.7.3" 1670 + version = "4.9.0" 1385 1671 source = "registry+https://github.com/rust-lang/crates.io-index" 1386 - checksum = "2acaf3f973e8616d7ceac415f53fc60e190b2a686fbcf8d27d0256c741c5007b" 1672 + checksum = "a4d91116f97173694f1642263b2ff837f80d933aa837e2314969f6728f661df3" 1387 1673 dependencies = [ 1388 1674 "bitflags 2.11.0", 1389 1675 "cfg-if", ··· 1394 1680 "nix 0.26.4", 1395 1681 "scopeguard", 1396 1682 "unescaper", 1397 - "winapi", 1683 + "windows-sys 0.52.0", 1398 1684 ] 1399 1685 1400 1686 [[package]] ··· 1404 1690 checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" 1405 1691 dependencies = [ 1406 1692 "cfg-if", 1407 - "cpufeatures", 1408 - "digest", 1693 + "cpufeatures 0.2.17", 1694 + "digest 0.10.7", 1695 + ] 1696 + 1697 + [[package]] 1698 + name = "sha2" 1699 + version = "0.11.0-rc.5" 1700 + source = "registry+https://github.com/rust-lang/crates.io-index" 1701 + checksum = "7c5f3b1e2dc8aad28310d8410bd4d7e180eca65fca176c52ab00d364475d0024" 1702 + dependencies = [ 1703 + "cfg-if", 1704 + "cpufeatures 0.2.17", 1705 + "digest 0.11.2", 1409 1706 ] 1410 1707 1411 1708 [[package]] ··· 1414 1711 source = "registry+https://github.com/rust-lang/crates.io-index" 1415 1712 checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 1416 1713 1714 + [[package]] 1715 + name = "signature" 1716 + version = "3.0.0-rc.10" 1717 + source = "registry+https://github.com/rust-lang/crates.io-index" 1718 + checksum = "7f1880df446116126965eeec169136b2e0251dba37c6223bcc819569550edea3" 1719 + dependencies = [ 1720 + "rand_core", 1721 + ] 1722 + 1417 1723 [[package]] 1418 1724 name = "smoltcp" 1419 1725 version = "0.12.0" ··· 1450 1756 source = "registry+https://github.com/rust-lang/crates.io-index" 1451 1757 checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 1452 1758 1759 + [[package]] 1760 + name = "subtle" 1761 + version = "2.6.1" 1762 + source = "registry+https://github.com/rust-lang/crates.io-index" 1763 + checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 1764 + 1453 1765 [[package]] 1454 1766 name = "supports-color" 1455 1767 version = "3.0.2" ··· 1493 1805 1494 1806 [[package]] 1495 1807 name = "tempfile" 1496 - version = "3.26.0" 1808 + version = "3.27.0" 1497 1809 source = "registry+https://github.com/rust-lang/crates.io-index" 1498 - checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" 1810 + checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" 1499 1811 dependencies = [ 1500 1812 "fastrand", 1501 1813 "getrandom", ··· 1566 1878 1567 1879 [[package]] 1568 1880 name = "toml_datetime" 1569 - version = "1.0.0+spec-1.1.0" 1881 + version = "1.0.1+spec-1.1.0" 1570 1882 source = "registry+https://github.com/rust-lang/crates.io-index" 1571 - checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e" 1883 + checksum = "9b320e741db58cac564e26c607d3cc1fdc4a88fd36c879568c07856ed83ff3e9" 1572 1884 dependencies = [ 1573 1885 "serde_core", 1574 1886 ] 1575 1887 1576 1888 [[package]] 1577 1889 name = "toml_edit" 1578 - version = "0.25.4+spec-1.1.0" 1890 + version = "0.25.5+spec-1.1.0" 1579 1891 source = "registry+https://github.com/rust-lang/crates.io-index" 1580 - checksum = "7193cbd0ce53dc966037f54351dbbcf0d5a642c7f0038c382ef9e677ce8c13f2" 1892 + checksum = "8ca1a40644a28bce036923f6a431df0b34236949d111cc07cb6dca830c9ef2e1" 1581 1893 dependencies = [ 1582 1894 "indexmap", 1583 1895 "toml_datetime", 1584 1896 "toml_parser", 1585 1897 "toml_writer", 1586 - "winnow", 1898 + "winnow 1.0.0", 1587 1899 ] 1588 1900 1589 1901 [[package]] 1590 1902 name = "toml_parser" 1591 - version = "1.0.9+spec-1.1.0" 1903 + version = "1.0.10+spec-1.1.0" 1592 1904 source = "registry+https://github.com/rust-lang/crates.io-index" 1593 - checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" 1905 + checksum = "7df25b4befd31c4816df190124375d5a20c6b6921e2cad937316de3fccd63420" 1594 1906 dependencies = [ 1595 - "winnow", 1907 + "winnow 1.0.0", 1596 1908 ] 1597 1909 1598 1910 [[package]] 1599 1911 name = "toml_writer" 1600 - version = "1.0.6+spec-1.1.0" 1912 + version = "1.0.7+spec-1.1.0" 1601 1913 source = "registry+https://github.com/rust-lang/crates.io-index" 1602 - checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" 1914 + checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d" 1603 1915 1604 1916 [[package]] 1605 1917 name = "typenum" ··· 1652 1964 source = "registry+https://github.com/rust-lang/crates.io-index" 1653 1965 checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" 1654 1966 1967 + [[package]] 1968 + name = "universal-hash" 1969 + version = "0.6.1" 1970 + source = "registry+https://github.com/rust-lang/crates.io-index" 1971 + checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" 1972 + dependencies = [ 1973 + "crypto-common 0.2.1", 1974 + "ctutils", 1975 + ] 1976 + 1655 1977 [[package]] 1656 1978 name = "version_check" 1657 1979 version = "0.9.5" ··· 1728 2050 "rustix 0.38.44", 1729 2051 ] 1730 2052 1731 - [[package]] 1732 - name = "winapi" 1733 - version = "0.3.9" 1734 - source = "registry+https://github.com/rust-lang/crates.io-index" 1735 - checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1736 - dependencies = [ 1737 - "winapi-i686-pc-windows-gnu", 1738 - "winapi-x86_64-pc-windows-gnu", 1739 - ] 1740 - 1741 - [[package]] 1742 - name = "winapi-i686-pc-windows-gnu" 1743 - version = "0.4.0" 1744 - source = "registry+https://github.com/rust-lang/crates.io-index" 1745 - checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1746 - 1747 - [[package]] 1748 - name = "winapi-x86_64-pc-windows-gnu" 1749 - version = "0.4.0" 1750 - source = "registry+https://github.com/rust-lang/crates.io-index" 1751 - checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1752 - 1753 2053 [[package]] 1754 2054 name = "windows-link" 1755 2055 version = "0.2.1" 1756 2056 source = "registry+https://github.com/rust-lang/crates.io-index" 1757 2057 checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 1758 2058 2059 + [[package]] 2060 + name = "windows-sys" 2061 + version = "0.52.0" 2062 + source = "registry+https://github.com/rust-lang/crates.io-index" 2063 + checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 2064 + dependencies = [ 2065 + "windows-targets 0.52.6", 2066 + ] 2067 + 1759 2068 [[package]] 1760 2069 name = "windows-sys" 1761 2070 version = "0.59.0" ··· 1914 2223 1915 2224 [[package]] 1916 2225 name = "winnow" 1917 - version = "0.7.14" 2226 + version = "0.7.15" 2227 + source = "registry+https://github.com/rust-lang/crates.io-index" 2228 + checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" 2229 + 2230 + [[package]] 2231 + name = "winnow" 2232 + version = "1.0.0" 1918 2233 source = "registry+https://github.com/rust-lang/crates.io-index" 1919 - checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" 2234 + checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" 1920 2235 dependencies = [ 1921 2236 "memchr", 1922 2237 ] ··· 2009 2324 "wasmparser", 2010 2325 ] 2011 2326 2327 + [[package]] 2328 + name = "zeroize" 2329 + version = "1.8.2" 2330 + source = "registry+https://github.com/rust-lang/crates.io-index" 2331 + checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" 2332 + 2012 2333 [[package]] 2013 2334 name = "zmij" 2014 2335 version = "1.0.21"
+1
Cargo.toml
··· 4 4 "sachy-battery", 5 5 "sachy-bthome", 6 6 "sachy-config", 7 + "sachy-crypto", 7 8 "sachy-esphome", 8 9 "sachy-fmt", 9 10 "sachy-fnv",
+13
sachy-crypto/Cargo.toml
··· 1 + [package] 2 + name = "sachy-crypto" 3 + authors.workspace = true 4 + edition.workspace = true 5 + repository.workspace = true 6 + license.workspace = true 7 + version.workspace = true 8 + rust-version.workspace = true 9 + 10 + [dependencies] 11 + chacha20poly1305 = { version = "=0.11.0-rc.3", default-features = false, features = ["getrandom", "alloc"] } 12 + k256 = { version = "=0.14.0-rc.8", default-features = false, features = ["ecdh", "getrandom"] } 13 + sha2 = { version = "=0.11.0-rc.5", default-features = false, features = [] }
+366
sachy-crypto/src/lib.rs
··· 1 + #![no_std] 2 + 3 + use core::ops::{AddAssign, Sub}; 4 + 5 + use chacha20poly1305::{ 6 + AeadCore, AeadInOut, ChaCha20Poly1305, KeyInit, 7 + aead::{ 8 + self, Buffer, 9 + array::{Array, ArraySize}, 10 + common::array::typenum::Unsigned, 11 + }, 12 + consts::U8, 13 + }; 14 + use k256::{ 15 + PublicKey, Sec1Point, 16 + ecdh::{EphemeralSecret, SharedSecret}, 17 + elliptic_curve::{Generate, subtle::ConstantTimeEq}, 18 + }; 19 + 20 + extern crate alloc; 21 + 22 + struct HandshakeTurn(bool); 23 + 24 + impl HandshakeTurn { 25 + fn next_turn(&mut self) { 26 + self.0 = !self.0; 27 + } 28 + 29 + fn is_mine(&self) -> bool { 30 + self.0 31 + } 32 + } 33 + 34 + pub struct Handshake { 35 + turn: HandshakeTurn, 36 + ephemeral: EphemeralSecret, 37 + shared: Option<SharedSecret>, 38 + sent_public: bool, 39 + } 40 + 41 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 42 + pub enum HandshakeError { 43 + InvalidTurn, 44 + InvalidSec1Bytes, 45 + BufferTooSmall, 46 + UnfinishedHandshake, 47 + } 48 + 49 + impl Handshake { 50 + pub fn client() -> Self { 51 + Self { 52 + turn: HandshakeTurn(true), 53 + ephemeral: EphemeralSecret::generate(), 54 + shared: None, 55 + sent_public: false, 56 + } 57 + } 58 + 59 + pub fn server() -> Self { 60 + Self { 61 + turn: HandshakeTurn(false), 62 + ephemeral: EphemeralSecret::generate(), 63 + shared: None, 64 + sent_public: false, 65 + } 66 + } 67 + 68 + pub fn send<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8], HandshakeError> { 69 + if !self.turn.is_mine() { 70 + return Err(HandshakeError::InvalidTurn); 71 + } 72 + 73 + let pub_key = self.ephemeral.public_key(); 74 + 75 + let sec = Sec1Point::from(pub_key); 76 + 77 + let len = sec.len(); 78 + 79 + if buf.len() < len { 80 + return Err(HandshakeError::BufferTooSmall); 81 + } 82 + 83 + buf[..len].copy_from_slice(sec.as_bytes()); 84 + 85 + self.turn.next_turn(); 86 + self.sent_public = true; 87 + 88 + Ok(&buf[..len]) 89 + } 90 + 91 + pub fn receive(&mut self, buf: &[u8]) -> Result<(), HandshakeError> { 92 + let public_key = 93 + PublicKey::from_sec1_bytes(buf).map_err(|_| HandshakeError::InvalidSec1Bytes)?; 94 + 95 + self.turn.next_turn(); 96 + 97 + self.shared = Some(self.ephemeral.diffie_hellman(&public_key)); 98 + 99 + Ok(()) 100 + } 101 + 102 + pub fn finish(self) -> Result<SharedSecret, HandshakeError> { 103 + if !self.sent_public { 104 + return Err(HandshakeError::UnfinishedHandshake); 105 + } 106 + 107 + if let Some(shared) = self.shared { 108 + Ok(shared) 109 + } else { 110 + Err(HandshakeError::UnfinishedHandshake) 111 + } 112 + } 113 + } 114 + 115 + /// Error type. 116 + /// 117 + /// This type is deliberately opaque as to avoid potential side-channel 118 + /// leakage (e.g. padding oracle). 119 + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] 120 + pub struct AeadError; 121 + 122 + impl core::fmt::Display for AeadError { 123 + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 124 + f.write_str("aead::Error") 125 + } 126 + } 127 + 128 + impl core::error::Error for AeadError {} 129 + 130 + impl From<chacha20poly1305::Error> for AeadError { 131 + fn from(_value: chacha20poly1305::Error) -> Self { 132 + AeadError 133 + } 134 + } 135 + 136 + /// Nonce as used by a given AEAD construction and STREAM primitive. 137 + pub type Nonce<A, S> = chacha20poly1305::aead::array::Array<u8, NonceSize<A, S>>; 138 + 139 + /// Size of a nonce as used by a STREAM construction, sans the overhead of 140 + /// the STREAM protocol itself. 141 + pub type NonceSize<A, S> = 142 + <<A as AeadCore>::NonceSize as Sub<<S as StreamPrimitive<A>>::NonceOverhead>>::Output; 143 + 144 + /// Low-level STREAM implementation. 145 + /// 146 + /// This trait provides a particular "flavor" of STREAM, as there are 147 + /// different ways the specifics of the construction can be implemented. 148 + /// 149 + /// Deliberately immutable and stateless to permit parallel operation. 150 + pub trait StreamPrimitive<A> 151 + where 152 + A: AeadInOut, 153 + A::NonceSize: Sub<Self::NonceOverhead>, 154 + NonceSize<A, Self>: ArraySize, 155 + { 156 + /// Number of bytes this STREAM primitive requires from the nonce. 157 + type NonceOverhead: ArraySize; 158 + 159 + /// Type used as the STREAM counter. 160 + type Counter: AddAssign + Copy + Default + Eq; 161 + 162 + /// Value to use when incrementing the STREAM counter (i.e. one) 163 + const COUNTER_INCR: Self::Counter; 164 + 165 + /// Maximum value of the STREAM counter. 166 + const COUNTER_MAX: Self::Counter; 167 + 168 + /// Encrypt an AEAD message in-place at the given position in the STREAM. 169 + fn encrypt_in_place( 170 + &self, 171 + position: Self::Counter, 172 + associated_data: &[u8], 173 + buffer: &mut dyn Buffer, 174 + ) -> Result<(), AeadError>; 175 + 176 + /// Decrypt an AEAD message in-place at the given position in the STREAM. 177 + fn decrypt_in_place( 178 + &self, 179 + position: Self::Counter, 180 + associated_data: &[u8], 181 + buffer: &mut dyn Buffer, 182 + ) -> Result<(), AeadError>; 183 + } 184 + 185 + pub struct TransportState { 186 + aead: ChaCha20Poly1305, 187 + epstein: Nonce<ChaCha20Poly1305, Self>, 188 + counter: u64, 189 + } 190 + 191 + impl StreamPrimitive<ChaCha20Poly1305> for TransportState { 192 + type NonceOverhead = U8; 193 + 194 + type Counter = u64; 195 + 196 + const COUNTER_INCR: Self::Counter = 1; 197 + 198 + const COUNTER_MAX: Self::Counter = u64::MAX; 199 + 200 + fn encrypt_in_place( 201 + &self, 202 + position: Self::Counter, 203 + associated_data: &[u8], 204 + buffer: &mut dyn Buffer, 205 + ) -> Result<(), AeadError> { 206 + let epstein = self.aead_nonce(position); 207 + self.aead 208 + .encrypt_in_place(&epstein, associated_data, buffer)?; 209 + Ok(()) 210 + } 211 + 212 + fn decrypt_in_place( 213 + &self, 214 + position: Self::Counter, 215 + associated_data: &[u8], 216 + buffer: &mut dyn Buffer, 217 + ) -> Result<(), AeadError> { 218 + let epstein = self.aead_nonce(position); 219 + self.aead 220 + .decrypt_in_place(&epstein, associated_data, buffer)?; 221 + Ok(()) 222 + } 223 + } 224 + 225 + impl TransportState { 226 + fn aead_nonce(&self, position: u64) -> aead::Nonce<ChaCha20Poly1305> { 227 + let mut result = Array::default(); 228 + 229 + let (prefix, tail) = result.split_at_mut(NonceSize::<ChaCha20Poly1305, Self>::to_usize()); 230 + 231 + prefix.copy_from_slice(&self.epstein); 232 + 233 + tail[..8].copy_from_slice(&position.to_be_bytes()); 234 + 235 + result 236 + } 237 + 238 + pub fn init(psk: &[u8; 32], shared: SharedSecret) -> Result<Self, AeadError> { 239 + let kdf = shared.extract::<sha2::Sha256>(Some(psk)); 240 + 241 + let mut key = [0u8; 32]; 242 + 243 + kdf.expand(b"sachy-crypto", &mut key) 244 + .map_err(|_| AeadError)?; 245 + 246 + let mut epstein = Nonce::<ChaCha20Poly1305, Self>::default(); 247 + 248 + kdf.expand(b"noncer", &mut epstein).map_err(|_| AeadError)?; 249 + 250 + Ok(Self { 251 + aead: ChaCha20Poly1305::new(&key.into()), 252 + epstein, 253 + counter: 0, 254 + }) 255 + } 256 + 257 + pub fn encrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), AeadError> { 258 + self.counter += Self::COUNTER_INCR; 259 + 260 + let counter_data = self.counter.to_be_bytes(); 261 + 262 + self.encrypt_in_place(self.counter, &counter_data, msg)?; 263 + 264 + if self.counter.ct_eq(&Self::COUNTER_MAX).into() { 265 + Err(AeadError) 266 + } else { 267 + Ok(()) 268 + } 269 + } 270 + 271 + pub fn decrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), AeadError> { 272 + self.counter += Self::COUNTER_INCR; 273 + 274 + let counter_data = self.counter.to_be_bytes(); 275 + 276 + self.decrypt_in_place(self.counter, &counter_data, msg)?; 277 + 278 + if self.counter.ct_eq(&Self::COUNTER_MAX).into() { 279 + Err(AeadError) 280 + } else { 281 + Ok(()) 282 + } 283 + } 284 + } 285 + 286 + #[cfg(test)] 287 + mod tests { 288 + use super::*; 289 + 290 + #[test] 291 + fn handshake_protocol_works() -> Result<(), HandshakeError> { 292 + let mut client = Handshake::client(); 293 + let mut server = Handshake::server(); 294 + 295 + let mut client_buf = alloc::vec![0u8; 2048]; 296 + let mut server_buf = alloc::vec![0u8; 2048]; 297 + 298 + let sent = client.send(&mut client_buf)?; 299 + server.receive(sent)?; 300 + 301 + let sent = server.send(&mut server_buf)?; 302 + client.receive(sent)?; 303 + 304 + let client_shared = client.finish()?; 305 + let server_shared = server.finish()?; 306 + 307 + assert_eq!( 308 + client_shared.raw_secret_bytes(), 309 + server_shared.raw_secret_bytes() 310 + ); 311 + 312 + Ok(()) 313 + } 314 + 315 + #[test] 316 + fn two_way_transport_sync_works() -> Result<(), AeadError> { 317 + let shared_secret = [ 318 + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 319 + 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 320 + 0x9c, 0x9d, 0x9e, 0x9f, 321 + ]; 322 + 323 + let psk: [u8; 32] = [ 324 + 31, 48, 29, 177, 88, 236, 186, 84, 65, 51, 214, 243, 174, 24, 45, 101, 229, 129, 62, 325 + 132, 45, 174, 183, 65, 89, 73, 107, 177, 77, 90, 164, 251, 326 + ]; 327 + 328 + let mut alice = TransportState::init(&psk, Array(shared_secret).into())?; 329 + let mut bob = TransportState::init(&psk, Array(shared_secret).into())?; 330 + 331 + let orig = b"Test Message, Please ignore.".to_vec(); 332 + 333 + let mut msg = orig.clone(); 334 + 335 + // a -> b 336 + alice.encrypt(&mut msg)?; 337 + 338 + assert_ne!(orig.as_slice(), msg.as_slice()); 339 + let a1 = msg.clone(); 340 + 341 + bob.decrypt(&mut msg)?; 342 + 343 + // a -> b 344 + alice.encrypt(&mut msg)?; 345 + 346 + assert_ne!(msg.as_slice(), a1.as_slice()); 347 + let a2 = msg.clone(); 348 + 349 + bob.decrypt(&mut msg)?; 350 + 351 + // b -> a 352 + bob.encrypt(&mut msg)?; 353 + 354 + // None of the ciphertexts should match each other 355 + assert_ne!(msg.as_slice(), a1.as_slice()); 356 + assert_ne!(msg.as_slice(), a2.as_slice()); 357 + assert_ne!(a1.as_slice(), a2.as_slice()); 358 + 359 + alice.decrypt(&mut msg)?; 360 + 361 + assert_eq!(orig.as_slice(), msg.as_slice()); 362 + assert_eq!(alice.counter, bob.counter); 363 + 364 + Ok(()) 365 + } 366 + }

History

8 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 failed
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
sachy.dev submitted #0
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments