1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![warn(unused_extern_crates)]
#![allow(warnings)]
extern crate rust_sodium_sys;
#[macro_use]
extern crate lazy_static;
extern crate lib3h_crypto_api;

lazy_static! {
    /// we only need to call sodium_init once
    static ref INIT: bool = {
        unsafe {
            rust_sodium_sys::sodium_init();
        }
        true
    };
}

/// make sure sodium_init is called
pub fn check_init() {
    assert_eq!(true, *INIT);
}

/// make invoking ffi functions taking SecBuf references more readable
macro_rules! raw_ptr_void {
    ($name: ident) => {
        $name.as_mut_ptr() as *mut libc::c_void
    };
}

/// make invoking ffi functions taking SecBuf references more readable
macro_rules! raw_ptr_char {
    ($name: ident) => {
        $name.as_mut_ptr() as *mut libc::c_uchar
    };
}

/// make invoking ffi functions taking SecBuf references more readable
macro_rules! raw_ptr_char_immut {
    ($name: ident) => {
        $name.as_ptr() as *const libc::c_uchar
    };
}

/// make invoking ffi functions taking SecBuf references more readable
macro_rules! raw_ptr_ichar_immut {
    ($name: ident) => {
        $name.as_ptr() as *const libc::c_char
    };
}

pub mod aead;
pub mod hash;
pub mod kdf;
pub mod kx;
pub mod pwhash;
pub mod secbuf;
pub mod secbuf_random;
pub mod secbuf_util;
pub mod sign;

mod crypto_system;
pub use crypto_system::{SecureBuffer, SodiumCryptoSystem};