feat: add ml kem demo
This commit is contained in:
23
README.md
23
README.md
@@ -5,7 +5,6 @@ Simple Rust Tests
|
||||
Project or files:
|
||||
```
|
||||
.
|
||||
├── README_2.md
|
||||
├── __alloc
|
||||
│ └── zeroizing-alloc-demo
|
||||
├── __args
|
||||
@@ -19,8 +18,8 @@ Project or files:
|
||||
│ └── zstd-demo
|
||||
├── __concurrent
|
||||
│ ├── arc-swap
|
||||
│ ├── async-fn-resumed-after-completion
|
||||
│ ├── async_study
|
||||
│ ├── async-fn-resumed-after-completion
|
||||
│ ├── crossbeam_n_parking_lot
|
||||
│ ├── glommio
|
||||
│ ├── green-threads
|
||||
@@ -46,6 +45,7 @@ Project or files:
|
||||
│ ├── jose-test
|
||||
│ ├── jsonwebtoken
|
||||
│ ├── liboqs-rust-demo
|
||||
│ ├── ml-kem-demo
|
||||
│ ├── okta-bcrypt-issue
|
||||
│ ├── orion-demo
|
||||
│ ├── passkey-rs-demo
|
||||
@@ -80,7 +80,7 @@ Project or files:
|
||||
│ └── sqlx
|
||||
├── __diff
|
||||
│ ├── diffy
|
||||
│ └── prettydiff
|
||||
│ ├── prettydiff
|
||||
├── __enclave
|
||||
│ └── virt_enclave
|
||||
├── __err
|
||||
@@ -92,9 +92,9 @@ Project or files:
|
||||
├── __ffi
|
||||
│ ├── abi_stable_crates
|
||||
│ ├── c
|
||||
│ ├── c2
|
||||
│ ├── c_export
|
||||
│ ├── c_layout
|
||||
│ ├── c2
|
||||
│ ├── calltoc
|
||||
│ ├── cpp
|
||||
│ ├── dotalib
|
||||
@@ -105,7 +105,7 @@ Project or files:
|
||||
├── __fs
|
||||
│ ├── crypt4ghfs-rust
|
||||
│ ├── fuse
|
||||
│ └── fuser
|
||||
│ ├── fuser
|
||||
├── __gui
|
||||
│ ├── druid
|
||||
│ ├── gtk
|
||||
@@ -180,8 +180,8 @@ Project or files:
|
||||
│ ├── pcap
|
||||
│ ├── pingora-demo
|
||||
│ ├── quinn
|
||||
│ ├── rust-rawsock-demo
|
||||
│ ├── rust_tcp
|
||||
│ ├── rust-rawsock-demo
|
||||
│ ├── s2n_quic
|
||||
│ ├── socket2
|
||||
│ ├── tcp
|
||||
@@ -227,10 +227,10 @@ Project or files:
|
||||
│ ├── sshrs
|
||||
│ └── xshell
|
||||
├── __shuttle
|
||||
│ └── hatter-test
|
||||
│ ├── hatter-test
|
||||
├── __std
|
||||
│ ├── async-fn
|
||||
│ ├── async_await
|
||||
│ ├── async-fn
|
||||
│ ├── into
|
||||
│ ├── iter
|
||||
│ ├── misc
|
||||
@@ -273,8 +273,8 @@ Project or files:
|
||||
│ ├── wasmtime-serde-demo
|
||||
│ └── wit-bindgen-sample
|
||||
├── __web
|
||||
│ ├── actix-web
|
||||
│ ├── actix_rustls
|
||||
│ ├── actix-web
|
||||
│ ├── alibabacloundfn
|
||||
│ ├── hyper_rustls
|
||||
│ ├── hyperrs
|
||||
@@ -288,8 +288,9 @@ Project or files:
|
||||
│ ├── tide
|
||||
│ └── warp
|
||||
├── build_readme.rs -> scripts/build_readme_rs/src/main.rs
|
||||
├── README_2.md
|
||||
├── scripts
|
||||
│ └── build_readme_rs
|
||||
│ ├── build_readme_rs
|
||||
└── single_file_tests
|
||||
├── 99.rs
|
||||
├── chain.rs
|
||||
@@ -313,6 +314,6 @@ Project or files:
|
||||
├── vec.rs
|
||||
└── while.rs
|
||||
|
||||
285 directories, 38 files
|
||||
286 directories, 38 files
|
||||
```
|
||||
|
||||
|
||||
258
__crypto/ml-kem-demo/Cargo.lock
generated
Normal file
258
__crypto/ml-kem-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,258 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
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 = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[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.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2d35805454dc9f8662a98d6d61886ffe26bd465f5960e0e55345c70d5c0d2a9"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keccak"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654"
|
||||
dependencies = [
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kem"
|
||||
version = "0.3.0-pre.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b8645470337db67b01a7f966decf7d0bafedbae74147d33e641c67a91df239f"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.176"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
|
||||
|
||||
[[package]]
|
||||
name = "ml-kem"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97befee0c869cb56f3118f49d0f9bb68c9e3f380dec23c1100aedc4ec3ba239a"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
"kem",
|
||||
"rand_core",
|
||||
"sha3",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ml-kem-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"ml-kem",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||
9
__crypto/ml-kem-demo/Cargo.toml
Normal file
9
__crypto/ml-kem-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "ml-kem-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22.1"
|
||||
ml-kem = { version = "0.2.1", features = ["zeroize"] }
|
||||
rand = "0.8"
|
||||
31
__crypto/ml-kem-demo/src/main.rs
Normal file
31
__crypto/ml-kem-demo/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use ml_kem::kem::Encapsulate;
|
||||
use ml_kem::{Encoded, EncodedSizeUser, KemCore, MlKem768};
|
||||
|
||||
fn main() {
|
||||
let ek_bytes = STANDARD.decode("fZKrgJTGZYMogAO0u8XI/skLXXCx/hCmQjKdEGGaBitoBWCrbaw\
|
||||
+t7nAT7G8lexlEdwGJrdwNuBVJFZOEnxH9Fu2e7kZrAA0EWZThrhrlCQb7SKSJ3MKP9jGeNA2igU/cXhQj9qSaWzNqplMffhuZHjBAT\
|
||||
Nxglk6IwBcUnNpgEit0dYJgsxsMkfD8AzOaHKm4ybKwzJtYBN6nREl/OZE9CvDtVmZx+wkE1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gatuqcDgIY2KH2NZapIOiRyZYs8shb2JJIRAWqcwRNIBL7ZwBOpafsyJc3BS4YSY\
|
||||
ErVdAOOZe8/G9mcrNwOKzkkPFDUsb+eBEdHIr4bCUGGyinLkGskkXb1Gl8FCbTOGU04ZZtqhFI6eP5Stb7MiY7ywRhiOvokduQTLN26\
|
||||
CsRJa579VOqdeSsNjFI6lxMhgwaxGaHcwWiGBDSbGGcyskujyPebYl+UlhDXGGVHYfZStkj8Sm84KGWqaq9BSQmIgU8oCj7SRMTGC3c\
|
||||
dmjK5QiTGV+LEZKWwpQ9+GU5TIrTqImmeBj+dpGoPFmbliytiKbH53ZsFCfVNMqOvJ24IxdfgWNpBmrChnYmLQ=").unwrap();
|
||||
|
||||
let e: Encoded<<MlKem768 as KemCore>::EncapsulationKey> =
|
||||
ek_bytes.as_slice().try_into().unwrap();
|
||||
let ek = <MlKem768 as KemCore>::EncapsulationKey::from_bytes(&e);
|
||||
let mut rng = rand::rngs::OsRng;
|
||||
let k = ek.encapsulate(&mut rng).unwrap();
|
||||
println!("{}", STANDARD.encode(k.0.as_slice()));
|
||||
println!("Shared secret: {}", STANDARD.encode(k.1.as_slice()));
|
||||
}
|
||||
Reference in New Issue
Block a user