Loading Makefile +2 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,5 @@ crypto: crypto.rc $(wildcard *.rs) clean: rm -f crypto libcrypto-*.so rm libcrypto-*.dylib rm -rf *.dSYM hash.rs +3 −1 Original line number Diff line number Diff line use std::libc::c_uint; use std::{libc,vec,ptr}; pub enum HashType { MD5, Loading Loading @@ -108,6 +109,7 @@ mod tests { use super::*; use hex::FromHex; use hex::ToHex; use std::vec; struct HashTest { input: ~[u8], Loading @@ -125,7 +127,7 @@ mod tests { let calced = calced_raw.to_hex(); if calced != hashtest.expected_output { io::println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output)); println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output)); } assert!(calced == hashtest.expected_output); Loading hex.rs +1 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ extern mod std; use std::{str,uint,vec}; pub trait ToHex { fn to_hex(&self) -> ~str; Loading hmac.rs +8 −7 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ use hash::*; use std::{libc,ptr,vec}; #[allow(non_camel_case_types)] pub struct HMAC_CTX { Loading Loading @@ -47,12 +48,12 @@ pub fn HMAC(ht: HashType, key: ~[u8]) -> HMAC { let (evp, mdlen) = evpmd(ht); let mut ctx : HMAC_CTX = HMAC_CTX { mut md: ptr::null(), mut md_ctx: ptr::null(), mut i_ctx: ptr::null(), mut o_ctx: ptr::null(), mut key_length: 0, mut key: [0u8, .. 128] md: ptr::null(), md_ctx: ptr::null(), i_ctx: ptr::null(), o_ctx: ptr::null(), key_length: 0, key: [0u8, .. 128] }; HMAC_CTX_init(&mut ctx, Loading Loading @@ -91,5 +92,5 @@ fn main() { h.update([00u8]); io::println(fmt!("%?", h.final())) println(fmt!("%?", h.final())) } pkcs5.rs +2 −0 Original line number Diff line number Diff line use std::libc::c_int; use std::{vec,str}; #[link_args = "-lcrypto"] #[abi = "cdecl"] Loading Loading @@ -43,6 +44,7 @@ pub fn pbkdf2_hmac_sha1(pass: &str, salt: &[u8], iter: uint, #[cfg(test)] mod tests { use super::*; use std::str; // Test vectors from // http://tools.ietf.org/html/draft-josefsson-pbkdf2-test-vectors-06 Loading Loading
Makefile +2 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,5 @@ crypto: crypto.rc $(wildcard *.rs) clean: rm -f crypto libcrypto-*.so rm libcrypto-*.dylib rm -rf *.dSYM
hash.rs +3 −1 Original line number Diff line number Diff line use std::libc::c_uint; use std::{libc,vec,ptr}; pub enum HashType { MD5, Loading Loading @@ -108,6 +109,7 @@ mod tests { use super::*; use hex::FromHex; use hex::ToHex; use std::vec; struct HashTest { input: ~[u8], Loading @@ -125,7 +127,7 @@ mod tests { let calced = calced_raw.to_hex(); if calced != hashtest.expected_output { io::println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output)); println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output)); } assert!(calced == hashtest.expected_output); Loading
hex.rs +1 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ extern mod std; use std::{str,uint,vec}; pub trait ToHex { fn to_hex(&self) -> ~str; Loading
hmac.rs +8 −7 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ use hash::*; use std::{libc,ptr,vec}; #[allow(non_camel_case_types)] pub struct HMAC_CTX { Loading Loading @@ -47,12 +48,12 @@ pub fn HMAC(ht: HashType, key: ~[u8]) -> HMAC { let (evp, mdlen) = evpmd(ht); let mut ctx : HMAC_CTX = HMAC_CTX { mut md: ptr::null(), mut md_ctx: ptr::null(), mut i_ctx: ptr::null(), mut o_ctx: ptr::null(), mut key_length: 0, mut key: [0u8, .. 128] md: ptr::null(), md_ctx: ptr::null(), i_ctx: ptr::null(), o_ctx: ptr::null(), key_length: 0, key: [0u8, .. 128] }; HMAC_CTX_init(&mut ctx, Loading Loading @@ -91,5 +92,5 @@ fn main() { h.update([00u8]); io::println(fmt!("%?", h.final())) println(fmt!("%?", h.final())) }
pkcs5.rs +2 −0 Original line number Diff line number Diff line use std::libc::c_int; use std::{vec,str}; #[link_args = "-lcrypto"] #[abi = "cdecl"] Loading Loading @@ -43,6 +44,7 @@ pub fn pbkdf2_hmac_sha1(pass: &str, salt: &[u8], iter: uint, #[cfg(test)] mod tests { use super::*; use std::str; // Test vectors from // http://tools.ietf.org/html/draft-josefsson-pbkdf2-test-vectors-06 Loading