Skip to content

Commit

Permalink
Test that the Rust Poly1305 code passes a large enough buffer to C.
Browse files Browse the repository at this point in the history
Also, reduce the size of that buffer, as it was more than twice the
size it needed to be.
  • Loading branch information
briansmith committed May 28, 2016
1 parent aebb3b9 commit 50c18bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions crypto/poly1305/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,5 @@ void CRYPTO_poly1305_finish(poly1305_state *statep, uint8_t mac[16]) {
poly1305_emit(&state.state, mac, state.nonce);
#endif
}

const size_t CRYPTO_POLY1305_STATE_LEN = sizeof(struct poly1305_state_st);
2 changes: 1 addition & 1 deletion include/openssl/poly1305.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {


typedef struct {
uint8_t bytes[512];
uint8_t bytes[256];
} poly1305_state;

/* CRYPTO_poly1305_init sets up |state| so that it can be used to calculate an
Expand Down
23 changes: 16 additions & 7 deletions src/aead/chacha20_poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core;
use super::super::{aead, c, polyfill};

const CHACHA20_KEY_LEN: usize = 256 / 8;
const POLY1305_STATE_LEN: usize = 512;
const POLY1305_STATE_LEN: usize = 256;
const POLY1305_KEY_LEN: usize = 32;


Expand Down Expand Up @@ -249,21 +249,30 @@ extern {

#[cfg(test)]
mod tests {
use super::super::super::aead;
use super::super::tests::test_aead;
use {aead, c};

bssl_test!(test_chacha, bssl_chacha_test_main);
bssl_test!(test_poly1305, bssl_poly1305_test_main);

#[test]
pub fn test_chacha20_poly1305() {
test_aead(&aead::CHACHA20_POLY1305,
"crypto/cipher/test/chacha20_poly1305_tests.txt");
aead::tests::test_aead(&aead::CHACHA20_POLY1305,
"crypto/cipher/test/chacha20_poly1305_tests.txt");
}

#[test]
pub fn test_chacha20_poly1305_old() {
test_aead(&aead::CHACHA20_POLY1305_OLD,
"crypto/cipher/test/chacha20_poly1305_old_tests.txt");
aead::tests::test_aead(&aead::CHACHA20_POLY1305_OLD,
"crypto/cipher/test/chacha20_poly1305_old_tests.txt");
}

#[test]
pub fn test_poly1305_state_len() {
assert_eq!((super::POLY1305_STATE_LEN + 255) / 256,
(CRYPTO_POLY1305_STATE_LEN + 255) / 256);
}

extern {
static CRYPTO_POLY1305_STATE_LEN: c::size_t;
}
}

0 comments on commit 50c18bf

Please sign in to comment.