diff --git a/__crypto/crypto2-demo/Cargo.lock b/__crypto/crypto2-demo/Cargo.lock new file mode 100644 index 0000000..3f0fc90 --- /dev/null +++ b/__crypto/crypto2-demo/Cargo.lock @@ -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" diff --git a/__crypto/crypto2-demo/Cargo.toml b/__crypto/crypto2-demo/Cargo.toml new file mode 100644 index 0000000..f9c882d --- /dev/null +++ b/__crypto/crypto2-demo/Cargo.toml @@ -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" diff --git a/__crypto/crypto2-demo/src/main.rs b/__crypto/crypto2-demo/src/main.rs new file mode 100644 index 0000000..c254922 --- /dev/null +++ b/__crypto/crypto2-demo/src/main.rs @@ -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[..]); +}