diff options
Diffstat (limited to 'src/tests/encrypt-decrypt.cc')
-rw-r--r-- | src/tests/encrypt-decrypt.cc | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/tests/encrypt-decrypt.cc b/src/tests/encrypt-decrypt.cc index 9829763..c7468d5 100644 --- a/src/tests/encrypt-decrypt.cc +++ b/src/tests/encrypt-decrypt.cc @@ -48,35 +48,37 @@ using namespace Crypto; PRNG prng; -const size_t MESSAGE_SIZE_MAX = (2048 - 16); +const size_t MESSAGE_SIZE_MAX = ( 2048 - 16 ); const size_t MESSAGES_PER_SESSION = 256; -const size_t NUM_SESSIONS = 64; +const size_t NUM_SESSIONS = 64; bool verbose = false; #define NONCE_FMT "%016" PRIx64 -static std::string random_payload( void ) { +static std::string random_payload( void ) +{ const size_t len = prng.uint32() % MESSAGE_SIZE_MAX; - char buf[ MESSAGE_SIZE_MAX ]; + char buf[MESSAGE_SIZE_MAX]; prng.fill( buf, len ); std::string payload( buf, len ); return payload; } -static void test_bad_decrypt( Session &decryption_session ) { +static void test_bad_decrypt( Session& decryption_session ) +{ std::string bad_ct = random_payload(); bool got_exn = false; try { decryption_session.decrypt( bad_ct ); - } catch ( const CryptoException &e ) { + } catch ( const CryptoException& e ) { got_exn = true; /* The "bad decrypt" exception needs to be non-fatal, otherwise we are vulnerable to an easy DoS. */ - fatal_assert( ! e.fatal ); + fatal_assert( !e.fatal ); } if ( verbose ) { @@ -86,7 +88,8 @@ static void test_bad_decrypt( Session &decryption_session ) { } /* Generate a single key and initial nonce, then perform some encryptions. */ -static void test_one_session( void ) { +static void test_one_session( void ) +{ Base64Key key; Session encryption_session( key ); Session decryption_session( key ); @@ -97,7 +100,7 @@ static void test_one_session( void ) { hexdump( key.data(), 16, "key" ); } - for ( size_t i=0; i<MESSAGES_PER_SESSION; i++ ) { + for ( size_t i = 0; i < MESSAGES_PER_SESSION; i++ ) { Nonce nonce( nonce_int ); fatal_assert( nonce.val() == nonce_int ); @@ -123,7 +126,7 @@ static void test_one_session( void ) { nonce_int++; - if ( ! ( prng.uint8() % 16 ) ) { + if ( !( prng.uint8() % 16 ) ) { test_bad_decrypt( decryption_session ); } @@ -133,17 +136,17 @@ static void test_one_session( void ) { } } -int main( int argc, char *argv[] ) { - if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { +int main( int argc, char* argv[] ) +{ + if ( argc >= 2 && strcmp( argv[1], "-v" ) == 0 ) { verbose = true; } - for ( size_t i=0; i<NUM_SESSIONS; i++ ) { + for ( size_t i = 0; i < NUM_SESSIONS; i++ ) { try { test_one_session(); - } catch ( const CryptoException &e ) { - fprintf( stderr, "Crypto exception: %s\r\n", - e.what() ); + } catch ( const CryptoException& e ) { + fprintf( stderr, "Crypto exception: %s\r\n", e.what() ); return 1; } } |