*/
/********************************************************/
/* */
+/* 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. */
/* */
#Equivalences
#--------------------------------------------------------------------
EXE= \
+ chkhex \
digmd5 \
SRC= \
- digmd5.c
+ chkhex.c \
+ digmd5.c \
#--------------------------------------------------------------------
#definitions
-lssl \
#--------------------------------------------------------------------
+VALKIND = "definite,possible,indirect"
#testing area
tstmd5 : digmd5
@ ./digmd5 xxx $(BASE64)
-VALKIND = "definite,possible,indirect"
valmd5 : digmd5
@ valgrind \
--leak-check=full \
--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)
- rm -f $(EXE) *.o
#--------------------------------------------------------------------
+HEXA = \
+ e7680cee0538ac00aff721c5c96e3d4b\
+ 1d9908089a1ca0c347758b81fe61b6a4\
+ Z7680cee0538ac00aff721c5c96e3d4b\
+ Too_short \
+
BASE64 = Y2hhcnNldD11dGYtOCxjbm9uY2U9ImFkZDJhNmM0ODFlZjYzMTA2ZWY4MDNlOGJmMzE4ZGQyIixkaWdlc3QtdXJpPSJzbXRwL2RldmVsNS5zYWZlLmNhIixuYz0wMDAwMDAwMSxub25jZT0iYWJjZGVmIixxb3A9YXV0aCxyZWFsbT0iZGV2ZWw1LnNhZmUuY2EiLHJlc3BvbnNlPTBiM2VkZThjODgyODg4OTFhMDY2MDNkOWQwYjg0ZjZmLHVzZXJuYW1lPSJ3ZWJtYXN0ZXJAZXhhbXBsZS5jb20i
#--------------------------------------------------------------------
--- /dev/null
+// 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;
+}