]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding module unidig.c to agg all digest-md5 function
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 5 Jul 2025 19:33:57 +0000 (15:33 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 5 Jul 2025 19:33:57 +0000 (15:33 -0400)
lib/Makefile
lib/lvleml.c
lib/subcnv.c
lib/subcnv.h
lib/unidig.c [new file with mode: 0644]
lib/unidig.h [new file with mode: 0644]

index 5ed5c29b9acede6024248f9c89b5edaa1fc9ad29..45a07b2dda22ef7346eab6c272299ced093b3fb2 100644 (file)
@@ -23,7 +23,7 @@ OBJS=                                         \
          lvleml.o                              \
          gesspf.o gestcp.o geseml.o            \
          devlog.o devsoc.o devsql.o            \
-         unidns.o unieml.o unipar.o            \
+         unidig.o unidns.o unieml.o unipar.o   \
          uniprc.o unisig.o unisql.o unitls.o   \
          subafn.o subcnv.o subrou.o 
 
@@ -45,7 +45,7 @@ modrec.o:                                     \
 
 lvleml.o:                                      \
           subcnv.h subrou.h                    \
-          unieml.h unidns.h                    \
+          unidig.h unidns.h unieml.h           \
           lvleml.h lvleml.c
 
 gesspf.o:                                      \
@@ -80,6 +80,10 @@ devsql.o:                                    \
           unimar.h                             \
           devsql.h devsql.c
 
+unidig.o:                                      \
+          subrou.h subcnv.h                    \
+          unidig.h unidig.c
+
 unidns.o:                                      \
           subafn.h subrou.h                    \
           unidns.h unidns.c
index 4734cb0f27e9a69b8cc3397ec285617ab4d8b66b..931a7cec66056d81a2f2c886bd1b385b1dc0f26e 100644 (file)
@@ -20,6 +20,7 @@
 
 #include       "subrou.h"
 #include       "subcnv.h"
+#include       "unidig.h"
 #include       "unieml.h"
 #include       "devlog.h"
 #include       "gestcp.h"
@@ -436,7 +437,7 @@ while (proceed==true) {
       char *local;
       char *hexa;
 
-      local=cnv_cryptmd5(passwd,(unsigned char *)challenge); 
+      local=dig_cryptmd5(passwd,(unsigned char *)challenge); 
       hexa=cnv_tohexa(local);
       //(void) rou_alert(0,"%s anwr=<%s>",OPEP,answer);
       //(void) rou_alert(0,"%s hexa=<%s>",OPEP,hexa);
@@ -518,6 +519,10 @@ while (proceed==true) {
         res=cnv_getb64(line);
         (void) snprintf(answer,sizeof(answer),"%s",res);
         (void) rou_alert(0,"JMPDBG Got <%s>",answer);
+        {
+        unsigned char *seq=(unsigned char *)"webmaster@example.com:devel5.safe.ca:xxx";
+        (void) dig_hashmd5(seq);
+        }
         res=rou_freestr(res);
         line=rou_freestr(line);
         }
@@ -625,7 +630,7 @@ while (proceed==true) {
 
       //local=cnv_cryptmd5(usr->passwd,(unsigned char *)seq); 
       (void) rou_asprintf(&decoded,"%s%s%s%s",IOBNULL,name,IOBNULL,(char *)0);
-      local=cnv_cryptmd5("mailleur",(unsigned char *)seq); 
+      local=dig_cryptmd5("mailleur",(unsigned char *)seq); 
       hexa=cnv_tohexa(local);
       (void) rou_alert(0,"%s code=<%s>",OPEP,code);
       (void) rou_alert(0,"%s hexa=<%s>",OPEP,hexa);
index 505edca00ffdfce6a3f08d65b55b37cce66f62aa..c4e167f1a780bc013e5de102ce7de7f27d946184 100644 (file)
@@ -8,13 +8,9 @@
 #include        <ctype.h>
 #include        <stdbool.h>
 #include        <string.h>
-
-#define         OPENSSL_NO_KRB5
 #include        <openssl/bio.h>
+#include        <openssl/buffer.h>
 #include        <openssl/evp.h>
-#include        <openssl/err.h>
-#include        <openssl/hmac.h>
-#include        <openssl/ssl.h>
 
 #include       "subcnv.h"
 
@@ -167,63 +163,6 @@ coded=(char *)calloc(bptr->length+1,sizeof(char));
 (void) BIO_free_all(b64);
 return coded;
 
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      Procedure to crypt a string with MD5 hash       */
-/*      function.                                       */
-/*                                                      */
-/********************************************************/
-PUBLIC char *cnv_cryptmd5(const void *key,unsigned char *seq)
-
-{
-#define OPEP    "subcnv.c:cnv_hashmd5,"
-
-char *hashmd5;          //function result
-unsigned char *d5;      //md5 hash result
-u_int reslen;
-int phase;
-int proceed;
-
-hashmd5=(char *)0;
-d5=(unsigned char *)0;
-reslen=-1;
-phase=1;
-proceed=true;
-while (proceed==true) {
-  switch (phase) {
-    case 0      :       //do ve have good parameters
-      if ((key==(const void  *)0)||(seq==(unsigned char *)0)) {
-        (void) fprintf(stderr,"%s key or seq undefined (Bug?)",OPEP);
-        phase=999;
-        }
-      break;
-    case 1      :       //computing sequence
-      d5=HMAC(EVP_md5(),key,strlen(key),seq,strlen((const char *)seq),d5,&reslen);
-      if (d5==(unsigned char *)0) {
-        (void) fprintf(stderr,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)",
-                               OPEP,(char *)key,seq);
-        phase=999;
-        }
-      break;
-    case 2      :       //duplicate md5 result
-      if (reslen>0) {
-        hashmd5=(char *)calloc(reslen+1,sizeof(char));
-        (void) memmove((void *)hashmd5,(void *)d5,reslen);
-        }
-      break;
-    default     :       //SAFE Guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-return hashmd5;
-
 #undef  OPEP
 }
 /*
index dfb54ff529c52d2282567b01a57fdc067e3e0522..d3d728e8a33c0960d72319c7ac2868f75c88dda1 100644 (file)
@@ -11,6 +11,9 @@
 //base64 char 0 coding
 #define IOBNULL "\\0"
 
+//MD5 hashing result
+typedef unsigned char MD5TYP[17];
+
 //Procedure to convert a plain ASCII B64 sequence
 //to a plain ASCII sequence
 extern char *cnv_getb64(char *b64);
@@ -19,13 +22,6 @@ extern char *cnv_getb64(char *b64);
 //to an ASCII B64 sequence
 extern char *cnv_setb64(const char *str);
 
-//procedure to convert a string to a 128 Bit sequence
-//as a string
-extern char *cnv_hashmd5(char *seq);
-
-//Procedure to crypt a string with MD5 hash function
-extern char *cnv_cryptmd5(const void *key,unsigned char *seq);
-
 //Procedure to convert a string of character as an HEXA string
 extern char *cnv_tohexa(const char *str);
 
diff --git a/lib/unidig.c b/lib/unidig.c
new file mode 100644 (file)
index 0000000..ffb1866
--- /dev/null
@@ -0,0 +1,128 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Implement all procedure to use digest-md5       */
+/*     authentication exchange.                        */
+/*                                                     */
+/********************************************************/
+#include        <openssl/evp.h>
+#include        <openssl/hmac.h>
+#include        <string.h>
+
+#include       "subrou.h"
+#include       "subcnv.h"
+#include       "unidig.h"
+
+/*
+ * \f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to hash a string with MD5 hash        */
+/*      an return a 16+1 Bytes.                         */
+/*                                                      */
+/********************************************************/
+PUBLIC MD5TYP *dig_hashmd5(unsigned char *seq)
+
+{
+#define OPEP    "subdig.c:dig_hashmd5,"
+
+MD5TYP *md5;
+EVP_MD_CTX *mdctx;
+unsigned int digestlength;
+int phase;
+_Bool proceed;
+
+md5=(MD5TYP *)0;
+mdctx=(EVP_MD_CTX *)0;
+digestlength=sizeof(MD5TYP)-1;
+phase=1;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //do we hae a sequence?
+      if ((seq==(unsigned char *)0)&&(strlen((const char *)seq)==0)) 
+        phase=999;      //no need to go further
+      break;
+    case 1      :       //getting md5 context
+      if ((mdctx=EVP_MD_CTX_new())==(EVP_MD_CTX *)0) {
+        (void) fprintf(stdout,"%s Unable to open MD5 context (System?)",OPEP);
+        phase=999;      //no need to go further
+        }
+      break;
+    case 2      :       //doing hashing
+      (void) EVP_DigestInit_ex(mdctx,EVP_md5(),(ENGINE *)0);
+      (void) EVP_DigestUpdate(mdctx,seq,strlen((const char *)seq));
+      break;
+    case 3      :       //assign memory
+      md5=calloc(1,sizeof(MD5TYP));
+      (void) EVP_DigestFinal_ex(mdctx,(unsigned char *)md5,&digestlength);
+      EVP_MD_CTX_free(mdctx);
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return md5;
+
+#undef  OPEP
+}
+/*
+ * \f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to crypt a string with MD5 hash       */
+/*      function.                                       */
+/*                                                      */
+/********************************************************/
+PUBLIC char *dig_cryptmd5(const void *key,unsigned char *seq)
+
+{
+#define OPEP    "subdig.c:dig_hashmd5,"
+
+char *hashmd5;          //function result
+unsigned char *d5;      //md5 hash result
+u_int reslen;
+int phase;
+int proceed;
+
+hashmd5=(char *)0;
+d5=(unsigned char *)0;
+reslen=-1;
+phase=1;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //do ve have good parameters
+      if ((key==(const void  *)0)||(seq==(unsigned char *)0)) {
+        (void) fprintf(stderr,"%s key or seq undefined (Bug?)",OPEP);
+        phase=999;
+        }
+      break;
+    case 1      :       //computing sequence
+      d5=HMAC(EVP_md5(),key,strlen(key),seq,strlen((const char *)seq),d5,&reslen);
+      if (d5==(unsigned char *)0) {
+        (void) fprintf(stderr,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)",
+                               OPEP,(char *)key,seq);
+        phase=999;
+        }
+      break;
+    case 2      :       //duplicate md5 result
+      if (reslen>0) {
+        hashmd5=(char *)calloc(reslen+1,sizeof(char));
+        (void) memmove((void *)hashmd5,(void *)d5,reslen);
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return hashmd5;
+
+#undef  OPEP
+}
diff --git a/lib/unidig.h b/lib/unidig.h
new file mode 100644 (file)
index 0000000..31e73c6
--- /dev/null
@@ -0,0 +1,18 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Define all procedure to use digest-md5          */
+/*      authentication exchanges.                       */
+/*                                                     */
+/********************************************************/
+#ifndef        UNIDIG
+#define UNIDIG
+
+//procedure to convert a string to a 128 Bit sequence
+//as a string
+extern MD5TYP *dig_hashmd5(unsigned char *seq);
+
+//Procedure to crypt a string with MD5 hash function
+extern char *dig_cryptmd5(const void *key,unsigned char *seq);
+
+#endif