From 99d48383286fbb865ab58db5e5f768d8ed14f41e Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Sat, 23 Dec 2023 10:47:28 +0100 Subject: New ndpi_sha256() nDPI API call (#2230) * Added ndpi_sha256.c to the Windows project * Added ndpi_sha256() nDPI API call --- src/lib/protocols/tls.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/lib/protocols') diff --git a/src/lib/protocols/tls.c b/src/lib/protocols/tls.c index 9bc948f23..fb3bd7d2e 100644 --- a/src/lib/protocols/tls.c +++ b/src/lib/protocols/tls.c @@ -1605,8 +1605,7 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct, union ja_info *ja) { u_int8_t tmp_str[JA_STR_LEN]; u_int tmp_str_len, num_extn; - SHA256_CTX sha_ctx; - u_int8_t sha_hash[SHA256_BLOCK_SIZE]; + u_int8_t sha_hash[NDPI_SHA256_BLOCK_SIZE]; char ja_str[JA_STR_LEN]; u_int16_t ja_str_len, i; 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; } - ndpi_sha256_init(&sha_ctx); - ndpi_sha256_update(&sha_ctx, tmp_str, tmp_str_len); - ndpi_sha256_final(&sha_ctx, sha_hash); + ndpi_sha256(tmp_str, tmp_str_len, sha_hash); rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len, "%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); #endif - ndpi_sha256_init(&sha_ctx); - ndpi_sha256_update(&sha_ctx, tmp_str, tmp_str_len); - ndpi_sha256_final(&sha_ctx, sha_hash); + ndpi_sha256(tmp_str, tmp_str_len, sha_hash); rc = ndpi_snprintf(&ja_str[ja_str_len], JA_STR_LEN-ja_str_len, "%02x%02x%02x%02x%02x%02x", -- cgit v1.2.3