summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2023-08-07 21:53:48 -0400
committerAlex Chernyakhovsky <achernya@mit.edu>2023-08-07 22:03:00 -0400
commit3acaa1c4d378e78497c218134b980442b60f3c6c (patch)
tree8d557ee066507626dafa19711127d6cd5fcce7a5
parent0b15dc94fa482ad253ab588038510af53306669d (diff)
clang-format Mosh
Run clang-format over the Mosh source tree. This is a large change and has been factored into its own commit for auditability. Reproduce it with find . -name \*.cc -or -name \*.h | while read f; do clang-format -i --style=file $f; done
-rw-r--r--src/crypto/ae.h60
-rw-r--r--src/crypto/base64.cc38
-rw-r--r--src/crypto/base64.h6
-rw-r--r--src/crypto/byteorder.h85
-rw-r--r--src/crypto/crypto.cc97
-rw-r--r--src/crypto/crypto.h229
-rw-r--r--src/crypto/ocb_openssl.cc177
-rw-r--r--src/crypto/prng.h25
-rw-r--r--src/examples/benchmark.cc48
-rw-r--r--src/examples/decrypt.cc11
-rw-r--r--src/examples/encrypt.cc8
-rw-r--r--src/examples/ntester.cc139
-rw-r--r--src/examples/parse.cc56
-rw-r--r--src/examples/termemu.cc89
-rw-r--r--src/frontend/mosh-client.cc122
-rw-r--r--src/frontend/mosh-server.cc737
-rw-r--r--src/frontend/stmclient.cc298
-rw-r--r--src/frontend/stmclient.h57
-rw-r--r--src/frontend/terminaloverlay.cc794
-rw-r--r--src/frontend/terminaloverlay.h510
-rw-r--r--src/fuzz/terminal_fuzzer.cc19
-rw-r--r--src/fuzz/terminal_parser_fuzzer.cc9
-rw-r--r--src/network/compressor.cc20
-rw-r--r--src/network/compressor.h27
-rw-r--r--src/network/network.cc322
-rw-r--r--src/network/network.h318
-rw-r--r--src/network/networktransport-impl.h120
-rw-r--r--src/network/networktransport.h119
-rw-r--r--src/network/transportfragment.cc52
-rw-r--r--src/network/transportfragment.h97
-rw-r--r--src/network/transportsender-impl.h154
-rw-r--r--src/network/transportsender.h195
-rw-r--r--src/network/transportstate.h24
-rw-r--r--src/statesync/completeterminal.cc70
-rw-r--r--src/statesync/completeterminal.h82
-rw-r--r--src/statesync/user.cc85
-rw-r--r--src/statesync/user.h95
-rw-r--r--src/terminal/parser.cc50
-rw-r--r--src/terminal/parser.h66
-rw-r--r--src/terminal/parseraction.cc27
-rw-r--r--src/terminal/parseraction.h248
-rw-r--r--src/terminal/parserstate.cc89
-rw-r--r--src/terminal/parserstate.h170
-rw-r--r--src/terminal/parserstatefamily.h78
-rw-r--r--src/terminal/parsertransition.h52
-rw-r--r--src/terminal/terminal.cc141
-rw-r--r--src/terminal/terminal.h77
-rw-r--r--src/terminal/terminaldispatcher.cc107
-rw-r--r--src/terminal/terminaldispatcher.h163
-rw-r--r--src/terminal/terminaldisplay.cc319
-rw-r--r--src/terminal/terminaldisplay.h73
-rw-r--r--src/terminal/terminaldisplayinit.cc80
-rw-r--r--src/terminal/terminalframebuffer.cc256
-rw-r--r--src/terminal/terminalframebuffer.h824
-rw-r--r--src/terminal/terminalfunctions.cc371
-rw-r--r--src/terminal/terminaluserinput.cc55
-rw-r--r--src/terminal/terminaluserinput.h41
-rw-r--r--src/tests/base64.cc53
-rw-r--r--src/tests/base64_vector.h8
-rw-r--r--src/tests/encrypt-decrypt.cc35
-rw-r--r--src/tests/inpty.cc8
-rw-r--r--src/tests/is-utf8-locale.cc2
-rw-r--r--src/tests/nonce-incr.cc2
-rw-r--r--src/tests/ocb-aes.cc730
-rw-r--r--src/tests/test_utils.cc13
-rw-r--r--src/tests/test_utils.h6
-rw-r--r--src/util/dos_assert.h18
-rw-r--r--src/util/fatal_assert.h15
-rw-r--r--src/util/locale_utils.cc26
-rw-r--r--src/util/locale_utils.h11
-rw-r--r--src/util/pty_compat.cc86
-rw-r--r--src/util/pty_compat.h10
-rw-r--r--src/util/select.cc4
-rw-r--r--src/util/select.h71
-rw-r--r--src/util/swrite.cc7
-rw-r--r--src/util/swrite.h2
-rw-r--r--src/util/timestamp.cc22
77 files changed, 4900 insertions, 4910 deletions
diff --git a/src/crypto/ae.h b/src/crypto/ae.h
index fb5c511..a0d8034 100644
--- a/src/crypto/ae.h
+++ b/src/crypto/ae.h
@@ -32,14 +32,14 @@ extern "C" {
/* Return status codes: Negative return values indicate an error occurred.
* For full explanations of error values, consult the implementation's
* documentation. */
-#define AE_SUCCESS ( 0) /* Indicates successful completion of call */
-#define AE_INVALID (-1) /* Indicates bad tag during decryption */
-#define AE_NOT_SUPPORTED (-2) /* Indicates unsupported option requested */
+#define AE_SUCCESS ( 0 ) /* Indicates successful completion of call */
+#define AE_INVALID ( -1 ) /* Indicates bad tag during decryption */
+#define AE_NOT_SUPPORTED ( -2 ) /* Indicates unsupported option requested */
/* Flags: When data can be processed "incrementally", these flags are used
* to indicate whether the submitted data is the last or not. */
-#define AE_FINALIZE (1) /* This is the last of data */
-#define AE_PENDING (0) /* More data of is coming */
+#define AE_FINALIZE ( 1 ) /* This is the last of data */
+#define AE_PENDING ( 0 ) /* More data of is coming */
/* --------------------------------------------------------------------------
*
@@ -55,10 +55,10 @@ typedef struct _ae_ctx ae_ctx;
*
* ----------------------------------------------------------------------- */
-ae_ctx* ae_allocate (void *misc); /* Allocate ae_ctx, set optional ptr */
-void ae_free (ae_ctx *ctx); /* Deallocate ae_ctx struct */
-int ae_clear (ae_ctx *ctx); /* Undo initialization */
-int ae_ctx_sizeof(void); /* Return sizeof(ae_ctx) */
+ae_ctx* ae_allocate( void* misc ); /* Allocate ae_ctx, set optional ptr */
+void ae_free( ae_ctx* ctx ); /* Deallocate ae_ctx struct */
+int ae_clear( ae_ctx* ctx ); /* Undo initialization */
+int ae_ctx_sizeof( void ); /* Return sizeof(ae_ctx) */
/* ae_allocate() allocates an ae_ctx structure, but does not initialize it.
* ae_free() deallocates an ae_ctx structure, but does not zeroize it.
* ae_clear() zeroes sensitive values associated with an ae_ctx structure
@@ -72,11 +72,7 @@ int ae_ctx_sizeof(void); /* Return sizeof(ae_ctx) */
*
* ----------------------------------------------------------------------- */
-int ae_init(ae_ctx *ctx,
- const void *key,
- int key_len,
- int nonce_len,
- int tag_len);
+int ae_init( ae_ctx* ctx, const void* key, int key_len, int nonce_len, int tag_len );
/* --------------------------------------------------------------------------
*
* Initialize an ae_ctx context structure.
@@ -95,15 +91,15 @@ int ae_init(ae_ctx *ctx,
*
* ----------------------------------------------------------------------- */
-int ae_encrypt(ae_ctx *ctx,
- const void *nonce,
- const void *pt,
- int pt_len,
- const void *ad,
- int ad_len,
- void *ct,
- void *tag,
- int final);
+int ae_encrypt( ae_ctx* ctx,
+ const void* nonce,
+ const void* pt,
+ int pt_len,
+ const void* ad,
+ int ad_len,
+ void* ct,
+ void* tag,
+ int final );
/* --------------------------------------------------------------------------
*
* Encrypt plaintext; provide for authentication of ciphertext/associated data.
@@ -132,15 +128,15 @@ int ae_encrypt(ae_ctx *ctx,
*
* ----------------------------------------------------------------------- */
-int ae_decrypt(ae_ctx *ctx,
- const void *nonce,
- const void *ct,
- int ct_len,
- const void *ad,
- int ad_len,
- void *pt,
- const void *tag,
- int final);
+int ae_decrypt( ae_ctx* ctx,
+ const void* nonce,
+ const void* ct,
+ int ct_len,
+ const void* ad,
+ int ad_len,
+ void* pt,
+ const void* tag,
+ int final );
/* --------------------------------------------------------------------------
*
* Decrypt ciphertext; provide authenticity of plaintext and associated data.
diff --git a/src/crypto/base64.cc b/src/crypto/base64.cc
index 129aecb..434ff65 100644
--- a/src/crypto/base64.cc
+++ b/src/crypto/base64.cc
@@ -33,8 +33,8 @@
#include <cstdlib>
#include <cstring>
-#include "src/util/fatal_assert.h"
#include "src/crypto/base64.h"
+#include "src/util/fatal_assert.h"
static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -60,27 +60,26 @@ static const unsigned char reverse[] = {
};
/* Reverse maps from an ASCII char to a base64 sixbit value. Returns > 0x3f on failure. */
-static unsigned char base64_char_to_sixbit(unsigned char c)
+static unsigned char base64_char_to_sixbit( unsigned char c )
{
return reverse[c];
}
-bool base64_decode( const char *b64, const size_t b64_len,
- uint8_t *raw, size_t *raw_len )
+bool base64_decode( const char* b64, const size_t b64_len, uint8_t* raw, size_t* raw_len )
{
fatal_assert( b64_len == 24 ); /* only useful for Mosh keys */
fatal_assert( *raw_len == 16 );
uint32_t bytes = 0;
- for (int i = 0; i < 22; i++) {
- unsigned char sixbit = base64_char_to_sixbit(*(b64++));
- if (sixbit > 0x3f) {
+ for ( int i = 0; i < 22; i++ ) {
+ unsigned char sixbit = base64_char_to_sixbit( *( b64++ ) );
+ if ( sixbit > 0x3f ) {
return false;
}
bytes <<= 6;
bytes |= sixbit;
/* write groups of 3 */
- if (i % 4 == 3) {
+ if ( i % 4 == 3 ) {
raw[0] = bytes >> 16;
raw[1] = bytes >> 8;
raw[2] = bytes;
@@ -90,33 +89,32 @@ bool base64_decode( const char *b64, const size_t b64_len,
}
/* last byte of output */
*raw = bytes >> 4;
- if (b64[0] != '=' || b64[1] != '=') {
+ if ( b64[0] != '=' || b64[1] != '=' ) {
return false;
}
return true;
}
-void base64_encode( const uint8_t *raw, const size_t raw_len,
- char *b64, const size_t b64_len )
+void base64_encode( const uint8_t* raw, const size_t raw_len, char* b64, const size_t b64_len )
{
fatal_assert( b64_len == 24 ); /* only useful for Mosh keys */
fatal_assert( raw_len == 16 );
/* first 15 bytes of input */
- for (int i = 0; i < 5; i++) {
- uint32_t bytes = (raw[0] << 16) | (raw[1] << 8) | raw[2];
- b64[0] = table[(bytes >> 18) & 0x3f];
- b64[1] = table[(bytes >> 12) & 0x3f];
- b64[2] = table[(bytes >> 6) & 0x3f];
- b64[3] = table[(bytes) & 0x3f];
+ for ( int i = 0; i < 5; i++ ) {
+ uint32_t bytes = ( raw[0] << 16 ) | ( raw[1] << 8 ) | raw[2];
+ b64[0] = table[( bytes >> 18 ) & 0x3f];
+ b64[1] = table[( bytes >> 12 ) & 0x3f];
+ b64[2] = table[( bytes >> 6 ) & 0x3f];
+ b64[3] = table[(bytes)&0x3f];
raw += 3;
b64 += 4;
}
-
+
/* last byte of input, last 4 of output */
uint8_t lastchar = *raw;
- b64[0] = table[(lastchar >> 2) & 0x3f];
- b64[1] = table[(lastchar << 4) & 0x3f];
+ b64[0] = table[( lastchar >> 2 ) & 0x3f];
+ b64[1] = table[( lastchar << 4 ) & 0x3f];
b64[2] = '=';
b64[3] = '=';
}
diff --git a/src/crypto/base64.h b/src/crypto/base64.h
index 80de7c6..780ed97 100644
--- a/src/crypto/base64.h
+++ b/src/crypto/base64.h
@@ -32,8 +32,6 @@
#include <cstdint>
-bool base64_decode( const char *b64, const size_t b64_len,
- uint8_t *raw, size_t *raw_len );
+bool base64_decode( const char* b64, const size_t b64_len, uint8_t* raw, size_t* raw_len );
-void base64_encode( const uint8_t *raw, const size_t raw_len,
- char *b64, const size_t b64_len );
+void base64_encode( const uint8_t* raw, const size_t raw_len, char* b64, const size_t b64_len );
diff --git a/src/crypto/byteorder.h b/src/crypto/byteorder.h
index fe7e8cd..f14f638 100644
--- a/src/crypto/byteorder.h
+++ b/src/crypto/byteorder.h
@@ -37,12 +37,12 @@
#if HAVE_DECL_BE64TOH || HAVE_DECL_BETOH64
-# if defined(HAVE_ENDIAN_H)
-# include <endian.h>
-# elif defined(HAVE_SYS_ENDIAN_H)
-# include <sys/types.h>
-# include <sys/endian.h>
-# endif
+#if defined( HAVE_ENDIAN_H )
+#include <endian.h>
+#elif defined( HAVE_SYS_ENDIAN_H )
+#include <sys/endian.h>
+#include <sys/types.h>
+#endif
#if !HAVE_DECL_BE64TOH && HAVE_DECL_BETOH64
#define be64toh betoh64
@@ -50,11 +50,11 @@
#endif
#elif HAVE_OSX_SWAP
-# include <libkern/OSByteOrder.h>
-# define htobe64 OSSwapHostToBigInt64
-# define be64toh OSSwapBigToHostInt64
-# define htobe16 OSSwapHostToBigInt16
-# define be16toh OSSwapBigToHostInt16
+#include <libkern/OSByteOrder.h>
+#define htobe64 OSSwapHostToBigInt64
+#define be64toh OSSwapBigToHostInt64
+#define htobe16 OSSwapHostToBigInt16
+#define be16toh OSSwapBigToHostInt16
#else
@@ -70,60 +70,55 @@
/* Use unions rather than casts, to comply with strict aliasing rules. */
-inline uint64_t htobe64( uint64_t x ) {
- uint8_t xs[ 8 ] = {
- static_cast<uint8_t>( ( x >> 56 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 48 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 40 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 32 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 24 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 16 ) & 0xFF ),
- static_cast<uint8_t>( ( x >> 8 ) & 0xFF ),
- static_cast<uint8_t>( ( x ) & 0xFF ) };
+inline uint64_t htobe64( uint64_t x )
+{
+ uint8_t xs[8] = { static_cast<uint8_t>( ( x >> 56 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 48 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 40 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 32 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 24 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 16 ) & 0xFF ),
+ static_cast<uint8_t>( ( x >> 8 ) & 0xFF ),
+ static_cast<uint8_t>( (x)&0xFF ) };
union {
- const uint8_t *p8;
- const uint64_t *p64;
+ const uint8_t* p8;
+ const uint64_t* p64;
} u;
u.p8 = xs;
return *u.p64;
}
-inline uint64_t be64toh( uint64_t x ) {
+inline uint64_t be64toh( uint64_t x )
+{
union {
- const uint8_t *p8;
- const uint64_t *p64;
+ const uint8_t* p8;
+ const uint64_t* p64;
} u;
u.p64 = &x;
- return ( uint64_t( u.p8[ 0 ] ) << 56 )
- | ( uint64_t( u.p8[ 1 ] ) << 48 )
- | ( uint64_t( u.p8[ 2 ] ) << 40 )
- | ( uint64_t( u.p8[ 3 ] ) << 32 )
- | ( uint64_t( u.p8[ 4 ] ) << 24 )
- | ( uint64_t( u.p8[ 5 ] ) << 16 )
- | ( uint64_t( u.p8[ 6 ] ) << 8 )
- | ( uint64_t( u.p8[ 7 ] ) );
+ return ( uint64_t( u.p8[0] ) << 56 ) | ( uint64_t( u.p8[1] ) << 48 ) | ( uint64_t( u.p8[2] ) << 40 )
+ | ( uint64_t( u.p8[3] ) << 32 ) | ( uint64_t( u.p8[4] ) << 24 ) | ( uint64_t( u.p8[5] ) << 16 )
+ | ( uint64_t( u.p8[6] ) << 8 ) | ( uint64_t( u.p8[7] ) );
}
-inline uint16_t htobe16( uint16_t x ) {
- uint8_t xs[ 2 ] = {
- static_cast<uint8_t>( ( x >> 8 ) & 0xFF ),
- static_cast<uint8_t>( ( x ) & 0xFF ) };
+inline uint16_t htobe16( uint16_t x )
+{
+ uint8_t xs[2] = { static_cast<uint8_t>( ( x >> 8 ) & 0xFF ), static_cast<uint8_t>( (x)&0xFF ) };
union {
- const uint8_t *p8;
- const uint16_t *p16;
+ const uint8_t* p8;
+ const uint16_t* p16;
} u;
u.p8 = xs;
return *u.p16;
}
-inline uint16_t be16toh( uint16_t x ) {
+inline uint16_t be16toh( uint16_t x )
+{
union {
- const uint8_t *p8;
- const uint16_t *p16;
+ const uint8_t* p8;
+ const uint16_t* p16;
} u;
u.p16 = &x;
- return ( uint16_t( u.p8[ 0 ] ) << 8 )
- | ( uint16_t( u.p8[ 1 ] ) );
+ return ( uint16_t( u.p8[0] ) << 8 ) | ( uint16_t( u.p8[1] ) );
}
#endif
diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc
index 62e04da..7a79d7e 100644
--- a/src/crypto/crypto.cc
+++ b/src/crypto/crypto.cc
@@ -39,23 +39,22 @@
#include <sys/resource.h>
+#include "src/crypto/base64.h"
#include "src/crypto/byteorder.h"
#include "src/crypto/crypto.h"
-#include "src/crypto/base64.h"
-#include "src/util/fatal_assert.h"
#include "src/crypto/prng.h"
+#include "src/util/fatal_assert.h"
using namespace Crypto;
-long int myatoi( const char *str )
+long int myatoi( const char* str )
{
- char *end;
+ char* end;
errno = 0;
long int ret = strtol( str, &end, 10 );
- if ( ( errno != 0 )
- || ( end != str + strlen( str ) ) ) {
+ if ( ( errno != 0 ) || ( end != str + strlen( str ) ) ) {
throw CryptoException( "Bad integer." );
}
@@ -72,16 +71,14 @@ uint64_t Crypto::unique( void )
return rv;
}
-AlignedBuffer::AlignedBuffer( size_t len, const char *data )
- : m_len( len ), m_allocated( NULL ), m_data( NULL )
+AlignedBuffer::AlignedBuffer( size_t len, const char* data ) : m_len( len ), m_allocated( NULL ), m_data( NULL )
{
size_t alloc_len = len ? len : 1;
-#if defined(HAVE_POSIX_MEMALIGN)
- if ( ( 0 != posix_memalign( &m_allocated, 16, alloc_len ) )
- || ( m_allocated == NULL ) ) {
+#if defined( HAVE_POSIX_MEMALIGN )
+ if ( ( 0 != posix_memalign( &m_allocated, 16, alloc_len ) ) || ( m_allocated == NULL ) ) {
throw std::bad_alloc();
}
- m_data = (char *) m_allocated;
+ m_data = (char*)m_allocated;
#else
/* malloc() a region 15 bytes larger than we need, and find
@@ -91,15 +88,15 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data )
throw std::bad_alloc();
}
- uintptr_t iptr = (uintptr_t) m_allocated;
+ uintptr_t iptr = (uintptr_t)m_allocated;
if ( iptr & 0xF ) {
iptr += 16 - ( iptr & 0xF );
}
assert( !( iptr & 0xF ) );
- assert( iptr >= (uintptr_t) m_allocated );
- assert( iptr <= ( 15 + (uintptr_t) m_allocated ) );
+ assert( iptr >= (uintptr_t)m_allocated );
+ assert( iptr <= ( 15 + (uintptr_t)m_allocated ) );
- m_data = (char *) iptr;
+ m_data = (char*)iptr;
#endif /* !defined(HAVE_POSIX_MEMALIGN) */
@@ -136,32 +133,28 @@ Base64Key::Base64Key()
PRNG().fill( key, sizeof( key ) );
}
-Base64Key::Base64Key(PRNG &prng)
+Base64Key::Base64Key( PRNG& prng )
{
prng.fill( key, sizeof( key ) );
}
std::string Base64Key::printable_key( void ) const
{
- char base64[ 24 ];
-
+ char base64[24];
+
base64_encode( key, 16, base64, 24 );
- if ( (base64[ 23 ] != '=')
- || (base64[ 22 ] != '=') ) {
+ if ( ( base64[23] != '=' ) || ( base64[22] != '=' ) ) {
throw CryptoException( std::string( "Unexpected output from base64_encode: " ) + std::string( base64, 24 ) );
}
- base64[ 22 ] = 0;
+ base64[22] = 0;
return std::string( base64 );
}
Session::Session( Base64Key s_key )
- : key( s_key ), ctx_buf( ae_ctx_sizeof() ),
- ctx( (ae_ctx *)ctx_buf.data() ), blocks_encrypted( 0 ),
- plaintext_buffer( RECEIVE_MTU ),
- ciphertext_buffer( RECEIVE_MTU ),
- nonce_buffer( Nonce::NONCE_LEN )
+ : key( s_key ), ctx_buf( ae_ctx_sizeof() ), ctx( (ae_ctx*)ctx_buf.data() ), blocks_encrypted( 0 ),
+ plaintext_buffer( RECEIVE_MTU ), ciphertext_buffer( RECEIVE_MTU ), nonce_buffer( Nonce::NONCE_LEN )
{
if ( AE_SUCCESS != ae_init( ctx, key.data(), 16, 12, 16 ) ) {
throw CryptoException( "Could not initialize AES-OCB context." );
@@ -188,7 +181,7 @@ uint64_t Nonce::val( void ) const
return be64toh( ret );
}
-Nonce::Nonce( const char *s_bytes, size_t len )
+Nonce::Nonce( const char* s_bytes, size_t len )
{
if ( len != 8 ) {
throw CryptoException( "Nonce representation must be 8 octets long." );
@@ -198,7 +191,7 @@ Nonce::Nonce( const char *s_bytes, size_t len )
memcpy( bytes + 4, s_bytes, 8 );
}
-const std::string Session::encrypt( const Message & plaintext )
+const std::string Session::encrypt( const Message& plaintext )
{
const size_t pt_len = plaintext.text.size();
const int ciphertext_len = pt_len + 16;
@@ -209,15 +202,16 @@ const std::string Session::encrypt( const Message & plaintext )
memcpy( plaintext_buffer.data(), plaintext.text.data(), pt_le