Merge matching code to new HashStdin routine.
authorJason Self <j@jxself.org>
Mon, 14 Sep 2015 02:55:59 +0000 (19:55 -0700)
committerJason Self <j@jxself.org>
Mon, 14 Sep 2015 02:55:59 +0000 (19:55 -0700)
skein_cli.c

index bbe820c4082c4316bbf36f9084cc95c8fd5f4803..011f98f746b03a04f7aefe2dedf523dd2aad8430 100644 (file)
@@ -183,12 +183,26 @@ int HashBinaryMode(char file_name[], char MsgDigest[])
        return HashWithMode(file_name, MsgDigest, 'b');
 }
 
-int HashStringMode(char Msg[],char MsgDigest[])
+void HashStringMode(char Msg[],char MsgDigest[])
 {
        unsigned char output[hashbitlen/4];
        Hash(hashbitlen,(unsigned char*) Msg,sizeof(Msg),output);
        printHexMsg(output,hashbitlen/4,MsgDigest);
-       return 1;
+}
+
+void HashStdin(char MsgDigest[], int tag)
+{
+       char stri[100];
+       char longstring[1000];
+       longstring[0] = 0;
+       while(fgets(stri,100,stdin))
+               strcat(longstring, stri);
+       HashStringMode(longstring, MsgDigest);
+       if (tag) {
+               printf("skein%d_v%s (-) = %s\n", hashbitlen, skeinVersion, MsgDigest);
+       } else {
+               printf("%s *-\n", MsgDigest);
+       }
 }
 
 int isProper(char MsgDigest[])
@@ -440,23 +454,8 @@ int main(int argc, char** argv)
                        }
                }
                else if(errorFound != 1)
-               { // read stdin for strings
-                       char stri[100];
-                       char longstring[1000];
-                       longstring[0] = 0;
-                       while((fgets(stri,100,stdin))!=NULL)
-                       {
-                               strcat(longstring,stri);
-                       }
-                       HashStringMode(longstring,MsgDigest);
-                       if(tag == 1)
-                       {
-                               printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest);
-                       }
-                       else
-                       {
-                               printf("%s *-\n",MsgDigest);
-                       }
+               {
+                       HashStdin(MsgDigest, tag);
                }
        }
 
@@ -489,23 +488,8 @@ int main(int argc, char** argv)
                        }
                }
                else if(errorFound != 1)
-               { // read stdin for strings
-                       char stri[100];
-                       char longstring[1000];
-                       longstring[0] = 0;
-                       while((fgets(stri,100,stdin))!=NULL)
-                       {
-                               strcat(longstring,stri);
-                       }
-                       HashStringMode(longstring,MsgDigest);
-                       if(tag == 1)
-                       {
-                               printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest);
-                       }
-                       else
-                       {
-                               printf("%s -\n",MsgDigest);
-                       }
+               {
+                       HashStdin(MsgDigest, tag);
                }
        }
 
@@ -546,23 +530,8 @@ int main(int argc, char** argv)
                                }
                        }
                        else if(errorFound != 1)
-                       { // hasing strings read from  stdin
-                               char stri[100];
-                               char longstring[1000];   /* TODO!!! Fix buffer overflow!!! */
-                               longstring[0] = 0;
-                               while((fgets(stri,100,stdin))!=NULL)
-                               {
-                                       strcat(longstring,stri);
-                               }
-                               HashStringMode(longstring,MsgDigest);
-                               if(tag == 1)
-                               {
-                                       printf("skein%d_v%s (-) = %s\n",hashbitlen,skeinVersion,MsgDigest);
-                               }
-                               else
-                               {
-                                       printf("%s -\n",MsgDigest);
-                               }
+                       {
+                               HashStdin(MsgDigest, tag);
                        }
                }
                else if(check == 1)
@@ -726,18 +695,8 @@ int main(int argc, char** argv)
                }
        }
 
-       if ((errorFound != 1) && (argc == 1 || (hashString == 1 && number_files == 0)))
-       {
-               char stri[100];
-               char longstring[1000];
-               longstring[0] = 0;
-               while((fgets(stri,100,stdin))!=NULL)
-               {
-                               strcat(longstring,stri);
-               }
-               HashStringMode(longstring,MsgDigest);
-               printf("%s -\n",MsgDigest);
-       }
+       if (!errorFound && (argc == 1 || (hashString == 1 && !number_files)))
+               HashStdin(MsgDigest, 0);
 
        return 1;
 }