feat: add crypto2-demo

This commit is contained in:
2023-02-12 13:37:29 +08:00
parent d1b1132cc3
commit 8803a8500a
3 changed files with 65 additions and 0 deletions

31
__crypto/crypto2-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,31 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crypto2"
version = "0.2.0"
source = "git+https://github.com/shadowsocks/crypto2#dbfd3bb4751abd9945370dee25350765039d050a"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto2-demo"
version = "0.1.0"
dependencies = [
"crypto2",
"hex",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"

View File

@@ -0,0 +1,10 @@
[package]
name = "crypto2-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crypto2 = { version = "0.2.0", git = "https://github.com/shadowsocks/crypto2" }
hex = "0.4.3"

View File

@@ -0,0 +1,24 @@
use crypto2::blockcipher::Aes128;
fn main() {
let key = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f,
];
let plaintext = [
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
0xff,
];
let cipher = Aes128::new(&key);
let mut ciphertext = plaintext.clone();
cipher.encrypt(&mut ciphertext);
let mut cleartext = ciphertext.clone();
cipher.decrypt(&mut cleartext);
println!("plaintext : {:?}", &plaintext[..]);
println!("ciphertext: {:?}", &ciphertext[..]);
println!("cleartext : {:?}", &cleartext[..]);
}