From d9eae07863fb93d3f0c591a856a40e6baac61c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 13 Mar 2026 12:01:31 +0100 Subject: [PATCH 1/4] chore: Bump the SDK to 22a9115d --- Cargo.lock | 611 +++++++++++++++++++++++++++++++++-------- Cargo.toml | 8 +- src/vodozemac/ecies.rs | 2 +- 3 files changed, 503 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d1464ede..a0301f6dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,10 +20,20 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "generic-array", ] +[[package]] +name = "aead" +version = "0.6.0-rc.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b657e772794c6b04730ea897b66a058ccd866c16d1967da05eeeecec39043fe" +dependencies = [ + "crypto-common 0.2.1", + "inout 0.2.2", +] + [[package]] name = "aes" version = "0.8.4" @@ -31,8 +41,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher", - "cpufeatures", + "cipher 0.4.4", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes" +version = "0.9.0-rc.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04097e08a47d9ad181c2e1f4a5fabc9ae06ce8839a333ba9a949bcb0d31fd2a3" +dependencies = [ + "cipher 0.5.1", + "cpubits", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes-gcm" +version = "0.11.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22c0c90bbe8d4f77c3ca9ddabe41a1f8382d6fc1f7cea89459d0f320371f972" +dependencies = [ + "aead 0.6.0-rc.10", + "aes 0.9.0-rc.4", + "cipher 0.5.1", + "ctr 0.10.0-rc.4", + "ghash", + "subtle", ] [[package]] @@ -114,6 +149,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.22.1" @@ -152,7 +193,7 @@ dependencies = [ "cc", "cfg-if", "constant_time_eq", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -164,13 +205,22 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + [[package]] name = "block-padding" -version = "0.3.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b" dependencies = [ - "generic-array", + "hybrid-array", ] [[package]] @@ -208,11 +258,11 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cbc" -version = "0.1.2" +version = "0.2.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +checksum = "ab1412b9ae2463ede01f1e591412dfbcfeacecf40e8c4c3e0655814c19065c38" dependencies = [ - "cipher", + "cipher 0.5.1", ] [[package]] @@ -238,8 +288,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" dependencies = [ "cfg-if", - "cipher", - "cpufeatures", + "cipher 0.4.4", + "cpufeatures 0.2.17", +] + +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cipher 0.5.1", + "cpufeatures 0.3.0", + "rand_core 0.10.0", ] [[package]] @@ -248,24 +310,53 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" dependencies = [ - "aead", - "chacha20", - "cipher", - "poly1305", + "aead 0.5.2", + "chacha20 0.9.1", + "cipher 0.4.4", + "poly1305 0.8.0", "zeroize", ] +[[package]] +name = "chacha20poly1305" +version = "0.11.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9ed179664f12fd6f155f6dd632edf5f3806d48c228c67ff78366f2a0eb6b5e" +dependencies = [ + "aead 0.6.0-rc.10", + "chacha20 0.10.0", + "cipher 0.5.1", + "poly1305 0.9.0-rc.6", +] + [[package]] name = "cipher" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ - "crypto-common", - "inout", + "crypto-common 0.1.7", + "inout 0.1.4", "zeroize", ] +[[package]] +name = "cipher" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea" +dependencies = [ + "block-buffer 0.12.0", + "crypto-common 0.2.1", + "inout 0.2.2", +] + +[[package]] +name = "cmov" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3" + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -282,6 +373,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "const_panic" version = "0.2.15" @@ -297,6 +394,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" +[[package]] +name = "cpubits" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef0c543070d296ea414df2dd7625d1b24866ce206709d8a4a424f28377f5861" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -306,6 +409,27 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.7" @@ -313,17 +437,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", - "rand_core 0.6.4", "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" +dependencies = [ + "getrandom 0.4.2", + "hybrid-array", + "rand_core 0.10.0", +] + [[package]] name = "ctr" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher", + "cipher 0.4.4", +] + +[[package]] +name = "ctr" +version = "0.10.0-rc.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fee683dd898fbd052617b4514bc31f98bc32081a83b69ec46adef3b1ef4ae36f" +dependencies = [ + "cipher 0.5.1", +] + +[[package]] +name = "ctutils" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1005a6d4446f5120ef475ad3d2af2b30c49c2c9c6904258e3bb30219bebed5e4" +dependencies = [ + "cmov", ] [[package]] @@ -333,10 +485,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", + "curve25519-dalek-derive", + "fiat-crypto 0.2.9", + "rustc_version", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "5.0.0-pre.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335f1947f241137a14106b6f5acc5918a5ede29c9d71d3f2cb1678d5075d9fc3" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", "curve25519-dalek-derive", - "digest", - "fiat-crypto", + "digest 0.11.1", + "fiat-crypto 0.3.0", "rustc_version", "serde", "subtle", @@ -421,7 +587,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "zeroize", ] @@ -524,11 +690,23 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", "subtle", ] +[[package]] +name = "digest" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "285743a676ccb6b3e116bc14cc69319b957867930ae9c4822f8e0f54509d7243" +dependencies = [ + "block-buffer 0.12.0", + "const-oid 0.10.2", + "crypto-common 0.2.1", + "ctutils", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -542,26 +720,25 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.3" +version = "3.0.0-rc.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +checksum = "c6e914c7c52decb085cea910552e24c63ac019e3ab8bf001ff736da9a9d9d890" dependencies = [ - "pkcs8", "serde", "signature", ] [[package]] name = "ed25519-dalek" -version = "2.2.0" +version = "3.0.0-pre.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +checksum = "053618a4c3d3bc24f188aa660ae75a46eeab74ef07fb415c61431e5e7cd4749b" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 5.0.0-pre.6", "ed25519", - "rand_core 0.6.4", + "rand_core 0.10.0", "serde", - "sha2", + "sha2 0.11.0-rc.5", "subtle", "zeroize", ] @@ -572,6 +749,25 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "hkdf 0.12.4", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -616,12 +812,28 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -730,6 +942,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -766,10 +979,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 6.0.0", + "rand_core 0.10.0", "wasip2", "wasip3", + "wasm-bindgen", +] + +[[package]] +name = "ghash" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5" +dependencies = [ + "polyval", ] [[package]] @@ -797,6 +1022,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "growable-bloom-filter" version = "2.1.1" @@ -836,7 +1072,16 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ - "hmac", + "hmac 0.12.1", +] + +[[package]] +name = "hkdf" +version = "0.13.0-rc.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbb55385998ae66b8d2d5143c05c94b9025ab863966f0c94ce7a5fde30105092" +dependencies = [ + "hmac 0.13.0-rc.5", ] [[package]] @@ -845,7 +1090,36 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0-rc.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef451d73f36d8a3f93ad32c332ea01146c9650e1ec821a9b0e46c01277d544f8" +dependencies = [ + "digest 0.11.1", +] + +[[package]] +name = "hpke" +version = "0.14.0-pre.2" +source = "git+https://github.com/poljar/rust-hpke/?rev=85f5efbe#85f5efbe062544b74d98f3b5fdf498fb053f7a80" +dependencies = [ + "aead 0.6.0-rc.10", + "aes-gcm", + "chacha20poly1305 0.11.0-rc.3", + "getrandom 0.4.2", + "hkdf 0.13.0-rc.5", + "hybrid-array", + "p256", + "rand_core 0.10.0", + "sha2 0.11.0-rc.5", + "sha3", + "subtle", + "x25519-dalek 2.0.1", + "zeroize", ] [[package]] @@ -869,6 +1143,15 @@ dependencies = [ "itoa", ] +[[package]] +name = "hybrid-array" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8655f91cd07f2b9d0c24137bd650fe69617773435ee5ec83022377777ce65ef1" +dependencies = [ + "typenum", +] + [[package]] name = "icu_collections" version = "2.1.1" @@ -1054,10 +1337,19 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" dependencies = [ - "block-padding", "generic-array", ] +[[package]] +name = "inout" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" +dependencies = [ + "block-padding", + "hybrid-array", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1110,6 +1402,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "keccak" +version = "0.2.0-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882b69cb15b1f78b51342322a97ccd16f5123d1dc8a3da981a95244f488e8692" +dependencies = [ + "cpufeatures 0.3.0", +] + [[package]] name = "konst" version = "0.3.16" @@ -1283,7 +1584,7 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ "as_variant", "async-trait", @@ -1309,7 +1610,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ "eyeball-im", "futures-core", @@ -1332,21 +1633,21 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ - "aes", + "aes 0.8.4", "aquamarine", "as_variant", "async-trait", "bs58", "byteorder", "cfg-if", - "ctr", + "ctr 0.9.2", "eyeball", "futures-core", "futures-util", - "hkdf", - "hmac", + "hkdf 0.12.4", + "hmac 0.12.1", "itertools 0.14.0", "js_option", "matrix-sdk-common", @@ -1357,7 +1658,7 @@ dependencies = [ "ruma", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "subtle", "thiserror", "time", @@ -1400,14 +1701,14 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ "async-trait", "base64", "futures-util", - "getrandom 0.2.17", + "getrandom 0.4.2", "gloo-utils", - "hkdf", + "hkdf 0.12.4", "js-sys", "matrix-sdk-base", "matrix-sdk-crypto", @@ -1418,7 +1719,7 @@ dependencies = [ "serde", "serde-wasm-bindgen", "serde_json", - "sha2", + "sha2 0.10.9", "thiserror", "tokio", "tracing", @@ -1431,7 +1732,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ "byteorder", "qrcode", @@ -1443,19 +1744,19 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=8472b55#8472b5504efd34074acab2cd9fcbbca5c5ec5d3e" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" dependencies = [ "base64", "blake3", - "chacha20poly1305", - "getrandom 0.2.17", - "hmac", + "chacha20poly1305 0.10.1", + "getrandom 0.4.2", + "hmac 0.12.1", "pbkdf2", "rand 0.8.5", "rmp-serde", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "thiserror", "zeroize", ] @@ -1573,6 +1874,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "elliptic-curve", + "primeorder", +] + [[package]] name = "parking_lot" version = "0.12.5" @@ -1602,7 +1913,7 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -1656,24 +1967,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] -name = "pkcs8" -version = "0.10.2" +name = "poly1305" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ - "der", - "spki", + "cpufeatures 0.2.17", + "opaque-debug", + "universal-hash 0.5.1", ] [[package]] name = "poly1305" -version = "0.8.0" +version = "0.9.0-rc.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +checksum = "19feddcbdf17fad33f40041c7f9e768faf19455f32a6d52ba1b8b65ffc7b1cae" dependencies = [ - "cpufeatures", - "opaque-debug", - "universal-hash", + "cpufeatures 0.3.0", + "universal-hash 0.6.1", +] + +[[package]] +name = "polyval" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfc63250416fea14f5749b90725916a6c903f599d51cb635aa7a52bfd03eede" +dependencies = [ + "cpubits", + "cpufeatures 0.3.0", + "universal-hash 0.6.1", ] [[package]] @@ -1716,6 +2038,15 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -1757,9 +2088,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.5" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" +checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568" dependencies = [ "bytes", "prost-derive", @@ -1767,12 +2098,12 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.5" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" +checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" dependencies = [ "anyhow", - "itertools 0.14.0", + "itertools 0.10.5", "proc-macro2", "quote", "syn 2.0.117", @@ -1826,6 +2157,17 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +dependencies = [ + "chacha20 0.10.0", + "getrandom 0.4.2", + "rand_core 0.10.0", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -1864,6 +2206,12 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + [[package]] name = "rand_xoshiro" version = "0.7.0" @@ -1948,7 +2296,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.14.1" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "assign", "js_int", @@ -1963,7 +2311,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.22.1" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "as_variant", "assign", @@ -1986,7 +2334,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "as_variant", "base64", @@ -1995,7 +2343,6 @@ dependencies = [ "getrandom 0.2.17", "http", "indexmap", - "js-sys", "js_int", "konst", "percent-encoding", @@ -2019,22 +2366,18 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.32.1" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "as_variant", "indexmap", "js_int", "js_option", - "percent-encoding", - "regex", "ruma-common", - "ruma-identifiers-validation", "ruma-macros", "serde", "serde_json", "thiserror", "tracing", - "url", "web-time", "wildmatch", "zeroize", @@ -2043,7 +2386,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.6.0" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "as_variant", "html5ever", @@ -2054,7 +2397,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "js_int", "thiserror", @@ -2063,7 +2406,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=84330744788e24137ee0fe0289ac2cdd40a28dd7#84330744788e24137ee0fe0289ac2cdd40a28dd7" +source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" dependencies = [ "as_variant", "cfg-if", @@ -2123,6 +2466,19 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + [[package]] name = "semver" version = "1.0.27" @@ -2222,8 +2578,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0-rc.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c5f3b1e2dc8aad28310d8410bd4d7e180eca65fca176c52ab00d364475d0024" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.11.1", +] + +[[package]] +name = "sha3" +version = "0.11.0-rc.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f78cd62cc39ece5aefbeb6caaa2ea44f70b4815d4b85f7e150ac685ada2bb5" +dependencies = [ + "digest 0.11.1", + "keccak", ] [[package]] @@ -2243,12 +2620,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signature" -version = "2.2.0" +version = "3.0.0-rc.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "rand_core 0.6.4", -] +checksum = "7f1880df446116126965eeec169136b2e0251dba37c6223bcc819569550edea3" [[package]] name = "siphasher" @@ -2271,16 +2645,6 @@ dependencies = [ "serde", ] -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -2655,10 +3019,20 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "subtle", ] +[[package]] +name = "universal-hash" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" +dependencies = [ + "crypto-common 0.2.1", + "ctutils", +] + [[package]] name = "url" version = "2.5.8" @@ -2754,30 +3128,31 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vodozemac" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c022a277687e4e8685d72b95a7ca3ccfec907daa946678e715f8badaa650883d" +source = "git+https://github.com/matrix-org/vodozemac/?rev=f17e2bd4#f17e2bd42b47378be0fd161396b9ee7b4dceb84a" dependencies = [ - "aes", + "aes 0.9.0-rc.4", "arrayvec", "base64", "base64ct", "cbc", - "chacha20poly1305", - "curve25519-dalek", + "chacha20poly1305 0.11.0-rc.3", + "cipher 0.5.1", + "curve25519-dalek 5.0.0-pre.6", "ed25519-dalek", - "getrandom 0.2.17", - "hkdf", - "hmac", + "getrandom 0.4.2", + "hkdf 0.13.0-rc.5", + "hmac 0.13.0-rc.5", + "hpke", "matrix-pickle", "prost", - "rand 0.8.5", + "rand 0.10.0", "serde", "serde_bytes", "serde_json", - "sha2", + "sha2 0.11.0-rc.5", "subtle", "thiserror", - "x25519-dalek", + "x25519-dalek 3.0.0-pre.6", "zeroize", ] @@ -3137,8 +3512,18 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 4.1.3", "rand_core 0.6.4", +] + +[[package]] +name = "x25519-dalek" +version = "3.0.0-pre.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d5d6ff67acd3945b933e592bfa7143db4fcbb2f871754b6b9fbd7847fc5aea" +dependencies = [ + "curve25519-dalek 5.0.0-pre.6", + "rand_core 0.10.0", "serde", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index ec0dbc426..d9b2335ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,9 +64,9 @@ futures-util = "0.3.27" getrandom = { version = "0.3.0", features = ["wasm_js"] } http = "1.1.0" js-sys = "0.3.91" -matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "8472b55" } -matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "8472b55" } -matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "8472b55" } +matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } +matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } +matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } serde = "1.0.91" serde_json = "1.0.91" serde-wasm-bindgen = "0.6.5" @@ -86,7 +86,7 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] } default-features = false features = ["js", "automatic-room-key-forwarding", "experimental-encrypted-state-events"] git = "https://github.com/matrix-org/matrix-rust-sdk" -rev = "8472b55" +rev = "22a9115d" [lints.rust] # Workaround for https://github.com/rustwasm/wasm-bindgen/issues/4283, while we work up the courage to upgrade diff --git a/src/vodozemac/ecies.rs b/src/vodozemac/ecies.rs index ecaf851e5..94f6293d7 100644 --- a/src/vodozemac/ecies.rs +++ b/src/vodozemac/ecies.rs @@ -184,7 +184,7 @@ impl CheckCode { /// The number should be displayed with a leading 0 in case the first digit /// is a 0. pub fn to_digit(&self) -> u8 { - self.inner.to_digit() + self.inner.to_digit(ecies::DigitMode::AllowLeadingZero) } } From 04d0abc6f89982612bd87b36b5efba178478dd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 13 Mar 2026 12:04:53 +0100 Subject: [PATCH 2/4] feat: Expose the HPKE module from vodozemac --- src/vodozemac/hpke.rs | 303 ++++++++++++++++++++++++++++++++++++++++++ src/vodozemac/mod.rs | 1 + tests/hpke.test.ts | 41 ++++++ 3 files changed, 345 insertions(+) create mode 100644 src/vodozemac/hpke.rs create mode 100644 tests/hpke.test.ts diff --git a/src/vodozemac/hpke.rs b/src/vodozemac/hpke.rs new file mode 100644 index 000000000..32db62f1c --- /dev/null +++ b/src/vodozemac/hpke.rs @@ -0,0 +1,303 @@ +//! This module implements [HPKE](https://www.rfc-editor.org/rfc/rfc9180.html). +//! +//! Please take a look at the vodozemac documentation of this module for more +//! info. + +#![allow(missing_debug_implementations)] +use std::sync::{Arc, Mutex}; + +use matrix_sdk_crypto::vodozemac::hpke; +use wasm_bindgen::prelude::*; + +use super::Curve25519PublicKey; + +fn used_up_error() -> JsError { + JsError::new("The HPKE channel was already established and used up.") +} + +/// The result of an recipient HPKE channel establishment. +#[wasm_bindgen(getter_with_clone)] +pub struct HpkeRecipientCreationResult { + /// The established HPKE channel. + pub channel: UnidirectionalRecipientChannel, + /// The plaintext of the initial message. + pub message: String, +} + +/// The result of an inbound HPKE channel establishment. +#[wasm_bindgen(getter_with_clone)] +pub struct HpkeSenderCreationResult { + /// The established HPKE channel. + pub channel: UnidirectionalSenderChannel, + /// The initial encrypted message. + pub message: String, +} + +/// The result of an outbound HPKE channel establishment. +#[wasm_bindgen(getter_with_clone)] +pub struct BidirectionalCreationResult { + /// The fully established HPKE channel. + pub channel: EstablishedHpkeChannel, + /// The initial response. + #[wasm_bindgen(js_name = "initialResponse")] + pub initial_response: String, +} + +/// An unestablished HPKE session. +#[wasm_bindgen] +pub struct HpkeRecipientChannel { + inner: Option, + public_key: Curve25519PublicKey, +} + +#[wasm_bindgen] +impl HpkeRecipientChannel { + /// Create a new, random, unestablished HPKE session. + /// + /// This method will use the + /// [`MATRIX_QR_CODE_LOGIN`](https://github.com/matrix-org/matrix-spec-proposals/pull/4108) + /// info for domain separation when creating the session. + #[wasm_bindgen(constructor)] + pub fn new() -> Self { + let inner = hpke::HpkeRecipientChannel::new(); + let public_key = inner.public_key().into(); + + Self { inner: Some(inner), public_key } + } + + /// Get our { @link Curve25519PublicKey }. + /// + /// This public key needs to be sent to the other side to be able to + /// establish an HPKE channel. + #[wasm_bindgen(getter, js_name = "publicKey")] + pub fn public_key(&self) -> Curve25519PublicKey { + self.public_key.clone() + } + + /// Create a { @link UnidirectionalRecipientChannel } from an initial + /// message encrypted by the other side. + #[wasm_bindgen(js_name = "establishChannel")] + pub fn establish_channel( + &mut self, + initial_message: &str, + aad: &str, + ) -> Result { + let message = hpke::InitialMessage::decode(&initial_message)?; + let result = self + .inner + .take() + .ok_or_else(used_up_error)? + .establish_channel(&message, aad.as_bytes())?; + + let message = String::from_utf8_lossy(&result.message).to_string(); + + Ok(HpkeRecipientCreationResult { message, channel: result.channel.into() }) + } +} + +#[wasm_bindgen] +#[derive(Clone)] +pub struct UnidirectionalRecipientChannel { + inner: Arc>>, +} + +#[wasm_bindgen] +impl UnidirectionalRecipientChannel { + #[wasm_bindgen(js_name = "establishBidirectionalChannel")] + pub fn establish_bidirectional_channel( + &mut self, + initial_response: &str, + aad: &str, + ) -> Result { + let hpke::BidirectionalCreationResult { channel, message } = self + .inner + .lock() + .unwrap() + .take() + .ok_or_else(used_up_error)? + .establish_bidirectional_channel(&initial_response.as_bytes(), aad.as_bytes()); + + Ok(BidirectionalCreationResult { + channel: channel.into(), + initial_response: message.encode(), + }) + } +} + +/// An unestablished HPKE channel. +#[wasm_bindgen] +pub struct HpkeSenderChannel { + inner: Option, +} + +#[wasm_bindgen] +impl HpkeSenderChannel { + /// Create a new, random, unestablished HPKE session. + /// + /// This method will use the + /// [`MATRIX_QR_CODE_LOGIN`](https://github.com/matrix-org/matrix-spec-proposals/pull/4108) + /// info for domain separation when creating the session. + #[wasm_bindgen(constructor)] + pub fn new() -> Self { + let inner = hpke::HpkeSenderChannel::new(); + + Self { inner: Some(inner) } + } + + /// Create a { @link UnidirectionalRecipientChannel } from an initial + /// message encrypted by the other side. + #[wasm_bindgen(js_name = "establishChannel")] + pub fn establish_channel( + &mut self, + their_public_key: Curve25519PublicKey, + initial_message: &str, + aad: &str, + ) -> Result { + let hpke::SenderCreationResult { channel, message } = self + .inner + .take() + .ok_or_else(used_up_error)? + .establish_channel(their_public_key.inner, &initial_message.as_bytes(), aad.as_bytes()); + + Ok(HpkeSenderCreationResult { message: message.encode(), channel: channel.into() }) + } +} + +#[wasm_bindgen] +#[derive(Clone)] +pub struct UnidirectionalSenderChannel { + inner: Arc>>, +} + +#[wasm_bindgen] +impl UnidirectionalSenderChannel { + #[wasm_bindgen(js_name = "establishBidirectionalChannel")] + pub fn establish_bidirectional_channel( + &mut self, + initial_response: &str, + aad: &str, + ) -> Result { + let initial_response = hpke::InitialResponse::decode(initial_response)?; + + let hpke::BidirectionalCreationResult { channel, message } = self + .inner + .lock() + .unwrap() + .take() + .ok_or_else(used_up_error)? + .establish_bidirectional_channel(&initial_response, aad.as_bytes())?; + + let message = String::from_utf8(message)?; + + Ok(BidirectionalCreationResult { channel: channel.into(), initial_response: message }) + } +} + +/// A fully established HPKE channel. +/// +/// This channel can be used to seal and open messages between the two +/// sides of the channel. +#[derive(Clone)] +#[wasm_bindgen] +pub struct EstablishedHpkeChannel { + inner: Arc>, +} + +#[wasm_bindgen] +impl EstablishedHpkeChannel { + /// Get our [`Curve25519PublicKey`]. + /// + /// This public key needs to be sent to the other side so that it can + /// complete the HPKE channel establishment. + #[wasm_bindgen(getter, js_name = "publicKey")] + pub fn public_key(&self) -> Curve25519PublicKey { + self.inner.lock().unwrap().public_key().into() + } + + /// Encrypt the given plaintext using this HPKE channel. + pub fn seal(&mut self, message: &str, aad: &str) -> String { + self.inner.lock().unwrap().seal(message.as_bytes(), aad.as_bytes()).encode() + } + + /// Decrypt the given message using this HPKE channel. + pub fn open(&mut self, message: &str, aad: &str) -> Result { + let message = hpke::Message::decode(message)?; + let result = self.inner.lock().unwrap().open(&message, aad.as_bytes())?; + + Ok(String::from_utf8_lossy(&result).to_string()) + } + + /// Get the [`CheckCode`] which uniquely identifies this { @link + /// EstablishedHpkeChannel }. + /// + /// This check code can be used to verify and confirm that both sides of the + /// session are indeed using the same shared secret. + #[wasm_bindgen(getter, js_name = "checkCode")] + pub fn check_code(&self) -> HpkeCheckCode { + self.inner.lock().unwrap().check_code().into() + } +} + +/// A check code that can be used to confirm that two { @link +/// EstablishedHpkeChannel } objects share the same secret. This is supposed to +/// be shared out-of-band to protect against active Man-in-the-middle (MITM) +/// attacks. +/// +/// Since the initiator device can always tell whether a MITM attack is in +/// progress after channel establishment, this code technically carries only a +/// single bit of information, representing whether the initiator has determined +/// that the channel is "secure" or "not secure". +/// +/// However, given this will need to be interactively confirmed by the user, +/// there is risk that the user would confirm the dialogue without paying +/// attention to its content. By expanding this single bit into a deterministic +/// two-digit check code, the user is forced to pay more attention by having to +/// enter it instead of just clicking through a dialogue. +#[derive(Clone)] +#[wasm_bindgen] +pub struct HpkeCheckCode { + inner: matrix_sdk_crypto::vodozemac::hpke::CheckCode, +} + +#[wasm_bindgen] +impl HpkeCheckCode { + /// Convert the check code to an array of two bytes. + /// + /// The bytes can be converted to a more user-friendly representation. The + /// [`CheckCode::to_digit`] converts the bytes to a two-digit number. + pub fn as_bytes(&self) -> Vec { + self.inner.as_bytes().to_vec() + } + + /// Convert the check code to two base-10 numbers. + /// + /// The number should be displayed with a leading 0 in case the first digit + /// is a 0. + pub fn to_digit(&self) -> u8 { + self.inner.to_digit(hpke::DigitMode::NoLeadingZero) + } +} + +impl From<&hpke::CheckCode> for HpkeCheckCode { + fn from(value: &matrix_sdk_crypto::vodozemac::hpke::CheckCode) -> Self { + Self { inner: value.clone() } + } +} + +impl From for EstablishedHpkeChannel { + fn from(value: hpke::EstablishedHpkeChannel) -> Self { + Self { inner: Mutex::new(value).into() } + } +} + +impl From for UnidirectionalRecipientChannel { + fn from(value: hpke::UnidirectionalRecipientChannel) -> Self { + Self { inner: Mutex::new(Some(value)).into() } + } +} + +impl From for UnidirectionalSenderChannel { + fn from(value: hpke::UnidirectionalSenderChannel) -> Self { + Self { inner: Mutex::new(Some(value)).into() } + } +} diff --git a/src/vodozemac/mod.rs b/src/vodozemac/mod.rs index 574c8df2d..42cdf15ef 100644 --- a/src/vodozemac/mod.rs +++ b/src/vodozemac/mod.rs @@ -7,6 +7,7 @@ use zeroize::{Zeroize, Zeroizing}; use crate::impl_from_to_inner; pub mod ecies; +pub mod hpke; pub mod pk_encryption; /// An Ed25519 public key, used to verify digital signatures. diff --git a/tests/hpke.test.ts b/tests/hpke.test.ts new file mode 100644 index 000000000..7480ee5c6 --- /dev/null +++ b/tests/hpke.test.ts @@ -0,0 +1,41 @@ +const { + HpkeRecipientChannel, + HpkeSenderChannel, + SecretsBundle, + UserId, + DeviceId, + OlmMachine, + RequestType, +} = require("@matrix-org/matrix-sdk-crypto-wasm"); + +describe("HPKE channel creation", () => { + test("can establish a channel and decrypt the initial message", () => { + const alice = new HpkeSenderChannel(); + const bob = new HpkeRecipientChannel(); + + const { message, channel: aliceUnidirectional } = alice.establishChannel( + bob.publicKey, + "It's a secret to everybody", + "AAD" + ); + + const { message: initialMessage, channel: bobUnidirectional } = bob.establishChannel(message, "AAD"); + expect(initialMessage).toStrictEqual("It's a secret to everybody"); + + const { initialResponse, channel: bobEstablished } = bobUnidirectional.establishBidirectionalChannel("Initial response", "AAD2"); + const { initialResponse: secondPlaintext, channel: aliceEstablished } = aliceUnidirectional.establishBidirectionalChannel(initialResponse, "AAD2"); + + expect(secondPlaintext).toStrictEqual("Initial response"); + + const aliceCheck = aliceEstablished.checkCode; + const bobCheck = bobEstablished.checkCode; + + expect(aliceCheck.as_bytes()).toStrictEqual(bobCheck.as_bytes()); + expect(aliceCheck.to_digit()).toStrictEqual(bobCheck.to_digit()); + + const ciphertext = bobEstablished.seal("Other message", ""); + const thirdPlaintext = aliceEstablished.open(ciphertext, ""); + + expect(thirdPlaintext).toStrictEqual("Other message"); + }); +}); From 9164fa3aba8569f0e7de7fa6855eb3d305315d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 18 Mar 2026 14:18:08 +0100 Subject: [PATCH 3/4] chore: Bump the SDK to 36217cda --- Cargo.lock | 29 +++++++++++++++-------------- Cargo.toml | 8 ++++---- src/vodozemac/hpke.rs | 11 ++++++----- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0301f6dc..00f4c7d6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1584,7 +1584,7 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "as_variant", "async-trait", @@ -1610,12 +1610,13 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "eyeball-im", "futures-core", "futures-executor", "futures-util", + "getrandom 0.3.4", "gloo-timers", "imbl", "ruma", @@ -1633,7 +1634,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "aes 0.8.4", "aquamarine", @@ -1701,7 +1702,7 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "async-trait", "base64", @@ -1732,7 +1733,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "byteorder", "qrcode", @@ -1744,7 +1745,7 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=22a9115d#22a9115d7b930982fa10d822fd8c652cc88ad99b" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" dependencies = [ "base64", "blake3", @@ -2296,7 +2297,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.14.1" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "assign", "js_int", @@ -2311,7 +2312,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.22.1" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "as_variant", "assign", @@ -2334,7 +2335,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "as_variant", "base64", @@ -2366,7 +2367,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.32.1" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "as_variant", "indexmap", @@ -2386,7 +2387,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.6.0" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "as_variant", "html5ever", @@ -2397,7 +2398,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "js_int", "thiserror", @@ -2406,7 +2407,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=2455c71ec8bd16318397865d9c6e231e792cb15e#2455c71ec8bd16318397865d9c6e231e792cb15e" +source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" dependencies = [ "as_variant", "cfg-if", @@ -3128,7 +3129,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vodozemac" version = "0.9.0" -source = "git+https://github.com/matrix-org/vodozemac/?rev=f17e2bd4#f17e2bd42b47378be0fd161396b9ee7b4dceb84a" +source = "git+https://github.com/matrix-org/vodozemac/?rev=7de70ace#7de70ace2bd1a408c648ff52d2bcf30f503a1443" dependencies = [ "aes 0.9.0-rc.4", "arrayvec", diff --git a/Cargo.toml b/Cargo.toml index d9b2335ef..68842aa17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,9 +64,9 @@ futures-util = "0.3.27" getrandom = { version = "0.3.0", features = ["wasm_js"] } http = "1.1.0" js-sys = "0.3.91" -matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } -matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } -matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "22a9115d" } +matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } +matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } +matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } serde = "1.0.91" serde_json = "1.0.91" serde-wasm-bindgen = "0.6.5" @@ -86,7 +86,7 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] } default-features = false features = ["js", "automatic-room-key-forwarding", "experimental-encrypted-state-events"] git = "https://github.com/matrix-org/matrix-rust-sdk" -rev = "22a9115d" +rev = "36217cda" [lints.rust] # Workaround for https://github.com/rustwasm/wasm-bindgen/issues/4283, while we work up the courage to upgrade diff --git a/src/vodozemac/hpke.rs b/src/vodozemac/hpke.rs index 32db62f1c..9dca914c2 100644 --- a/src/vodozemac/hpke.rs +++ b/src/vodozemac/hpke.rs @@ -153,11 +153,12 @@ impl HpkeSenderChannel { initial_message: &str, aad: &str, ) -> Result { - let hpke::SenderCreationResult { channel, message } = self - .inner - .take() - .ok_or_else(used_up_error)? - .establish_channel(their_public_key.inner, &initial_message.as_bytes(), aad.as_bytes()); + let hpke::SenderCreationResult { channel, message } = + self.inner.take().ok_or_else(used_up_error)?.establish_channel( + their_public_key.inner, + &initial_message.as_bytes(), + aad.as_bytes(), + )?; Ok(HpkeSenderCreationResult { message: message.encode(), channel: channel.into() }) } From ae0ee0f3f30776b44d83d9bdcec82a03d7d4d5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 20 Mar 2026 12:22:07 +0100 Subject: [PATCH 4/4] chore: Bump the SDK to aa5baf90 --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00f4c7d6f..65961ec35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1584,7 +1584,7 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "as_variant", "async-trait", @@ -1610,7 +1610,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "eyeball-im", "futures-core", @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "aes 0.8.4", "aquamarine", @@ -1702,7 +1702,7 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "async-trait", "base64", @@ -1733,7 +1733,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "byteorder", "qrcode", @@ -1745,7 +1745,7 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.16.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=36217cda#36217cdaa8bd7f4ea6295adfbadf6643fc5e7fba" +source = "git+https://github.com/matrix-org/matrix-rust-sdk?rev=aa5baf90#aa5baf90b1d71edd1c9a78ddc1731473010ad662" dependencies = [ "base64", "blake3", @@ -2297,7 +2297,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.14.1" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "assign", "js_int", @@ -2312,7 +2312,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.22.1" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "as_variant", "assign", @@ -2335,7 +2335,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "as_variant", "base64", @@ -2367,7 +2367,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.32.1" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "as_variant", "indexmap", @@ -2387,7 +2387,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.6.0" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "as_variant", "html5ever", @@ -2398,7 +2398,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.12.0" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "js_int", "thiserror", @@ -2407,7 +2407,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.17.1" -source = "git+https://github.com/ruma/ruma?rev=c242467a8ac13e691af10d69f76ca8c293e165db#c242467a8ac13e691af10d69f76ca8c293e165db" +source = "git+https://github.com/ruma/ruma?rev=7f461cb0115aeeb98c2167363759ef99d1a565ee#7f461cb0115aeeb98c2167363759ef99d1a565ee" dependencies = [ "as_variant", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 68842aa17..91d14da6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,9 +64,9 @@ futures-util = "0.3.27" getrandom = { version = "0.3.0", features = ["wasm_js"] } http = "1.1.0" js-sys = "0.3.91" -matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } -matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } -matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "36217cda" } +matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "aa5baf90" } +matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "aa5baf90" } +matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "aa5baf90" } serde = "1.0.91" serde_json = "1.0.91" serde-wasm-bindgen = "0.6.5" @@ -86,7 +86,7 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] } default-features = false features = ["js", "automatic-room-key-forwarding", "experimental-encrypted-state-events"] git = "https://github.com/matrix-org/matrix-rust-sdk" -rev = "36217cda" +rev = "aa5baf90" [lints.rust] # Workaround for https://github.com/rustwasm/wasm-bindgen/issues/4283, while we work up the courage to upgrade