aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_utils.c
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2024-09-24 12:51:55 +0200
committerLuca Deri <deri@ntop.org>2024-09-24 12:51:55 +0200
commit9a8dc640be989fd2358beaa8256fbe1eb95ecf66 (patch)
treea2633a53898a43e94784e2c33f82e8c2b06394f1 /src/lib/ndpi_utils.c
parent42cfd29cc3d7dd2c883c8fd3c5f53319f752fbfc (diff)
buffer lenghtt is now returned by ndpi_quick_encrypt() and ndpi_quick_deecrypt()
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r--src/lib/ndpi_utils.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index ebe057c56..14a716298 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -3734,6 +3734,7 @@ u_int ndpi_bin2hex(u_char *out, u_int out_len, u_char* in, u_int in_len) {
*/
char* ndpi_quick_encrypt(const char *cleartext_msg,
u_int16_t cleartext_msg_len,
+ u_int16_t *encrypted_msg_len,
u_char encrypt_key[64]) {
char *encoded = NULL, *encoded_buf;
struct AES_ctx ctx;
@@ -3745,6 +3746,7 @@ char* ndpi_quick_encrypt(const char *cleartext_msg,
* But AES, being a block cipher, requires the input to be multiple of block size (16 bytes). */
encoded_len = cleartext_msg_len + 16 - (cleartext_msg_len % 16);
+ *encrypted_msg_len = 0;
encoded_buf = (char *)ndpi_calloc(encoded_len, 1);
if (encoded_buf == NULL) {
@@ -3768,6 +3770,8 @@ char* ndpi_quick_encrypt(const char *cleartext_msg,
encoded = ndpi_base64_encode((const unsigned char *)encoded_buf, encoded_len);
ndpi_free(encoded_buf);
+ *encrypted_msg_len = strlen(encoded);
+
return(encoded);
}
@@ -3775,6 +3779,7 @@ char* ndpi_quick_encrypt(const char *cleartext_msg,
char* ndpi_quick_decrypt(const char *encrypted_msg,
u_int16_t encrypted_msg_len,
+ u_int16_t *decrypted_msg_len,
u_char decrypt_key[64]) {
u_char nonce[24] = { 0x0 };
u_char binary_decrypt_key[32];
@@ -3784,6 +3789,8 @@ char* ndpi_quick_decrypt(const char *encrypted_msg,
u_int n_padding;
struct AES_ctx ctx;
+ *decrypted_msg_len = 0;
+
if(decoded_string == NULL) {
/* Allocation failure */
return(NULL);
@@ -3818,6 +3825,8 @@ char* ndpi_quick_decrypt(const char *encrypted_msg,
decoded_string[content_len] = 0;
}
+ *decrypted_msg_len = content_len;
+
ndpi_free(content);
return(decoded_string);