mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 20:54:41 +02:00
Cleanup to consolidate the inline helpers like cto, ato and bto into misc.c. Relocate the word24 typedef into types.h.
This commit is contained in:
@@ -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 */
|
||||
|
36
src/ssl.c
36
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;
|
||||
|
47
src/tls.c
47
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) {
|
||||
|
74
src/tls13.c
74
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)
|
||||
*
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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 */
|
||||
|
||||
|
||||
|
@@ -46,6 +46,7 @@
|
||||
#endif
|
||||
typedef unsigned short word16;
|
||||
typedef unsigned int word32;
|
||||
typedef unsigned char word24[3];
|
||||
#endif
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user