diff --git a/src/internal.c b/src/internal.c index e58dd19b4..c09562040 100755 --- a/src/internal.c +++ b/src/internal.c @@ -317,64 +317,6 @@ static word32 GetEntropy(unsigned char* out, word32 num_bytes) } #endif /* HAVE_NTRU */ -/* used by ssl.c too */ -void c32to24(word32 in, word24 out) -{ - out[0] = (in >> 16) & 0xff; - out[1] = (in >> 8) & 0xff; - out[2] = in & 0xff; -} - - -/* convert 16 bit integer to opaque */ -static INLINE void c16toa(word16 u16, byte* c) -{ - c[0] = (u16 >> 8) & 0xff; - c[1] = u16 & 0xff; -} - - -#if !defined(NO_OLD_TLS) || defined(HAVE_CHACHA) || defined(HAVE_AESCCM) \ - || defined(HAVE_AESGCM) || defined(WOLFSSL_SESSION_EXPORT) \ - || defined(WOLFSSL_DTLS) || defined(HAVE_SESSION_TICKET) -/* convert 32 bit integer to opaque */ -static INLINE void c32toa(word32 u32, byte* c) -{ - c[0] = (u32 >> 24) & 0xff; - c[1] = (u32 >> 16) & 0xff; - c[2] = (u32 >> 8) & 0xff; - c[3] = u32 & 0xff; -} - -#endif - - -/* convert a 24 bit integer into a 32 bit one */ -static INLINE void c24to32(const word24 u24, word32* u32) -{ - *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; -} - - -/* convert opaque to 16 bit integer */ -static INLINE void ato16(const byte* c, word16* u16) -{ - *u16 = (word16) ((c[0] << 8) | (c[1])); -} - - -#if defined(WOLFSSL_DTLS) || defined(HAVE_SESSION_TICKET) || \ - defined(WOLFSSL_SESSION_EXPORT) - -/* convert opaque to 32 bit integer */ -static INLINE void ato32(const byte* c, word32* u32) -{ - *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; -} - -#endif /* WOLFSSL_DTLS */ - - #ifdef HAVE_LIBZ /* alloc user allocs to work with zlib */ diff --git a/src/ssl.c b/src/ssl.c index bb3e7d507..6cafbb35d 100755 --- a/src/ssl.c +++ b/src/ssl.c @@ -17545,23 +17545,6 @@ void wolfSSL_CTX_sess_set_remove_cb(WOLFSSL_CTX* ctx, void (*f)(WOLFSSL_CTX*, #endif } -#ifdef HAVE_EXT_CACHE -/* convert 32 bit integer to opaque */ -static INLINE void c32toa(word32 u32, byte* c) -{ - c[0] = (u32 >> 24) & 0xff; - c[1] = (u32 >> 16) & 0xff; - c[2] = (u32 >> 8) & 0xff; - c[3] = u32 & 0xff; -} - -static INLINE void c16toa(word16 u16, byte* c) -{ - c[0] = (u16 >> 8) & 0xff; - c[1] = u16 & 0xff; -} -#endif - int wolfSSL_i2d_SSL_SESSION(WOLFSSL_SESSION* sess, unsigned char** p) { int size = 0; @@ -17642,20 +17625,6 @@ int wolfSSL_i2d_SSL_SESSION(WOLFSSL_SESSION* sess, unsigned char** p) return size; } -#ifdef HAVE_EXT_CACHE -/* convert opaque to 16 bit integer */ -static INLINE void ato16(const byte* c, word16* u16) -{ - *u16 = (word16) ((c[0] << 8) | (c[1])); -} - -/* convert opaque to 32 bit integer */ -static INLINE void ato32(const byte* c, word32* u32) -{ - *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; -} -#endif - /* TODO: no function to free new session. */ WOLFSSL_SESSION* wolfSSL_d2i_SSL_SESSION(WOLFSSL_SESSION** sess, const unsigned char** p, long i) @@ -25564,11 +25533,6 @@ int wolfSSL_set_ocsp_url(WOLFSSL* ssl, char* url) return WOLFSSL_SUCCESS; } -static INLINE void ato24(const byte* c, word32* u24) -{ - *u24 = (c[0] << 16) | (c[1] << 8) | c[2]; -} - int wolfSSL_CTX_get_extra_chain_certs(WOLFSSL_CTX* ctx, WOLF_STACK_OF(X509)** chain) { word32 idx; diff --git a/src/tls.c b/src/tls.c index a0b8377e6..52158c9bb 100755 --- a/src/tls.c +++ b/src/tls.c @@ -683,53 +683,6 @@ int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* msk, unsigned int len, } -/*** next for static INLINE s copied internal.c ***/ - -/* convert 16 bit integer to opaque */ -static INLINE void c16toa(word16 u16, byte* c) -{ - c[0] = (u16 >> 8) & 0xff; - c[1] = u16 & 0xff; -} - -#ifdef HAVE_TLS_EXTENSIONS -/* convert opaque to 16 bit integer */ -static INLINE void ato16(const byte* c, word16* u16) -{ - *u16 = (c[0] << 8) | (c[1]); -} - -#if defined(HAVE_SNI) && !defined(NO_WOLFSSL_SERVER) -/* convert a 24 bit integer into a 32 bit one */ -static INLINE void c24to32(const word24 u24, word32* u32) -{ - *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; -} -#endif - -#if defined(WOLFSSL_TLS13) && (defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)) -/* Convert opaque data to a 32-bit unsigned integer. - * - * c The opaque data holding a 32-bit integer. - * u32 The 32-bit unsigned integer. - */ -static INLINE void ato32(const byte* c, word32* u32) -{ - *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; -} -#endif -#endif /* HAVE_TLS_EXTENSIONS */ - -/* convert 32 bit integer to opaque */ -static INLINE void c32toa(word32 u32, byte* c) -{ - c[0] = (u32 >> 24) & 0xff; - c[1] = (u32 >> 16) & 0xff; - c[2] = (u32 >> 8) & 0xff; - c[3] = u32 & 0xff; -} - - static INLINE void GetSEQIncrement(WOLFSSL* ssl, int verify, word32 seq[2]) { if (verify) { diff --git a/src/tls13.c b/src/tls13.c index 1f3fb9575..644183c4a 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -101,80 +101,6 @@ #define ERROR_OUT(err, eLabel) { ret = (err); goto eLabel; } -#ifndef WOLFSSL_HAVE_MIN -#define WOLFSSL_HAVE_MIN -/* Return the minimum of the two values. - * - * a First value. - * b Second value. - * returns the minimum of a and b. - */ -static INLINE word32 min(word32 a, word32 b) -{ - return a > b ? b : a; -} -#endif /* WOLFSSL_HAVE_MIN */ - -/* Convert 16-bit integer to opaque data. - * - * u16 Unsigned 16-bit value. - * c The buffer to write to. - */ -static INLINE void c16toa(word16 u16, byte* c) -{ - c[0] = (u16 >> 8) & 0xff; - c[1] = u16 & 0xff; -} - -/* Convert 32-bit integer to opaque data. - * - * u32 Unsigned 32-bit value. - * c The buffer to write to. - */ -static INLINE void c32toa(word32 u32, byte* c) -{ - c[0] = (u32 >> 24) & 0xff; - c[1] = (u32 >> 16) & 0xff; - c[2] = (u32 >> 8) & 0xff; - c[3] = u32 & 0xff; -} - - -/* Convert 24-bit opaque data into a 32-bit value. - * - * u24 The opaque data holding a 24-bit integer. - * u32 Unsigned 32-bit value. - */ -static INLINE void c24to32(const word24 u24, word32* u32) -{ - *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; -} - - -/* Convert opaque data into a 16-bit value. - * - * c The opaque data. - * u16 Unsigned 16-bit value. - */ -static INLINE void ato16(const byte* c, word16* u16) -{ - *u16 = (word16) ((c[0] << 8) | (c[1])); -} - -#ifndef NO_WOLFSSL_CLIENT -#ifdef HAVE_SESSION_TICKET -/* Convert opaque data into a 32-bit value. - * - * c The opaque data. - * u32 Unsigned 32-bit value. - */ -static INLINE void ato32(const byte* c, word32* u32) -{ - *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; -} -#endif -#endif - /* Extract data using HMAC, salt and input. * RFC 5869 - HMAC-based Extract-and-Expand Key Derivation Function (HKDF) * diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 36ff9fbee..2bb6caa63 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -461,12 +461,6 @@ time_t XTIME(time_t * timer) #endif /* WOLFSSL_TIRTOS */ -static INLINE word32 btoi(byte b) -{ - return (word32)(b - 0x30); -} - - /* two byte date/time, add to value */ static INLINE void GetTime(int* value, const byte* date, int* idx) { diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c index 08ba55e86..2aaec44fb 100644 --- a/wolfcrypt/src/misc.c +++ b/wolfcrypt/src/misc.c @@ -239,6 +239,62 @@ STATIC INLINE int ConstantCompare(const byte* a, const byte* b, int length) } #endif /* !WOLFSSL_HAVE_MAX */ +/* converts a 32 bit integer to 24 bit */ +static INLINE void c32to24(word32 in, word24 out) +{ + out[0] = (in >> 16) & 0xff; + out[1] = (in >> 8) & 0xff; + out[2] = in & 0xff; +} + +/* convert 16 bit integer to opaque */ +static INLINE void c16toa(word16 u16, byte* c) +{ + c[0] = (u16 >> 8) & 0xff; + c[1] = u16 & 0xff; +} + +/* convert 32 bit integer to opaque */ +static INLINE void c32toa(word32 u32, byte* c) +{ + c[0] = (u32 >> 24) & 0xff; + c[1] = (u32 >> 16) & 0xff; + c[2] = (u32 >> 8) & 0xff; + c[3] = u32 & 0xff; +} + +/* convert a 24 bit integer into a 32 bit one */ +static INLINE void c24to32(const word24 u24, word32* u32) +{ + *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; +} + + +/* convert opaque to 24 bit integer */ +static INLINE void ato24(const byte* c, word32* u24) +{ + *u24 = (c[0] << 16) | (c[1] << 8) | c[2]; +} + +/* convert opaque to 16 bit integer */ +static INLINE void ato16(const byte* c, word16* u16) +{ + *u16 = (word16) ((c[0] << 8) | (c[1])); +} + +/* convert opaque to 32 bit integer */ +static INLINE void ato32(const byte* c, word32* u32) +{ + *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; +} + + +static INLINE word32 btoi(byte b) +{ + return (word32)(b - 0x30); +} + + #undef STATIC diff --git a/wolfssl/internal.h b/wolfssl/internal.h index ac8507aaa..dd3f1ac2b 100755 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -200,9 +200,6 @@ extern "C" { #endif - -typedef byte word24[3]; - /* Define or comment out the cipher suites you'd like to be compiled in make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined @@ -3781,9 +3778,6 @@ WOLFSSL_LOCAL word32 LowResTimer(void); WOLFSSL_LOCAL int CopyDecodedToX509(WOLFSSL_X509*, DecodedCert*); #endif -/* used by ssl.c and internal.c */ -WOLFSSL_LOCAL void c32to24(word32 in, word24 out); - WOLFSSL_LOCAL const char* const* GetCipherNames(void); WOLFSSL_LOCAL int GetCipherNamesSize(void); WOLFSSL_LOCAL const char* GetCipherNameInternal(const char* cipherName, int cipherSuite); diff --git a/wolfssl/wolfcrypt/misc.h b/wolfssl/wolfcrypt/misc.h index ed64159c8..5f4de41a7 100644 --- a/wolfssl/wolfcrypt/misc.h +++ b/wolfssl/wolfcrypt/misc.h @@ -82,6 +82,14 @@ void ByteReverseWords64(word64*, const word64*, word32); #endif /* WOLFSSL_HAVE_MAX */ +void c32to24(word32 in, word24 out); +void c16toa(word16 u16, byte* c); +void c32toa(word32 u32, byte* c); +void c24to32(const word24 u24, word32* u32); +void ato16(const byte* c, word16* u16); +void ato32(const byte* c, word32* u32); +word32 btoi(byte b); + #endif /* NO_INLINE */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index d9bf9a7b7..1a5cfe463 100755 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -46,6 +46,7 @@ #endif typedef unsigned short word16; typedef unsigned int word32; + typedef unsigned char word24[3]; #endif