diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-26 07:19:46 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-26 07:19:46 +0000 |
commit | 0e20ad37f8c445a170f4599b911ab66a6c0cdf53 (patch) | |
tree | e1e5436a32935dcc58947157ac58123d573b2cfc | |
parent | b94738c677fc7a53014bf1332bfb51ee0d4af0cb (diff) | |
download | gnutls-0e20ad37f8c445a170f4599b911ab66a6c0cdf53.tar.gz |
updated uint24 functions.
-rw-r--r-- | lib/.cvsignore | 4 | ||||
-rw-r--r-- | lib/gnutls_handshake.c | 28 | ||||
-rw-r--r-- | lib/gnutls_int.h | 5 | ||||
-rw-r--r-- | lib/gnutls_num.c | 28 | ||||
-rw-r--r-- | lib/gnutls_num.h | 1 | ||||
-rw-r--r-- | src/.cvsignore | 2 |
6 files changed, 41 insertions, 27 deletions
diff --git a/lib/.cvsignore b/lib/.cvsignore index cd302be4b9..3bdc11d17e 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -9,4 +9,6 @@ Makefile *.da *.gcov *.bb -*.bbg
\ No newline at end of file +*.bbg +libgnutls-config +gnutls.h diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c index e30c726b20..4cda4ea2e5 100644 --- a/lib/gnutls_handshake.c +++ b/lib/gnutls_handshake.c @@ -475,21 +475,21 @@ int _gnutls_send_handshake(int cd, GNUTLS_STATE state, void *i_data, { int ret; uint8 *data; - uint24 length; + uint24 length24; uint32 datasize; int pos = 0; - datasize = CONVuint32(i_datasize); + datasize = CONVuint32( i_datasize); - length = uint32touint24(datasize); + length24 = uint32touint24( datasize); i_datasize += HANDSHAKE_HEADERS_SIZE; data = gnutls_malloc(i_datasize); memcpy(&data[pos++], &type, 1); - memcpy(&data[pos++], &length.pint[0], 1); - memcpy(&data[pos++], &length.pint[1], 1); - memcpy(&data[pos++], &length.pint[2], 1); + memcpy(&data[pos++], &length24.pint[0], 1); + memcpy(&data[pos++], &length24.pint[1], 1); + memcpy(&data[pos++], &length24.pint[2], 1); if (i_datasize > 4) memcpy(&data[pos], i_data, i_datasize - 4); @@ -525,7 +525,6 @@ int _gnutls_recv_handshake(int cd, GNUTLS_STATE state, uint8 ** data, int ret; uint32 length32 = 0, sum = 0; uint8 *dataptr=NULL; /* for realloc */ - uint24 num; int handshake_headers = HANDSHAKE_HEADERS_SIZE; HandshakeType recv_type; @@ -579,12 +578,7 @@ int _gnutls_recv_handshake(int cd, GNUTLS_STATE state, uint8 ** data, return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET; } - num.pint[0] = dataptr[1]; - num.pint[1] = dataptr[2]; - num.pint[2] = dataptr[3]; - length32 = uint24touint32(num); - - length32 = CONVuint32(length32); + length32 = READuint24( &dataptr[1]); #ifdef HANDSHAKE_DEBUG fprintf(stderr, "Handshake: %s was received [%ld bytes]\n", @@ -1099,7 +1093,6 @@ int _gnutls_recv_certificate(int cd, GNUTLS_STATE state, char *data, char *certificate_list; int ret = 0; uint32 sizeOfCert; - uint24 num; if (state->security_parameters.entity == GNUTLS_CLIENT) { if (datalen < 2) { @@ -1107,13 +1100,8 @@ int _gnutls_recv_certificate(int cd, GNUTLS_STATE state, char *data, return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; } - num.pint[0] = data[pos]; - num.pint[1] = data[pos + 1]; - num.pint[2] = data[pos + 2]; - sizeOfCert = uint24touint32(num); - + sizeOfCert = READuint24( &data[pos]); pos += 3; - sizeOfCert = CONVuint32( sizeOfCert); if (sizeOfCert > MAX24) { gnutls_assert(); diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 556a56b6d5..561cbfa154 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -63,11 +63,8 @@ #define gnutls_calloc calloc #define gnutls_free free -typedef struct { - uint8 pint[3]; -} uint24; - typedef unsigned char opaque; +typedef struct { opaque pint[3]; } uint24; typedef enum crypt_algo { SRPSHA1_CRYPT, BLOWFISH_CRYPT=2 } crypt_algo; typedef enum ChangeCipherSpecType { GNUTLS_TYPE_CHANGE_CIPHER_SPEC=1 } ChangeCipherSpecType; diff --git a/lib/gnutls_num.c b/lib/gnutls_num.c index 67733772c5..1ca5126847 100644 --- a/lib/gnutls_num.c +++ b/lib/gnutls_num.c @@ -32,7 +32,7 @@ #define byteswap32(x) ((rotl32(x, 8) & 0x00ff00ff) | (rotr32(x, 8) & 0xff00ff00)) #define byteswap64(x) ((rotl64(x, 8) & 0x00ff00ff00ff00ffLL) | (rotr64(x, 8) & 0xff00ff00ff00ff00LL)) - +inline uint32 uint24touint32( uint24 num) { uint32 ret=0; @@ -41,6 +41,8 @@ uint32 ret=0; ((uint8*)&ret)[3] = num.pint[2]; return ret; } + +inline uint24 uint32touint24( uint32 num) { uint24 ret; @@ -51,6 +53,24 @@ uint24 ret; } +/* data should be at least 3 bytes */ +inline +uint32 READuint24( const opaque* data) { +uint32 res; +uint24 num; + + num.pint[0] = data[0]; + num.pint[1] = data[1]; + num.pint[2] = data[2]; + + res = uint24touint32( num); +#ifndef WORDS_BIGENDIAN + res = byteswap32( res); +#endif +return res; +} + +inline uint32 READuint32( const opaque* data) { uint32 res; @@ -61,6 +81,7 @@ uint32 res; return res; } +inline uint16 READuint16( const opaque* data) { uint16 res; memcpy( &res, data, sizeof(uint16)); @@ -70,6 +91,7 @@ uint16 res; return res; } +inline uint32 CONVuint32( uint32 data) { #ifndef WORDS_BIGENDIAN return byteswap32( data); @@ -78,6 +100,7 @@ uint32 CONVuint32( uint32 data) { #endif } +inline uint16 CONVuint16( uint16 data) { #ifndef WORDS_BIGENDIAN return byteswap16( data); @@ -86,6 +109,7 @@ uint16 CONVuint16( uint16 data) { #endif } +inline uint64 READuint64( const opaque* data) { uint64 res; @@ -96,7 +120,7 @@ uint64 res; return res; } - +inline uint64 CONVuint64( uint64 data) { #ifndef WORDS_BIGENDIAN return byteswap64( data); diff --git a/lib/gnutls_num.h b/lib/gnutls_num.h index 648a4ecce0..97da2f051b 100644 --- a/lib/gnutls_num.h +++ b/lib/gnutls_num.h @@ -26,3 +26,4 @@ uint32 CONVuint32( uint32 data); uint16 CONVuint16( uint16 data); uint16 READuint64( const opaque* data); uint32 CONVuint64( uint64 data); +uint32 READuint24( const opaque* data); diff --git a/src/.cvsignore b/src/.cvsignore index 24f239b79a..5714013642 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,6 +1,8 @@ .cvsignore cli serv +prime +gnutls-rsm.db Makefile Makefile.in .deps |