From cd2ae36f366ddca23f3573a86273584d2d7c9bf6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 23 Apr 2014 16:31:27 -0400 Subject: [PATCH] Mark local functions as static This helps to catch unused functions like the former mosh_read_line, allows the compiler to make better inlining decisions, and reduces the binary size a bit. Signed-off-by: Anders Kaseorg --- src/examples/parse.cc | 12 +++--- src/examples/termemu.cc | 8 ++-- src/frontend/mosh-client.cc | 4 +- src/frontend/mosh-server.cc | 44 +++++++++---------- src/terminal/terminalfunctions.cc | 70 +++++++++++++++---------------- src/tests/encrypt-decrypt.cc | 6 +-- src/tests/ocb-aes.cc | 32 +++++++------- 7 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/examples/parse.cc b/src/examples/parse.cc index 3c45001..42dfc45 100644 --- a/src/examples/parse.cc +++ b/src/examples/parse.cc @@ -63,9 +63,9 @@ const size_t buf_size = 1024; -void emulate_terminal( int fd ); -int copy( int src, int dest ); -int vt_parser( int fd, Parser::UTF8Parser *parser ); +static void emulate_terminal( int fd ); +static int copy( int src, int dest ); +static int vt_parser( int fd, Parser::UTF8Parser *parser ); int main( int argc __attribute__((unused)), char *argv[] __attribute__((unused)), @@ -135,7 +135,7 @@ int main( int argc __attribute__((unused)), return 0; } -void emulate_terminal( int fd ) +static void emulate_terminal( int fd ) { Parser::UTF8Parser parser; @@ -166,7 +166,7 @@ void emulate_terminal( int fd ) } } -int copy( int src, int dest ) +static int copy( int src, int dest ) { char buf[ buf_size ]; @@ -181,7 +181,7 @@ int copy( int src, int dest ) return swrite( dest, buf, bytes_read ); } -int vt_parser( int fd, Parser::UTF8Parser *parser ) +static int vt_parser( int fd, Parser::UTF8Parser *parser ) { char buf[ buf_size ]; diff --git a/src/examples/termemu.cc b/src/examples/termemu.cc index bdbbbb4..34b55ba 100644 --- a/src/examples/termemu.cc +++ b/src/examples/termemu.cc @@ -70,7 +70,7 @@ const size_t buf_size = 16384; -void emulate_terminal( int fd ); +static void emulate_terminal( int fd ); int main( void ) { @@ -158,8 +158,8 @@ int main( void ) } /* Print a frame if the last frame was more than 1/50 seconds ago */ -bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame, - const Terminal::Display &display ) +static bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame, + const Terminal::Display &display ) { static bool initialized = false; static struct timeval last_time; @@ -207,7 +207,7 @@ bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame, assume the previous frame was sent to the real terminal. */ -void emulate_terminal( int fd ) +static void emulate_terminal( int fd ) { /* get current window size */ struct winsize window_size; diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 75894e2..3523a71 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -70,7 +70,7 @@ # error "SysV or X/Open-compatible Curses header file required" #endif -void usage( const char *argv0 ) { +static void usage( const char *argv0 ) { fprintf( stderr, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION ); fprintf( stderr, "Copyright 2012 Keith Winstein \n" ); fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later .\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" ); @@ -78,7 +78,7 @@ void usage( const char *argv0 ) { fprintf( stderr, "Usage: %s IP PORT\n %s -c\n", argv0, argv0 ); } -void print_colorcount( void ) +static void print_colorcount( void ) { /* check colors */ setupterm((char *)0, 1, (int *)0); diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 006e786..f6d0750 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -91,28 +91,28 @@ typedef Network::Transport< Terminal::Complete, Network::UserStream > ServerConnection; -void serve( int host_fd, - Terminal::Complete &terminal, - ServerConnection &network ); +static void serve( int host_fd, + Terminal::Complete &terminal, + ServerConnection &network ); -int run_server( const char *desired_ip, const char *desired_port, - const string &command_path, char *command_argv[], - const int colors, bool verbose, bool with_motd ); +static int run_server( const char *desired_ip, const char *desired_port, + const string &command_path, char *command_argv[], + const int colors, bool verbose, bool with_motd ); using namespace std; -void print_usage( const char *argv0 ) +static void print_usage( const char *argv0 ) { fprintf( stderr, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 ); } -void print_motd( void ); -void chdir_homedir( void ); -bool motd_hushed( void ); -void warn_unattached( const string & ignore_entry ); +static void print_motd( void ); +static void chdir_homedir( void ); +static bool motd_hushed( void ); +static void warn_unattached( const string & ignore_entry ); /* Simple spinloop */ -void spin( void ) +static void spin( void ) { static unsigned int spincount = 0; spincount++; @@ -126,7 +126,7 @@ void spin( void ) } } -string get_SSH_IP( void ) +static string get_SSH_IP( void ) { const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" ); if ( !SSH_CONNECTION ) { /* Older sshds don't set this */ @@ -327,9 +327,9 @@ int main( int argc, char *argv[] ) } } -int run_server( const char *desired_ip, const char *desired_port, - const string &command_path, char *command_argv[], - const int colors, bool verbose, bool with_motd ) { +static int run_server( const char *desired_ip, const char *desired_port, + const string &command_path, char *command_argv[], + const int colors, bool verbose, bool with_motd ) { /* get initial window size */ struct winsize window_size; if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 || @@ -521,7 +521,7 @@ int run_server( const char *desired_ip, const char *desired_port, return 0; } -void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network ) +static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network ) { /* prepare to poll for events */ Select &sel = Select::get_instance(); @@ -746,7 +746,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network } /* OpenSSH prints the motd on startup, so we will too */ -void print_motd( void ) +static void print_motd( void ) { FILE *motd = fopen( "/etc/motd", "r" ); if ( !motd ) { @@ -770,7 +770,7 @@ void print_motd( void ) fclose( motd ); } -void chdir_homedir( void ) +static void chdir_homedir( void ) { struct passwd *pw = getpwuid( geteuid() ); if ( pw == NULL ) { @@ -787,21 +787,21 @@ void chdir_homedir( void ) } } -bool motd_hushed( void ) +static bool motd_hushed( void ) { /* must be in home directory already */ struct stat buf; return (0 == lstat( ".hushlogin", &buf )); } -bool device_exists( const char *ut_line ) +static bool device_exists( const char *ut_line ) { string device_name = string( "/dev/" ) + string( ut_line ); struct stat buf; return (0 == lstat( device_name.c_str(), &buf )); } -void warn_unattached( const string & ignore_entry ) +static void warn_unattached( const string & ignore_entry ) { #ifdef HAVE_UTMPX_H /* get username */ diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc index 547e00a..833fb7d 100644 --- a/src/terminal/terminalfunctions.cc +++ b/src/terminal/terminalfunctions.cc @@ -50,7 +50,7 @@ static void clearline( Framebuffer *fb, int row, int start, int end ) } /* erase in line */ -void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) { switch ( dispatch->getparam( 0, 0 ) ) { case 0: /* default: active position to end of line, inclusive */ @@ -68,7 +68,7 @@ void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_EL( CSI, "K", CSI_EL ); /* erase in display */ -void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) { +static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) { switch ( dispatch->getparam( 0, 0 ) ) { case 0: /* active position to end of screen, inclusive */ clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 ); @@ -93,7 +93,7 @@ void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) { static Function func_CSI_ED( CSI, "J", CSI_ED ); /* cursor movement -- relative and absolute */ -void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch ) { int num = dispatch->getparam( 0, 1 ); @@ -127,7 +127,7 @@ static Function func_CSI_cursormove_H( CSI, "H", CSI_cursormove ); static Function func_CSI_cursormove_f( CSI, "f", CSI_cursormove ); /* device attributes */ -void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) +static void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) { dispatch->terminal_to_host.append( "\033[?62c" ); /* plain vt220 */ } @@ -135,7 +135,7 @@ void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) static Function func_CSI_DA( CSI, "c", CSI_DA ); /* secondary device attributes */ -void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) +static void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) { dispatch->terminal_to_host.append( "\033[>1;10;0c" ); /* plain vt220 */ } @@ -143,7 +143,7 @@ void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) static Function func_CSI_SDA( CSI, ">c", CSI_SDA ); /* screen alignment diagnostic */ -void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { for ( int y = 0; y < fb->ds.get_height(); y++ ) { for ( int x = 0; x < fb->ds.get_width(); x++ ) { @@ -156,7 +156,7 @@ void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN ); /* line feed */ -void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->move_rows_autoscroll( 1 ); } @@ -168,7 +168,7 @@ static Function func_Ctrl_VT( CONTROL, "\x0b", Ctrl_LF ); static Function func_Ctrl_FF( CONTROL, "\x0c", Ctrl_LF ); /* carriage return */ -void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.move_col( 0 ); } @@ -176,7 +176,7 @@ void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR ); /* backspace */ -void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.move_col( -1, true ); } @@ -184,7 +184,7 @@ void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS ); /* reverse index -- like a backwards line feed */ -void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->move_rows_autoscroll( -1 ); } @@ -192,7 +192,7 @@ void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_RI( CONTROL, "\x8D", Ctrl_RI ); /* newline */ -void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.move_col( 0 ); fb->move_rows_autoscroll( 1 ); @@ -201,7 +201,7 @@ void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL ); /* horizontal tab */ -void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { int col = fb->ds.get_next_tab(); if ( col == -1 ) { /* no tabs, go to end of line */ @@ -219,7 +219,7 @@ void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT, false ); /* horizontal tab set */ -void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.set_tab(); } @@ -227,7 +227,7 @@ void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HTS ); /* tabulation clear */ -void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) { int param = dispatch->getparam( 0, 0 ); switch ( param ) { @@ -285,7 +285,7 @@ void set_if_available( bool *mode, bool value ) } /* set private mode */ -void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { int param = dispatch->getparam( i, 0 ); @@ -300,7 +300,7 @@ void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) } /* clear private mode */ -void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { int param = dispatch->getparam( i, 0 ); @@ -327,7 +327,7 @@ static bool *get_ANSI_mode( int param, Framebuffer *fb ) { } /* set mode */ -void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); @@ -338,7 +338,7 @@ void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) } /* clear mode */ -void CSI_RM( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_RM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); @@ -352,7 +352,7 @@ static Function func_CSI_SM( CSI, "h", CSI_SM ); static Function func_CSI_RM( CSI, "l", CSI_RM ); /* set top and bottom margins */ -void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) { int top = dispatch->getparam( 0, 1 ); int bottom = dispatch->getparam( 1, fb->ds.get_height() ); @@ -371,14 +371,14 @@ void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DECSTMB( CSI, "r", CSI_DECSTBM ); /* terminal bell */ -void Ctrl_BEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { +static void Ctrl_BEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ring_bell(); } static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL ); /* select graphics rendition -- e.g., bold, blinking, etc. */ -void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) { /* We need to special-case the handling of CSI [34]8 ; 5 ; Ps m, because Ps of 0 in that case does not mean reset to default, even @@ -404,12 +404,12 @@ void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_SGR( CSI, "m", CSI_SGR, false ); /* changing renditions doesn't clear wrap flag */ /* save and restore cursor */ -void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.save_cursor(); } -void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->ds.restore_cursor(); } @@ -418,7 +418,7 @@ static Function func_Esc_DECSC( ESCAPE, "7", Esc_DECSC ); static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC ); /* device status report -- e.g., cursor position (used by resize) */ -void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) { int param = dispatch->getparam( 0, 0 ); @@ -439,7 +439,7 @@ void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DSR( CSI, "n", CSI_DSR ); /* insert line */ -void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) { int lines = dispatch->getparam( 0, 1 ); @@ -455,7 +455,7 @@ void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_IL( CSI, "L", CSI_IL ); /* delete line */ -void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) { int lines = dispatch->getparam( 0, 1 ); @@ -471,7 +471,7 @@ void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DL( CSI, "M", CSI_DL ); /* insert characters */ -void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) { int cells = dispatch->getparam( 0, 1 ); @@ -483,7 +483,7 @@ void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_ICH( CSI, "@", CSI_ICH ); /* delete character */ -void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) { int cells = dispatch->getparam( 0, 1 ); @@ -495,7 +495,7 @@ void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DCH( CSI, "P", CSI_DCH ); /* line position absolute */ -void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) { int row = dispatch->getparam( 0, 1 ); fb->ds.move_row( row - 1 ); @@ -504,7 +504,7 @@ void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_VPA( CSI, "d", CSI_VPA ); /* character position absolute */ -void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch ) { int col = dispatch->getparam( 0, 1 ); fb->ds.move_col( col - 1 ); @@ -514,7 +514,7 @@ static Function func_CSI_CHA( CSI, "G", CSI_HPA ); /* ECMA-48 name: CHA */ static Function func_CSI_HPA( CSI, "\x60", CSI_HPA ); /* ECMA-48 name: HPA */ /* erase character */ -void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) { int num = dispatch->getparam( 0, 1 ); int limit = fb->ds.get_cursor_col() + num - 1; @@ -528,7 +528,7 @@ void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_ECH( CSI, "X", CSI_ECH ); /* reset to initial state */ -void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->reset(); } @@ -536,7 +536,7 @@ void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static Function func_Esc_RIS( ESCAPE, "c", Esc_RIS ); /* soft reset */ -void CSI_DECSTR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +static void CSI_DECSTR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { fb->soft_reset(); } @@ -575,7 +575,7 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act, Framebuffer *fb ) } /* scroll down or terminfo indn */ -void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) { fb->scroll( dispatch->getparam( 0, 1 ) ); } @@ -583,7 +583,7 @@ void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_SD( CSI, "S", CSI_SD ); /* scroll up or terminfo rin */ -void CSI_SU( Framebuffer *fb, Dispatcher *dispatch ) +static void CSI_SU( Framebuffer *fb, Dispatcher *dispatch ) { fb->scroll( -dispatch->getparam( 0, 1 ) ); } diff --git a/src/tests/encrypt-decrypt.cc b/src/tests/encrypt-decrypt.cc index fc92778..179a6c0 100644 --- a/src/tests/encrypt-decrypt.cc +++ b/src/tests/encrypt-decrypt.cc @@ -56,7 +56,7 @@ bool verbose = false; #define NONCE_FMT "%016"PRIx64 -std::string random_payload( void ) { +static std::string random_payload( void ) { const size_t len = prng.uint32() % MESSAGE_SIZE_MAX; char *buf = new char[len]; prng.fill( buf, len ); @@ -66,7 +66,7 @@ std::string random_payload( void ) { return payload; } -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; @@ -87,7 +87,7 @@ void test_bad_decrypt( Session &decryption_session ) { } /* Generate a single key and initial nonce, then perform some encryptions. */ -void test_one_session( void ) { +static void test_one_session( void ) { Base64Key key; Session encryption_session( key ); Session decryption_session( key ); diff --git a/src/tests/ocb-aes.cc b/src/tests/ocb-aes.cc index c04c44b..4100c4f 100644 --- a/src/tests/ocb-aes.cc +++ b/src/tests/ocb-aes.cc @@ -55,26 +55,26 @@ using Crypto::AlignedBuffer; bool verbose = false; -bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) { +static bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) { return ( a.len() == b.len() ) && !memcmp( a.data(), b.data(), a.len() ); } -AlignedBuffer *get_ctx( const AlignedBuffer &key ) { +static AlignedBuffer *get_ctx( const AlignedBuffer &key ) { AlignedBuffer *ctx_buf = new AlignedBuffer( ae_ctx_sizeof() ); fatal_assert( ctx_buf ); fatal_assert( AE_SUCCESS == ae_init( (ae_ctx *)ctx_buf->data(), key.data(), key.len(), NONCE_LEN, TAG_LEN ) ); return ctx_buf; } -void scrap_ctx( AlignedBuffer *ctx_buf ) { +static void scrap_ctx( AlignedBuffer *ctx_buf ) { fatal_assert( AE_SUCCESS == ae_clear( (ae_ctx *)ctx_buf->data() ) ); delete ctx_buf; } -void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, - const AlignedBuffer &plaintext, const AlignedBuffer &assoc, - const AlignedBuffer &expected_ciphertext ) { +static void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, + const AlignedBuffer &plaintext, const AlignedBuffer &assoc, + const AlignedBuffer &expected_ciphertext ) { AlignedBuffer *ctx_buf = get_ctx( key ); ae_ctx *ctx = (ae_ctx *)ctx_buf->data(); @@ -97,10 +97,10 @@ void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, scrap_ctx( ctx_buf ); } -void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, - const AlignedBuffer &ciphertext, const AlignedBuffer &assoc, - const AlignedBuffer &expected_plaintext, - bool valid ) { +static void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, + const AlignedBuffer &ciphertext, const AlignedBuffer &assoc, + const AlignedBuffer &expected_plaintext, + bool valid ) { AlignedBuffer *ctx_buf = get_ctx( key ); ae_ctx *ctx = (ae_ctx *)ctx_buf->data(); @@ -129,10 +129,10 @@ void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, scrap_ctx( ctx_buf ); } -void test_vector( const char *key_p, const char *nonce_p, - size_t assoc_len, const char *assoc_p, - size_t plaintext_len, const char *plaintext_p, - size_t ciphertext_len, const char *ciphertext_p ) { +static void test_vector( const char *key_p, const char *nonce_p, + size_t assoc_len, const char *assoc_p, + size_t plaintext_len, const char *plaintext_p, + size_t ciphertext_len, const char *ciphertext_p ) { AlignedBuffer key ( KEY_LEN, key_p ); AlignedBuffer nonce ( NONCE_LEN, nonce_p ); @@ -172,7 +172,7 @@ void test_vector( const char *key_p, const char *nonce_p, #define TEST_VECTOR( _key, _nonce, _assoc, _pt, _ct ) \ test_vector( _key, _nonce, sizeof(_assoc)-1, _assoc, sizeof(_pt)-1, _pt, sizeof(_ct)-1, _ct ) -void test_all_vectors( void ) { +static void test_all_vectors( void ) { /* Test vectors from http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A */ const char ietf_key[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; @@ -463,7 +463,7 @@ void test_all_vectors( void ) { /* http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A also specifies an iterative test algorithm, which we implement here. */ -void test_iterative( void ) { +static void test_iterative( void ) { /* Key is always all zeros */ AlignedBuffer key( KEY_LEN ); memset( key.data(), 0, KEY_LEN );