feat: add orion-demo
This commit is contained in:
108
__crypto/orion-demo/Cargo.lock
generated
Normal file
108
__crypto/orion-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ct-codecs"
|
||||||
|
version = "1.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b10589d1a5e400d61f9f38f12f884cfd080ff345de8f17efda36fe0e4a02aa8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fiat-crypto"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.174"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "orion"
|
||||||
|
version = "0.17.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21b3da83b2b4cdc74ab6a556b2e7b473da046d5aa4008c0a7a3ae96b1b4aabb4"
|
||||||
|
dependencies = [
|
||||||
|
"ct-codecs",
|
||||||
|
"fiat-crypto",
|
||||||
|
"getrandom",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "orion-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"hex",
|
||||||
|
"orion",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||||
8
__crypto/orion-demo/Cargo.toml
Normal file
8
__crypto/orion-demo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "orion-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
hex = "0.4.3"
|
||||||
|
orion = "0.17.11"
|
||||||
44
__crypto/orion-demo/src/main.rs
Normal file
44
__crypto/orion-demo/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use orion::hazardous::ecc::x25519::key_agreement;
|
||||||
|
use orion::kex::{PrivateKey, PublicKey};
|
||||||
|
use orion::pwhash::{Password, hash_password, hash_password_verify};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let password = Password::from_slice(b"hello_world").unwrap();
|
||||||
|
let password_hash = hash_password(&password, 100, 1024).unwrap();
|
||||||
|
println!("{}", password_hash.unprotected_as_encoded());
|
||||||
|
println!("{:?}", hash_password_verify(&password_hash, &password));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let alice_sk = PrivateKey::generate();
|
||||||
|
let alice_pk = PublicKey::try_from(&alice_sk).unwrap();
|
||||||
|
|
||||||
|
let bob_sk = PrivateKey::generate();
|
||||||
|
let bob_pk = PublicKey::try_from(&bob_sk).unwrap();
|
||||||
|
|
||||||
|
let alice_shared = key_agreement(&alice_sk, &bob_pk).unwrap();
|
||||||
|
let bob_shared = key_agreement(&bob_sk, &alice_pk).unwrap();
|
||||||
|
|
||||||
|
println!("{}", hex::encode(alice_shared.unprotected_as_bytes()));
|
||||||
|
println!("{}", hex::encode(bob_shared.unprotected_as_bytes()));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let user_password = Password::from_slice(b"hello_world").unwrap();
|
||||||
|
let salt = orion::kdf::Salt::default();
|
||||||
|
let derived_key = orion::kdf::derive_key(&user_password, &salt, 3, 1 << 16, 32).unwrap();
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
hex::encode(salt.as_ref()),
|
||||||
|
hex::encode(derived_key.unprotected_as_bytes())
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let aead_key = orion::aead::SecretKey::generate(32).unwrap();
|
||||||
|
let ciphertext = orion::aead::seal(&aead_key, b"hello world").unwrap();
|
||||||
|
|
||||||
|
let plaintext = orion::aead::open(&aead_key, &ciphertext).unwrap();
|
||||||
|
println!("{}", hex::encode(&ciphertext));
|
||||||
|
println!("{} {}", hex::encode(&plaintext), String::from_utf8_lossy(&plaintext));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user