X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=blobdiff_plain;f=lab1_rust%2Fsrc%2Fcrypto.rs;h=67d0b388eab422bc9475ab5d750d494ba603c2d3;hp=ad7e6fab2f1af5589199f99ad2c2e5cd10a652ff;hb=d7f0bb987b21e93a5798403d294f7905151682f7;hpb=a8641e8dd205140af9206e82169ff5ad107c23f8 diff --git a/lab1_rust/src/crypto.rs b/lab1_rust/src/crypto.rs index ad7e6fa..67d0b38 100644 --- a/lab1_rust/src/crypto.rs +++ b/lab1_rust/src/crypto.rs @@ -4,16 +4,17 @@ use std::slice::bytes::copy_memory; use openssl::crypto::hash::HashType::SHA256; use openssl::crypto::hmac::HMAC; use openssl::crypto::symm; +use utils::from_elem; // These aren't the keys you're looking for. const KEY_A: &'static [u8] = &[125, 31, 131, 118, 143, 180, 252, 53, 211, 217, 79, 240, 128, 91, 252, 87, 104, 236, 145, 198, 163, 203, 161, 12, 53, 56, 218, 40, 221, 95, 171, 140]; const KEY_C: &'static [u8] = &[75, 226, 88, 31, 223, 216, 182, 216, 178, 58, 59, 193, 245, 80, 254, 128, 125, 246, 246, 224, 194, 190, 123, 123, 10, 131, 217, 183, 112, 157, 166, 102]; /// Only returns the first ten bytes from HMAC-SHA256. -pub fn compute_mac(data: &[u8]) -> [u8, ..10] { +pub fn compute_mac(data: &[u8]) -> [u8; 10] { let mut hmac = HMAC(SHA256, KEY_A); hmac.update(data); - let mut result = [0u8, ..10]; + let mut result = [0u8; 10]; copy_memory(&mut result, hmac.finalize().slice(0, 10)); result } @@ -47,8 +48,8 @@ pub fn decrypt(cipherdata: &[u8], iv: &[u8]) -> Option> { } pub fn generate_key(size_byte: uint) -> IoResult> { - let mut bytes = Vec::from_elem(size_byte, 0u8); + let mut bytes = from_elem(size_byte, 0u8); let mut generator = try!(OsRng::new()); // Uses '/dev/urandom' on Unix-like systems. - generator.fill_bytes(bytes.as_mut_slice_()); + generator.fill_bytes(bytes.as_mut_slice()); Ok(bytes) } \ No newline at end of file