Update for latest incoming (3a3bf8b)
This commit is contained in:
parent
08cdf5fde4
commit
2eba04e579
2
Makefile
2
Makefile
|
|
@ -5,3 +5,5 @@ crypto: crypto.rc $(wildcard *.rs)
|
|||
|
||||
clean:
|
||||
rm -f crypto libcrypto-*.so
|
||||
rm libcrypto-*.dylib
|
||||
rm -rf *.dSYM
|
||||
|
|
|
|||
4
hash.rs
4
hash.rs
|
|
@ -1,4 +1,5 @@
|
|||
use std::libc::c_uint;
|
||||
use std::{libc,vec,ptr};
|
||||
|
||||
pub enum HashType {
|
||||
MD5,
|
||||
|
|
@ -108,6 +109,7 @@ mod tests {
|
|||
use super::*;
|
||||
use hex::FromHex;
|
||||
use hex::ToHex;
|
||||
use std::vec;
|
||||
|
||||
struct HashTest {
|
||||
input: ~[u8],
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
2
hex.rs
2
hex.rs
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
extern mod std;
|
||||
use std::{str,uint,vec};
|
||||
|
||||
pub trait ToHex {
|
||||
fn to_hex(&self) -> ~str;
|
||||
|
|
|
|||
15
hmac.rs
15
hmac.rs
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
use hash::*;
|
||||
use std::{libc,ptr,vec};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct HMAC_CTX {
|
||||
|
|
@ -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,
|
||||
|
|
@ -91,5 +92,5 @@ fn main() {
|
|||
|
||||
h.update([00u8]);
|
||||
|
||||
io::println(fmt!("%?", h.final()))
|
||||
println(fmt!("%?", h.final()))
|
||||
}
|
||||
|
|
|
|||
2
pkcs5.rs
2
pkcs5.rs
|
|
@ -1,4 +1,5 @@
|
|||
use std::libc::c_int;
|
||||
use std::{vec,str};
|
||||
|
||||
#[link_args = "-lcrypto"]
|
||||
#[abi = "cdecl"]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
5
pkey.rs
5
pkey.rs
|
|
@ -1,4 +1,5 @@
|
|||
use std::libc::{c_int, c_uint};
|
||||
use std::{libc,cast,ptr,vec};
|
||||
use hash::{HashType, MD5, SHA1, SHA224, SHA256, SHA384, SHA512};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
|
|
@ -99,7 +100,7 @@ pub fn PKey() -> PKey {
|
|||
|
||||
///Represents a public key, optionally with a private key attached.
|
||||
priv impl PKey {
|
||||
priv fn _tostr(&self, f: extern "C" unsafe fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
|
||||
priv unsafe fn _tostr(&self, f: extern "C" unsafe fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
|
||||
let buf = ptr::mut_null();
|
||||
let len = f(self.evp, &buf);
|
||||
if len < 0 as c_int { return ~[]; }
|
||||
|
|
@ -112,7 +113,7 @@ priv impl PKey {
|
|||
vec::slice(s, 0u, r as uint).to_owned()
|
||||
}
|
||||
|
||||
priv fn _fromstr(
|
||||
priv unsafe fn _fromstr(
|
||||
&mut self,
|
||||
s: &[u8],
|
||||
f: extern "C" unsafe fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY
|
||||
|
|
|
|||
3
rand.rs
3
rand.rs
|
|
@ -1,4 +1,5 @@
|
|||
use std::libc::c_int;
|
||||
use std::vec;
|
||||
|
||||
#[link_args = "-lcrypto"]
|
||||
#[abi = "cdecl"]
|
||||
|
|
@ -28,6 +29,6 @@ mod tests {
|
|||
#[test]
|
||||
fn test_rand_bytes() {
|
||||
let bytes = rand_bytes(32u);
|
||||
io::println(fmt!("%?", bytes));
|
||||
println(fmt!("%?", bytes));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
symm.rs
9
symm.rs
|
|
@ -1,4 +1,5 @@
|
|||
use std::libc::{c_int, c_uint};
|
||||
use std::{libc,vec};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
type EVP_CIPHER_CTX = *libc::c_void;
|
||||
|
|
@ -236,11 +237,11 @@ mod tests {
|
|||
let computed = cipher.update(pt.from_hex()) + cipher.final();
|
||||
|
||||
if computed != expected {
|
||||
io::println(fmt!("Computed: %s", computed.to_hex()));
|
||||
io::println(fmt!("Expected: %s", expected.to_hex()));
|
||||
println(fmt!("Computed: %s", computed.to_hex()));
|
||||
println(fmt!("Expected: %s", expected.to_hex()));
|
||||
if computed.len() != expected.len() {
|
||||
io::println(fmt!("Lengths differ: %u in computed vs %u expected",
|
||||
computed.len(), expected.len()));
|
||||
println(fmt!("Lengths differ: %u in computed vs %u expected",
|
||||
computed.len(), expected.len()));
|
||||
}
|
||||
fail!(~"test failure");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue