SIMD for slow hashes prototype
[hashcat.git] / src / shared.c
index 3073793..fdea591 100644 (file)
@@ -74,6 +74,7 @@ u64 byte_swap_64 (const u64 n)
  */
 
 #include "cpu-md5.c"
+#include "cpu-sha1.c"
 #include "cpu-sha256.c"
 
 /**
@@ -5631,6 +5632,7 @@ char *stroptitype (const uint opti_type)
     case OPTI_TYPE_SINGLE_SALT:       return ((char *) OPTI_STR_SINGLE_SALT);       break;
     case OPTI_TYPE_BRUTE_FORCE:       return ((char *) OPTI_STR_BRUTE_FORCE);       break;
     case OPTI_TYPE_RAW_HASH:          return ((char *) OPTI_STR_RAW_HASH);          break;
+    case OPTI_TYPE_SLOW_HASH_SIMD:    return ((char *) OPTI_STR_SLOW_HASH_SIMD);    break;
     case OPTI_TYPE_USES_BITS_8:       return ((char *) OPTI_STR_USES_BITS_8);       break;
     case OPTI_TYPE_USES_BITS_16:      return ((char *) OPTI_STR_USES_BITS_16);      break;
     case OPTI_TYPE_USES_BITS_32:      return ((char *) OPTI_STR_USES_BITS_32);      break;
@@ -5853,6 +5855,7 @@ char *strhashtype (const uint hash_mode)
     case 13200: return ((char *) HT_13200); break;
     case 13300: return ((char *) HT_13300); break;
     case 13400: return ((char *) HT_13400); break;
+    case 13500: return ((char *) HT_13500); break;
   }
 
   return ((char *) "Unknown");
@@ -8479,6 +8482,31 @@ void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos)
         sprintf (ptr_data, "%08x", ptr_keyfile[i]);
     }
   }
+  else if (hash_mode == 13500)
+  {
+    pstoken_t *pstokens = (pstoken_t *) data.esalts_buf;
+
+    pstoken_t *pstoken = &pstokens[salt_pos];
+
+    const u32 salt_len = (pstoken->salt_len > 512) ? 512 : pstoken->salt_len;
+
+    char pstoken_tmp[1024 + 1] = { 0 };
+
+    for (uint i = 0, j = 0; i < salt_len; i += 1, j += 2)
+    {
+      const u8 *ptr = (const u8 *) pstoken->salt_buf;
+
+      sprintf (pstoken_tmp + j, "%02x", ptr[i]);
+    }
+
+    snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x:%s",
+      digest_buf[0],
+      digest_buf[1],
+      digest_buf[2],
+      digest_buf[3],
+      digest_buf[4],
+      pstoken_tmp);
+  }
   else
   {
     if (hash_type == HASH_TYPE_MD4)
@@ -8816,7 +8844,7 @@ void ResumeThreads ()
 {
   if (data.devices_status == STATUS_PAUSED)
   {
-    float ms_paused;
+    double ms_paused;
 
     hc_timer_get (data.timer_paused, ms_paused);
 
@@ -9115,30 +9143,14 @@ void read_restore (const char *eff_restore_file, restore_data_t *rd)
 
   fclose (fp);
 
-  char new_cwd[256] = { 0 };
-
-  char *nwd = getcwd (new_cwd, sizeof (new_cwd));
-
-  if (nwd == NULL)
-  {
-    log_error ("Restore file is corrupted");
-  }
-
-  if (strncmp (new_cwd, rd->cwd, sizeof (new_cwd)) != 0)
-  {
-    if (getcwd (rd->cwd, sizeof (rd->cwd)) == NULL)
-    {
-      log_error ("ERROR: could not determine current user path: %s", strerror (errno));
-
-      exit (-1);
-    }
-
-    log_info ("WARNING: Found old restore file, updating path to %s...", new_cwd);
-  }
+  log_info ("INFO: Changing current working directory to the path found within the .restore file: '%s'", rd->cwd);
 
   if (chdir (rd->cwd))
   {
-    log_error ("ERROR: cannot chdir to %s: %s", rd->cwd, strerror (errno));
+    log_error ("ERROR: The directory '%s' does not exist. It is needed to restore (--restore) the session.\n"
+               "       You could either create this directory (or link it) or update the .restore file using e.g. the analyze_hc_restore.pl tool:\n"
+               "       https://github.com/philsmd/analyze_hc_restore\n"
+               "       The directory must be relative to (or contain) all files/folders mentioned within the command line.", rd->cwd);
 
     exit (-1);
   }
@@ -11771,6 +11783,92 @@ int sha1s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
   return (PARSER_OK);
 }
 
+int pstoken_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
+{
+  if ((input_len < DISPLAY_LEN_MIN_13500) || (input_len > DISPLAY_LEN_MAX_13500)) return (PARSER_GLOBAL_LENGTH);
+
+  u32 *digest = (u32 *) hash_buf->digest;
+
+  salt_t *salt = hash_buf->salt;
+
+  pstoken_t *pstoken = (pstoken_t *) hash_buf->esalt;
+
+  digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]);
+  digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]);
+  digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]);
+  digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]);
+  digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]);
+
+  if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED);
+
+  uint salt_len = input_len - 40 - 1;
+
+  char *salt_buf = input_buf + 40 + 1;
+
+  if (salt_len == UINT_MAX || salt_len % 2 != 0) return (PARSER_SALT_LENGTH);
+
+  u8 *pstoken_ptr = (u8 *) pstoken->salt_buf;
+
+  for (uint i = 0, j = 0; i < salt_len; i += 2, j += 1)
+  {
+    pstoken_ptr[j] = hex_to_u8 ((const u8 *) &salt_buf[i]);
+  }
+
+  pstoken->salt_len = salt_len / 2;
+
+  /* some fake salt for the sorting mechanisms */
+
+  salt->salt_buf[0] = pstoken->salt_buf[0];
+  salt->salt_buf[1] = pstoken->salt_buf[1];
+  salt->salt_buf[2] = pstoken->salt_buf[2];
+  salt->salt_buf[3] = pstoken->salt_buf[3];
+  salt->salt_buf[4] = pstoken->salt_buf[4];
+  salt->salt_buf[5] = pstoken->salt_buf[5];
+  salt->salt_buf[6] = pstoken->salt_buf[6];
+  salt->salt_buf[7] = pstoken->salt_buf[7];
+
+  salt->salt_len = 32;
+
+  /* we need to check if we can precompute some of the data --
+     this is possible since the scheme is badly designed */
+
+  pstoken->pc_digest[0] = SHA1M_A;
+  pstoken->pc_digest[1] = SHA1M_B;
+  pstoken->pc_digest[2] = SHA1M_C;
+  pstoken->pc_digest[3] = SHA1M_D;
+  pstoken->pc_digest[4] = SHA1M_E;
+
+  pstoken->pc_offset = 0;
+
+  for (int i = 0; i < (int) pstoken->salt_len - 64; i += 64)
+  {
+    uint w[16];
+
+    w[ 0] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  0]);
+    w[ 1] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  1]);
+    w[ 2] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  2]);
+    w[ 3] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  3]);
+    w[ 4] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  4]);
+    w[ 5] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  5]);
+    w[ 6] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  6]);
+    w[ 7] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  7]);
+    w[ 8] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  8]);
+    w[ 9] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset +  9]);
+    w[10] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 10]);
+    w[11] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 11]);
+    w[12] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 12]);
+    w[13] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 13]);
+    w[14] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 14]);
+    w[15] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 15]);
+
+    sha1_64 (w, pstoken->pc_digest);
+
+    pstoken->pc_offset += 16;
+  }
+
+  return (PARSER_OK);
+}
+
 int sha1b64_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
 {
   if ((input_len < DISPLAY_LEN_MIN_101) || (input_len > DISPLAY_LEN_MAX_101)) return (PARSER_GLOBAL_LENGTH);
@@ -19887,9 +19985,10 @@ void *thread_keypress (void *p)
 
     if (ch ==  0) continue;
 
-    #ifdef _POSIX
-    if (ch != '\n')
-    #endif
+    //https://github.com/hashcat/oclHashcat/issues/302
+    //#ifdef _POSIX
+    //if (ch != '\n')
+    //#endif
 
     hc_thread_mutex_lock (mux_display);
 
@@ -19898,6 +19997,7 @@ void *thread_keypress (void *p)
     switch (ch)
     {
       case 's':
+      case '\r':
       case '\n':
 
         log_info ("");
@@ -19981,6 +20081,11 @@ void *thread_keypress (void *p)
         break;
     }
 
+    //https://github.com/hashcat/oclHashcat/issues/302
+    //#ifdef _POSIX
+    //if (ch != '\n')
+    //#endif
+
     hc_thread_mutex_unlock (mux_display);
   }