Changes to avoid type redefinition on windows

This commit is contained in:
Luca Deri
2023-12-23 09:15:42 +01:00
parent 5c7200f2bb
commit caa223d2ba
3 changed files with 16 additions and 17 deletions
+2 -2
View File
@@ -1603,10 +1603,10 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int32_t quic_version,
union ja_info *ja) {
BYTE tmp_str[JA_STR_LEN];
u_int8_t tmp_str[JA_STR_LEN];
u_int tmp_str_len, num_extn;
SHA256_CTX sha_ctx;
BYTE sha_hash[SHA256_BLOCK_SIZE];
u_int8_t sha_hash[SHA256_BLOCK_SIZE];
char ja_str[JA_STR_LEN];
u_int16_t ja_str_len, i;
int rc;
+4 -5
View File
@@ -11,19 +11,18 @@
/*************************** HEADER FILES ***************************/
#include <stddef.h>
#include "ndpi_typedefs.h"
/****************************** MACROS ******************************/
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
typedef struct {
BYTE data[64];
WORD datalen;
u_int8_t data[64];
u_int32_t datalen;
unsigned long long bitlen;
WORD state[8];
u_int32_t state[8];
} SHA256_CTX;
/*********************** FUNCTION DECLARATIONS **********************/
+10 -10
View File
@@ -11,7 +11,7 @@
offered in this implementation.
Algorithm specification can be found here:
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
This implementation uses little endian byte order.
This implementation uses little endian u_int8_t order.
*********************************************************************/
/*************************** HEADER FILES ***************************/
@@ -31,7 +31,7 @@
#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
/**************************** VARIABLES *****************************/
static const WORD k[64] = {
static const u_int32_t k[64] = {
0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
@@ -43,9 +43,9 @@ static const WORD k[64] = {
};
/*********************** FUNCTION DEFINITIONS ***********************/
void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
void sha256_transform(SHA256_CTX *ctx, const u_int8_t data[])
{
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
u_int32_t a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
for (i = 0, j = 0; i < 16; ++i, j += 4)
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
@@ -98,9 +98,9 @@ void ndpi_sha256_init(SHA256_CTX *ctx)
ctx->state[7] = 0x5be0cd19;
}
void ndpi_sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
void ndpi_sha256_update(SHA256_CTX *ctx, const u_int8_t data[], size_t len)
{
WORD i;
u_int32_t i;
for (i = 0; i < len; ++i) {
ctx->data[ctx->datalen] = data[i];
@@ -113,9 +113,9 @@ void ndpi_sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len)
}
}
void ndpi_sha256_final(SHA256_CTX *ctx, BYTE hash[])
void ndpi_sha256_final(SHA256_CTX *ctx, u_int8_t hash[])
{
WORD i;
u_int32_t i;
i = ctx->datalen;
@@ -145,8 +145,8 @@ void ndpi_sha256_final(SHA256_CTX *ctx, BYTE hash[])
ctx->data[56] = ctx->bitlen >> 56;
sha256_transform(ctx, ctx->data);
// Since this implementation uses little endian byte ordering and SHA uses big endian,
// reverse all the bytes when copying the final state to the output hash.
// Since this implementation uses little endian u_int8_t ordering and SHA uses big endian,
// reverse all the u_int8_ts when copying the final state to the output hash.
for (i = 0; i < 4; ++i) {
hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;