diff --git a/Cargo.lock b/Cargo.lock index 058ff12..7d6baa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,12 +18,12 @@ checksum = "d9aa1eef3994e2ccd304a78fe3fea4a73e5792007f85f09b79bb82143ca5f82b" [[package]] name = "belt-hash" -version = "0.1.1" +version = "0.2.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc405b3b8472f6e019aedf942fdee9516a0546d12e053d3744416e8f21ddb8a" +checksum = "4f27c3b1a850b9948ab73e1f8064ac701716cad53259d43d173017f7dd4b0ec6" dependencies = [ "belt-block", - "digest 0.10.7", + "digest", ] [[package]] @@ -34,20 +34,11 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-buffer" -version = "0.10.4" +version = "0.11.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "3ded684142010808eb980d9974ef794da2bcf97d13396143b1515e9f0fb4a10e" dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.11.0-pre.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edadbde8e0243b49d434f9a23ec0590af201f400a34d7d51049284e4a77c568" -dependencies = [ - "crypto-common 0.2.0-pre.4", + "crypto-common", ] [[package]] @@ -60,35 +51,25 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "concat-kdf" version = "0.2.0-pre" dependencies = [ - "digest 0.11.0-pre.4", + "digest", "hex-literal", "sha2", ] [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "crypto-common" -version = "0.2.0-pre.4" +version = "0.2.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806e4e3731d44f1340b069551225b44c2056c105cad9e67f0c46266db8a3a6b9" +checksum = "b7aa2ec04f5120b830272a481e8d9d8ba4dda140d2cda59b0f1110d5eb93c38e" dependencies = [ "getrandom", "hybrid-array", @@ -97,40 +78,20 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "crypto-common 0.1.6", -] - -[[package]] -name = "digest" -version = "0.11.0-pre.4" +version = "0.11.0-pre.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b429fb535b92bad18c86f1d7ee7584a175c2810800c7ac5b75b9408b13981979" +checksum = "065d93ead7c220b85d5b4be4795d8398eac4ff68b5ee63895de0a3c1fb6edf25" dependencies = [ - "block-buffer 0.11.0-pre.4", - "crypto-common 0.2.0-pre.4", + "block-buffer", + "crypto-common", "subtle", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -145,7 +106,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hkdf" -version = "0.13.0-pre.0" +version = "0.13.0-pre.3" dependencies = [ "blobby", "hex-literal", @@ -156,27 +117,27 @@ dependencies = [ [[package]] name = "hmac" -version = "0.13.0-pre.1" +version = "0.13.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad9bdb2c4daa57033321e5e64c7a8cab02086ee130f8702f72b5c164893026a" +checksum = "ffd790a0795ee332ed3e8959e5b177beb70d7112eb7d345428ec17427897d5ce" dependencies = [ - "digest 0.11.0-pre.4", + "digest", ] [[package]] name = "hybrid-array" -version = "0.2.0-rc.0" +version = "0.2.0-rc.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8c5517ac29f08e88170b9647d85cc5f21c2596de177b4867232e20b214b8da1" +checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" dependencies = [ "typenum", ] [[package]] name = "libc" -version = "0.2.151" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "rand_core" @@ -189,31 +150,31 @@ dependencies = [ [[package]] name = "sha1" -version = "0.11.0-pre.1" +version = "0.11.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "731912b869ff1fb4c6432ad4737a5951d5388fbdda0417163a29638206935fe6" +checksum = "3885de8cb916f223718c1ccd47a840b91f806333e76002dc5cb3862154b4fed3" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.11.0-pre.4", + "digest", ] [[package]] name = "sha2" -version = "0.11.0-pre.1" +version = "0.11.0-pre.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9daa731ca112bb569b34b41775363a461422813d8ed1ea6dba352eb58ec4e684" +checksum = "8f33549bf3064b62478926aa89cbfc7c109aab66ae8f0d5d2ef839e482cc30d6" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.11.0-pre.4", + "digest", ] [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "typenum" @@ -221,12 +182,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/bake-kdf/Cargo.toml b/bake-kdf/Cargo.toml index 573270a..5e57843 100644 --- a/bake-kdf/Cargo.toml +++ b/bake-kdf/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["crypto", "bake", "stb", "kdf"] categories = ["cryptography", "no-std"] [dependencies] -belt-hash = { version = "0.1.1", default-features = false } +belt-hash = { version = "0.2.0-pre.3", default-features = false } [dev-dependencies] hex-literal = "0.4.1" diff --git a/bake-kdf/src/lib.rs b/bake-kdf/src/lib.rs index afb96bc..22277cc 100644 --- a/bake-kdf/src/lib.rs +++ b/bake-kdf/src/lib.rs @@ -11,7 +11,7 @@ //! //! [1]: https://apmi.bsu.by/assets/files/std/bake-spec19.pdf -#![no_std] +// #![no_std] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", @@ -117,6 +117,12 @@ pub fn belt_keyrep( _ => unreachable!(), }; + let mut x_swapped = [0u32; 8]; + for (i, &val) in x.iter().enumerate() { + x_swapped[i] = u32::swap_bytes(val); + } + let x = &x_swapped[..(n / 32)]; + let s = belt_keyexpand(x).map_err(|_| InvalidKeyLength)?; let mut d = [d[0], d[1], d[2]]; let mut i = [i[0], i[1], i[2], i[3]]; @@ -154,6 +160,11 @@ pub fn bake_kdf(x: &[u8], s: &[u8], c: u128) -> Result<[u32; 8], Error> { hasher.update(x); hasher.update(s); let y = hasher.finalize_fixed(); + + let mut y = to_u32::<8>(&y); + for y in y.iter_mut() { + *y = u32::swap_bytes(*y); + } let d: [u32; 3] = [0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF]; @@ -161,6 +172,6 @@ pub fn bake_kdf(x: &[u8], s: &[u8], c: u128) -> Result<[u32; 8], Error> { c.reverse(); let mut out = [0u32; 8]; - belt_keyrep::<256>(&to_u32::<8>(&y), &d, &c, &mut out)?; + belt_keyrep::<256>(&y, &d, &c, &mut out)?; Ok(out) } diff --git a/bake-kdf/tests/tests.rs b/bake-kdf/tests/tests.rs index bcb26b5..c61ceba 100644 --- a/bake-kdf/tests/tests.rs +++ b/bake-kdf/tests/tests.rs @@ -28,15 +28,13 @@ fn test_keyexpand() { #[test] fn test_keyrep() { - let mut x: [u32; 8] = [ + let x: [u32; 8] = [ 0xE9DEE72C, 0x8F0C0FA6, 0x2DDB49F4, 0x6F739647, 0x06075316, 0xED247A37, 0x39CBA383, 0x03A98BF6, ]; let d: [u32; 3] = [0x01000000, 0x00000000, 0x00000000]; let i: [u32; 4] = [0x5BE3D612, 0x17B96181, 0xFE6786AD, 0x716B890B]; - - x.iter_mut().for_each(|x| *x = u32::swap_bytes(*x)); - + let out: &mut [u32] = &mut [0; 4]; belt_keyrep::<128>(&x, &d, &i, out).unwrap(); assert_eq!(out, [0x6BBBC233, 0x6670D31A, 0xB83DAA90, 0xD52C0541]);