From d903187eea6412e0fc2716b1096a7983f6f5eae5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 14 Oct 2024 00:42:09 +0300 Subject: [PATCH] public: make crc value init functions inline, move hex2char/ex2string to crclib and make them private to it --- public/crclib.c | 57 +++++++++++++++++++++++-------------------------- public/crclib.h | 35 +++++++++++++++++++++++++++--- public/crtlib.c | 27 ----------------------- public/crtlib.h | 2 -- 4 files changed, 59 insertions(+), 62 deletions(-) diff --git a/public/crclib.c b/public/crclib.c index de64ec7a..8b13a752 100644 --- a/public/crclib.c +++ b/public/crclib.c @@ -19,8 +19,6 @@ GNU General Public License for more details. #include #define NUM_BYTES 256 -#define CRC32_INIT_VALUE 0xFFFFFFFFUL -#define CRC32_XOR_VALUE 0xFFFFFFFFUL static const uint32_t crc32table[NUM_BYTES] = { @@ -90,16 +88,6 @@ static const uint32_t crc32table[NUM_BYTES] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -void GAME_EXPORT CRC32_Init( uint32_t *pulCRC ) -{ - *pulCRC = CRC32_INIT_VALUE; -} - -uint32_t GAME_EXPORT CRC32_Final( uint32_t pulCRC ) -{ - return pulCRC ^ CRC32_XOR_VALUE; -} - void GAME_EXPORT CRC32_ProcessByte( uint32_t *pulCRC, byte ch ) { uint32_t ulCrc = *pulCRC; @@ -185,24 +173,6 @@ byte CRC32_BlockSequence( byte *base, int length, int sequence ) void MD5Transform( uint buf[4], const uint in[16] ); -/* -================== -MD5Init - -Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants. -================== -*/ -void MD5Init( MD5Context_t *ctx ) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; -} - /* =================== MD5Update @@ -405,6 +375,33 @@ void MD5Transform( uint buf[4], const uint in[16] ) buf[3] += d; } +/* +============ +COM_Hex2Char +============ +*/ +static char COM_Hex2Char( uint8_t hex ) +{ + if( hex >= 0x0 && hex <= 0x9 ) + hex += '0'; + else if( hex >= 0xA && hex <= 0xF ) + hex += '7'; + + return (char)hex; +} + +/* +============ +COM_Hex2String +============ +*/ +static void COM_Hex2String( uint8_t hex, char *str ) +{ + *str++ = COM_Hex2Char( hex >> 4 ); + *str++ = COM_Hex2Char( hex & 0x0F ); + *str = '\0'; +} + /* ================= MD5_Print diff --git a/public/crclib.h b/public/crclib.h index ab565148..69233729 100644 --- a/public/crclib.h +++ b/public/crclib.h @@ -26,12 +26,41 @@ typedef struct uint in[16]; } MD5Context_t; -void CRC32_Init( uint32_t *pulCRC ); +#define CRC32_INIT_VALUE 0xFFFFFFFFUL +#define CRC32_XOR_VALUE 0xFFFFFFFFUL + +static inline void CRC32_Init( uint32_t *pulCRC ) +{ + *pulCRC = CRC32_INIT_VALUE; +} + +static inline uint32_t CRC32_Final( uint32_t pulCRC ) +{ + return pulCRC ^ CRC32_XOR_VALUE; +} + byte CRC32_BlockSequence( byte *base, int length, int sequence ); void CRC32_ProcessBuffer( uint32_t *pulCRC, const void *pBuffer, int nBuffer ); void CRC32_ProcessByte( uint32_t *pulCRC, byte ch ); -uint32_t CRC32_Final( uint32_t pulCRC ); -void MD5Init( MD5Context_t *ctx ); + +/* +================== +MD5Init + +Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants. +================== +*/ +static inline void MD5Init( MD5Context_t *ctx ) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + void MD5Update( MD5Context_t *ctx, const byte *buf, uint len ); void MD5Final( byte digest[16], MD5Context_t *ctx ); uint COM_HashKey( const char *string, uint hashSize ); diff --git a/public/crtlib.c b/public/crtlib.c index ec1fe04e..08c728e9 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -702,33 +702,6 @@ void COM_PathSlashFix( char *path ) } } -/* -============ -COM_Hex2Char -============ -*/ -char COM_Hex2Char( uint8_t hex ) -{ - if( hex >= 0x0 && hex <= 0x9 ) - hex += '0'; - else if( hex >= 0xA && hex <= 0xF ) - hex += '7'; - - return (char)hex; -} - -/* -============ -COM_Hex2String -============ -*/ -void COM_Hex2String( uint8_t hex, char *str ) -{ - *str++ = COM_Hex2Char( hex >> 4 ); - *str++ = COM_Hex2Char( hex & 0x0F ); - *str = '\0'; -} - /* ============== COM_IsSingleChar diff --git a/public/crtlib.h b/public/crtlib.h index d03f308a..65927a0b 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -94,8 +94,6 @@ void COM_StripExtension( char *path ); void COM_RemoveLineFeed( char *str, size_t bufsize ); void COM_FixSlashes( char *pname ); void COM_PathSlashFix( char *path ); -char COM_Hex2Char( uint8_t hex ); -void COM_Hex2String( uint8_t hex, char *str ); // return 0 on empty or null string, 1 otherwise #define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 ) #define COM_CheckStringEmpty( string ) ( ( !*string ) ? 0 : 1 )