]> SAFE projects GIT repository - jmp/mailleur/commitdiff
tools chkhex seems to be working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 10:57:30 +0000 (06:57 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 10:58:07 +0000 (06:58 -0400)
lib/unidig.c
tools/Makefile
tools/chkhex.c [new file with mode: 0644]

index c812dbb42d02ef70673275a4dd78c6d9a7bd503c..c327a5e21d79407007db5cb4fa42078eb816a160 100644 (file)
@@ -310,6 +310,45 @@ return hashmd5;
 */
 /********************************************************/
 /*                                                      */
+/*      Procedure to convert an MD5TYP array in         */
+/*      hexadecimal structure to be a pure/plain MD5TYP */
+/*      array.                                          */
+/*      Return (MD5TYP *)0 if trouble.                  */
+/*                                                      */
+/********************************************************/
+PUBLIC MD5TYP *dig_get_plain_md5(char *hexa)
+
+{
+MD5TYP *plain;
+
+plain=(MD5TYP *)0;
+if (strlen(hexa)==sizeof(MD5TYP)*2) {
+  _Bool ok;
+  MD5TYP travail;
+  char tmp[3];
+
+  ok=true;
+  (void) memset(travail,'\000',sizeof(travail));
+  (void) memset(tmp,'\000',sizeof(tmp));
+  for (register int i=0;i<sizeof(MD5TYP);i++) {
+    (void) memcpy(tmp,hexa+(i*2),2);
+    if (sscanf(tmp,"%hhx",&(travail[i]))!=1) {
+      ok=false; //Wrong hexa decimal number
+      break;
+      }
+    }
+  if (ok==true) {
+    plain=calloc(sizeof(MD5TYP),sizeof(char));
+    (void) memmove(plain,travail,sizeof(MD5TYP));
+    }
+  }
+return plain;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*      Procedure to generate a unique DIGEST-M5        */
 /*      challenge as an B64 string.                     */
 /*                                                      */
index e4c153602f705716f5843b2233a0db312842740d..ed16040ca4a5966d5835ae31425c3274e39aa14f 100644 (file)
@@ -21,10 +21,12 @@ clean       :
 #Equivalences
 #--------------------------------------------------------------------
 EXE=                                                           \
+       chkhex                                                  \
        digmd5                                                  \
 
 SRC=                                                           \
-       digmd5.c
+       chkhex.c                                                \
+       digmd5.c                                                \
 
 #--------------------------------------------------------------------
 #definitions
@@ -41,11 +43,11 @@ LIBS        =       $(LIBMAIL)                      \
                -lssl                           \
 
 #--------------------------------------------------------------------
+VALKIND        =  "definite,possible,indirect"
 #testing area
 tstmd5 :  digmd5
           @ ./digmd5 xxx $(BASE64)
 
-VALKIND        =  "definite,possible,indirect"
 valmd5 :  digmd5
           @ valgrind                           \
                --leak-check=full               \
@@ -57,10 +59,35 @@ dbgmd5      :  digmd5
                        --args                  \
                        ./digmd5 xxx $(BASE64)
 
+tsthex :  chkhex
+          @ ./chkhex                           \
+                       $(HEXA)
+
+dbghex :  chkhex
+          @ gdb                                \
+                       --args                  \
+                ./chkhex                       \
+                       $(HEXA)
+
+valhex :  chkhex
+          @ valgrind                           \
+               --leak-check=full               \
+               --show-leak-kinds=$(VALKIND)    \
+                ./chkhex                       \
+                       $(HEXA)
+
 #--------------------------------------------------------------------
 #Dependances
 #--------------------------------------------------------------------
 
+chkhex :  toremake chkhex.o
+          @ $(LD) $(LDFLAGS) -o ../tools/$@ $@.o $(LIBS)
+
+chkhex.o:  chkhex.c                            \
+          ../lib/unidig.h                      \
+          ../lib/subcnv.h                      \
+
+
 digmd5 :  toremake digmd5.o
           @ $(LD) $(LDFLAGS) -o ../tools/$@ $@.o $(LIBS)
 
@@ -75,5 +102,11 @@ toremake:  Makefile
           - rm -f $(EXE) *.o
 
 #--------------------------------------------------------------------
+HEXA   =                                       \
+               e7680cee0538ac00aff721c5c96e3d4b\
+               1d9908089a1ca0c347758b81fe61b6a4\
+               Z7680cee0538ac00aff721c5c96e3d4b\
+               Too_short                       \
+       
 BASE64 =  Y2hhcnNldD11dGYtOCxjbm9uY2U9ImFkZDJhNmM0ODFlZjYzMTA2ZWY4MDNlOGJmMzE4ZGQyIixkaWdlc3QtdXJpPSJzbXRwL2RldmVsNS5zYWZlLmNhIixuYz0wMDAwMDAwMSxub25jZT0iYWJjZGVmIixxb3A9YXV0aCxyZWFsbT0iZGV2ZWw1LnNhZmUuY2EiLHJlc3BvbnNlPTBiM2VkZThjODgyODg4OTFhMDY2MDNkOWQwYjg0ZjZmLHVzZXJuYW1lPSJ3ZWJtYXN0ZXJAZXhhbXBsZS5jb20i
 #--------------------------------------------------------------------
diff --git a/tools/chkhex.c b/tools/chkhex.c
new file mode 100644 (file)
index 0000000..6b97bb5
--- /dev/null
@@ -0,0 +1,61 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Validation program to check                     */
+/*              MD5TYP/hexadecimal sequence             */
+/*                                                     */
+/*      Usage:                                          */
+/*      chkhexa an MD5 heaxdecimal number.              */
+/*                                                     */
+/********************************************************/
+#include       <errno.h>
+#include       <stdio.h>
+#include       <stdbool.h>
+#include       <stdlib.h>
+#include       <string.h>
+#include       <unistd.h>
+
+#include       "subcnv.h"
+#include       "unidig.h"
+
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Main routine                                    */
+/*             Read the the hexadecimal number         */
+/*              convert it to binary and convert-it back*/
+/*              to  hexadecimal and compare it.         */
+/*                                                     */
+/********************************************************/
+int main(int argc,char *argv[])
+
+{
+int status;
+
+status=0;
+for (int i=1;i<argc;i++) {
+  _Bool ok;
+  MD5TYP *cnv;
+
+  ok=false;
+  if ((cnv=dig_get_plain_md5(argv[i]))!=(MD5TYP *)0) {
+    char *isgood;
+
+    isgood=cnv_tohexa((char *)cnv,sizeof(MD5TYP));
+    if (isgood!=(char *)0) {
+      if (strcmp(argv[i],isgood)==0)
+        ok=true;
+      (void) free(isgood);
+      }
+    (void) free(cnv);
+    }
+  if (ok==true)
+    (void) fprintf(stdout,"GOOD  MD5 HASH");
+  else
+    (void) fprintf(stdout,"WRONG MD5 HASH");
+  (void) fprintf(stdout," <%s>\n",argv[i]);
+  }
+return status;
+}