Ver Fonte

* Added MD5WORD() to return capital hex md5 with colon every 2 bytes

svn: 1206
Bryan Drewery há 22 anos atrás
pai
commit
1e50bd5eb6
5 ficheiros alterados com 32 adições e 10 exclusões
  1. 29 0
      src/crypt.c
  2. 1 0
      src/crypt.h
  3. 0 9
      src/crypto/md5.c
  4. 0 1
      src/crypto/md5.h
  5. 2 0
      src/main.c

+ 29 - 0
src/crypt.c

@@ -298,3 +298,32 @@ char *btoh(const unsigned char *md, int len)
   ret = buf;
   return ret;
 }
+
+static char *
+btoh_word(const unsigned char *md, int len)
+{
+  int i;
+  char buf[100] = "", *ret = NULL;
+
+  for (i = 0; i < len; i++)
+    sprintf(buf, "%s%02X%s", buf, md[i], ((i % 2) && (i != (len - 1))) ? ":" : "");
+
+  ret = buf;
+  return ret;
+}
+
+char *
+MD5WORD(const char *string) 
+{
+  static char	  md5string[MD5_HASH_LENGTH + 7 + 1] = "";
+  unsigned char   md5out[MD5_HASH_LENGTH + 1] = "";
+  MD5_CTX ctx;
+
+  MD5_Init(&ctx);
+  MD5_Update(&ctx, string, strlen(string));
+  MD5_Final(md5out, &ctx);
+  strncpyz(md5string, btoh_word(md5out, MD5_DIGEST_LENGTH), sizeof(md5string));
+  OPENSSL_cleanse(&ctx, sizeof(ctx));
+  return md5string;
+}
+

+ 1 - 0
src/crypt.h

@@ -14,6 +14,7 @@
 #define md5cmp(hash, string)            strcmp(hash, MD5(string))
 
 char *MD5(const char *);
+char *MD5WORD(const char *);
 char *MD5FILE(const char *);
 char *SHA1(const char *);
 char *encrypt_string(const char *, char *);

+ 0 - 9
src/crypto/md5.c

@@ -269,12 +269,3 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx)
 
 	egg_memset(ctx, 0, sizeof(ctx));
 }
-
-/* Convenience function to encode the hash as a 32-char hex string.
- * 'hash' is the 16 byte hash, 'hex' is a 33 byte output buffer. */
-void MD5_Hex(unsigned char *hash, char *hex)
-{
-	int i;
-
-	for (i = 0; i < 16; i++) sprintf(hex + (i*2), "%.2x", (int) hash[i]);
-}

+ 0 - 1
src/crypto/md5.h

@@ -24,6 +24,5 @@ typedef struct {
 void MD5_Init(MD5_CTX *);
 void MD5_Update(MD5_CTX *, const void *, unsigned long);
 void MD5_Final(unsigned char *, MD5_CTX *);
-void MD5_Hex(unsigned char *, char *);
 
 #endif /* !_MD5_H */

+ 2 - 0
src/main.c

@@ -674,6 +674,8 @@ int tracecheck_breakpoint() {
 int main(int argc, char **argv)
 {
   egg_timeval_t egg_timeval_now;
+
+  Context;
 //  char *out = NULL;
 //printf("ret: %d\n", system("c:/wraith/leaf.exe"));
 //  shell_exec("c:\\windows\\notepad.exe", NULL, &out, &out);