Skip to content

Commit

Permalink
Simplify constant_time_test & remove its stdlib.h dependency.
Browse files Browse the repository at this point in the history
Remove the trivial stdlib.h dependency from the test. Now the test
works more like other tests, so it's a double win.
  • Loading branch information
briansmith committed Feb 3, 2019
1 parent bd96baa commit 1194b80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
9 changes: 1 addition & 8 deletions crypto/constant_time_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@

#include "internal.h"

#include <stdlib.h>


int bssl_constant_time_test_main(void);

static int test_binary_op_w(crypto_word (*op)(crypto_word a, crypto_word b),
Expand Down Expand Up @@ -127,9 +124,5 @@ int bssl_constant_time_test_main(void) {
}
}

if (!num_failed) {
return EXIT_SUCCESS;
}

return EXIT_FAILURE;
return num_failed == 0;
}
25 changes: 0 additions & 25 deletions src/bssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,6 @@ impl From<Result> for core::result::Result<(), error::Unspecified> {
}
}

// Adapt a BoringSSL test suite to a Rust test.
//
// The BoringSSL test suite is broken up into multiple files. Originally, they
// were all executables with their own `main` functions. Those main functions
// have been replaced with uniquely-named functions so that they can all be
// linked into the same executable.
#[cfg(test)]
macro_rules! bssl_test {
( $fn_name:ident, $bssl_test_main_fn_name:ident ) => {
#[test]
fn $fn_name() {
use $crate::{c, cpu};
extern "C" {
#[must_use]
fn $bssl_test_main_fn_name() -> c::int;
}

let _ = cpu::features();

let result = unsafe { $bssl_test_main_fn_name() };
assert_eq!(result, 0);
}
};
}

#[cfg(test)]
mod tests {
mod result {
Expand Down
13 changes: 13 additions & 0 deletions src/constant_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ pub fn verify_slices_are_equal(a: &[u8], b: &[u8]) -> Result<(), error::Unspecif
extern "C" {
fn GFp_memcmp(a: *const u8, b: *const u8, len: c::size_t) -> c::int;
}

#[cfg(test)]
mod tests {
use crate::{bssl, error};

#[test]
fn test_constant_time() -> Result<(), error::Unspecified> {
extern "C" {
fn bssl_constant_time_test_main() -> bssl::Result;
}
Result::from(unsafe { bssl_constant_time_test_main() })
}
}
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,3 @@ mod sealed {
// ```
pub trait Sealed {}
}

#[cfg(test)]
mod tests {
bssl_test!(test_constant_time, bssl_constant_time_test_main);
}

0 comments on commit 1194b80

Please sign in to comment.