瀏覽代碼

rtpengine: Replace sha1 generation

- Remove dep on crypto module
- Use core implementation
Xenofon Karamanos 1 月之前
父節點
當前提交
2c2c585986
共有 1 個文件被更改,包括 9 次插入23 次删除
  1. 9 23
      src/modules/rtpengine/rtpengine.c

+ 9 - 23
src/modules/rtpengine/rtpengine.c

@@ -58,6 +58,7 @@
 #include "../../core/fmsg.h"
 #include "../../core/forward.h"
 #include "../../core/mem/mem.h"
+#include "../../core/crypto/shautils.h"
 #include "../../core/parser/parse_from.h"
 #include "../../core/parser/parse_to.h"
 #include "../../core/parser/parse_uri.h"
@@ -85,7 +86,6 @@
 #include "../../core/cfg/cfg_struct.h"
 #include "../../core/rand/fastrand.h"
 #include "../../modules/tm/tm_load.h"
-#include "../../modules/crypto/api.h"
 #include "../../modules/lwsc/api.h"
 #include "rtpengine.h"
 #include "rtpengine_funcs.h"
@@ -441,8 +441,6 @@ static pv_elem_t *extra_id_pv = NULL;
 static struct minmax_mos_label_stats global_mos_stats, side_A_mos_stats,
 		side_B_mos_stats;
 int got_any_mos_pvs;
-struct crypto_binds rtpengine_cb;
-
 
 /* clang-format off */
 static cmd_export_t cmds[] = {
@@ -2601,13 +2599,6 @@ static int mod_init(void)
 		return -1;
 	}
 
-	if(hash_algo == RTP_HASH_SHA1_CALLID) {
-		if(load_crypto_api(&rtpengine_cb) != 0) {
-			LM_ERR("Crypto module required in order to have SHA1 hashing!\n");
-			return -1;
-		}
-	}
-
 	/* Enable ping timer if interval is positive */
 	if(rtpengine_ping_interval > 0) {
 		register_timer(rtpengine_ping_check_timer, 0, rtpengine_ping_interval);
@@ -3181,7 +3172,7 @@ static char *gencookie(void)
 	static char cook[35]; // 11 + 1 + 10 + 1 + 10 + 1 + 1
 
 	snprintf(cook, 35, "%" PRId32 "_%" PRIu32 "_%" PRIu32 " ",
-			(int32_t) server_id, (uint32_t) fastrand(), (uint32_t) myseqn);
+			(int32_t)server_id, (uint32_t)fastrand(), (uint32_t)myseqn);
 	myseqn++;
 	return cook;
 }
@@ -4556,8 +4547,8 @@ static struct rtpp_node *select_rtpp_node_new(str callid, str viabranch,
 	struct rtpp_node *node;
 	unsigned i, sum, sumcut, weight_sum;
 	int was_forced = 0;
-
-	str hash_data;
+	unsigned char sha1[SHA1_DIGEST_LENGTH];
+	str hash_data = STR_NULL;
 
 	switch(hash_algo) {
 		case RTP_HASH_CALLID:
@@ -4565,18 +4556,13 @@ static struct rtpp_node *select_rtpp_node_new(str callid, str viabranch,
 
 			break;
 		case RTP_HASH_SHA1_CALLID:
-			if(rtpengine_cb.SHA1 == NULL) {
-				/* don't throw warning here; there is already a warni*/
-				LM_BUG("SHA1 algo set but crypto not loaded! Program shouldn't "
-					   "have started!");
+			if(callid.len <= 0 || callid.s == NULL) {
+				LM_ERR("Invalid callid for SHA1 hashing\n");
 				return NULL;
 			}
-
-			if(rtpengine_cb.SHA1(&callid, &hash_data) < 0) {
-				LM_ERR("SHA1 hash in crypto module failed!\n");
-				return NULL;
-			}
-
+			compute_sha1_raw(sha1, (u_int8_t *)callid.s, callid.len);
+			hash_data.s = (char *)sha1;
+			hash_data.len = SHA1_DIGEST_LENGTH;
 			break;
 		case RTP_HASH_CRC32_CALLID:
 			crc32_uint(&callid, &sum);