New ndpi_sha256() nDPI API call (#2230)
* Added ndpi_sha256.c to the Windows project * Added ndpi_sha256() nDPI API call
This commit is contained in:
@@ -1787,6 +1787,8 @@ extern "C" {
|
|||||||
/* ******************************* */
|
/* ******************************* */
|
||||||
|
|
||||||
void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
|
void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
|
||||||
|
void ndpi_sha256(const u_char *data, size_t data_len, u_int8_t sha_hash[32]);
|
||||||
|
|
||||||
u_int16_t ndpi_crc16_ccit(const void* data, size_t n_bytes);
|
u_int16_t ndpi_crc16_ccit(const void* data, size_t n_bytes);
|
||||||
u_int16_t ndpi_crc16_ccit_false(const void *data, size_t n_bytes);
|
u_int16_t ndpi_crc16_ccit_false(const void *data, size_t n_bytes);
|
||||||
u_int16_t ndpi_crc16_xmodem(const void *data, size_t n_bytes);
|
u_int16_t ndpi_crc16_xmodem(const void *data, size_t n_bytes);
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
/* Third party libraries */
|
/* Third party libraries */
|
||||||
#include "third_party/include/ndpi_patricia.h"
|
#include "third_party/include/ndpi_patricia.h"
|
||||||
#include "third_party/include/ndpi_md5.h"
|
#include "third_party/include/ndpi_md5.h"
|
||||||
|
#include "third_party/include/ndpi_sha256.h"
|
||||||
|
|
||||||
#ifdef HAVE_NBPF
|
#ifdef HAVE_NBPF
|
||||||
#include "nbpf.h"
|
#include "nbpf.h"
|
||||||
@@ -10092,6 +10093,16 @@ void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]) {
|
|||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
void ndpi_sha256(const u_char *data, size_t data_len, u_int8_t sha_hash[32]) {
|
||||||
|
ndpi_SHA256_CTX sha_ctx;
|
||||||
|
|
||||||
|
ndpi_sha256_init(&sha_ctx);
|
||||||
|
ndpi_sha256_update(&sha_ctx, data, data_len);
|
||||||
|
ndpi_sha256_final(&sha_ctx, sha_hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************************************** */
|
||||||
|
|
||||||
static int enough(int a, int b) {
|
static int enough(int a, int b) {
|
||||||
u_int8_t percentage = 20;
|
u_int8_t percentage = 20;
|
||||||
|
|
||||||
|
|||||||
@@ -1605,8 +1605,7 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
union ja_info *ja) {
|
union ja_info *ja) {
|
||||||
u_int8_t tmp_str[JA_STR_LEN];
|
u_int8_t tmp_str[JA_STR_LEN];
|
||||||
u_int tmp_str_len, num_extn;
|
u_int tmp_str_len, num_extn;
|
||||||
SHA256_CTX sha_ctx;
|
u_int8_t sha_hash[NDPI_SHA256_BLOCK_SIZE];
|
||||||
u_int8_t sha_hash[SHA256_BLOCK_SIZE];
|
|
||||||
char ja_str[JA_STR_LEN];
|
char ja_str[JA_STR_LEN];
|
||||||
u_int16_t ja_str_len, i;
|
u_int16_t ja_str_len, i;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -1690,9 +1689,7 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
if((rc > 0) && (tmp_str_len + rc < JA_STR_LEN)) tmp_str_len += rc; else break;
|
if((rc > 0) && (tmp_str_len + rc < JA_STR_LEN)) tmp_str_len += rc; else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_sha256_init(&sha_ctx);
|
ndpi_sha256(tmp_str, tmp_str_len, sha_hash);
|
||||||
ndpi_sha256_update(&sha_ctx, tmp_str, tmp_str_len);
|
|
||||||
ndpi_sha256_final(&sha_ctx, sha_hash);
|
|
||||||
|
|
||||||
rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len,
|
rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len,
|
||||||
"%02x%02x%02x%02x%02x%02x_",
|
"%02x%02x%02x%02x%02x%02x_",
|
||||||
@@ -1724,9 +1721,7 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
printf("[EXTN] %s [len: %u]\n", tmp_str, tmp_str_len);
|
printf("[EXTN] %s [len: %u]\n", tmp_str, tmp_str_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ndpi_sha256_init(&sha_ctx);
|
ndpi_sha256(tmp_str, tmp_str_len, sha_hash);
|
||||||
ndpi_sha256_update(&sha_ctx, tmp_str, tmp_str_len);
|
|
||||||
ndpi_sha256_final(&sha_ctx, sha_hash);
|
|
||||||
|
|
||||||
rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len,
|
rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len,
|
||||||
"%02x%02x%02x%02x%02x%02x",
|
"%02x%02x%02x%02x%02x%02x",
|
||||||
|
|||||||
+6
-5
@@ -14,7 +14,8 @@
|
|||||||
#include "ndpi_typedefs.h"
|
#include "ndpi_typedefs.h"
|
||||||
|
|
||||||
/****************************** MACROS ******************************/
|
/****************************** MACROS ******************************/
|
||||||
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
|
|
||||||
|
#define NDPI_SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
|
||||||
|
|
||||||
/**************************** DATA TYPES ****************************/
|
/**************************** DATA TYPES ****************************/
|
||||||
|
|
||||||
@@ -23,12 +24,12 @@ typedef struct {
|
|||||||
u_int32_t datalen;
|
u_int32_t datalen;
|
||||||
unsigned long long bitlen;
|
unsigned long long bitlen;
|
||||||
u_int32_t state[8];
|
u_int32_t state[8];
|
||||||
} SHA256_CTX;
|
} ndpi_SHA256_CTX;
|
||||||
|
|
||||||
/*********************** FUNCTION DECLARATIONS **********************/
|
/*********************** FUNCTION DECLARATIONS **********************/
|
||||||
|
|
||||||
void ndpi_sha256_init(SHA256_CTX *ctx);
|
void ndpi_sha256_init(ndpi_SHA256_CTX *ctx);
|
||||||
void ndpi_sha256_update(SHA256_CTX *ctx, const u_int8_t data[], size_t len);
|
void ndpi_sha256_update(ndpi_SHA256_CTX *ctx, const u_int8_t data[], size_t len);
|
||||||
void ndpi_sha256_final(SHA256_CTX *ctx, u_int8_t hash[]);
|
void ndpi_sha256_final(ndpi_SHA256_CTX *ctx, u_int8_t hash[]);
|
||||||
|
|
||||||
#endif // SHA256_H
|
#endif // SHA256_H
|
||||||
|
|||||||
+4
-4
@@ -43,7 +43,7 @@ static const u_int32_t k[64] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*********************** FUNCTION DEFINITIONS ***********************/
|
/*********************** FUNCTION DEFINITIONS ***********************/
|
||||||
void sha256_transform(SHA256_CTX *ctx, const u_int8_t data[])
|
void sha256_transform(ndpi_SHA256_CTX *ctx, const u_int8_t data[])
|
||||||
{
|
{
|
||||||
u_int32_t 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];
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ void sha256_transform(SHA256_CTX *ctx, const u_int8_t data[])
|
|||||||
ctx->state[7] += h;
|
ctx->state[7] += h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndpi_sha256_init(SHA256_CTX *ctx)
|
void ndpi_sha256_init(ndpi_SHA256_CTX *ctx)
|
||||||
{
|
{
|
||||||
ctx->datalen = 0;
|
ctx->datalen = 0;
|
||||||
ctx->bitlen = 0;
|
ctx->bitlen = 0;
|
||||||
@@ -98,7 +98,7 @@ void ndpi_sha256_init(SHA256_CTX *ctx)
|
|||||||
ctx->state[7] = 0x5be0cd19;
|
ctx->state[7] = 0x5be0cd19;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndpi_sha256_update(SHA256_CTX *ctx, const u_int8_t data[], size_t len)
|
void ndpi_sha256_update(ndpi_SHA256_CTX *ctx, const u_int8_t data[], size_t len)
|
||||||
{
|
{
|
||||||
u_int32_t i;
|
u_int32_t i;
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ void ndpi_sha256_update(SHA256_CTX *ctx, const u_int8_t data[], size_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndpi_sha256_final(SHA256_CTX *ctx, u_int8_t hash[])
|
void ndpi_sha256_final(ndpi_SHA256_CTX *ctx, u_int8_t hash[])
|
||||||
{
|
{
|
||||||
u_int32_t i;
|
u_int32_t i;
|
||||||
|
|
||||||
|
|||||||
@@ -356,6 +356,7 @@
|
|||||||
<ClCompile Include="..\src\lib\third_party\src\ndpi_md5.c" />
|
<ClCompile Include="..\src\lib\third_party\src\ndpi_md5.c" />
|
||||||
<ClCompile Include="..\src\lib\third_party\src\ndpi_patricia.c" />
|
<ClCompile Include="..\src\lib\third_party\src\ndpi_patricia.c" />
|
||||||
<ClCompile Include="..\src\lib\third_party\src\ndpi_sha1.c" />
|
<ClCompile Include="..\src\lib\third_party\src\ndpi_sha1.c" />
|
||||||
|
<ClCompile Include="..\src\lib\third_party\src\ndpi_sha256.c" />
|
||||||
<ClCompile Include="..\src\lib\third_party\src\sha1-fast.c" />
|
<ClCompile Include="..\src\lib\third_party\src\sha1-fast.c" />
|
||||||
<ClCompile Include="..\src\lib\third_party\src\strptime.c" />
|
<ClCompile Include="..\src\lib\third_party\src\strptime.c" />
|
||||||
<ClCompile Include="..\src\lib\third_party\src\hll\MurmurHash3.c" />
|
<ClCompile Include="..\src\lib\third_party\src\hll\MurmurHash3.c" />
|
||||||
|
|||||||
Reference in New Issue
Block a user