[tac_plus] Compute MD5 block cipher without marshalling

Philp Prindeville philipp at redfish-solutions.com
Sun Aug 28 22:37:22 UTC 2016


The MD5Update() function can be called multiple times with 1-byte 
granularity, so there's no reason to marshall data first (or allocate 
memory for marshalling) when the component values can be hashed 
individually.

Note sure if any of these patches are being seen.  Fingers crossed.

-Philip


-------------- next part --------------
--- a/encrypt.c	2009-07-17 11:34:30.000000000 -0600
+++ b/encrypt.c	2016-08-28 16:18:15.626522787 -0600
@@ -41,37 +41,16 @@ void
 create_md5_hash(int session_id, char *key, u_char version, u_char seq_no,
 		u_char *prev_hash, u_char *hash)
 {
-    u_char *md_stream, *mdp;
-    int md_len;
     MD5_CTX mdcontext;
 
-    md_len = sizeof(session_id) + strlen(key) + sizeof(version) +
-	sizeof(seq_no);
-
-    if (prev_hash) {
-	md_len += MD5_LEN;
-    }
-    mdp = md_stream = (u_char *) tac_malloc(md_len);
-    memcpy(mdp, &session_id, sizeof(session_id));
-    mdp += sizeof(session_id);
-
-    memcpy(mdp, key, strlen(key));
-    mdp += strlen(key);
-
-    memcpy(mdp, &version, sizeof(version));
-    mdp += sizeof(version);
-
-    memcpy(mdp, &seq_no, sizeof(seq_no));
-    mdp += sizeof(seq_no);
-
-    if (prev_hash) {
-	memcpy(mdp, prev_hash, MD5_LEN);
-	mdp += MD5_LEN;
-    }
     MD5Init(&mdcontext);
-    MD5Update(&mdcontext, md_stream, md_len);
+    MD5Update(&mdcontext, &session_id, sizeof(session_id));
+    MD5Update(&mdcontext, key, strlen(key));
+    MD5Update(&mdcontext, &version, sizeof(version));
+    MD5Update(&mdcontext, &seq_no, sizeof(seq_no));
+    if (prev_hash)
+	MD5Update(&mdcontext, prev_hash, MD5_LEN);
     MD5Final(hash, &mdcontext);
-    free(md_stream);
     return;
 }
 


More information about the tac_plus mailing list