diff --git a/rust_sodium-sys/lib.rs b/rust_sodium-sys/lib.rs index 3b79c52c..07d3effb 100644 --- a/rust_sodium-sys/lib.rs +++ b/rust_sodium-sys/lib.rs @@ -27,8 +27,7 @@ extern crate rand; #[macro_use] extern crate unwrap; - -use libc::{c_char, c_int, c_ulonglong, c_void, size_t, uint32_t}; +use libc::{c_char, c_int, c_uchar, c_ulonglong, c_void, size_t, uint32_t, uint64_t, uint8_t}; use rand::{Rng, SeedableRng, XorShiftRng}; use std::cell::RefCell; use std::ffi::CString; @@ -52,8 +51,9 @@ include!("src/crypto_core_salsa20.rs"); include!("src/crypto_core_salsa2012.rs"); include!("src/crypto_core_salsa208.rs"); -include!("src/crypto_generichash.rs"); -include!("src/crypto_generichash_blake2b.rs"); +// TODO re-include once https://github.com/rust-lang/rust/issues/33626 is in stable. +// include!("src/crypto_generichash.rs"); +// include!("src/crypto_generichash_blake2b.rs"); include!("src/crypto_hash.rs"); include!("src/crypto_hash_sha256.rs"); diff --git a/rust_sodium-sys/src/crypto_aead_chacha20poly1305.rs b/rust_sodium-sys/src/crypto_aead_chacha20poly1305.rs index 460f1ade..f20c28ca 100644 --- a/rust_sodium-sys/src/crypto_aead_chacha20poly1305.rs +++ b/rust_sodium-sys/src/crypto_aead_chacha20poly1305.rs @@ -1,10 +1,9 @@ // crypto_aead_chacha20poly1305.h -pub const crypto_aead_chacha20poly1305_KEYBYTES: usize = 32; -pub const crypto_aead_chacha20poly1305_NSECBYTES: usize = 0; -pub const crypto_aead_chacha20poly1305_NPUBBYTES: usize = 8; -pub const crypto_aead_chacha20poly1305_ABYTES: usize = 16; - +pub const crypto_aead_chacha20poly1305_KEYBYTES: size_t = 32; +pub const crypto_aead_chacha20poly1305_NSECBYTES: size_t = 0; +pub const crypto_aead_chacha20poly1305_NPUBBYTES: size_t = 8; +pub const crypto_aead_chacha20poly1305_ABYTES: size_t = 16; extern "C" { pub fn crypto_aead_chacha20poly1305_keybytes() -> size_t; @@ -12,54 +11,57 @@ extern "C" { pub fn crypto_aead_chacha20poly1305_npubbytes() -> size_t; pub fn crypto_aead_chacha20poly1305_abytes() -> size_t; pub fn crypto_aead_chacha20poly1305_encrypt( - c: *mut u8, + c: *mut c_uchar, clen: *mut c_ulonglong, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, - ad: *const u8, + ad: *const c_uchar, adlen: c_ulonglong, - nsec: *const u8, - npub: *const u8, - k: *const u8, + nsec: *const c_uchar, + npub: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_aead_chacha20poly1305_decrypt( - m: *mut u8, + m: *mut c_uchar, mlen: *mut c_ulonglong, - nsec: *mut u8, - c: *const u8, + nsec: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - ad: *const u8, + ad: *const c_uchar, adlen: c_ulonglong, - npub: *const u8, - k: *const u8, + npub: *const c_uchar, + k: *const c_uchar, ) -> c_int; } - #[test] fn test_crypto_aead_chacha20poly1305_keybytes() { - assert!( - unsafe { crypto_aead_chacha20poly1305_keybytes() as usize } == - crypto_aead_chacha20poly1305_KEYBYTES + assert_eq!( + unsafe { crypto_aead_chacha20poly1305_keybytes() }, + crypto_aead_chacha20poly1305_KEYBYTES ) } + #[test] fn test_crypto_aead_chacha20poly1305_nsecbytes() { - assert!( - unsafe { crypto_aead_chacha20poly1305_nsecbytes() as usize } == - crypto_aead_chacha20poly1305_NSECBYTES + assert_eq!( + unsafe { crypto_aead_chacha20poly1305_nsecbytes() }, + crypto_aead_chacha20poly1305_NSECBYTES ) } + #[test] fn test_crypto_aead_chacha20poly1305_npubbytes() { - assert!( - unsafe { crypto_aead_chacha20poly1305_npubbytes() as usize } == - crypto_aead_chacha20poly1305_NPUBBYTES + assert_eq!( + unsafe { crypto_aead_chacha20poly1305_npubbytes() }, + crypto_aead_chacha20poly1305_NPUBBYTES ) } + #[test] fn test_crypto_aead_chacha20poly1305_abytes() { - assert!( - unsafe { crypto_aead_chacha20poly1305_abytes() as usize } == crypto_aead_chacha20poly1305_ABYTES + assert_eq!( + unsafe { crypto_aead_chacha20poly1305_abytes() }, + crypto_aead_chacha20poly1305_ABYTES ) } diff --git a/rust_sodium-sys/src/crypto_auth.rs b/rust_sodium-sys/src/crypto_auth.rs index 620e57e7..b7a8aaae 100644 --- a/rust_sodium-sys/src/crypto_auth.rs +++ b/rust_sodium-sys/src/crypto_auth.rs @@ -1,28 +1,38 @@ // crypto_auth.h -pub const crypto_auth_BYTES: usize = crypto_auth_hmacsha512256_BYTES; -pub const crypto_auth_KEYBYTES: usize = crypto_auth_hmacsha512256_KEYBYTES; -pub const crypto_auth_PRIMITIVE: *const c_char = (b"hmacsha512256\0" as *const u8) as *const c_char; - +pub const crypto_auth_BYTES: size_t = crypto_auth_hmacsha512256_BYTES; +pub const crypto_auth_KEYBYTES: size_t = crypto_auth_hmacsha512256_KEYBYTES; +pub const crypto_auth_PRIMITIVE: *const c_char = (b"hmacsha512256\0" as *const c_uchar) as + *const c_char; extern "C" { pub fn crypto_auth_bytes() -> size_t; pub fn crypto_auth_keybytes() -> size_t; pub fn crypto_auth_primitive() -> *const c_char; - pub fn crypto_auth(a: *mut u8, m: *const u8, mlen: c_ulonglong, k: *const u8) -> c_int; - pub fn crypto_auth_verify(a: *const u8, m: *const u8, mlen: c_ulonglong, k: *const u8) - -> c_int; + pub fn crypto_auth( + a: *mut c_uchar, + m: *const c_uchar, + mlen: c_ulonglong, + k: *const c_uchar, + ) -> c_int; + pub fn crypto_auth_verify( + a: *const c_uchar, + m: *const c_uchar, + mlen: c_ulonglong, + k: *const c_uchar, + ) -> c_int; } - #[test] fn test_crypto_auth_bytes() { - assert!(unsafe { crypto_auth_bytes() as usize } == crypto_auth_BYTES) + assert_eq!(unsafe { crypto_auth_bytes() }, crypto_auth_BYTES) } + #[test] fn test_crypto_auth_keybytes() { - assert!(unsafe { crypto_auth_keybytes() as usize } == crypto_auth_KEYBYTES) + assert_eq!(unsafe { crypto_auth_keybytes() }, crypto_auth_KEYBYTES) } + #[test] fn test_crypto_auth_primitive() { use std::ffi::CStr; diff --git a/rust_sodium-sys/src/crypto_auth_hmacsha256.rs b/rust_sodium-sys/src/crypto_auth_hmacsha256.rs index 291b7866..c5ffe008 100644 --- a/rust_sodium-sys/src/crypto_auth_hmacsha256.rs +++ b/rust_sodium-sys/src/crypto_auth_hmacsha256.rs @@ -7,49 +7,52 @@ pub struct crypto_auth_hmacsha256_state { octx: crypto_hash_sha256_state, } -pub const crypto_auth_hmacsha256_BYTES: usize = 32; -pub const crypto_auth_hmacsha256_KEYBYTES: usize = 32; - +pub const crypto_auth_hmacsha256_BYTES: size_t = 32; +pub const crypto_auth_hmacsha256_KEYBYTES: size_t = 32; extern "C" { pub fn crypto_auth_hmacsha256_bytes() -> size_t; pub fn crypto_auth_hmacsha256_keybytes() -> size_t; pub fn crypto_auth_hmacsha256( - a: *mut u8, - m: *const u8, + a: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha256_verify( - a: *const u8, - m: *const u8, + a: *const c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha256_init( state: *mut crypto_auth_hmacsha256_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, ) -> c_int; pub fn crypto_auth_hmacsha256_update( state: *mut crypto_auth_hmacsha256_state, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, ) -> c_int; pub fn crypto_auth_hmacsha256_final( state: *mut crypto_auth_hmacsha256_state, - a: *mut u8, + a: *mut c_uchar, ) -> c_int; } - #[test] fn test_crypto_auth_hmacsha256_bytes() { - assert!(unsafe { crypto_auth_hmacsha256_bytes() as usize } == crypto_auth_hmacsha256_BYTES) + assert_eq!( + unsafe { crypto_auth_hmacsha256_bytes() }, + crypto_auth_hmacsha256_BYTES + ) } + #[test] fn test_crypto_auth_hmacsha256_keybytes() { - assert!( - unsafe { crypto_auth_hmacsha256_keybytes() as usize } == crypto_auth_hmacsha256_KEYBYTES + assert_eq!( + unsafe { crypto_auth_hmacsha256_keybytes() }, + crypto_auth_hmacsha256_KEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_auth_hmacsha512.rs b/rust_sodium-sys/src/crypto_auth_hmacsha512.rs index eeb067d0..39044695 100644 --- a/rust_sodium-sys/src/crypto_auth_hmacsha512.rs +++ b/rust_sodium-sys/src/crypto_auth_hmacsha512.rs @@ -7,49 +7,52 @@ pub struct crypto_auth_hmacsha512_state { octx: crypto_hash_sha512_state, } -pub const crypto_auth_hmacsha512_BYTES: usize = 64; -pub const crypto_auth_hmacsha512_KEYBYTES: usize = 32; - +pub const crypto_auth_hmacsha512_BYTES: size_t = 64; +pub const crypto_auth_hmacsha512_KEYBYTES: size_t = 32; extern "C" { pub fn crypto_auth_hmacsha512_bytes() -> size_t; pub fn crypto_auth_hmacsha512_keybytes() -> size_t; pub fn crypto_auth_hmacsha512( - a: *mut u8, - m: *const u8, + a: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha512_verify( - a: *const u8, - m: *const u8, + a: *const c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha512_init( state: *mut crypto_auth_hmacsha512_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, ) -> c_int; pub fn crypto_auth_hmacsha512_update( state: *mut crypto_auth_hmacsha512_state, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, ) -> c_int; pub fn crypto_auth_hmacsha512_final( state: *mut crypto_auth_hmacsha512_state, - a: *mut u8, + a: *mut c_uchar, ) -> c_int; } - #[test] fn test_crypto_auth_hmacsha512_bytes() { - assert!(unsafe { crypto_auth_hmacsha512_bytes() as usize } == crypto_auth_hmacsha512_BYTES) + assert_eq!( + unsafe { crypto_auth_hmacsha512_bytes() }, + crypto_auth_hmacsha512_BYTES + ) } + #[test] fn test_crypto_auth_hmacsha512_keybytes() { - assert!( - unsafe { crypto_auth_hmacsha512_keybytes() as usize } == crypto_auth_hmacsha512_KEYBYTES + assert_eq!( + unsafe { crypto_auth_hmacsha512_keybytes() }, + crypto_auth_hmacsha512_KEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_auth_hmacsha512256.rs b/rust_sodium-sys/src/crypto_auth_hmacsha512256.rs index 107808d2..7a4c4cce 100644 --- a/rust_sodium-sys/src/crypto_auth_hmacsha512256.rs +++ b/rust_sodium-sys/src/crypto_auth_hmacsha512256.rs @@ -6,48 +6,49 @@ pub type crypto_auth_hmacsha512256_state = crypto_auth_hmacsha512_state; pub const crypto_auth_hmacsha512256_BYTES: size_t = 32; pub const crypto_auth_hmacsha512256_KEYBYTES: size_t = 32; - extern "C" { pub fn crypto_auth_hmacsha512256_bytes() -> size_t; pub fn crypto_auth_hmacsha512256_keybytes() -> size_t; pub fn crypto_auth_hmacsha512256( - a: *mut u8, - m: *const u8, + a: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha512256_verify( - a: *const u8, - m: *const u8, + a: *const c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_auth_hmacsha512256_init( state: *mut crypto_auth_hmacsha512256_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, ) -> c_int; pub fn crypto_auth_hmacsha512256_update( state: *mut crypto_auth_hmacsha512256_state, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, ) -> c_int; pub fn crypto_auth_hmacsha512256_final( state: *mut crypto_auth_hmacsha512256_state, - a: *mut u8, + a: *mut c_uchar, ) -> c_int; } - #[test] fn test_crypto_auth_hmacsha512256_bytes() { - assert!( - unsafe { crypto_auth_hmacsha512256_bytes() as usize } == crypto_auth_hmacsha512256_BYTES + assert_eq!( + unsafe { crypto_auth_hmacsha512256_bytes() }, + crypto_auth_hmacsha512256_BYTES ) } + #[test] fn test_crypto_auth_hmacsha512256_keybytes() { - assert!( - unsafe { crypto_auth_hmacsha512256_keybytes() as usize } == crypto_auth_hmacsha512256_KEYBYTES + assert_eq!( + unsafe { crypto_auth_hmacsha512256_keybytes() }, + crypto_auth_hmacsha512256_KEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_box.rs b/rust_sodium-sys/src/crypto_box.rs index d3abcb25..352efd4f 100644 --- a/rust_sodium-sys/src/crypto_box.rs +++ b/rust_sodium-sys/src/crypto_box.rs @@ -1,17 +1,16 @@ // crypto_box.h -pub const crypto_box_SEEDBYTES: usize = crypto_box_curve25519xsalsa20poly1305_SEEDBYTES; -pub const crypto_box_PUBLICKEYBYTES: usize = crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; -pub const crypto_box_SECRETKEYBYTES: usize = crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; -pub const crypto_box_BEFORENMBYTES: usize = crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES; -pub const crypto_box_NONCEBYTES: usize = crypto_box_curve25519xsalsa20poly1305_NONCEBYTES; -pub const crypto_box_ZEROBYTES: usize = crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; -pub const crypto_box_BOXZEROBYTES: usize = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; -pub const crypto_box_MACBYTES: usize = crypto_box_curve25519xsalsa20poly1305_MACBYTES; -pub const crypto_box_PRIMITIVE: *const c_char = (b"curve25519xsalsa20poly1305\0" as *const u8) as - *const c_char; -pub const crypto_box_SEALBYTES: usize = (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES); - +pub const crypto_box_SEEDBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_SEEDBYTES; +pub const crypto_box_PUBLICKEYBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; +pub const crypto_box_SECRETKEYBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; +pub const crypto_box_BEFORENMBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES; +pub const crypto_box_NONCEBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_NONCEBYTES; +pub const crypto_box_ZEROBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; +pub const crypto_box_BOXZEROBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; +pub const crypto_box_MACBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_MACBYTES; +pub const crypto_box_PRIMITIVE: *const c_char = + (b"curve25519xsalsa20poly1305\0" as *const c_uchar) as *const c_char; +pub const crypto_box_SEALBYTES: size_t = (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES); extern "C" { pub fn crypto_box_seedbytes() -> size_t; @@ -25,145 +24,174 @@ extern "C" { pub fn crypto_box_primitive() -> *const c_char; pub fn crypto_box_sealbytes() -> size_t; - pub fn crypto_box_seed_keypair(pk: *mut u8, sk: *mut u8, seed: *const u8) -> c_int; - pub fn crypto_box_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn crypto_box_beforenm(k: *mut u8, pk: *const u8, sk: *const u8) -> c_int; + pub fn crypto_box_seed_keypair( + pk: *mut c_uchar, + sk: *mut c_uchar, + seed: *const c_uchar, + ) -> c_int; + pub fn crypto_box_keypair(pk: *mut c_uchar, sk: *mut c_uchar) -> c_int; + pub fn crypto_box_beforenm(k: *mut c_uchar, pk: *const c_uchar, sk: *const c_uchar) -> c_int; pub fn crypto_box_afternm( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box_open_afternm( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_open( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_easy( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_open_easy( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_detached( - c: *mut u8, - mac: *mut u8, - m: *const u8, + c: *mut c_uchar, + mac: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_open_detached( - m: *mut u8, - c: *const u8, - mac: *const u8, + m: *mut c_uchar, + c: *const c_uchar, + mac: *const c_uchar, clen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_detached_afternm( - c: *mut u8, - mac: *mut u8, - m: *const u8, + c: *mut c_uchar, + mac: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box_open_detached_afternm( - m: *mut u8, - c: *const u8, - mac: *const u8, + m: *mut c_uchar, + c: *const c_uchar, + mac: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, + ) -> c_int; + pub fn crypto_box_seal( + c: *mut c_uchar, + m: *const c_uchar, + mlen: c_ulonglong, + pk: *const c_uchar, ) -> c_int; - pub fn crypto_box_seal(c: *mut u8, m: *const u8, mlen: c_ulonglong, pk: *const u8) -> c_int; pub fn crypto_box_seal_open( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - pk: *const u8, - sk: *const u8, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_easy_afternm( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box_open_easy_afternm( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; } #[test] fn test_crypto_box_seedbytes() { - assert!(unsafe { crypto_box_seedbytes() as usize } == crypto_box_SEEDBYTES) + assert_eq!(unsafe { crypto_box_seedbytes() }, crypto_box_SEEDBYTES) } + #[test] fn test_crypto_box_publickeybytes() { - assert!(unsafe { crypto_box_publickeybytes() as usize } == crypto_box_PUBLICKEYBYTES) + assert_eq!( + unsafe { crypto_box_publickeybytes() }, + crypto_box_PUBLICKEYBYTES + ) } + #[test] fn test_crypto_box_secretkeybytes() { - assert!(unsafe { crypto_box_secretkeybytes() as usize } == crypto_box_SECRETKEYBYTES) + assert_eq!( + unsafe { crypto_box_secretkeybytes() }, + crypto_box_SECRETKEYBYTES + ) } + #[test] fn test_crypto_box_beforenmbytes() { - assert!(unsafe { crypto_box_beforenmbytes() as usize } == crypto_box_BEFORENMBYTES) + assert_eq!( + unsafe { crypto_box_beforenmbytes() }, + crypto_box_BEFORENMBYTES + ) } + #[test] fn test_crypto_box_noncebytes() { - assert!(unsafe { crypto_box_noncebytes() as usize } == crypto_box_NONCEBYTES) + assert_eq!(unsafe { crypto_box_noncebytes() }, crypto_box_NONCEBYTES) } + #[test] fn test_crypto_box_zerobytes() { - assert!(unsafe { crypto_box_zerobytes() as usize } == crypto_box_ZEROBYTES) + assert_eq!(unsafe { crypto_box_zerobytes() }, crypto_box_ZEROBYTES) } + #[test] fn test_crypto_box_boxzerobytes() { - assert!(unsafe { crypto_box_boxzerobytes() as usize } == crypto_box_BOXZEROBYTES) + assert_eq!( + unsafe { crypto_box_boxzerobytes() }, + crypto_box_BOXZEROBYTES + ) } + #[test] fn test_crypto_box_macbytes() { - assert!(unsafe { crypto_box_macbytes() as usize } == crypto_box_MACBYTES) + assert_eq!(unsafe { crypto_box_macbytes() }, crypto_box_MACBYTES) } + #[test] fn test_crypto_box_primitive() { use std::ffi::CStr; @@ -174,7 +202,8 @@ fn test_crypto_box_primitive() { ); } } + #[test] fn test_crypto_box_sealbytes() { - assert!(unsafe { crypto_box_sealbytes() as usize } == crypto_box_SEALBYTES) + assert_eq!(unsafe { crypto_box_sealbytes() }, crypto_box_SEALBYTES) } diff --git a/rust_sodium-sys/src/crypto_box_curve25519xsalsa20poly1305.rs b/rust_sodium-sys/src/crypto_box_curve25519xsalsa20poly1305.rs index b8727dab..8bbcdbc1 100644 --- a/rust_sodium-sys/src/crypto_box_curve25519xsalsa20poly1305.rs +++ b/rust_sodium-sys/src/crypto_box_curve25519xsalsa20poly1305.rs @@ -1,53 +1,55 @@ // crypto_box_curve25519xsalsa20poly1305.h -pub const crypto_box_curve25519xsalsa20poly1305_SEEDBYTES: usize = 32; -pub const crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES: usize = 32; -pub const crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES: usize = 32; -pub const crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES: usize = 32; -pub const crypto_box_curve25519xsalsa20poly1305_NONCEBYTES: usize = 24; -pub const crypto_box_curve25519xsalsa20poly1305_ZEROBYTES: usize = 32; -pub const crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES: usize = 16; -pub const crypto_box_curve25519xsalsa20poly1305_MACBYTES: usize = +pub const crypto_box_curve25519xsalsa20poly1305_SEEDBYTES: size_t = 32; +pub const crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES: size_t = 32; +pub const crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES: size_t = 32; +pub const crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES: size_t = 32; +pub const crypto_box_curve25519xsalsa20poly1305_NONCEBYTES: size_t = 24; +pub const crypto_box_curve25519xsalsa20poly1305_ZEROBYTES: size_t = 32; +pub const crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES: size_t = 16; +pub const crypto_box_curve25519xsalsa20poly1305_MACBYTES: size_t = crypto_box_curve25519xsalsa20poly1305_ZEROBYTES - crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; - extern "C" { - pub fn crypto_box_curve25519xsalsa20poly1305_keypair(pk: *mut u8, sk: *mut u8) -> c_int; + pub fn crypto_box_curve25519xsalsa20poly1305_keypair( + pk: *mut c_uchar, + sk: *mut c_uchar, + ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305_open( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - pk: *const u8, - sk: *const u8, + n: *const c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305_beforenm( - k: *mut u8, - pk: *const u8, - sk: *const u8, + k: *mut c_uchar, + pk: *const c_uchar, + sk: *const c_uchar, ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305_afternm( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305_open_afternm( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_box_curve25519xsalsa20poly1305_seedbytes() -> size_t; pub fn crypto_box_curve25519xsalsa20poly1305_publickeybytes() -> size_t; @@ -59,60 +61,66 @@ extern "C" { pub fn crypto_box_curve25519xsalsa20poly1305_macbytes() -> size_t; } - #[test] fn test_crypto_box_curve25519xsalsa20poly1305_seedbytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_seedbytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_SEEDBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_seedbytes() }, + crypto_box_curve25519xsalsa20poly1305_SEEDBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_publickeybytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_publickeybytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_publickeybytes() }, + crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_secretkeybytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_secretkeybytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_secretkeybytes() }, + crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_beforenmbytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_beforenmbytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_beforenmbytes() }, + crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_noncebytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_noncebytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_NONCEBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_noncebytes() }, + crypto_box_curve25519xsalsa20poly1305_NONCEBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_zerobytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_zerobytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_ZEROBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_zerobytes() }, + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_boxzerobytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_boxzerobytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_boxzerobytes() }, + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES ) } + #[test] fn test_crypto_box_curve25519xsalsa20poly1305_macbytes() { - assert!( - unsafe { crypto_box_curve25519xsalsa20poly1305_macbytes() as usize } == - crypto_box_curve25519xsalsa20poly1305_MACBYTES + assert_eq!( + unsafe { crypto_box_curve25519xsalsa20poly1305_macbytes() }, + crypto_box_curve25519xsalsa20poly1305_MACBYTES ) } diff --git a/rust_sodium-sys/src/crypto_core_hsalsa20.rs b/rust_sodium-sys/src/crypto_core_hsalsa20.rs index 8803662c..b9c2cf0a 100644 --- a/rust_sodium-sys/src/crypto_core_hsalsa20.rs +++ b/rust_sodium-sys/src/crypto_core_hsalsa20.rs @@ -1,10 +1,9 @@ // crypto_core_hsalsa20.h -pub const crypto_core_hsalsa20_OUTPUTBYTES: usize = 32; -pub const crypto_core_hsalsa20_INPUTBYTES: usize = 16; -pub const crypto_core_hsalsa20_KEYBYTES: usize = 32; -pub const crypto_core_hsalsa20_CONSTBYTES: usize = 16; - +pub const crypto_core_hsalsa20_OUTPUTBYTES: size_t = 32; +pub const crypto_core_hsalsa20_INPUTBYTES: size_t = 16; +pub const crypto_core_hsalsa20_KEYBYTES: size_t = 32; +pub const crypto_core_hsalsa20_CONSTBYTES: size_t = 16; extern "C" { pub fn crypto_core_hsalsa20_outputbytes() -> size_t; @@ -12,29 +11,42 @@ extern "C" { pub fn crypto_core_hsalsa20_keybytes() -> size_t; pub fn crypto_core_hsalsa20_constbytes() -> size_t; - pub fn crypto_core_hsalsa20(out: *mut u8, in_: *const u8, k: *const u8, c: *const u8) -> c_int; + pub fn crypto_core_hsalsa20( + out: *mut c_uchar, + in_: *const c_uchar, + k: *const c_uchar, + c: *const c_uchar, + ) -> c_int; } - #[test] fn test_crypto_core_hsalsa20_outputbytes() { - assert!( - unsafe { crypto_core_hsalsa20_outputbytes() as usize } == crypto_core_hsalsa20_OUTPUTBYTES + assert_eq!( + unsafe { crypto_core_hsalsa20_outputbytes() }, + crypto_core_hsalsa20_OUTPUTBYTES ) } + #[test] fn test_crypto_core_hsalsa20_inputbytes() { - assert!( - unsafe { crypto_core_hsalsa20_inputbytes() as usize } == crypto_core_hsalsa20_INPUTBYTES + assert_eq!( + unsafe { crypto_core_hsalsa20_inputbytes() }, + crypto_core_hsalsa20_INPUTBYTES ) } + #[test] fn test_crypto_core_hsalsa20_keybytes() { - assert!(unsafe { crypto_core_hsalsa20_keybytes() as usize } == crypto_core_hsalsa20_KEYBYTES) + assert_eq!( + unsafe { crypto_core_hsalsa20_keybytes() }, + crypto_core_hsalsa20_KEYBYTES + ) } + #[test] fn test_crypto_core_hsalsa20_constbytes() { - assert!( - unsafe { crypto_core_hsalsa20_constbytes() as usize } == crypto_core_hsalsa20_CONSTBYTES + assert_eq!( + unsafe { crypto_core_hsalsa20_constbytes() }, + crypto_core_hsalsa20_CONSTBYTES ) } diff --git a/rust_sodium-sys/src/crypto_core_salsa20.rs b/rust_sodium-sys/src/crypto_core_salsa20.rs index 03caa6b6..989578a1 100644 --- a/rust_sodium-sys/src/crypto_core_salsa20.rs +++ b/rust_sodium-sys/src/crypto_core_salsa20.rs @@ -1,9 +1,9 @@ // crypto_core_salsa20.h -pub const crypto_core_salsa20_OUTPUTBYTES: usize = 64; -pub const crypto_core_salsa20_INPUTBYTES: usize = 16; -pub const crypto_core_salsa20_KEYBYTES: usize = 32; -pub const crypto_core_salsa20_CONSTBYTES: usize = 16; +pub const crypto_core_salsa20_OUTPUTBYTES: size_t = 64; +pub const crypto_core_salsa20_INPUTBYTES: size_t = 16; +pub const crypto_core_salsa20_KEYBYTES: size_t = 32; +pub const crypto_core_salsa20_CONSTBYTES: size_t = 16; extern "C" { pub fn crypto_core_salsa20_outputbytes() -> size_t; @@ -11,27 +11,42 @@ extern "C" { pub fn crypto_core_salsa20_keybytes() -> size_t; pub fn crypto_core_salsa20_constbytes() -> size_t; - pub fn crypto_core_salsa20(out: *mut u8, in_: *const u8, k: *const u8, c: *const u8) -> c_int; + pub fn crypto_core_salsa20( + out: *mut c_uchar, + in_: *const c_uchar, + k: *const c_uchar, + c: *const c_uchar, + ) -> c_int; } #[test] fn test_crypto_core_salsa20_outputbytes() { - assert!( - unsafe { crypto_core_salsa20_outputbytes() as usize } == crypto_core_salsa20_OUTPUTBYTES + assert_eq!( + unsafe { crypto_core_salsa20_outputbytes() }, + crypto_core_salsa20_OUTPUTBYTES ) } #[test] fn test_crypto_core_salsa20_inputbytes() { - assert!(unsafe { crypto_core_salsa20_inputbytes() as usize } == crypto_core_salsa20_INPUTBYTES) + assert_eq!( + unsafe { crypto_core_salsa20_inputbytes() }, + crypto_core_salsa20_INPUTBYTES + ) } #[test] fn test_crypto_core_salsa20_keybytes() { - assert!(unsafe { crypto_core_salsa20_keybytes() as usize } == crypto_core_salsa20_KEYBYTES) + assert_eq!( + unsafe { crypto_core_salsa20_keybytes() }, + crypto_core_salsa20_KEYBYTES + ) } #[test] fn test_crypto_core_salsa20_constbytes() { - assert!(unsafe { crypto_core_salsa20_constbytes() as usize } == crypto_core_salsa20_CONSTBYTES) + assert_eq!( + unsafe { crypto_core_salsa20_constbytes() }, + crypto_core_salsa20_CONSTBYTES + ) } diff --git a/rust_sodium-sys/src/crypto_core_salsa2012.rs b/rust_sodium-sys/src/crypto_core_salsa2012.rs index 05cbc347..de14ab10 100644 --- a/rust_sodium-sys/src/crypto_core_salsa2012.rs +++ b/rust_sodium-sys/src/crypto_core_salsa2012.rs @@ -1,9 +1,9 @@ // crypto_core_salsa2012.h -pub const crypto_core_salsa2012_OUTPUTBYTES: usize = 64; -pub const crypto_core_salsa2012_INPUTBYTES: usize = 16; -pub const crypto_core_salsa2012_KEYBYTES: usize = 32; -pub const crypto_core_salsa2012_CONSTBYTES: usize = 16; +pub const crypto_core_salsa2012_OUTPUTBYTES: size_t = 64; +pub const crypto_core_salsa2012_INPUTBYTES: size_t = 16; +pub const crypto_core_salsa2012_KEYBYTES: size_t = 32; +pub const crypto_core_salsa2012_CONSTBYTES: size_t = 16; extern "C" { pub fn crypto_core_salsa2012_outputbytes() -> size_t; @@ -11,32 +11,42 @@ extern "C" { pub fn crypto_core_salsa2012_keybytes() -> size_t; pub fn crypto_core_salsa2012_constbytes() -> size_t; - pub fn crypto_core_salsa2012(out: *mut u8, in_: *const u8, k: *const u8, c: *const u8) - -> c_int; + pub fn crypto_core_salsa2012( + out: *mut c_uchar, + in_: *const c_uchar, + k: *const c_uchar, + c: *const c_uchar, + ) -> c_int; } #[test] fn test_crypto_core_salsa2012_outputbytes() { - assert!( - unsafe { crypto_core_salsa2012_outputbytes() as usize } == crypto_core_salsa2012_OUTPUTBYTES + assert_eq!( + unsafe { crypto_core_salsa2012_outputbytes() }, + crypto_core_salsa2012_OUTPUTBYTES ) } #[test] fn test_crypto_core_salsa2012_inputbytes() { - assert!( - unsafe { crypto_core_salsa2012_inputbytes() as usize } == crypto_core_salsa2012_INPUTBYTES + assert_eq!( + unsafe { crypto_core_salsa2012_inputbytes() }, + crypto_core_salsa2012_INPUTBYTES ) } #[test] fn test_crypto_core_salsa2012_keybytes() { - assert!(unsafe { crypto_core_salsa2012_keybytes() as usize } == crypto_core_salsa2012_KEYBYTES) + assert_eq!( + unsafe { crypto_core_salsa2012_keybytes() }, + crypto_core_salsa2012_KEYBYTES + ) } #[test] fn test_crypto_core_salsa2012_constbytes() { - assert!( - unsafe { crypto_core_salsa2012_constbytes() as usize } == crypto_core_salsa2012_CONSTBYTES + assert_eq!( + unsafe { crypto_core_salsa2012_constbytes() }, + crypto_core_salsa2012_CONSTBYTES ) } diff --git a/rust_sodium-sys/src/crypto_core_salsa208.rs b/rust_sodium-sys/src/crypto_core_salsa208.rs index 68e0832c..ae7b6757 100644 --- a/rust_sodium-sys/src/crypto_core_salsa208.rs +++ b/rust_sodium-sys/src/crypto_core_salsa208.rs @@ -1,9 +1,9 @@ // crypto_core_salsa208.h -pub const crypto_core_salsa208_OUTPUTBYTES: usize = 64; -pub const crypto_core_salsa208_INPUTBYTES: usize = 16; -pub const crypto_core_salsa208_KEYBYTES: usize = 32; -pub const crypto_core_salsa208_CONSTBYTES: usize = 16; +pub const crypto_core_salsa208_OUTPUTBYTES: size_t = 64; +pub const crypto_core_salsa208_INPUTBYTES: size_t = 16; +pub const crypto_core_salsa208_KEYBYTES: size_t = 32; +pub const crypto_core_salsa208_CONSTBYTES: size_t = 16; extern "C" { pub fn crypto_core_salsa208_outputbytes() -> size_t; @@ -11,31 +11,42 @@ extern "C" { pub fn crypto_core_salsa208_keybytes() -> size_t; pub fn crypto_core_salsa208_constbytes() -> size_t; - pub fn crypto_core_salsa208(out: *mut u8, in_: *const u8, k: *const u8, c: *const u8) -> c_int; + pub fn crypto_core_salsa208( + out: *mut c_uchar, + in_: *const c_uchar, + k: *const c_uchar, + c: *const c_uchar, + ) -> c_int; } #[test] fn test_crypto_core_salsa208_outputbytes() { - assert!( - unsafe { crypto_core_salsa208_outputbytes() as usize } == crypto_core_salsa208_OUTPUTBYTES + assert_eq!( + unsafe { crypto_core_salsa208_outputbytes() }, + crypto_core_salsa208_OUTPUTBYTES ) } #[test] fn test_crypto_core_salsa208_inputbytes() { - assert!( - unsafe { crypto_core_salsa208_inputbytes() as usize } == crypto_core_salsa208_INPUTBYTES + assert_eq!( + unsafe { crypto_core_salsa208_inputbytes() }, + crypto_core_salsa208_INPUTBYTES ) } #[test] fn test_crypto_core_salsa208_keybytes() { - assert!(unsafe { crypto_core_salsa208_keybytes() as usize } == crypto_core_salsa208_KEYBYTES) + assert_eq!( + unsafe { crypto_core_salsa208_keybytes() }, + crypto_core_salsa208_KEYBYTES + ) } #[test] fn test_crypto_core_salsa208_constbytes() { - assert!( - unsafe { crypto_core_salsa208_constbytes() as usize } == crypto_core_salsa208_CONSTBYTES + assert_eq!( + unsafe { crypto_core_salsa208_constbytes() }, + crypto_core_salsa208_CONSTBYTES ) } diff --git a/rust_sodium-sys/src/crypto_generichash.rs b/rust_sodium-sys/src/crypto_generichash.rs index 93634fed..5bb9e585 100644 --- a/rust_sodium-sys/src/crypto_generichash.rs +++ b/rust_sodium-sys/src/crypto_generichash.rs @@ -1,16 +1,16 @@ // crypto_generichash.h -pub const crypto_generichash_BYTES_MIN: usize = crypto_generichash_blake2b_BYTES_MIN; -pub const crypto_generichash_BYTES_MAX: usize = crypto_generichash_blake2b_BYTES_MAX; -pub const crypto_generichash_BYTES: usize = crypto_generichash_blake2b_BYTES; -pub const crypto_generichash_KEYBYTES_MIN: usize = crypto_generichash_blake2b_KEYBYTES_MIN; -pub const crypto_generichash_KEYBYTES_MAX: usize = crypto_generichash_blake2b_KEYBYTES_MAX; -pub const crypto_generichash_KEYBYTES: usize = crypto_generichash_blake2b_KEYBYTES; -pub const crypto_generichash_PRIMITIVE: *const c_char = (b"blake2b\0" as *const u8) as +pub const crypto_generichash_BYTES_MIN: size_t = crypto_generichash_blake2b_BYTES_MIN; +pub const crypto_generichash_BYTES_MAX: size_t = crypto_generichash_blake2b_BYTES_MAX; +pub const crypto_generichash_BYTES: size_t = crypto_generichash_blake2b_BYTES; +pub const crypto_generichash_KEYBYTES_MIN: size_t = crypto_generichash_blake2b_KEYBYTES_MIN; +pub const crypto_generichash_KEYBYTES_MAX: size_t = crypto_generichash_blake2b_KEYBYTES_MAX; +pub const crypto_generichash_KEYBYTES: size_t = crypto_generichash_blake2b_KEYBYTES; +pub const crypto_generichash_PRIMITIVE: *const c_char = (b"blake2b\0" as *const c_uchar) as *const c_char; #[allow(non_camel_case_types)] -pub enum crypto_generichash_state { } +pub type crypto_generichash_state = crypto_generichash_blake2b_state; extern "C" { pub fn crypto_generichash_bytes_min() -> size_t; @@ -22,40 +22,36 @@ extern "C" { pub fn crypto_generichash_primitive() -> *const c_char; pub fn crypto_generichash( - out: *mut u8, + out: *mut c_uchar, outlen: size_t, - in_: *const u8, + in_: *const c_uchar, inlen: c_ulonglong, - key: *const u8, + key: *const c_uchar, keylen: size_t, ) -> c_int; - pub fn crypto_generichash_init( state: *mut crypto_generichash_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, outlen: size_t, ) -> c_int; - pub fn crypto_generichash_update( state: *mut crypto_generichash_state, - in_: *const u8, + in_: *const c_uchar, inlen: c_ulonglong, ) -> c_int; - pub fn crypto_generichash_final( state: *mut crypto_generichash_state, - out: *mut u8, + out: *mut c_uchar, outlen: size_t, ) -> c_int; - pub fn crypto_generichash_statebytes() -> size_t; } #[test] fn test_crypto_generichash_bytes_min() { assert_eq!( - unsafe { crypto_generichash_bytes_min() as usize }, + unsafe { crypto_generichash_bytes_min() }, crypto_generichash_BYTES_MIN ) } @@ -63,7 +59,7 @@ fn test_crypto_generichash_bytes_min() { #[test] fn test_crypto_generichash_bytes_max() { assert_eq!( - unsafe { crypto_generichash_bytes_max() as usize }, + unsafe { crypto_generichash_bytes_max() }, crypto_generichash_BYTES_MAX ) } @@ -71,7 +67,7 @@ fn test_crypto_generichash_bytes_max() { #[test] fn test_crypto_generichash_bytes() { assert_eq!( - unsafe { crypto_generichash_bytes() as usize }, + unsafe { crypto_generichash_bytes() }, crypto_generichash_BYTES ) } @@ -79,7 +75,7 @@ fn test_crypto_generichash_bytes() { #[test] fn test_crypto_generichash_keybytes_min() { assert_eq!( - unsafe { crypto_generichash_keybytes_min() as usize }, + unsafe { crypto_generichash_keybytes_min() }, crypto_generichash_KEYBYTES_MIN ) } @@ -87,7 +83,7 @@ fn test_crypto_generichash_keybytes_min() { #[test] fn test_crypto_generichash_keybytes_max() { assert_eq!( - unsafe { crypto_generichash_keybytes_max() as usize }, + unsafe { crypto_generichash_keybytes_max() }, crypto_generichash_KEYBYTES_MAX ) } @@ -95,7 +91,7 @@ fn test_crypto_generichash_keybytes_max() { #[test] fn test_crypto_generichash_keybytes() { assert_eq!( - unsafe { crypto_generichash_keybytes() as usize }, + unsafe { crypto_generichash_keybytes() }, crypto_generichash_KEYBYTES ) } @@ -145,7 +141,8 @@ fn test_crypto_generichash_multipart() { let key = [0u8; crypto_generichash_KEYBYTES]; let mut st = vec![0u8; (unsafe { crypto_generichash_statebytes() })]; - let pst = unsafe { mem::transmute::<*mut u8, *mut crypto_generichash_state>(st.as_mut_ptr()) }; + let pst = + unsafe { mem::transmute::<*mut c_uchar, *mut crypto_generichash_state>(st.as_mut_ptr()) }; assert_eq!( unsafe { crypto_generichash_init(pst, key.as_ptr(), key.len(), out.len()) }, diff --git a/rust_sodium-sys/src/crypto_generichash_blake2b.rs b/rust_sodium-sys/src/crypto_generichash_blake2b.rs index 6fa679cf..0373c22a 100644 --- a/rust_sodium-sys/src/crypto_generichash_blake2b.rs +++ b/rust_sodium-sys/src/crypto_generichash_blake2b.rs @@ -1,16 +1,24 @@ // crypto_generichash_blake2b.h -pub const crypto_generichash_blake2b_BYTES_MIN: usize = 16; -pub const crypto_generichash_blake2b_BYTES_MAX: usize = 64; -pub const crypto_generichash_blake2b_BYTES: usize = 32; -pub const crypto_generichash_blake2b_KEYBYTES_MIN: usize = 16; -pub const crypto_generichash_blake2b_KEYBYTES_MAX: usize = 64; -pub const crypto_generichash_blake2b_KEYBYTES: usize = 32; -pub const crypto_generichash_blake2b_SALTBYTES: usize = 16; -pub const crypto_generichash_blake2b_PERSONALBYTES: usize = 16; - -#[allow(non_camel_case_types)] -pub enum crypto_generichash_blake2b_state { } +pub const crypto_generichash_blake2b_BYTES_MIN: size_t = 16; +pub const crypto_generichash_blake2b_BYTES_MAX: size_t = 64; +pub const crypto_generichash_blake2b_BYTES: size_t = 32; +pub const crypto_generichash_blake2b_KEYBYTES_MIN: size_t = 16; +pub const crypto_generichash_blake2b_KEYBYTES_MAX: size_t = 64; +pub const crypto_generichash_blake2b_KEYBYTES: size_t = 32; +pub const crypto_generichash_blake2b_SALTBYTES: size_t = 16; +pub const crypto_generichash_blake2b_PERSONALBYTES: size_t = 16; + +#[repr(C)] +#[repr(align = "64")] +pub struct crypto_generichash_blake2b_state { + h: [uint64_t; 8], + t: [uint64_t; 2], + f: [uint64_t; 2], + buf: [uint8_t; 2 * 128], + buflen: size_t, + last_node: uint8_t, +} extern "C" { pub fn crypto_generichash_blake2b_bytes_min() -> size_t; @@ -23,50 +31,45 @@ extern "C" { pub fn crypto_generichash_blake2b_personalbytes() -> size_t; pub fn crypto_generichash_blake2b( - out: *mut u8, + out: *mut c_uchar, outlen: size_t, - in_: *const u8, + in_: *const c_uchar, inlen: c_ulonglong, - key: *const u8, + key: *const c_uchar, keylen: size_t, ) -> c_int; - pub fn crypto_generichash_blake2b_salt_personal( - out: *mut u8, + out: *mut c_uchar, outlen: size_t, - in_: *const u8, + in_: *const c_uchar, inlen: c_ulonglong, - key: *const u8, + key: *const c_uchar, keylen: size_t, - salt: *const u8, - personal: *const u8, + salt: *const c_uchar, + personal: *const c_uchar, ) -> c_int; - pub fn crypto_generichash_blake2b_init( state: *mut crypto_generichash_blake2b_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, outlen: size_t, ) -> c_int; - pub fn crypto_generichash_blake2b_init_salt_personal( state: *mut crypto_generichash_blake2b_state, - key: *const u8, + key: *const c_uchar, keylen: size_t, outlen: size_t, - salt: *const u8, - personal: *const u8, + salt: *const c_uchar, + personal: *const c_uchar, ) -> c_int; - pub fn crypto_generichash_blake2b_update( state: *mut crypto_generichash_blake2b_state, - in_: *const u8, + in_: *const c_uchar, inlen: c_ulonglong, ) -> c_int; - pub fn crypto_generichash_blake2b_final( state: *mut crypto_generichash_blake2b_state, - out: *mut u8, + out: *mut c_uchar, outlen: size_t, ) -> c_int; } @@ -74,7 +77,7 @@ extern "C" { #[test] fn test_crypto_generichash_blake2b_bytes_min() { assert_eq!( - unsafe { crypto_generichash_blake2b_bytes_min() as usize }, + unsafe { crypto_generichash_blake2b_bytes_min() }, crypto_generichash_blake2b_BYTES_MIN ) } @@ -82,7 +85,7 @@ fn test_crypto_generichash_blake2b_bytes_min() { #[test] fn test_crypto_generichash_blake2b_bytes_max() { assert_eq!( - unsafe { crypto_generichash_blake2b_bytes_max() as usize }, + unsafe { crypto_generichash_blake2b_bytes_max() }, crypto_generichash_blake2b_BYTES_MAX ) } @@ -90,7 +93,7 @@ fn test_crypto_generichash_blake2b_bytes_max() { #[test] fn test_crypto_generichash_blake2b_bytes() { assert_eq!( - unsafe { crypto_generichash_blake2b_bytes() as usize }, + unsafe { crypto_generichash_blake2b_bytes() }, crypto_generichash_blake2b_BYTES ) } @@ -98,7 +101,7 @@ fn test_crypto_generichash_blake2b_bytes() { #[test] fn test_crypto_generichash_blake2b_keybytes_min() { assert_eq!( - unsafe { crypto_generichash_blake2b_keybytes_min() as usize }, + unsafe { crypto_generichash_blake2b_keybytes_min() }, crypto_generichash_blake2b_KEYBYTES_MIN ) } @@ -106,7 +109,7 @@ fn test_crypto_generichash_blake2b_keybytes_min() { #[test] fn test_crypto_generichash_blake2b_keybytes_max() { assert_eq!( - unsafe { crypto_generichash_blake2b_keybytes_max() as usize }, + unsafe { crypto_generichash_blake2b_keybytes_max() }, crypto_generichash_blake2b_KEYBYTES_MAX ) } @@ -114,7 +117,7 @@ fn test_crypto_generichash_blake2b_keybytes_max() { #[test] fn test_crypto_generichash_blake2b_keybytes() { assert_eq!( - unsafe { crypto_generichash_blake2b_keybytes() as usize }, + unsafe { crypto_generichash_blake2b_keybytes() }, crypto_generichash_blake2b_KEYBYTES ) } @@ -122,7 +125,7 @@ fn test_crypto_generichash_blake2b_keybytes() { #[test] fn test_crypto_generichash_blake2b_saltbytes() { assert_eq!( - unsafe { crypto_generichash_blake2b_saltbytes() as usize }, + unsafe { crypto_generichash_blake2b_saltbytes() }, crypto_generichash_blake2b_SALTBYTES ) } @@ -130,7 +133,7 @@ fn test_crypto_generichash_blake2b_saltbytes() { #[test] fn test_crypto_generichash_blake2b_personalbytes() { assert_eq!( - unsafe { crypto_generichash_blake2b_personalbytes() as usize }, + unsafe { crypto_generichash_blake2b_personalbytes() }, crypto_generichash_blake2b_PERSONALBYTES ) } diff --git a/rust_sodium-sys/src/crypto_hash.rs b/rust_sodium-sys/src/crypto_hash.rs index d209a0b6..c23f27be 100644 --- a/rust_sodium-sys/src/crypto_hash.rs +++ b/rust_sodium-sys/src/crypto_hash.rs @@ -1,20 +1,19 @@ // crypto_hash.h -pub const crypto_hash_BYTES: usize = crypto_hash_sha512_BYTES; -pub const crypto_hash_PRIMITIVE: *const c_char = (b"sha512\0" as *const u8) as *const c_char; - +pub const crypto_hash_BYTES: size_t = crypto_hash_sha512_BYTES; +pub const crypto_hash_PRIMITIVE: *const c_char = (b"sha512\0" as *const c_uchar) as *const c_char; extern "C" { pub fn crypto_hash_bytes() -> size_t; - pub fn crypto_hash(h: *mut u8, m: *const u8, mlen: c_ulonglong) -> c_int; + pub fn crypto_hash(h: *mut c_uchar, m: *const c_uchar, mlen: c_ulonglong) -> c_int; pub fn crypto_hash_primitive() -> *const c_char; } - #[test] fn test_crypto_hash_bytes() { - assert!(unsafe { crypto_hash_bytes() as usize } == crypto_hash_BYTES) + assert_eq!(unsafe { crypto_hash_bytes() }, crypto_hash_BYTES) } + #[test] fn test_crypto_hash_primitive() { use std::ffi::CStr; diff --git a/rust_sodium-sys/src/crypto_hash_sha256.rs b/rust_sodium-sys/src/crypto_hash_sha256.rs index 3e939eaf..63365567 100644 --- a/rust_sodium-sys/src/crypto_hash_sha256.rs +++ b/rust_sodium-sys/src/crypto_hash_sha256.rs @@ -1,29 +1,38 @@ // crypto_hash_sha256.h #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct crypto_hash_sha256_state { - state: [u32; 8], - count: u64, - buf: [u8; 64], + state: [uint32_t; 8], + count: uint64_t, + buf: [uint8_t; 64], } -pub const crypto_hash_sha256_BYTES: usize = 32; +impl Clone for crypto_hash_sha256_state { + fn clone(&self) -> crypto_hash_sha256_state { + *self + } +} + +pub const crypto_hash_sha256_BYTES: size_t = 32; extern "C" { pub fn crypto_hash_sha256_bytes() -> size_t; - pub fn crypto_hash_sha256(h: *mut u8, m: *const u8, mlen: c_ulonglong) -> c_int; + pub fn crypto_hash_sha256(h: *mut c_uchar, m: *const c_uchar, mlen: c_ulonglong) -> c_int; pub fn crypto_hash_sha256_init(state: *mut crypto_hash_sha256_state) -> c_int; pub fn crypto_hash_sha256_update( state: *mut crypto_hash_sha256_state, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, ) -> c_int; - pub fn crypto_hash_sha256_final(state: *mut crypto_hash_sha256_state, h: *mut u8) -> c_int; + pub fn crypto_hash_sha256_final(state: *mut crypto_hash_sha256_state, h: *mut c_uchar) + -> c_int; } - #[test] fn test_crypto_hash_sha256_bytes() { - assert!(unsafe { crypto_hash_sha256_bytes() as usize } == crypto_hash_sha256_BYTES) + assert_eq!( + unsafe { crypto_hash_sha256_bytes() }, + crypto_hash_sha256_BYTES + ) } diff --git a/rust_sodium-sys/src/crypto_hash_sha512.rs b/rust_sodium-sys/src/crypto_hash_sha512.rs index b3041f12..e8cf97ac 100644 --- a/rust_sodium-sys/src/crypto_hash_sha512.rs +++ b/rust_sodium-sys/src/crypto_hash_sha512.rs @@ -1,29 +1,38 @@ // crypto_hash_sha512.h #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct crypto_hash_sha512_state { - state: [u64; 8], - count: [u64; 2], - buf: [u8; 128], + state: [uint64_t; 8], + count: [uint64_t; 2], + buf: [uint8_t; 128], } -pub const crypto_hash_sha512_BYTES: usize = 64; +impl Clone for crypto_hash_sha512_state { + fn clone(&self) -> crypto_hash_sha512_state { + *self + } +} + +pub const crypto_hash_sha512_BYTES: size_t = 64; extern "C" { pub fn crypto_hash_sha512_bytes() -> size_t; - pub fn crypto_hash_sha512(h: *mut u8, m: *const u8, mlen: c_ulonglong) -> c_int; + pub fn crypto_hash_sha512(h: *mut c_uchar, m: *const c_uchar, mlen: c_ulonglong) -> c_int; pub fn crypto_hash_sha512_init(state: *mut crypto_hash_sha512_state) -> c_int; pub fn crypto_hash_sha512_update( state: *mut crypto_hash_sha512_state, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, ) -> c_int; - pub fn crypto_hash_sha512_final(state: *mut crypto_hash_sha512_state, h: *mut u8) -> c_int; + pub fn crypto_hash_sha512_final(state: *mut crypto_hash_sha512_state, h: *mut c_uchar) + -> c_int; } - #[test] fn test_crypto_hash_sha512_bytes() { - assert!(unsafe { crypto_hash_sha512_bytes() as usize } == crypto_hash_sha512_BYTES) + assert_eq!( + unsafe { crypto_hash_sha512_bytes() }, + crypto_hash_sha512_BYTES + ) } diff --git a/rust_sodium-sys/src/crypto_onetimeauth.rs b/rust_sodium-sys/src/crypto_onetimeauth.rs index daae6a75..b3abe3af 100644 --- a/rust_sodium-sys/src/crypto_onetimeauth.rs +++ b/rust_sodium-sys/src/crypto_onetimeauth.rs @@ -1,26 +1,32 @@ // crypto_onetimeauth.h -pub const crypto_onetimeauth_BYTES: usize = crypto_onetimeauth_poly1305_BYTES; -pub const crypto_onetimeauth_KEYBYTES: usize = crypto_onetimeauth_poly1305_KEYBYTES; -pub const crypto_onetimeauth_PRIMITIVE: *const c_char = (b"poly1305\0" as *const u8) as +pub const crypto_onetimeauth_BYTES: size_t = crypto_onetimeauth_poly1305_BYTES; +pub const crypto_onetimeauth_KEYBYTES: size_t = crypto_onetimeauth_poly1305_KEYBYTES; +pub const crypto_onetimeauth_PRIMITIVE: *const c_char = (b"poly1305\0" as *const c_uchar) as *const c_char; - extern "C" { pub fn crypto_onetimeauth_bytes() -> size_t; pub fn crypto_onetimeauth_keybytes() -> size_t; pub fn crypto_onetimeauth_primitive() -> *const c_char; } - #[test] fn test_crypto_onetimeauth_bytes() { - assert!(unsafe { crypto_onetimeauth_bytes() as usize } == crypto_onetimeauth_BYTES) + assert_eq!( + unsafe { crypto_onetimeauth_bytes() }, + crypto_onetimeauth_BYTES + ) } + #[test] fn test_crypto_onetimeauth_keybytes() { - assert!(unsafe { crypto_onetimeauth_keybytes() as usize } == crypto_onetimeauth_KEYBYTES) + assert_eq!( + unsafe { crypto_onetimeauth_keybytes() }, + crypto_onetimeauth_KEYBYTES + ) } + #[test] fn test_crypto_onetimeauth_primitive() { use std::ffi::CStr; diff --git a/rust_sodium-sys/src/crypto_onetimeauth_poly1305.rs b/rust_sodium-sys/src/crypto_onetimeauth_poly1305.rs index 9a6b2d72..9cf87f30 100644 --- a/rust_sodium-sys/src/crypto_onetimeauth_poly1305.rs +++ b/rust_sodium-sys/src/crypto_onetimeauth_poly1305.rs @@ -1,37 +1,37 @@ // crypto_onetimeauth_poly1305.h -pub const crypto_onetimeauth_poly1305_BYTES: usize = 16; -pub const crypto_onetimeauth_poly1305_KEYBYTES: usize = 32; - +pub const crypto_onetimeauth_poly1305_BYTES: size_t = 16; +pub const crypto_onetimeauth_poly1305_KEYBYTES: size_t = 32; extern "C" { pub fn crypto_onetimeauth_poly1305( - a: *mut u8, - m: *const u8, + a: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_onetimeauth_poly1305_verify( - a: *const u8, - m: *const u8, + a: *const c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_onetimeauth_poly1305_bytes() -> size_t; pub fn crypto_onetimeauth_poly1305_keybytes() -> size_t; } - #[test] fn test_crypto_onetimeauth_poly1305_bytes() { - assert!( - unsafe { crypto_onetimeauth_poly1305_bytes() as usize } == crypto_onetimeauth_poly1305_BYTES + assert_eq!( + unsafe { crypto_onetimeauth_poly1305_bytes() }, + crypto_onetimeauth_poly1305_BYTES ) } + #[test] fn test_crypto_onetimeauth_poly1305_keybytes() { - assert!( - unsafe { crypto_onetimeauth_poly1305_keybytes() as usize } == - crypto_onetimeauth_poly1305_KEYBYTES + assert_eq!( + unsafe { crypto_onetimeauth_poly1305_keybytes() }, + crypto_onetimeauth_poly1305_KEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_pwhash_scryptsalsa208sha256.rs b/rust_sodium-sys/src/crypto_pwhash_scryptsalsa208sha256.rs index 5a46e14f..65dfec2f 100644 --- a/rust_sodium-sys/src/crypto_pwhash_scryptsalsa208sha256.rs +++ b/rust_sodium-sys/src/crypto_pwhash_scryptsalsa208sha256.rs @@ -1,14 +1,13 @@ // crypto_pwhash_scryptsalsa208sha256.h -pub const crypto_pwhash_scryptsalsa208sha256_SALTBYTES: usize = 32; -pub const crypto_pwhash_scryptsalsa208sha256_STRBYTES: usize = 102; -pub const crypto_pwhash_scryptsalsa208sha256_STRPREFIX: *const c_char = (b"$7$\0" as *const u8) as - *const c_char; -pub const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE: usize = 524_288; -pub const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE: usize = 16_777_216; -pub const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE: usize = 33_554_432; -pub const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE: usize = 1_073_741_824; - +pub const crypto_pwhash_scryptsalsa208sha256_SALTBYTES: size_t = 32; +pub const crypto_pwhash_scryptsalsa208sha256_STRBYTES: size_t = 102; +pub const crypto_pwhash_scryptsalsa208sha256_STRPREFIX: *const c_char = + (b"$7$\0" as *const c_uchar) as *const c_char; +pub const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE: size_t = 524288; +pub const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE: size_t = 16777216; +pub const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE: size_t = 33554432; +pub const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE: size_t = 1073741824; extern "C" { pub fn crypto_pwhash_scryptsalsa208sha256_saltbytes() -> size_t; @@ -19,11 +18,11 @@ extern "C" { pub fn crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() -> size_t; pub fn crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() -> size_t; pub fn crypto_pwhash_scryptsalsa208sha256( - out: *mut u8, + out: *mut c_uchar, outlen: c_ulonglong, passwd: *const c_char, passwdlen: c_ulonglong, - salt: *const u8, + salt: *const c_uchar, opslimit: c_ulonglong, memlimit: size_t, ) -> c_int; @@ -40,61 +39,66 @@ extern "C" { passwdlen: c_ulonglong, ) -> c_int; pub fn crypto_pwhash_scryptsalsa208sha256_ll( - passwd: *const u8, + passwd: *const c_uchar, passwdlen: size_t, - salt: *const u8, + salt: *const c_uchar, saltlen: size_t, N: u64, r: u32, p: u32, - buf: *mut u8, + buf: *mut c_uchar, buflen: size_t, ) -> c_int; } - #[test] fn test_crypto_pwhash_scryptsalsa208sha256_saltbytes() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_saltbytes() as usize } == - crypto_pwhash_scryptsalsa208sha256_SALTBYTES + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_saltbytes() }, + crypto_pwhash_scryptsalsa208sha256_SALTBYTES ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_strbytes() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_strbytes() as usize } == - crypto_pwhash_scryptsalsa208sha256_STRBYTES + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_strbytes() }, + crypto_pwhash_scryptsalsa208sha256_STRBYTES ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() as usize } == - crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() }, + crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() as usize } == - crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() }, + crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() as usize } == - crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() }, + crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() { - assert!( - unsafe { crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() as usize } == - crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE + assert_eq!( + unsafe { crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() }, + crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE ) } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_strprefix() { use std::ffi::CStr; @@ -105,6 +109,7 @@ fn test_crypto_pwhash_scryptsalsa208sha256_strprefix() { ); } } + #[test] fn test_crypto_pwhash_scryptsalsa208sha256_str() { let password = "Correct Horse Battery Staple"; @@ -118,7 +123,7 @@ fn test_crypto_pwhash_scryptsalsa208sha256_str() { crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE as size_t, ) }; - assert!(ret_hash == 0); + assert_eq!(ret_hash, 0); let ret_verify = unsafe { crypto_pwhash_scryptsalsa208sha256_str_verify( hashed_password.as_ptr(), @@ -126,9 +131,11 @@ fn test_crypto_pwhash_scryptsalsa208sha256_str() { password.len() as c_ulonglong, ) }; - assert!(ret_verify == 0); + assert_eq!(ret_verify, 0); } + #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_crypto_pwhash_scryptsalsa208sha256_ll_1() { // See https://www.tarsnap.com/scrypt/scrypt.pdf Page 16 let password = ""; @@ -137,72 +144,11 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_1() { let r = 1; let p = 1; let mut buf = [0u8; 64]; - let expected = [ - 0x77, - 0xd6, - 0x57, - 0x62, - 0x38, - 0x65, - 0x7b, - 0x20, - 0x3b, - 0x19, - 0xca, - 0x42, - 0xc1, - 0x8a, - 0x04, - 0x97, - 0xf1, - 0x6b, - 0x48, - 0x44, - 0xe3, - 0x07, - 0x4a, - 0xe8, - 0xdf, - 0xdf, - 0xfa, - 0x3f, - 0xed, - 0xe2, - 0x14, - 0x42, - 0xfc, - 0xd0, - 0x06, - 0x9d, - 0xed, - 0x09, - 0x48, - 0xf8, - 0x32, - 0x6a, - 0x75, - 0x3a, - 0x0f, - 0xc8, - 0x1f, - 0x17, - 0xe8, - 0xd3, - 0xe0, - 0xfb, - 0x2e, - 0x0d, - 0x36, - 0x28, - 0xcf, - 0x35, - 0xe2, - 0x0c, - 0x38, - 0xd1, - 0x89, - 0x06, - ]; + let expected = [0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20, 0x3b, 0x19, 0xca, 0x42, 0xc1, + 0x8a, 0x04, 0x97, 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8, 0xdf, 0xdf, + 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42, 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, + 0xf8, 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17, 0xe8, 0xd3, 0xe0, 0xfb, + 0x2e, 0x0d, 0x36, 0x28, 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06]; let ret = unsafe { crypto_pwhash_scryptsalsa208sha256_ll( password.as_ptr(), @@ -216,10 +162,12 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_1() { buf.len() as size_t, ) }; - assert!(ret == 0); + assert_eq!(ret, 0); assert!(buf[0..] == expected[0..]); } + #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_crypto_pwhash_scryptsalsa208sha256_ll_2() { // See https://www.tarsnap.com/scrypt/scrypt.pdf Page 16 let password = "password"; @@ -228,72 +176,11 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_2() { let r = 8; let p = 16; let mut buf = [0u8; 64]; - let expected = [ - 0xfd, - 0xba, - 0xbe, - 0x1c, - 0x9d, - 0x34, - 0x72, - 0x00, - 0x78, - 0x56, - 0xe7, - 0x19, - 0x0d, - 0x01, - 0xe9, - 0xfe, - 0x7c, - 0x6a, - 0xd7, - 0xcb, - 0xc8, - 0x23, - 0x78, - 0x30, - 0xe7, - 0x73, - 0x76, - 0x63, - 0x4b, - 0x37, - 0x31, - 0x62, - 0x2e, - 0xaf, - 0x30, - 0xd9, - 0x2e, - 0x22, - 0xa3, - 0x88, - 0x6f, - 0xf1, - 0x09, - 0x27, - 0x9d, - 0x98, - 0x30, - 0xda, - 0xc7, - 0x27, - 0xaf, - 0xb9, - 0x4a, - 0x83, - 0xee, - 0x6d, - 0x83, - 0x60, - 0xcb, - 0xdf, - 0xa2, - 0xcc, - 0x06, - 0x40, - ]; + let expected = [0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, 0x78, 0x56, 0xe7, 0x19, 0x0d, + 0x01, 0xe9, 0xfe, 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, 0xe7, 0x73, + 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62, 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, + 0x88, 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda, 0xc7, 0x27, 0xaf, 0xb9, + 0x4a, 0x83, 0xee, 0x6d, 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40]; let ret = unsafe { crypto_pwhash_scryptsalsa208sha256_ll( password.as_ptr(), @@ -307,84 +194,25 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_2() { buf.len() as size_t, ) }; - assert!(ret == 0); + assert_eq!(ret, 0); assert!(buf[0..] == expected[0..]); } + #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_crypto_pwhash_scryptsalsa208sha256_ll_3() { // See https://www.tarsnap.com/scrypt/scrypt.pdf Page 16 let password = "pleaseletmein"; let salt = "SodiumChloride"; - let n = 16_384; + let n = 16384; let r = 8; let p = 1; let mut buf = [0u8; 64]; - let expected = [ - 0x70, - 0x23, - 0xbd, - 0xcb, - 0x3a, - 0xfd, - 0x73, - 0x48, - 0x46, - 0x1c, - 0x06, - 0xcd, - 0x81, - 0xfd, - 0x38, - 0xeb, - 0xfd, - 0xa8, - 0xfb, - 0xba, - 0x90, - 0x4f, - 0x8e, - 0x3e, - 0xa9, - 0xb5, - 0x43, - 0xf6, - 0x54, - 0x5d, - 0xa1, - 0xf2, - 0xd5, - 0x43, - 0x29, - 0x55, - 0x61, - 0x3f, - 0x0f, - 0xcf, - 0x62, - 0xd4, - 0x97, - 0x05, - 0x24, - 0x2a, - 0x9a, - 0xf9, - 0xe6, - 0x1e, - 0x85, - 0xdc, - 0x0d, - 0x65, - 0x1e, - 0x40, - 0xdf, - 0xcf, - 0x01, - 0x7b, - 0x45, - 0x57, - 0x58, - 0x87, - ]; + let expected = [0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48, 0x46, 0x1c, 0x06, 0xcd, 0x81, + 0xfd, 0x38, 0xeb, 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e, 0xa9, 0xb5, + 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2, 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, + 0xcf, 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9, 0xe6, 0x1e, 0x85, 0xdc, + 0x0d, 0x65, 0x1e, 0x40, 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87]; let ret = unsafe { crypto_pwhash_scryptsalsa208sha256_ll( password.as_ptr(), @@ -398,84 +226,25 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_3() { buf.len() as size_t, ) }; - assert!(ret == 0); + assert_eq!(ret, 0); assert!(buf[0..] == expected[0..]); } + #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_crypto_pwhash_scryptsalsa208sha256_ll_4() { // See https://www.tarsnap.com/scrypt/scrypt.pdf Page 16 let password = "pleaseletmein"; let salt = "SodiumChloride"; - let n = 1_048_576; + let n = 1048576; let r = 8; let p = 1; let mut buf = [0u8; 64]; - let expected = [ - 0x21, - 0x01, - 0xcb, - 0x9b, - 0x6a, - 0x51, - 0x1a, - 0xae, - 0xad, - 0xdb, - 0xbe, - 0x09, - 0xcf, - 0x70, - 0xf8, - 0x81, - 0xec, - 0x56, - 0x8d, - 0x57, - 0x4a, - 0x2f, - 0xfd, - 0x4d, - 0xab, - 0xe5, - 0xee, - 0x98, - 0x20, - 0xad, - 0xaa, - 0x47, - 0x8e, - 0x56, - 0xfd, - 0x8f, - 0x4b, - 0xa5, - 0xd0, - 0x9f, - 0xfa, - 0x1c, - 0x6d, - 0x92, - 0x7c, - 0x40, - 0xf4, - 0xc3, - 0x37, - 0x30, - 0x40, - 0x49, - 0xe8, - 0xa9, - 0x52, - 0xfb, - 0xcb, - 0xf4, - 0x5c, - 0x6f, - 0xa7, - 0x7a, - 0x41, - 0xa4, - ]; + let expected = [0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae, 0xad, 0xdb, 0xbe, 0x09, 0xcf, + 0x70, 0xf8, 0x81, 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d, 0xab, 0xe5, + 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47, 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, + 0x9f, 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3, 0x37, 0x30, 0x40, 0x49, + 0xe8, 0xa9, 0x52, 0xfb, 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4]; let ret = unsafe { crypto_pwhash_scryptsalsa208sha256_ll( password.as_ptr(), @@ -489,6 +258,6 @@ fn test_crypto_pwhash_scryptsalsa208sha256_ll_4() { buf.len() as size_t, ) }; - assert!(ret == 0); + assert_eq!(ret, 0); assert!(buf[0..] == expected[0..]); } diff --git a/rust_sodium-sys/src/crypto_scalarmult.rs b/rust_sodium-sys/src/crypto_scalarmult.rs index 06eea2e6..6a5973f6 100644 --- a/rust_sodium-sys/src/crypto_scalarmult.rs +++ b/rust_sodium-sys/src/crypto_scalarmult.rs @@ -1,22 +1,22 @@ // crypto_scalarmult.h -pub const crypto_scalarmult_BYTES: usize = crypto_scalarmult_curve25519_BYTES; -pub const crypto_scalarmult_SCALARBYTES: usize = crypto_scalarmult_curve25519_SCALARBYTES; -pub const crypto_scalarmult_PRIMITIVE: *const c_char = (b"curve25519\0" as *const u8) as +pub const crypto_scalarmult_BYTES: size_t = crypto_scalarmult_curve25519_BYTES; +pub const crypto_scalarmult_SCALARBYTES: size_t = crypto_scalarmult_curve25519_SCALARBYTES; +pub const crypto_scalarmult_PRIMITIVE: *const c_char = (b"curve25519\0" as *const c_uchar) as *const c_char; extern "C" { pub fn crypto_scalarmult_bytes() -> size_t; pub fn crypto_scalarmult_scalarbytes() -> size_t; pub fn crypto_scalarmult_primitive() -> *const c_char; - pub fn crypto_scalarmult_base(q: *mut u8, n: *const u8) -> c_int; - pub fn crypto_scalarmult(q: *mut u8, n: *const u8, p: *const u8) -> c_int; + pub fn crypto_scalarmult_base(q: *mut c_uchar, n: *const c_uchar) -> c_int; + pub fn crypto_scalarmult(q: *mut c_uchar, n: *const c_uchar, p: *const c_uchar) -> c_int; } #[test] fn test_crypto_scalarmult_bytes() { assert_eq!( - unsafe { crypto_scalarmult_bytes() as usize }, + unsafe { crypto_scalarmult_bytes() }, crypto_scalarmult_BYTES ); } @@ -24,7 +24,7 @@ fn test_crypto_scalarmult_bytes() { #[test] fn test_crypto_scalarmult_scalarbytes() { assert_eq!( - unsafe { crypto_scalarmult_scalarbytes() as usize }, + unsafe { crypto_scalarmult_scalarbytes() }, crypto_scalarmult_SCALARBYTES ); } diff --git a/rust_sodium-sys/src/crypto_scalarmult_curve25519.rs b/rust_sodium-sys/src/crypto_scalarmult_curve25519.rs index 9830916a..a852e2c0 100644 --- a/rust_sodium-sys/src/crypto_scalarmult_curve25519.rs +++ b/rust_sodium-sys/src/crypto_scalarmult_curve25519.rs @@ -1,19 +1,23 @@ // crypto_scalarmult_curve25519.h -pub const crypto_scalarmult_curve25519_BYTES: usize = 32; -pub const crypto_scalarmult_curve25519_SCALARBYTES: usize = 32; +pub const crypto_scalarmult_curve25519_BYTES: size_t = 32; +pub const crypto_scalarmult_curve25519_SCALARBYTES: size_t = 32; extern "C" { pub fn crypto_scalarmult_curve25519_bytes() -> size_t; pub fn crypto_scalarmult_curve25519_scalarbytes() -> size_t; - pub fn crypto_scalarmult_curve25519_base(q: *mut u8, n: *const u8) -> c_int; - pub fn crypto_scalarmult_curve25519(q: *mut u8, n: *const u8, p: *const u8) -> c_int; + pub fn crypto_scalarmult_curve25519_base(q: *mut c_uchar, n: *const c_uchar) -> c_int; + pub fn crypto_scalarmult_curve25519( + q: *mut c_uchar, + n: *const c_uchar, + p: *const c_uchar, + ) -> c_int; } #[test] fn test_crypto_scalarmult_curve25519_bytes() { assert_eq!( - unsafe { crypto_scalarmult_curve25519_bytes() as usize }, + unsafe { crypto_scalarmult_curve25519_bytes() }, crypto_scalarmult_curve25519_BYTES ); } @@ -21,7 +25,7 @@ fn test_crypto_scalarmult_curve25519_bytes() { #[test] fn test_crypto_scalarmult_curve25519_scalarbytes() { assert_eq!( - unsafe { crypto_scalarmult_curve25519_scalarbytes() as usize }, + unsafe { crypto_scalarmult_curve25519_scalarbytes() }, crypto_scalarmult_curve25519_SCALARBYTES ); } diff --git a/rust_sodium-sys/src/crypto_secretbox.rs b/rust_sodium-sys/src/crypto_secretbox.rs index 68e9d3b1..99329f25 100644 --- a/rust_sodium-sys/src/crypto_secretbox.rs +++ b/rust_sodium-sys/src/crypto_secretbox.rs @@ -1,39 +1,41 @@ -pub const crypto_secretbox_KEYBYTES: usize = 32; -pub const crypto_secretbox_NONCEBYTES: usize = 24; -pub const crypto_secretbox_MACBYTES: usize = 16; -pub const crypto_secretbox_PRIMITIVE: *const c_char = (b"xsalsa20poly1305\0" as *const u8) as +// crypto_secretbox.h + +pub const crypto_secretbox_KEYBYTES: size_t = 32; +pub const crypto_secretbox_NONCEBYTES: size_t = 24; +pub const crypto_secretbox_MACBYTES: size_t = 16; +pub const crypto_secretbox_PRIMITIVE: *const c_char = (b"xsalsa20poly1305\0" as *const c_uchar) as *const c_char; extern "C" { pub fn crypto_secretbox_easy( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_open_easy( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_detached( - c: *mut u8, - mac: *mut u8, - m: *const u8, + c: *mut c_uchar, + mac: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_open_detached( - m: *mut u8, - c: *const u8, - mac: *const u8, + m: *mut c_uchar, + c: *const c_uchar, + mac: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_keybytes() -> size_t; pub fn crypto_secretbox_noncebytes() -> size_t; @@ -43,17 +45,26 @@ extern "C" { #[test] fn test_crypto_secretbox_keybytes() { - assert!(unsafe { crypto_secretbox_keybytes() as usize } == crypto_secretbox_KEYBYTES) + assert_eq!( + unsafe { crypto_secretbox_keybytes() }, + crypto_secretbox_KEYBYTES + ) } #[test] fn test_crypto_secretbox_noncebytes() { - assert!(unsafe { crypto_secretbox_noncebytes() as usize } == crypto_secretbox_NONCEBYTES) + assert_eq!( + unsafe { crypto_secretbox_noncebytes() }, + crypto_secretbox_NONCEBYTES + ) } #[test] fn test_crypto_secretbox_macbytes() { - assert!(unsafe { crypto_secretbox_macbytes() as usize } == crypto_secretbox_MACBYTES) + assert_eq!( + unsafe { crypto_secretbox_macbytes() }, + crypto_secretbox_MACBYTES + ) } #[test] diff --git a/rust_sodium-sys/src/crypto_secretbox_xsalsa20poly1305.rs b/rust_sodium-sys/src/crypto_secretbox_xsalsa20poly1305.rs index 32142517..2845c1e9 100644 --- a/rust_sodium-sys/src/crypto_secretbox_xsalsa20poly1305.rs +++ b/rust_sodium-sys/src/crypto_secretbox_xsalsa20poly1305.rs @@ -1,27 +1,26 @@ // crypto_secretbox_xsalsa20poly1305.h -pub const crypto_secretbox_xsalsa20poly1305_KEYBYTES: usize = 32; -pub const crypto_secretbox_xsalsa20poly1305_NONCEBYTES: usize = 24; -pub const crypto_secretbox_xsalsa20poly1305_ZEROBYTES: usize = 32; -pub const crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES: usize = 16; -pub const crypto_secretbox_xsalsa20poly1305_MACBYTES: usize = +pub const crypto_secretbox_xsalsa20poly1305_KEYBYTES: size_t = 32; +pub const crypto_secretbox_xsalsa20poly1305_NONCEBYTES: size_t = 24; +pub const crypto_secretbox_xsalsa20poly1305_ZEROBYTES: size_t = 32; +pub const crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES: size_t = 16; +pub const crypto_secretbox_xsalsa20poly1305_MACBYTES: size_t = crypto_secretbox_xsalsa20poly1305_ZEROBYTES - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES; - extern "C" { pub fn crypto_secretbox_xsalsa20poly1305( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_xsalsa20poly1305_open( - m: *mut u8, - c: *const u8, + m: *mut c_uchar, + c: *const c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_secretbox_xsalsa20poly1305_keybytes() -> size_t; pub fn crypto_secretbox_xsalsa20poly1305_noncebytes() -> size_t; @@ -30,39 +29,42 @@ extern "C" { pub fn crypto_secretbox_xsalsa20poly1305_macbytes() -> size_t; } - #[test] fn test_crypto_secretbox_xsalsa20poly1305_keybytes() { - assert!( - unsafe { crypto_secretbox_xsalsa20poly1305_keybytes() as usize } == - crypto_secretbox_xsalsa20poly1305_KEYBYTES + assert_eq!( + unsafe { crypto_secretbox_xsalsa20poly1305_keybytes() }, + crypto_secretbox_xsalsa20poly1305_KEYBYTES ) } + #[test] fn test_crypto_secretbox_xsalsa20poly1305_noncebytes() { - assert!( - unsafe { crypto_secretbox_xsalsa20poly1305_noncebytes() as usize } == - crypto_secretbox_xsalsa20poly1305_NONCEBYTES + assert_eq!( + unsafe { crypto_secretbox_xsalsa20poly1305_noncebytes() }, + crypto_secretbox_xsalsa20poly1305_NONCEBYTES ) } + #[test] fn test_crypto_secretbox_xsalsa20poly1305_zerobytes() { - assert!( - unsafe { crypto_secretbox_xsalsa20poly1305_zerobytes() as usize } == - crypto_secretbox_xsalsa20poly1305_ZEROBYTES + assert_eq!( + unsafe { crypto_secretbox_xsalsa20poly1305_zerobytes() }, + crypto_secretbox_xsalsa20poly1305_ZEROBYTES ) } + #[test] fn test_crypto_secretbox_xsalsa20poly1305_boxzerobytes() { - assert!( - unsafe { crypto_secretbox_xsalsa20poly1305_boxzerobytes() as usize } == - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + assert_eq!( + unsafe { crypto_secretbox_xsalsa20poly1305_boxzerobytes() }, + crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES ) } + #[test] fn test_crypto_secretbox_xsalsa20poly1305_macbytes() { - assert!( - unsafe { crypto_secretbox_xsalsa20poly1305_macbytes() as usize } == - crypto_secretbox_xsalsa20poly1305_MACBYTES + assert_eq!( + unsafe { crypto_secretbox_xsalsa20poly1305_macbytes() }, + crypto_secretbox_xsalsa20poly1305_MACBYTES ) } diff --git a/rust_sodium-sys/src/crypto_shorthash_siphash24.rs b/rust_sodium-sys/src/crypto_shorthash_siphash24.rs index 7ca470f5..5a9281b1 100644 --- a/rust_sodium-sys/src/crypto_shorthash_siphash24.rs +++ b/rust_sodium-sys/src/crypto_shorthash_siphash24.rs @@ -1,30 +1,31 @@ // crypto_shorthash_siphash24.h -pub const crypto_shorthash_siphash24_BYTES: usize = 8; -pub const crypto_shorthash_siphash24_KEYBYTES: usize = 16; - +pub const crypto_shorthash_siphash24_BYTES: size_t = 8; +pub const crypto_shorthash_siphash24_KEYBYTES: size_t = 16; extern "C" { pub fn crypto_shorthash_siphash24( - h: *mut u8, - m: *const u8, + h: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - k: *const u8, + k: *const c_uchar, ) -> c_int; pub fn crypto_shorthash_siphash24_bytes() -> size_t; pub fn crypto_shorthash_siphash24_keybytes() -> size_t; } - #[test] fn test_crypto_shorthash_siphash24_bytes() { - assert!( - unsafe { crypto_shorthash_siphash24_bytes() as usize } == crypto_shorthash_siphash24_BYTES + assert_eq!( + unsafe { crypto_shorthash_siphash24_bytes() }, + crypto_shorthash_siphash24_BYTES ) } + #[test] fn test_crypto_shorthash_siphash24_keybytes() { - assert!( - unsafe { crypto_shorthash_siphash24_keybytes() as usize } == crypto_shorthash_siphash24_KEYBYTES + assert_eq!( + unsafe { crypto_shorthash_siphash24_keybytes() }, + crypto_shorthash_siphash24_KEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_sign_ed25519.rs b/rust_sodium-sys/src/crypto_sign_ed25519.rs index 561df668..5149eea1 100644 --- a/rust_sodium-sys/src/crypto_sign_ed25519.rs +++ b/rust_sodium-sys/src/crypto_sign_ed25519.rs @@ -1,40 +1,43 @@ // crypto_sign_ed25519.h -pub const crypto_sign_ed25519_BYTES: usize = 64; -pub const crypto_sign_ed25519_SEEDBYTES: usize = 32; -pub const crypto_sign_ed25519_PUBLICKEYBYTES: usize = 32; -pub const crypto_sign_ed25519_SECRETKEYBYTES: usize = 64; - +pub const crypto_sign_ed25519_BYTES: size_t = 64; +pub const crypto_sign_ed25519_SEEDBYTES: size_t = 32; +pub const crypto_sign_ed25519_PUBLICKEYBYTES: size_t = 32; +pub const crypto_sign_ed25519_SECRETKEYBYTES: size_t = 64; extern "C" { - pub fn crypto_sign_ed25519_keypair(pk: *mut u8, sk: *mut u8) -> c_int; - pub fn crypto_sign_ed25519_seed_keypair(pk: *mut u8, sk: *mut u8, seed: *const u8) -> c_int; + pub fn crypto_sign_ed25519_keypair(pk: *mut c_uchar, sk: *mut c_uchar) -> c_int; + pub fn crypto_sign_ed25519_seed_keypair( + pk: *mut c_uchar, + sk: *mut c_uchar, + seed: *const c_uchar, + ) -> c_int; pub fn crypto_sign_ed25519( - sm: *mut u8, + sm: *mut c_uchar, smlen: *mut c_ulonglong, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, - sk: *const u8, + sk: *const c_uchar, ) -> c_int; pub fn crypto_sign_ed25519_open( - m: *mut u8, + m: *mut c_uchar, mlen: *mut c_ulonglong, - sm: *const u8, + sm: *const c_uchar, smlen: c_ulonglong, - pk: *const u8, + pk: *const c_uchar, ) -> c_int; pub fn crypto_sign_ed25519_detached( - sig: *mut u8, + sig: *mut c_uchar, siglen: *mut c_ulonglong, - m: *const u8, + m: *const c_uchar, mlen: c_ulonglong, - sk: *const u8, + sk: *const c_uchar, ) -> c_int; pub fn crypto_sign_ed25519_verify_detached( - sig: *const u8, - m: *const u8, + sig: *const c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - pk: *const u8, + pk: *const c_uchar, ) -> c_int; pub fn crypto_sign_ed25519_bytes() -> size_t; pub fn crypto_sign_ed25519_seedbytes() -> size_t; @@ -42,24 +45,34 @@ extern "C" { pub fn crypto_sign_ed25519_secretkeybytes() -> size_t; } - #[test] fn test_crypto_sign_ed25519_bytes() { - assert!(unsafe { crypto_sign_ed25519_bytes() as usize } == crypto_sign_ed25519_BYTES) + assert_eq!( + unsafe { crypto_sign_ed25519_bytes() }, + crypto_sign_ed25519_BYTES + ) } + #[test] fn test_crypto_sign_ed25519_seedbytes() { - assert!(unsafe { crypto_sign_ed25519_seedbytes() as usize } == crypto_sign_ed25519_SEEDBYTES) + assert_eq!( + unsafe { crypto_sign_ed25519_seedbytes() }, + crypto_sign_ed25519_SEEDBYTES + ) } + #[test] fn test_crypto_sign_ed25519_publickeybytes() { - assert!( - unsafe { crypto_sign_ed25519_publickeybytes() as usize } == crypto_sign_ed25519_PUBLICKEYBYTES + assert_eq!( + unsafe { crypto_sign_ed25519_publickeybytes() }, + crypto_sign_ed25519_PUBLICKEYBYTES ) } + #[test] fn test_crypto_sign_ed25519_secretkeybytes() { - assert!( - unsafe { crypto_sign_ed25519_secretkeybytes() as usize } == crypto_sign_ed25519_SECRETKEYBYTES + assert_eq!( + unsafe { crypto_sign_ed25519_secretkeybytes() }, + crypto_sign_ed25519_SECRETKEYBYTES ) } diff --git a/rust_sodium-sys/src/crypto_stream.rs b/rust_sodium-sys/src/crypto_stream.rs index b2b7fa45..deb65012 100644 --- a/rust_sodium-sys/src/crypto_stream.rs +++ b/rust_sodium-sys/src/crypto_stream.rs @@ -1,9 +1,9 @@ // crypto_stream.h -pub const crypto_stream_KEYBYTES: usize = crypto_stream_xsalsa20_KEYBYTES; -pub const crypto_stream_NONCEBYTES: usize = crypto_stream_xsalsa20_NONCEBYTES; -pub const crypto_stream_PRIMITIVE: *const c_char = (b"xsalsa20\0" as *const u8) as *const c_char; - +pub const crypto_stream_KEYBYTES: size_t = crypto_stream_xsalsa20_KEYBYTES; +pub const crypto_stream_NONCEBYTES: size_t = crypto_stream_xsalsa20_NONCEBYTES; +pub const crypto_stream_PRIMITIVE: *const c_char = (b"xsalsa20\0" as *const c_uchar) as + *const c_char; extern "C" { pub fn crypto_stream_keybytes() -> size_t; @@ -11,15 +11,19 @@ extern "C" { pub fn crypto_stream_primitive() -> *const c_char; } - #[test] fn test_crypto_stream_keybytes() { - assert!(unsafe { crypto_stream_keybytes() as usize } == crypto_stream_KEYBYTES) + assert_eq!(unsafe { crypto_stream_keybytes() }, crypto_stream_KEYBYTES) } + #[test] fn test_crypto_stream_noncebytes() { - assert!(unsafe { crypto_stream_noncebytes() as usize } == crypto_stream_NONCEBYTES) + assert_eq!( + unsafe { crypto_stream_noncebytes() }, + crypto_stream_NONCEBYTES + ) } + #[test] fn test_crypto_stream_primitive() { use std::ffi::CStr; diff --git a/rust_sodium-sys/src/crypto_stream_chacha20.rs b/rust_sodium-sys/src/crypto_stream_chacha20.rs index 973ca70f..8e5c2aeb 100644 --- a/rust_sodium-sys/src/crypto_stream_chacha20.rs +++ b/rust_sodium-sys/src/crypto_stream_chacha20.rs @@ -1,37 +1,38 @@ // crypto_stream_chacha20.h -pub const crypto_stream_chacha20_KEYBYTES: usize = 32; -pub const crypto_stream_chacha20_NONCEBYTES: usize = 8; - +pub const crypto_stream_chacha20_KEYBYTES: size_t = 32; +pub const crypto_stream_chacha20_NONCEBYTES: size_t = 8; extern "C" { pub fn crypto_stream_chacha20( - c: *mut u8, + c: *mut c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_chacha20_xor( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_chacha20_keybytes() -> size_t; pub fn crypto_stream_chacha20_noncebytes() -> size_t; } - #[test] fn test_crypto_stream_chacha20_keybytes() { - assert!( - unsafe { crypto_stream_chacha20_keybytes() as usize } == crypto_stream_chacha20_KEYBYTES + assert_eq!( + unsafe { crypto_stream_chacha20_keybytes() }, + crypto_stream_chacha20_KEYBYTES ) } + #[test] fn test_crypto_stream_chacha20_noncebytes() { - assert!( - unsafe { crypto_stream_chacha20_noncebytes() as usize } == crypto_stream_chacha20_NONCEBYTES + assert_eq!( + unsafe { crypto_stream_chacha20_noncebytes() }, + crypto_stream_chacha20_NONCEBYTES ) } diff --git a/rust_sodium-sys/src/crypto_stream_salsa20.rs b/rust_sodium-sys/src/crypto_stream_salsa20.rs index 6058fd79..90d92120 100644 --- a/rust_sodium-sys/src/crypto_stream_salsa20.rs +++ b/rust_sodium-sys/src/crypto_stream_salsa20.rs @@ -1,35 +1,38 @@ // crypto_stream_salsa20.h -pub const crypto_stream_salsa20_KEYBYTES: usize = 32; -pub const crypto_stream_salsa20_NONCEBYTES: usize = 8; - +pub const crypto_stream_salsa20_KEYBYTES: size_t = 32; +pub const crypto_stream_salsa20_NONCEBYTES: size_t = 8; extern "C" { pub fn crypto_stream_salsa20( - c: *mut u8, + c: *mut c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa20_xor( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa20_keybytes() -> size_t; pub fn crypto_stream_salsa20_noncebytes() -> size_t; } - #[test] fn test_crypto_stream_salsa20_keybytes() { - assert!(unsafe { crypto_stream_salsa20_keybytes() as usize } == crypto_stream_salsa20_KEYBYTES) + assert_eq!( + unsafe { crypto_stream_salsa20_keybytes() }, + crypto_stream_salsa20_KEYBYTES + ) } + #[test] fn test_crypto_stream_salsa20_noncebytes() { - assert!( - unsafe { crypto_stream_salsa20_noncebytes() as usize } == crypto_stream_salsa20_NONCEBYTES + assert_eq!( + unsafe { crypto_stream_salsa20_noncebytes() }, + crypto_stream_salsa20_NONCEBYTES ) } diff --git a/rust_sodium-sys/src/crypto_stream_salsa2012.rs b/rust_sodium-sys/src/crypto_stream_salsa2012.rs index 351acf5f..a5a5ac87 100644 --- a/rust_sodium-sys/src/crypto_stream_salsa2012.rs +++ b/rust_sodium-sys/src/crypto_stream_salsa2012.rs @@ -1,37 +1,38 @@ // crypto_stream_salsa2012.h -pub const crypto_stream_salsa2012_KEYBYTES: usize = 32; -pub const crypto_stream_salsa2012_NONCEBYTES: usize = 8; - +pub const crypto_stream_salsa2012_KEYBYTES: size_t = 32; +pub const crypto_stream_salsa2012_NONCEBYTES: size_t = 8; extern "C" { pub fn crypto_stream_salsa2012( - c: *mut u8, + c: *mut c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa2012_xor( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa2012_keybytes() -> size_t; pub fn crypto_stream_salsa2012_noncebytes() -> size_t; } - #[test] fn test_crypto_stream_salsa2012_keybytes() { - assert!( - unsafe { crypto_stream_salsa2012_keybytes() as usize } == crypto_stream_salsa2012_KEYBYTES + assert_eq!( + unsafe { crypto_stream_salsa2012_keybytes() }, + crypto_stream_salsa2012_KEYBYTES ) } + #[test] fn test_crypto_stream_salsa2012_noncebytes() { - assert!( - unsafe { crypto_stream_salsa2012_noncebytes() as usize } == crypto_stream_salsa2012_NONCEBYTES + assert_eq!( + unsafe { crypto_stream_salsa2012_noncebytes() }, + crypto_stream_salsa2012_NONCEBYTES ) } diff --git a/rust_sodium-sys/src/crypto_stream_salsa208.rs b/rust_sodium-sys/src/crypto_stream_salsa208.rs index ecc071f4..3ae807b8 100644 --- a/rust_sodium-sys/src/crypto_stream_salsa208.rs +++ b/rust_sodium-sys/src/crypto_stream_salsa208.rs @@ -1,37 +1,38 @@ // crypto_stream_salsa208.h -pub const crypto_stream_salsa208_KEYBYTES: usize = 32; -pub const crypto_stream_salsa208_NONCEBYTES: usize = 8; - +pub const crypto_stream_salsa208_KEYBYTES: size_t = 32; +pub const crypto_stream_salsa208_NONCEBYTES: size_t = 8; extern "C" { pub fn crypto_stream_salsa208( - c: *mut u8, + c: *mut c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa208_xor( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_salsa208_keybytes() -> size_t; pub fn crypto_stream_salsa208_noncebytes() -> size_t; } - #[test] fn test_crypto_stream_salsa208_keybytes() { - assert!( - unsafe { crypto_stream_salsa208_keybytes() as usize } == crypto_stream_salsa208_KEYBYTES + assert_eq!( + unsafe { crypto_stream_salsa208_keybytes() }, + crypto_stream_salsa208_KEYBYTES ) } + #[test] fn test_crypto_stream_salsa208_noncebytes() { - assert!( - unsafe { crypto_stream_salsa208_noncebytes() as usize } == crypto_stream_salsa208_NONCEBYTES + assert_eq!( + unsafe { crypto_stream_salsa208_noncebytes() }, + crypto_stream_salsa208_NONCEBYTES ) } diff --git a/rust_sodium-sys/src/crypto_stream_xsalsa20.rs b/rust_sodium-sys/src/crypto_stream_xsalsa20.rs index 47204912..00702d07 100644 --- a/rust_sodium-sys/src/crypto_stream_xsalsa20.rs +++ b/rust_sodium-sys/src/crypto_stream_xsalsa20.rs @@ -1,37 +1,38 @@ // crypto_stream_xsalsa20.h -pub const crypto_stream_xsalsa20_KEYBYTES: usize = 32; -pub const crypto_stream_xsalsa20_NONCEBYTES: usize = 24; - +pub const crypto_stream_xsalsa20_KEYBYTES: size_t = 32; +pub const crypto_stream_xsalsa20_NONCEBYTES: size_t = 24; extern "C" { pub fn crypto_stream_xsalsa20( - c: *mut u8, + c: *mut c_uchar, clen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_xsalsa20_xor( - c: *mut u8, - m: *const u8, + c: *mut c_uchar, + m: *const c_uchar, mlen: c_ulonglong, - n: *const u8, - k: *const u8, + n: *const c_uchar, + k: *const c_uchar, ) -> c_int; pub fn crypto_stream_xsalsa20_keybytes() -> size_t; pub fn crypto_stream_xsalsa20_noncebytes() -> size_t; } - #[test] fn test_crypto_stream_xsalsa20_keybytes() { - assert!( - unsafe { crypto_stream_xsalsa20_keybytes() as usize } == crypto_stream_xsalsa20_KEYBYTES + assert_eq!( + unsafe { crypto_stream_xsalsa20_keybytes() }, + crypto_stream_xsalsa20_KEYBYTES ) } + #[test] fn test_crypto_stream_xsalsa20_noncebytes() { - assert!( - unsafe { crypto_stream_xsalsa20_noncebytes() as usize } == crypto_stream_xsalsa20_NONCEBYTES + assert_eq!( + unsafe { crypto_stream_xsalsa20_noncebytes() }, + crypto_stream_xsalsa20_NONCEBYTES ) } diff --git a/rust_sodium-sys/src/crypto_verify_16.rs b/rust_sodium-sys/src/crypto_verify_16.rs index f7e07705..c6b5705d 100644 --- a/rust_sodium-sys/src/crypto_verify_16.rs +++ b/rust_sodium-sys/src/crypto_verify_16.rs @@ -1,16 +1,13 @@ // crypto_verify_16.h -pub const crypto_verify_16_BYTES: usize = 16; +pub const crypto_verify_16_BYTES: size_t = 16; extern "C" { pub fn crypto_verify_16_bytes() -> size_t; - pub fn crypto_verify_16(x: *const u8, y: *const u8) -> c_int; + pub fn crypto_verify_16(x: *const c_uchar, y: *const c_uchar) -> c_int; } #[test] fn test_crypto_verify_16_bytes() { - assert_eq!( - unsafe { crypto_verify_16_bytes() as usize }, - crypto_verify_16_BYTES - ); + assert_eq!(unsafe { crypto_verify_16_bytes() }, crypto_verify_16_BYTES); } diff --git a/rust_sodium-sys/src/crypto_verify_32.rs b/rust_sodium-sys/src/crypto_verify_32.rs index 82568130..fc1126c6 100644 --- a/rust_sodium-sys/src/crypto_verify_32.rs +++ b/rust_sodium-sys/src/crypto_verify_32.rs @@ -1,17 +1,13 @@ // crypto_verify_32.h -pub const crypto_verify_32_BYTES: usize = 32; +pub const crypto_verify_32_BYTES: size_t = 32; extern "C" { pub fn crypto_verify_32_bytes() -> size_t; - pub fn crypto_verify_32(x: *const u8, y: *const u8) -> c_int; + pub fn crypto_verify_32(x: *const c_uchar, y: *const c_uchar) -> c_int; } - #[test] fn test_crypto_verify_32_bytes() { - assert_eq!( - unsafe { crypto_verify_32_bytes() as usize }, - crypto_verify_32_BYTES - ); + assert_eq!(unsafe { crypto_verify_32_bytes() }, crypto_verify_32_BYTES); } diff --git a/rust_sodium-sys/src/crypto_verify_64.rs b/rust_sodium-sys/src/crypto_verify_64.rs index e1ffdf00..73714204 100644 --- a/rust_sodium-sys/src/crypto_verify_64.rs +++ b/rust_sodium-sys/src/crypto_verify_64.rs @@ -1,17 +1,13 @@ // crypto_verify_64.h -pub const crypto_verify_64_BYTES: usize = 64; +pub const crypto_verify_64_BYTES: size_t = 64; extern "C" { pub fn crypto_verify_64_bytes() -> size_t; - pub fn crypto_verify_64(x: *const u8, y: *const u8) -> c_int; + pub fn crypto_verify_64(x: *const c_uchar, y: *const c_uchar) -> c_int; } - #[test] fn test_crypto_verify_64_bytes() { - assert_eq!( - unsafe { crypto_verify_64_bytes() as usize }, - crypto_verify_64_BYTES - ); + assert_eq!(unsafe { crypto_verify_64_bytes() }, crypto_verify_64_BYTES); } diff --git a/rust_sodium-sys/src/init_with_rng.rs b/rust_sodium-sys/src/init_with_rng.rs index 7d379b6e..5aa1ecf2 100644 --- a/rust_sodium-sys/src/init_with_rng.rs +++ b/rust_sodium-sys/src/init_with_rng.rs @@ -64,8 +64,8 @@ extern "C" fn random() -> uint32_t { #[cfg_attr(feature = "cargo-clippy", allow(cast_possible_wrap))] extern "C" fn buf(buf: *mut c_void, size: size_t) { unsafe { - let ptr = buf as *mut u8; - let rng_ptr = RNG.with(|rng| Rc::clone(rng)); + let ptr = buf as *mut c_uchar; + let rng_ptr = RNG.with(|rng| rng.clone()); let rng = &mut *rng_ptr.borrow_mut(); for i in 0..size { *ptr.offset(i as isize) = rng.gen(); diff --git a/rust_sodium-sys/src/utils.rs b/rust_sodium-sys/src/utils.rs index 153ca51a..9a590814 100644 --- a/rust_sodium-sys/src/utils.rs +++ b/rust_sodium-sys/src/utils.rs @@ -3,7 +3,7 @@ extern "C" { pub fn sodium_memzero(pnt: *mut c_void, len: size_t); pub fn sodium_memcmp(b1_: *const c_void, b2_: *const c_void, len: size_t) -> c_int; - pub fn sodium_increment(n: *mut u8, len: size_t); + pub fn sodium_increment(n: *mut c_uchar, len: size_t); pub fn sodium_mlock(addr: *mut c_void, len: size_t) -> c_int; pub fn sodium_munlock(addr: *mut c_void, len: size_t) -> c_int;