rugged 0.26.0b3 → 0.26.0b4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/ext/rugged/extconf.rb +10 -7
  4. data/ext/rugged/rugged.c +4 -6
  5. data/ext/rugged/rugged_repo.c +1 -1
  6. data/ext/rugged/rugged_revwalk.c +4 -4
  7. data/ext/rugged/rugged_tree.c +2 -2
  8. data/lib/rugged/version.rb +1 -1
  9. data/vendor/libgit2/CMakeLists.txt +13 -6
  10. data/vendor/libgit2/COPYING +33 -0
  11. data/vendor/libgit2/include/git2/branch.h +12 -0
  12. data/vendor/libgit2/include/git2/commit.h +6 -3
  13. data/vendor/libgit2/include/git2/common.h +11 -0
  14. data/vendor/libgit2/include/git2/errors.h +2 -0
  15. data/vendor/libgit2/include/git2/index.h +7 -6
  16. data/vendor/libgit2/include/git2/repository.h +91 -0
  17. data/vendor/libgit2/include/git2/stash.h +2 -2
  18. data/vendor/libgit2/include/git2/types.h +3 -0
  19. data/vendor/libgit2/include/git2/worktree.h +161 -0
  20. data/vendor/libgit2/src/attr.c +24 -16
  21. data/vendor/libgit2/src/attr_file.h +1 -1
  22. data/vendor/libgit2/src/attrcache.c +11 -10
  23. data/vendor/libgit2/src/attrcache.h +1 -4
  24. data/vendor/libgit2/src/blob.c +2 -2
  25. data/vendor/libgit2/src/branch.c +63 -0
  26. data/vendor/libgit2/src/buffer.h +2 -1
  27. data/vendor/libgit2/src/cache.c +21 -25
  28. data/vendor/libgit2/src/cache.h +1 -1
  29. data/vendor/libgit2/src/checkout.c +0 -2
  30. data/vendor/libgit2/src/cherrypick.c +2 -2
  31. data/vendor/libgit2/src/clone.c +2 -3
  32. data/vendor/libgit2/src/commit.c +8 -4
  33. data/vendor/libgit2/src/config_file.c +1 -3
  34. data/vendor/libgit2/src/describe.c +1 -3
  35. data/vendor/libgit2/src/diff_driver.c +2 -4
  36. data/vendor/libgit2/src/fetchhead.c +2 -2
  37. data/vendor/libgit2/src/fileops.c +1 -3
  38. data/vendor/libgit2/src/hash.h +5 -3
  39. data/vendor/libgit2/src/hash/hash_collisiondetect.h +57 -0
  40. data/vendor/libgit2/src/hash/sha1dc/sha1.c +1149 -0
  41. data/vendor/libgit2/src/hash/sha1dc/sha1.h +94 -0
  42. data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +361 -0
  43. data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +35 -0
  44. data/vendor/libgit2/src/idxmap.c +133 -0
  45. data/vendor/libgit2/src/idxmap.h +22 -60
  46. data/vendor/libgit2/src/ignore.c +7 -1
  47. data/vendor/libgit2/src/ignore.h +1 -1
  48. data/vendor/libgit2/src/index.c +11 -14
  49. data/vendor/libgit2/src/indexer.c +8 -11
  50. data/vendor/libgit2/src/merge.c +5 -5
  51. data/vendor/libgit2/src/mwindow.c +1 -3
  52. data/vendor/libgit2/src/odb.c +3 -3
  53. data/vendor/libgit2/src/odb.h +3 -0
  54. data/vendor/libgit2/src/odb_mempack.c +11 -18
  55. data/vendor/libgit2/src/offmap.c +83 -0
  56. data/vendor/libgit2/src/offmap.h +14 -34
  57. data/vendor/libgit2/src/oidmap.c +105 -0
  58. data/vendor/libgit2/src/oidmap.h +19 -22
  59. data/vendor/libgit2/src/pack-objects.c +10 -13
  60. data/vendor/libgit2/src/pack.c +17 -26
  61. data/vendor/libgit2/src/path.c +45 -24
  62. data/vendor/libgit2/src/rebase.c +3 -3
  63. data/vendor/libgit2/src/refdb_fs.c +81 -46
  64. data/vendor/libgit2/src/refs.c +13 -3
  65. data/vendor/libgit2/src/remote.c +6 -2
  66. data/vendor/libgit2/src/repository.c +318 -46
  67. data/vendor/libgit2/src/repository.h +5 -2
  68. data/vendor/libgit2/src/revert.c +2 -2
  69. data/vendor/libgit2/src/revwalk.c +6 -8
  70. data/vendor/libgit2/src/settings.c +5 -0
  71. data/vendor/libgit2/src/sortedcache.c +3 -5
  72. data/vendor/libgit2/src/strmap.c +95 -0
  73. data/vendor/libgit2/src/strmap.h +17 -37
  74. data/vendor/libgit2/src/submodule.c +12 -8
  75. data/vendor/libgit2/src/thread-utils.h +6 -0
  76. data/vendor/libgit2/src/transaction.c +5 -17
  77. data/vendor/libgit2/src/transports/local.c +2 -1
  78. data/vendor/libgit2/src/transports/smart.h +2 -0
  79. data/vendor/libgit2/src/transports/smart_protocol.c +3 -1
  80. data/vendor/libgit2/src/tree.c +2 -4
  81. data/vendor/libgit2/src/unix/posix.h +1 -1
  82. data/vendor/libgit2/src/worktree.c +432 -0
  83. data/vendor/libgit2/src/worktree.h +35 -0
  84. metadata +13 -2
@@ -66,7 +66,8 @@ extern int git_buf_try_grow(
66
66
  * library, when providing git_buf's, may wish to provide a NULL ptr for
67
67
  * ease of handling. The buffer routines, however, expect a non-NULL ptr
68
68
  * always. This helper method simply handles NULL input, converting to a
69
- * git_buf__initbuf.
69
+ * git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
70
+ * assures that the buffer is '\0'-terminated.
70
71
  */
71
72
  extern void git_buf_sanitize(git_buf *buf);
72
73
 
@@ -15,8 +15,6 @@
15
15
  #include "object.h"
16
16
  #include "git2/oid.h"
17
17
 
18
- GIT__USE_OIDMAP
19
-
20
18
  bool git_cache__enabled = true;
21
19
  ssize_t git_cache__max_storage = (256 * 1024 * 1024);
22
20
  git_atomic_ssize git_cache__current_storage = {0};
@@ -47,13 +45,13 @@ void git_cache_dump_stats(git_cache *cache)
47
45
  {
48
46
  git_cached_obj *object;
49
47
 
50
- if (kh_size(cache->map) == 0)
48
+ if (git_cache_size(cache) == 0)
51
49
  return;
52
50
 
53
- printf("Cache %p: %d items cached, %"PRIdZ" bytes\n",
54
- cache, kh_size(cache->map), cache->used_memory);
51
+ printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n",
52
+ cache, git_cache_size(cache), cache->used_memory);
55
53
 
56
- kh_foreach_value(cache->map, object, {
54
+ git_oidmap_foreach_value(cache->map, object, {
57
55
  char oid_str[9];
58
56
  printf(" %s%c %s (%"PRIuZ")\n",
59
57
  git_object_type2string(object->type),
@@ -81,14 +79,14 @@ static void clear_cache(git_cache *cache)
81
79
  {
82
80
  git_cached_obj *evict = NULL;
83
81
 
84
- if (kh_size(cache->map) == 0)
82
+ if (git_cache_size(cache) == 0)
85
83
  return;
86
84
 
87
- kh_foreach_value(cache->map, evict, {
85
+ git_oidmap_foreach_value(cache->map, evict, {
88
86
  git_cached_obj_decref(evict);
89
87
  });
90
88
 
91
- kh_clear(oid, cache->map);
89
+ git_oidmap_clear(cache->map);
92
90
  git_atomic_ssize_add(&git_cache__current_storage, -cache->used_memory);
93
91
  cache->used_memory = 0;
94
92
  }
@@ -119,22 +117,22 @@ static void cache_evict_entries(git_cache *cache)
119
117
  ssize_t evicted_memory = 0;
120
118
 
121
119
  /* do not infinite loop if there's not enough entries to evict */
122
- if (evict_count > kh_size(cache->map)) {
120
+ if (evict_count > git_cache_size(cache)) {
123
121
  clear_cache(cache);
124
122
  return;
125
123
  }
126
124
 
127
125
  while (evict_count > 0) {
128
- khiter_t pos = seed++ % kh_end(cache->map);
126
+ khiter_t pos = seed++ % git_oidmap_end(cache->map);
129
127
 
130
- if (kh_exist(cache->map, pos)) {
131
- git_cached_obj *evict = kh_val(cache->map, pos);
128
+ if (git_oidmap_has_data(cache->map, pos)) {
129
+ git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
132
130
 
133
131
  evict_count--;
134
132
  evicted_memory += evict->size;
135
133
  git_cached_obj_decref(evict);
136
134
 
137
- kh_del(oid, cache->map, pos);
135
+ git_oidmap_delete_at(cache->map, pos);
138
136
  }
139
137
  }
140
138
 
@@ -156,9 +154,9 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
156
154
  if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0)
157
155
  return NULL;
158
156
 
159
- pos = kh_get(oid, cache->map, oid);
160
- if (pos != kh_end(cache->map)) {
161
- entry = kh_val(cache->map, pos);
157
+ pos = git_oidmap_lookup_index(cache->map, oid);
158
+ if (git_oidmap_valid_index(cache->map, pos)) {
159
+ entry = git_oidmap_value_at(cache->map, pos);
162
160
 
163
161
  if (flags && entry->flags != flags) {
164
162
  entry = NULL;
@@ -193,16 +191,14 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
193
191
  if (git_cache__current_storage.val > git_cache__max_storage)
194
192
  cache_evict_entries(cache);
195
193
 
196
- pos = kh_get(oid, cache->map, &entry->oid);
194
+ pos = git_oidmap_lookup_index(cache->map, &entry->oid);
197
195
 
198
196
  /* not found */
199
- if (pos == kh_end(cache->map)) {
197
+ if (!git_oidmap_valid_index(cache->map, pos)) {
200
198
  int rval;
201
199
 
202
- pos = kh_put(oid, cache->map, &entry->oid, &rval);
200
+ git_oidmap_insert(cache->map, &entry->oid, entry, &rval);
203
201
  if (rval >= 0) {
204
- kh_key(cache->map, pos) = &entry->oid;
205
- kh_val(cache->map, pos) = entry;
206
202
  git_cached_obj_incref(entry);
207
203
  cache->used_memory += entry->size;
208
204
  git_atomic_ssize_add(&git_cache__current_storage, (ssize_t)entry->size);
@@ -210,7 +206,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
210
206
  }
211
207
  /* found */
212
208
  else {
213
- git_cached_obj *stored_entry = kh_val(cache->map, pos);
209
+ git_cached_obj *stored_entry = git_oidmap_value_at(cache->map, pos);
214
210
 
215
211
  if (stored_entry->flags == entry->flags) {
216
212
  git_cached_obj_decref(entry);
@@ -221,8 +217,8 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
221
217
  git_cached_obj_decref(stored_entry);
222
218
  git_cached_obj_incref(entry);
223
219
 
224
- kh_key(cache->map, pos) = &entry->oid;
225
- kh_val(cache->map, pos) = entry;
220
+ git_oidmap_set_key_at(cache->map, pos, &entry->oid);
221
+ git_oidmap_set_value_at(cache->map, pos, entry);
226
222
  } else {
227
223
  /* NO OP */
228
224
  }
@@ -53,7 +53,7 @@ void *git_cache_get_any(git_cache *cache, const git_oid *oid);
53
53
 
54
54
  GIT_INLINE(size_t) git_cache_size(git_cache *cache)
55
55
  {
56
- return (size_t)kh_size(cache->map);
56
+ return (size_t)git_oidmap_size(cache->map);
57
57
  }
58
58
 
59
59
  GIT_INLINE(void) git_cached_obj_incref(void *_obj)
@@ -35,8 +35,6 @@
35
35
  #include "pool.h"
36
36
  #include "strmap.h"
37
37
 
38
- GIT__USE_STRMAP
39
-
40
38
  /* See docs/checkout-internals.md for more information */
41
39
 
42
40
  enum {
@@ -28,7 +28,7 @@ static int write_cherrypick_head(
28
28
  git_buf file_path = GIT_BUF_INIT;
29
29
  int error = 0;
30
30
 
31
- if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
31
+ if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
32
32
  (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
33
33
  (error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
34
34
  error = git_filebuf_commit(&file);
@@ -49,7 +49,7 @@ static int write_merge_msg(
49
49
  git_buf file_path = GIT_BUF_INIT;
50
50
  int error = 0;
51
51
 
52
- if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
52
+ if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
53
53
  (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
54
54
  (error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
55
55
  goto cleanup;
@@ -513,9 +513,8 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_
513
513
  return error;
514
514
  }
515
515
 
516
- git_buf_joinpath(&src_odb, git_repository_path(src), GIT_OBJECTS_DIR);
517
- git_buf_joinpath(&dst_odb, git_repository_path(repo), GIT_OBJECTS_DIR);
518
- if (git_buf_oom(&src_odb) || git_buf_oom(&dst_odb)) {
516
+ if (git_repository_item_path(&src_odb, src, GIT_REPOSITORY_ITEM_OBJECTS) < 0
517
+ || git_repository_item_path(&dst_odb, repo, GIT_REPOSITORY_ITEM_OBJECTS) < 0) {
519
518
  error = -1;
520
519
  goto cleanup;
521
520
  }
@@ -159,6 +159,9 @@ static int git_commit__create_internal(
159
159
  if (git_repository_odb__weakptr(&odb, repo) < 0)
160
160
  goto cleanup;
161
161
 
162
+ if (git_odb__freshen(odb, tree) < 0)
163
+ goto cleanup;
164
+
162
165
  if (git_odb_write(id, odb, buf.ptr, buf.size, GIT_OBJ_COMMIT) < 0)
163
166
  goto cleanup;
164
167
 
@@ -642,7 +645,7 @@ int git_commit_header_field(git_buf *out, const git_commit *commit, const char *
642
645
  {
643
646
  const char *eol, *buf = commit->raw_header;
644
647
 
645
- git_buf_sanitize(out);
648
+ git_buf_clear(out);
646
649
 
647
650
  while ((eol = strchr(buf, '\n'))) {
648
651
  /* We can skip continuations here */
@@ -706,8 +709,8 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
706
709
  const char *h, *eol;
707
710
  int error;
708
711
 
709
- git_buf_sanitize(signature);
710
- git_buf_sanitize(signed_data);
712
+ git_buf_clear(signature);
713
+ git_buf_clear(signed_data);
711
714
 
712
715
  if (!field)
713
716
  field = "gpgsig";
@@ -766,8 +769,9 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
766
769
  if (git_buf_oom(signature))
767
770
  goto oom;
768
771
 
772
+ error = git_buf_puts(signed_data, eol+1);
769
773
  git_odb_object_free(obj);
770
- return git_buf_puts(signed_data, eol+1);
774
+ return error;
771
775
  }
772
776
 
773
777
  giterr_set(GITERR_OBJECT, "this commit is not signed");
@@ -21,8 +21,6 @@
21
21
  #include <sys/types.h>
22
22
  #include <regex.h>
23
23
 
24
- GIT__USE_STRMAP
25
-
26
24
  typedef struct cvar_t {
27
25
  struct cvar_t *next;
28
26
  git_config_entry *entry;
@@ -179,7 +177,7 @@ static int append_entry(git_strmap *values, cvar_t *var)
179
177
 
180
178
  pos = git_strmap_lookup_index(values, var->entry->name);
181
179
  if (!git_strmap_valid_index(values, pos)) {
182
- git_strmap_insert(values, var->entry->name, var, error);
180
+ git_strmap_insert(values, var->entry->name, var, &error);
183
181
  } else {
184
182
  existing = git_strmap_value_at(values, pos);
185
183
  while (existing->next != NULL) {
@@ -19,8 +19,6 @@
19
19
  #include "vector.h"
20
20
  #include "repository.h"
21
21
 
22
- GIT__USE_OIDMAP
23
-
24
22
  /* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */
25
23
 
26
24
  struct commit_name {
@@ -127,7 +125,7 @@ static int add_to_known_names(
127
125
  if (!found) {
128
126
  int ret;
129
127
 
130
- git_oidmap_insert(names, &e->peeled, e, ret);
128
+ git_oidmap_insert(names, &e->peeled, e, &ret);
131
129
  if (ret < 0)
132
130
  return -1;
133
131
  }
@@ -16,8 +16,6 @@
16
16
  #include "config.h"
17
17
  #include "repository.h"
18
18
 
19
- GIT__USE_STRMAP
20
-
21
19
  typedef enum {
22
20
  DIFF_DRIVER_AUTO = 0,
23
21
  DIFF_DRIVER_BINARY = 1,
@@ -217,7 +215,7 @@ static int git_diff_driver_builtin(
217
215
  goto done;
218
216
  }
219
217
 
220
- git_strmap_insert(reg->drivers, drv->name, drv, error);
218
+ git_strmap_insert(reg->drivers, drv->name, drv, &error);
221
219
  if (error > 0)
222
220
  error = 0;
223
221
 
@@ -331,7 +329,7 @@ static int git_diff_driver_load(
331
329
  goto done;
332
330
 
333
331
  /* store driver in registry */
334
- git_strmap_insert(reg->drivers, drv->name, drv, error);
332
+ git_strmap_insert(reg->drivers, drv->name, drv, &error);
335
333
  if (error < 0)
336
334
  goto done;
337
335
  error = 0;
@@ -115,7 +115,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
115
115
 
116
116
  assert(repo && fetchhead_refs);
117
117
 
118
- if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
118
+ if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
119
119
  return -1;
120
120
 
121
121
  if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) {
@@ -249,7 +249,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
249
249
 
250
250
  assert(repo && cb);
251
251
 
252
- if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
252
+ if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
253
253
  return -1;
254
254
 
255
255
  if ((error = git_futils_readbuffer(&file, git_buf_cstr(&path))) < 0)
@@ -13,8 +13,6 @@
13
13
  #include "win32/findfile.h"
14
14
  #endif
15
15
 
16
- GIT__USE_STRMAP
17
-
18
16
  int git_futils_mkpath2file(const char *file_path, const mode_t mode)
19
17
  {
20
18
  return git_futils_mkdir(
@@ -607,7 +605,7 @@ retry_lstat:
607
605
 
608
606
  memcpy(cache_path, make_path.ptr, make_path.size + 1);
609
607
 
610
- git_strmap_insert(opts->dir_map, cache_path, cache_path, error);
608
+ git_strmap_insert(opts->dir_map, cache_path, cache_path, &error);
611
609
  if (error < 0)
612
610
  goto done;
613
611
  }
@@ -16,11 +16,13 @@ int git_hash_global_init(void);
16
16
  int git_hash_ctx_init(git_hash_ctx *ctx);
17
17
  void git_hash_ctx_cleanup(git_hash_ctx *ctx);
18
18
 
19
- #if defined(GIT_COMMON_CRYPTO)
19
+ #if defined(GIT_SHA1_COLLISIONDETECT)
20
+ # include "hash/hash_collisiondetect.h"
21
+ #elif defined(GIT_SHA1_COMMON_CRYPTO)
20
22
  # include "hash/hash_common_crypto.h"
21
- #elif defined(OPENSSL_SHA1)
23
+ #elif defined(GIT_SHA1_OPENSSL)
22
24
  # include "hash/hash_openssl.h"
23
- #elif defined(WIN32_SHA1)
25
+ #elif defined(GIT_SHA1_WIN32)
24
26
  # include "hash/hash_win32.h"
25
27
  #else
26
28
  # include "hash/hash_generic.h"
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_hash_collisiondetect_h__
9
+ #define INCLUDE_hash_collisiondetect_h__
10
+
11
+ #include "hash.h"
12
+ #include "sha1dc/sha1.h"
13
+
14
+ struct git_hash_ctx {
15
+ SHA1_CTX c;
16
+ };
17
+
18
+ #define git_hash_global_init() 0
19
+ #define git_hash_ctx_init(ctx) git_hash_init(ctx)
20
+ #define git_hash_ctx_cleanup(ctx)
21
+
22
+ GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
23
+ {
24
+ assert(ctx);
25
+ SHA1DCInit(&ctx->c);
26
+ return 0;
27
+ }
28
+
29
+ GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
30
+ {
31
+ const char *p = data;
32
+
33
+ assert(ctx);
34
+
35
+ /* We expect a size_t, but sha1dc only takes an int */
36
+ while (len > INT_MAX) {
37
+ SHA1DCUpdate(&ctx->c, p, INT_MAX);
38
+ p += INT_MAX;
39
+ len -= INT_MAX;
40
+ }
41
+
42
+ SHA1DCUpdate(&ctx->c, p, len);
43
+ return 0;
44
+ }
45
+
46
+ GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
47
+ {
48
+ assert(ctx);
49
+ if (SHA1DCFinal(out->id, &ctx->c)) {
50
+ giterr_set(GITERR_SHA1, "SHA1 collision attack detected");
51
+ return -1;
52
+ }
53
+
54
+ return 0;
55
+ }
56
+
57
+ #endif /* INCLUDE_hash_collisiondetect_h__ */
@@ -0,0 +1,1149 @@
1
+ /***
2
+ * Copyright 2017 Marc Stevens <marc@marc-stevens.nl>, Dan Shumow (danshu@microsoft.com)
3
+ * Distributed under the MIT Software License.
4
+ * See accompanying file LICENSE.txt or copy at
5
+ * https://opensource.org/licenses/MIT
6
+ ***/
7
+
8
+ #include <string.h>
9
+ #include <memory.h>
10
+ #include <stdio.h>
11
+
12
+ #include "sha1.h"
13
+ #include "ubc_check.h"
14
+
15
+ #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))
16
+ #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n))))
17
+
18
+ #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d))))
19
+ #define sha1_f2(b,c,d) ((b)^(c)^(d))
20
+ #define sha1_f3(b,c,d) (((b) & ((c)|(d))) | ((c)&(d)))
21
+ #define sha1_f4(b,c,d) ((b)^(c)^(d))
22
+
23
+ #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \
24
+ { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); }
25
+ #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \
26
+ { e += rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; b = rotate_left(b, 30); }
27
+ #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \
28
+ { e += rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; b = rotate_left(b, 30); }
29
+ #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \
30
+ { e += rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; b = rotate_left(b, 30); }
31
+
32
+ #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \
33
+ { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; }
34
+ #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \
35
+ { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; }
36
+ #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \
37
+ { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; }
38
+ #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \
39
+ { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; }
40
+
41
+ #define SHA1_STORE_STATE(i) states[i][0] = a; states[i][1] = b; states[i][2] = c; states[i][3] = d; states[i][4] = e;
42
+
43
+
44
+
45
+ void sha1_message_expansion(uint32_t W[80])
46
+ {
47
+ unsigned i;
48
+
49
+ for (i = 16; i < 80; ++i)
50
+ W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
51
+ }
52
+
53
+ void sha1_compression(uint32_t ihv[5], const uint32_t m[16])
54
+ {
55
+ uint32_t a, b, c, d, e, W[80];
56
+ unsigned i;
57
+
58
+ memcpy(W, m, 16 * 4);
59
+ for (i = 16; i < 80; ++i)
60
+ W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
61
+
62
+ a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
63
+
64
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
65
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
66
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
67
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
68
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
69
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
70
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
71
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
72
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
73
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
74
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
75
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
76
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
77
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
78
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
79
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
80
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
81
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
82
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
83
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
84
+
85
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
86
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
87
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
88
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
89
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
90
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
91
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
92
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
93
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
94
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
95
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
96
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
97
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
98
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
99
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
100
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
101
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
102
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
103
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
104
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
105
+
106
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
107
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
108
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
109
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
110
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
111
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
112
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
113
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
114
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
115
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
116
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
117
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
118
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
119
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
120
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
121
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
122
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
123
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
124
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
125
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
126
+
127
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
128
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
129
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
130
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
131
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
132
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
133
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
134
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
135
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
136
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
137
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
138
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
139
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
140
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
141
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
142
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
143
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
144
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
145
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
146
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
147
+
148
+ ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
149
+ }
150
+
151
+
152
+
153
+ void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80])
154
+ {
155
+ uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
156
+
157
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
158
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
159
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
160
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
161
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
162
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
163
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
164
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
165
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
166
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
167
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
168
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
169
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
170
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
171
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
172
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
173
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
174
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
175
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
176
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
177
+
178
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
179
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
180
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
181
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
182
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
183
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
184
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
185
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
186
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
187
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
188
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
189
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
190
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
191
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
192
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
193
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
194
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
195
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
196
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
197
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
198
+
199
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
200
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
201
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
202
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
203
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
204
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
205
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
206
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
207
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
208
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
209
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
210
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
211
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
212
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
213
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
214
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
215
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
216
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
217
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
218
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
219
+
220
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
221
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
222
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
223
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
224
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
225
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
226
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
227
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
228
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
229
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
230
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
231
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
232
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
233
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
234
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
235
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
236
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
237
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
238
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
239
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
240
+
241
+ ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
242
+ }
243
+
244
+
245
+
246
+ void sha1_compression_states(uint32_t ihv[5], const uint32_t W[80], uint32_t states[80][5])
247
+ {
248
+ uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
249
+
250
+ #ifdef DOSTORESTATE00
251
+ SHA1_STORE_STATE(0)
252
+ #endif
253
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
254
+
255
+ #ifdef DOSTORESTATE01
256
+ SHA1_STORE_STATE(1)
257
+ #endif
258
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
259
+
260
+ #ifdef DOSTORESTATE02
261
+ SHA1_STORE_STATE(2)
262
+ #endif
263
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
264
+
265
+ #ifdef DOSTORESTATE03
266
+ SHA1_STORE_STATE(3)
267
+ #endif
268
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
269
+
270
+ #ifdef DOSTORESTATE04
271
+ SHA1_STORE_STATE(4)
272
+ #endif
273
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
274
+
275
+ #ifdef DOSTORESTATE05
276
+ SHA1_STORE_STATE(5)
277
+ #endif
278
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
279
+
280
+ #ifdef DOSTORESTATE06
281
+ SHA1_STORE_STATE(6)
282
+ #endif
283
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
284
+
285
+ #ifdef DOSTORESTATE07
286
+ SHA1_STORE_STATE(7)
287
+ #endif
288
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
289
+
290
+ #ifdef DOSTORESTATE08
291
+ SHA1_STORE_STATE(8)
292
+ #endif
293
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
294
+
295
+ #ifdef DOSTORESTATE09
296
+ SHA1_STORE_STATE(9)
297
+ #endif
298
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
299
+
300
+ #ifdef DOSTORESTATE10
301
+ SHA1_STORE_STATE(10)
302
+ #endif
303
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
304
+
305
+ #ifdef DOSTORESTATE11
306
+ SHA1_STORE_STATE(11)
307
+ #endif
308
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
309
+
310
+ #ifdef DOSTORESTATE12
311
+ SHA1_STORE_STATE(12)
312
+ #endif
313
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
314
+
315
+ #ifdef DOSTORESTATE13
316
+ SHA1_STORE_STATE(13)
317
+ #endif
318
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
319
+
320
+ #ifdef DOSTORESTATE14
321
+ SHA1_STORE_STATE(14)
322
+ #endif
323
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
324
+
325
+ #ifdef DOSTORESTATE15
326
+ SHA1_STORE_STATE(15)
327
+ #endif
328
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
329
+
330
+ #ifdef DOSTORESTATE16
331
+ SHA1_STORE_STATE(16)
332
+ #endif
333
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
334
+
335
+ #ifdef DOSTORESTATE17
336
+ SHA1_STORE_STATE(17)
337
+ #endif
338
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
339
+
340
+ #ifdef DOSTORESTATE18
341
+ SHA1_STORE_STATE(18)
342
+ #endif
343
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
344
+
345
+ #ifdef DOSTORESTATE19
346
+ SHA1_STORE_STATE(19)
347
+ #endif
348
+ HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
349
+
350
+
351
+
352
+ #ifdef DOSTORESTATE20
353
+ SHA1_STORE_STATE(20)
354
+ #endif
355
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
356
+
357
+ #ifdef DOSTORESTATE21
358
+ SHA1_STORE_STATE(21)
359
+ #endif
360
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
361
+
362
+ #ifdef DOSTORESTATE22
363
+ SHA1_STORE_STATE(22)
364
+ #endif
365
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
366
+
367
+ #ifdef DOSTORESTATE23
368
+ SHA1_STORE_STATE(23)
369
+ #endif
370
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
371
+
372
+ #ifdef DOSTORESTATE24
373
+ SHA1_STORE_STATE(24)
374
+ #endif
375
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
376
+
377
+ #ifdef DOSTORESTATE25
378
+ SHA1_STORE_STATE(25)
379
+ #endif
380
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
381
+
382
+ #ifdef DOSTORESTATE26
383
+ SHA1_STORE_STATE(26)
384
+ #endif
385
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
386
+
387
+ #ifdef DOSTORESTATE27
388
+ SHA1_STORE_STATE(27)
389
+ #endif
390
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
391
+
392
+ #ifdef DOSTORESTATE28
393
+ SHA1_STORE_STATE(28)
394
+ #endif
395
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
396
+
397
+ #ifdef DOSTORESTATE29
398
+ SHA1_STORE_STATE(29)
399
+ #endif
400
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
401
+
402
+ #ifdef DOSTORESTATE30
403
+ SHA1_STORE_STATE(30)
404
+ #endif
405
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
406
+
407
+ #ifdef DOSTORESTATE31
408
+ SHA1_STORE_STATE(31)
409
+ #endif
410
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
411
+
412
+ #ifdef DOSTORESTATE32
413
+ SHA1_STORE_STATE(32)
414
+ #endif
415
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
416
+
417
+ #ifdef DOSTORESTATE33
418
+ SHA1_STORE_STATE(33)
419
+ #endif
420
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
421
+
422
+ #ifdef DOSTORESTATE34
423
+ SHA1_STORE_STATE(34)
424
+ #endif
425
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
426
+
427
+ #ifdef DOSTORESTATE35
428
+ SHA1_STORE_STATE(35)
429
+ #endif
430
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
431
+
432
+ #ifdef DOSTORESTATE36
433
+ SHA1_STORE_STATE(36)
434
+ #endif
435
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
436
+
437
+ #ifdef DOSTORESTATE37
438
+ SHA1_STORE_STATE(37)
439
+ #endif
440
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
441
+
442
+ #ifdef DOSTORESTATE38
443
+ SHA1_STORE_STATE(38)
444
+ #endif
445
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
446
+
447
+ #ifdef DOSTORESTATE39
448
+ SHA1_STORE_STATE(39)
449
+ #endif
450
+ HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
451
+
452
+
453
+
454
+ #ifdef DOSTORESTATE40
455
+ SHA1_STORE_STATE(40)
456
+ #endif
457
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
458
+
459
+ #ifdef DOSTORESTATE41
460
+ SHA1_STORE_STATE(41)
461
+ #endif
462
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
463
+
464
+ #ifdef DOSTORESTATE42
465
+ SHA1_STORE_STATE(42)
466
+ #endif
467
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
468
+
469
+ #ifdef DOSTORESTATE43
470
+ SHA1_STORE_STATE(43)
471
+ #endif
472
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
473
+
474
+ #ifdef DOSTORESTATE44
475
+ SHA1_STORE_STATE(44)
476
+ #endif
477
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
478
+
479
+ #ifdef DOSTORESTATE45
480
+ SHA1_STORE_STATE(45)
481
+ #endif
482
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
483
+
484
+ #ifdef DOSTORESTATE46
485
+ SHA1_STORE_STATE(46)
486
+ #endif
487
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
488
+
489
+ #ifdef DOSTORESTATE47
490
+ SHA1_STORE_STATE(47)
491
+ #endif
492
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
493
+
494
+ #ifdef DOSTORESTATE48
495
+ SHA1_STORE_STATE(48)
496
+ #endif
497
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
498
+
499
+ #ifdef DOSTORESTATE49
500
+ SHA1_STORE_STATE(49)
501
+ #endif
502
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
503
+
504
+ #ifdef DOSTORESTATE50
505
+ SHA1_STORE_STATE(50)
506
+ #endif
507
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
508
+
509
+ #ifdef DOSTORESTATE51
510
+ SHA1_STORE_STATE(51)
511
+ #endif
512
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
513
+
514
+ #ifdef DOSTORESTATE52
515
+ SHA1_STORE_STATE(52)
516
+ #endif
517
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
518
+
519
+ #ifdef DOSTORESTATE53
520
+ SHA1_STORE_STATE(53)
521
+ #endif
522
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
523
+
524
+ #ifdef DOSTORESTATE54
525
+ SHA1_STORE_STATE(54)
526
+ #endif
527
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
528
+
529
+ #ifdef DOSTORESTATE55
530
+ SHA1_STORE_STATE(55)
531
+ #endif
532
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
533
+
534
+ #ifdef DOSTORESTATE56
535
+ SHA1_STORE_STATE(56)
536
+ #endif
537
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
538
+
539
+ #ifdef DOSTORESTATE57
540
+ SHA1_STORE_STATE(57)
541
+ #endif
542
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
543
+
544
+ #ifdef DOSTORESTATE58
545
+ SHA1_STORE_STATE(58)
546
+ #endif
547
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
548
+
549
+ #ifdef DOSTORESTATE59
550
+ SHA1_STORE_STATE(59)
551
+ #endif
552
+ HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
553
+
554
+
555
+
556
+
557
+ #ifdef DOSTORESTATE60
558
+ SHA1_STORE_STATE(60)
559
+ #endif
560
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
561
+
562
+ #ifdef DOSTORESTATE61
563
+ SHA1_STORE_STATE(61)
564
+ #endif
565
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
566
+
567
+ #ifdef DOSTORESTATE62
568
+ SHA1_STORE_STATE(62)
569
+ #endif
570
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
571
+
572
+ #ifdef DOSTORESTATE63
573
+ SHA1_STORE_STATE(63)
574
+ #endif
575
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
576
+
577
+ #ifdef DOSTORESTATE64
578
+ SHA1_STORE_STATE(64)
579
+ #endif
580
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
581
+
582
+ #ifdef DOSTORESTATE65
583
+ SHA1_STORE_STATE(65)
584
+ #endif
585
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
586
+
587
+ #ifdef DOSTORESTATE66
588
+ SHA1_STORE_STATE(66)
589
+ #endif
590
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
591
+
592
+ #ifdef DOSTORESTATE67
593
+ SHA1_STORE_STATE(67)
594
+ #endif
595
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
596
+
597
+ #ifdef DOSTORESTATE68
598
+ SHA1_STORE_STATE(68)
599
+ #endif
600
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
601
+
602
+ #ifdef DOSTORESTATE69
603
+ SHA1_STORE_STATE(69)
604
+ #endif
605
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
606
+
607
+ #ifdef DOSTORESTATE70
608
+ SHA1_STORE_STATE(70)
609
+ #endif
610
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
611
+
612
+ #ifdef DOSTORESTATE71
613
+ SHA1_STORE_STATE(71)
614
+ #endif
615
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
616
+
617
+ #ifdef DOSTORESTATE72
618
+ SHA1_STORE_STATE(72)
619
+ #endif
620
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
621
+
622
+ #ifdef DOSTORESTATE73
623
+ SHA1_STORE_STATE(73)
624
+ #endif
625
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
626
+
627
+ #ifdef DOSTORESTATE74
628
+ SHA1_STORE_STATE(74)
629
+ #endif
630
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
631
+
632
+ #ifdef DOSTORESTATE75
633
+ SHA1_STORE_STATE(75)
634
+ #endif
635
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
636
+
637
+ #ifdef DOSTORESTATE76
638
+ SHA1_STORE_STATE(76)
639
+ #endif
640
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
641
+
642
+ #ifdef DOSTORESTATE77
643
+ SHA1_STORE_STATE(77)
644
+ #endif
645
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
646
+
647
+ #ifdef DOSTORESTATE78
648
+ SHA1_STORE_STATE(78)
649
+ #endif
650
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
651
+
652
+ #ifdef DOSTORESTATE79
653
+ SHA1_STORE_STATE(79)
654
+ #endif
655
+ HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
656
+
657
+
658
+
659
+ ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
660
+ }
661
+
662
+
663
+
664
+
665
+ #define SHA1_RECOMPRESS(t) \
666
+ void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \
667
+ { \
668
+ uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \
669
+ if (t > 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \
670
+ if (t > 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \
671
+ if (t > 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \
672
+ if (t > 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \
673
+ if (t > 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \
674
+ if (t > 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \
675
+ if (t > 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \
676
+ if (t > 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \
677
+ if (t > 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \
678
+ if (t > 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \
679
+ if (t > 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \
680
+ if (t > 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \
681
+ if (t > 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \
682
+ if (t > 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \
683
+ if (t > 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \
684
+ if (t > 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \
685
+ if (t > 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \
686
+ if (t > 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \
687
+ if (t > 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \
688
+ if (t > 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \
689
+ if (t > 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \
690
+ if (t > 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \
691
+ if (t > 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \
692
+ if (t > 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \
693
+ if (t > 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \
694
+ if (t > 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \
695
+ if (t > 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \
696
+ if (t > 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \
697
+ if (t > 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \
698
+ if (t > 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \
699
+ if (t > 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \
700
+ if (t > 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \
701
+ if (t > 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \
702
+ if (t > 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \
703
+ if (t > 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \
704
+ if (t > 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \
705
+ if (t > 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \
706
+ if (t > 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \
707
+ if (t > 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \
708
+ if (t > 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \
709
+ if (t > 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \
710
+ if (t > 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \
711
+ if (t > 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \
712
+ if (t > 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \
713
+ if (t > 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \
714
+ if (t > 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \
715
+ if (t > 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \
716
+ if (t > 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \
717
+ if (t > 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \
718
+ if (t > 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \
719
+ if (t > 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \
720
+ if (t > 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \
721
+ if (t > 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \
722
+ if (t > 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \
723
+ if (t > 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \
724
+ if (t > 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \
725
+ if (t > 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \
726
+ if (t > 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \
727
+ if (t > 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \
728
+ if (t > 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \
729
+ if (t > 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \
730
+ if (t > 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \
731
+ if (t > 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \
732
+ if (t > 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \
733
+ if (t > 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \
734
+ if (t > 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \
735
+ if (t > 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \
736
+ if (t > 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \
737
+ if (t > 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \
738
+ if (t > 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \
739
+ if (t > 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \
740
+ if (t > 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \
741
+ if (t > 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \
742
+ if (t > 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \
743
+ if (t > 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \
744
+ if (t > 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \
745
+ if (t > 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \
746
+ if (t > 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \
747
+ if (t > 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \
748
+ if (t > 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \
749
+ ihvin[0] = a; ihvin[1] = b; ihvin[2] = c; ihvin[3] = d; ihvin[4] = e; \
750
+ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; \
751
+ if (t <= 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \
752
+ if (t <= 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \
753
+ if (t <= 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \
754
+ if (t <= 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \
755
+ if (t <= 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \
756
+ if (t <= 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \
757
+ if (t <= 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \
758
+ if (t <= 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \
759
+ if (t <= 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \
760
+ if (t <= 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \
761
+ if (t <= 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \
762
+ if (t <= 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \
763
+ if (t <= 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \
764
+ if (t <= 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \
765
+ if (t <= 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \
766
+ if (t <= 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \
767
+ if (t <= 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \
768
+ if (t <= 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \
769
+ if (t <= 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \
770
+ if (t <= 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \
771
+ if (t <= 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \
772
+ if (t <= 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \
773
+ if (t <= 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \
774
+ if (t <= 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \
775
+ if (t <= 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \
776
+ if (t <= 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \
777
+ if (t <= 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \
778
+ if (t <= 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \
779
+ if (t <= 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \
780
+ if (t <= 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \
781
+ if (t <= 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \
782
+ if (t <= 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \
783
+ if (t <= 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \
784
+ if (t <= 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \
785
+ if (t <= 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \
786
+ if (t <= 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \
787
+ if (t <= 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \
788
+ if (t <= 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \
789
+ if (t <= 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \
790
+ if (t <= 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \
791
+ if (t <= 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \
792
+ if (t <= 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \
793
+ if (t <= 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \
794
+ if (t <= 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \
795
+ if (t <= 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \
796
+ if (t <= 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \
797
+ if (t <= 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \
798
+ if (t <= 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \
799
+ if (t <= 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \
800
+ if (t <= 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \
801
+ if (t <= 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \
802
+ if (t <= 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \
803
+ if (t <= 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \
804
+ if (t <= 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \
805
+ if (t <= 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \
806
+ if (t <= 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \
807
+ if (t <= 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \
808
+ if (t <= 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \
809
+ if (t <= 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \
810
+ if (t <= 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \
811
+ if (t <= 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \
812
+ if (t <= 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \
813
+ if (t <= 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \
814
+ if (t <= 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \
815
+ if (t <= 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \
816
+ if (t <= 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \
817
+ if (t <= 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \
818
+ if (t <= 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \
819
+ if (t <= 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \
820
+ if (t <= 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \
821
+ if (t <= 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \
822
+ if (t <= 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \
823
+ if (t <= 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \
824
+ if (t <= 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \
825
+ if (t <= 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \
826
+ if (t <= 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \
827
+ if (t <= 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \
828
+ if (t <= 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \
829
+ if (t <= 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \
830
+ if (t <= 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \
831
+ ihvout[0] = ihvin[0] + a; ihvout[1] = ihvin[1] + b; ihvout[2] = ihvin[2] + c; ihvout[3] = ihvin[3] + d; ihvout[4] = ihvin[4] + e; \
832
+ }
833
+
834
+ SHA1_RECOMPRESS(0)
835
+ SHA1_RECOMPRESS(1)
836
+ SHA1_RECOMPRESS(2)
837
+ SHA1_RECOMPRESS(3)
838
+ SHA1_RECOMPRESS(4)
839
+ SHA1_RECOMPRESS(5)
840
+ SHA1_RECOMPRESS(6)
841
+ SHA1_RECOMPRESS(7)
842
+ SHA1_RECOMPRESS(8)
843
+ SHA1_RECOMPRESS(9)
844
+
845
+ SHA1_RECOMPRESS(10)
846
+ SHA1_RECOMPRESS(11)
847
+ SHA1_RECOMPRESS(12)
848
+ SHA1_RECOMPRESS(13)
849
+ SHA1_RECOMPRESS(14)
850
+ SHA1_RECOMPRESS(15)
851
+ SHA1_RECOMPRESS(16)
852
+ SHA1_RECOMPRESS(17)
853
+ SHA1_RECOMPRESS(18)
854
+ SHA1_RECOMPRESS(19)
855
+
856
+ SHA1_RECOMPRESS(20)
857
+ SHA1_RECOMPRESS(21)
858
+ SHA1_RECOMPRESS(22)
859
+ SHA1_RECOMPRESS(23)
860
+ SHA1_RECOMPRESS(24)
861
+ SHA1_RECOMPRESS(25)
862
+ SHA1_RECOMPRESS(26)
863
+ SHA1_RECOMPRESS(27)
864
+ SHA1_RECOMPRESS(28)
865
+ SHA1_RECOMPRESS(29)
866
+
867
+ SHA1_RECOMPRESS(30)
868
+ SHA1_RECOMPRESS(31)
869
+ SHA1_RECOMPRESS(32)
870
+ SHA1_RECOMPRESS(33)
871
+ SHA1_RECOMPRESS(34)
872
+ SHA1_RECOMPRESS(35)
873
+ SHA1_RECOMPRESS(36)
874
+ SHA1_RECOMPRESS(37)
875
+ SHA1_RECOMPRESS(38)
876
+ SHA1_RECOMPRESS(39)
877
+
878
+ SHA1_RECOMPRESS(40)
879
+ SHA1_RECOMPRESS(41)
880
+ SHA1_RECOMPRESS(42)
881
+ SHA1_RECOMPRESS(43)
882
+ SHA1_RECOMPRESS(44)
883
+ SHA1_RECOMPRESS(45)
884
+ SHA1_RECOMPRESS(46)
885
+ SHA1_RECOMPRESS(47)
886
+ SHA1_RECOMPRESS(48)
887
+ SHA1_RECOMPRESS(49)
888
+
889
+ SHA1_RECOMPRESS(50)
890
+ SHA1_RECOMPRESS(51)
891
+ SHA1_RECOMPRESS(52)
892
+ SHA1_RECOMPRESS(53)
893
+ SHA1_RECOMPRESS(54)
894
+ SHA1_RECOMPRESS(55)
895
+ SHA1_RECOMPRESS(56)
896
+ SHA1_RECOMPRESS(57)
897
+ SHA1_RECOMPRESS(58)
898
+ SHA1_RECOMPRESS(59)
899
+
900
+ SHA1_RECOMPRESS(60)
901
+ SHA1_RECOMPRESS(61)
902
+ SHA1_RECOMPRESS(62)
903
+ SHA1_RECOMPRESS(63)
904
+ SHA1_RECOMPRESS(64)
905
+ SHA1_RECOMPRESS(65)
906
+ SHA1_RECOMPRESS(66)
907
+ SHA1_RECOMPRESS(67)
908
+ SHA1_RECOMPRESS(68)
909
+ SHA1_RECOMPRESS(69)
910
+
911
+ SHA1_RECOMPRESS(70)
912
+ SHA1_RECOMPRESS(71)
913
+ SHA1_RECOMPRESS(72)
914
+ SHA1_RECOMPRESS(73)
915
+ SHA1_RECOMPRESS(74)
916
+ SHA1_RECOMPRESS(75)
917
+ SHA1_RECOMPRESS(76)
918
+ SHA1_RECOMPRESS(77)
919
+ SHA1_RECOMPRESS(78)
920
+ SHA1_RECOMPRESS(79)
921
+
922
+ sha1_recompression_type sha1_recompression_step[80] =
923
+ {
924
+ sha1recompress_fast_0, sha1recompress_fast_1, sha1recompress_fast_2, sha1recompress_fast_3, sha1recompress_fast_4, sha1recompress_fast_5, sha1recompress_fast_6, sha1recompress_fast_7, sha1recompress_fast_8, sha1recompress_fast_9,
925
+ sha1recompress_fast_10, sha1recompress_fast_11, sha1recompress_fast_12, sha1recompress_fast_13, sha1recompress_fast_14, sha1recompress_fast_15, sha1recompress_fast_16, sha1recompress_fast_17, sha1recompress_fast_18, sha1recompress_fast_19,
926
+ sha1recompress_fast_20, sha1recompress_fast_21, sha1recompress_fast_22, sha1recompress_fast_23, sha1recompress_fast_24, sha1recompress_fast_25, sha1recompress_fast_26, sha1recompress_fast_27, sha1recompress_fast_28, sha1recompress_fast_29,
927
+ sha1recompress_fast_30, sha1recompress_fast_31, sha1recompress_fast_32, sha1recompress_fast_33, sha1recompress_fast_34, sha1recompress_fast_35, sha1recompress_fast_36, sha1recompress_fast_37, sha1recompress_fast_38, sha1recompress_fast_39,
928
+ sha1recompress_fast_40, sha1recompress_fast_41, sha1recompress_fast_42, sha1recompress_fast_43, sha1recompress_fast_44, sha1recompress_fast_45, sha1recompress_fast_46, sha1recompress_fast_47, sha1recompress_fast_48, sha1recompress_fast_49,
929
+ sha1recompress_fast_50, sha1recompress_fast_51, sha1recompress_fast_52, sha1recompress_fast_53, sha1recompress_fast_54, sha1recompress_fast_55, sha1recompress_fast_56, sha1recompress_fast_57, sha1recompress_fast_58, sha1recompress_fast_59,
930
+ sha1recompress_fast_60, sha1recompress_fast_61, sha1recompress_fast_62, sha1recompress_fast_63, sha1recompress_fast_64, sha1recompress_fast_65, sha1recompress_fast_66, sha1recompress_fast_67, sha1recompress_fast_68, sha1recompress_fast_69,
931
+ sha1recompress_fast_70, sha1recompress_fast_71, sha1recompress_fast_72, sha1recompress_fast_73, sha1recompress_fast_74, sha1recompress_fast_75, sha1recompress_fast_76, sha1recompress_fast_77, sha1recompress_fast_78, sha1recompress_fast_79,
932
+ };
933
+
934
+
935
+
936
+
937
+
938
+ void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
939
+ {
940
+ unsigned i, j;
941
+ uint32_t ubc_dv_mask[DVMASKSIZE];
942
+ uint32_t ihvtmp[5];
943
+ for (i=0; i < DVMASKSIZE; ++i)
944
+ ubc_dv_mask[i]=0;
945
+ ctx->ihv1[0] = ctx->ihv[0];
946
+ ctx->ihv1[1] = ctx->ihv[1];
947
+ ctx->ihv1[2] = ctx->ihv[2];
948
+ ctx->ihv1[3] = ctx->ihv[3];
949
+ ctx->ihv1[4] = ctx->ihv[4];
950
+ memcpy(ctx->m1, block, 64);
951
+ sha1_message_expansion(ctx->m1);
952
+ if (ctx->detect_coll && ctx->ubc_check)
953
+ {
954
+ ubc_check(ctx->m1, ubc_dv_mask);
955
+ }
956
+ sha1_compression_states(ctx->ihv, ctx->m1, ctx->states);
957
+ if (ctx->detect_coll)
958
+ {
959
+ for (i = 0; sha1_dvs[i].dvType != 0; ++i)
960
+ {
961
+ if ((0 == ctx->ubc_check) || (((uint32_t)(1) << sha1_dvs[i].maskb) & ubc_dv_mask[sha1_dvs[i].maski]))
962
+ {
963
+ for (j = 0; j < 80; ++j)
964
+ ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j];
965
+ (sha1_recompression_step[sha1_dvs[i].testt])(ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]);
966
+ // to verify SHA-1 collision detection code with collisions for reduced-step SHA-1
967
+ if ((ihvtmp[0] == ctx->ihv[0] && ihvtmp[1] == ctx->ihv[1] && ihvtmp[2] == ctx->ihv[2] && ihvtmp[3] == ctx->ihv[3] && ihvtmp[4] == ctx->ihv[4])
968
+ || (ctx->reduced_round_coll && ctx->ihv1[0] == ctx->ihv2[0] && ctx->ihv1[1] == ctx->ihv2[1] && ctx->ihv1[2] == ctx->ihv2[2] && ctx->ihv1[3] == ctx->ihv2[3] && ctx->ihv1[4] == ctx->ihv2[4]))
969
+ {
970
+ ctx->found_collision = 1;
971
+ // TODO: call callback
972
+ if (ctx->callback != NULL)
973
+ ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2);
974
+
975
+ if (ctx->safe_hash)
976
+ {
977
+ sha1_compression_W(ctx->ihv, ctx->m1);
978
+ sha1_compression_W(ctx->ihv, ctx->m1);
979
+ }
980
+
981
+ break;
982
+ }
983
+ }
984
+ }
985
+ }
986
+ }
987
+
988
+
989
+
990
+
991
+
992
+ void swap_bytes(uint32_t val[16])
993
+ {
994
+ unsigned i;
995
+ for (i = 0; i < 16; ++i)
996
+ {
997
+ val[i] = ((val[i] << 8) & 0xFF00FF00) | ((val[i] >> 8) & 0xFF00FF);
998
+ val[i] = (val[i] << 16) | (val[i] >> 16);
999
+ }
1000
+ }
1001
+
1002
+ void SHA1DCInit(SHA1_CTX* ctx)
1003
+ {
1004
+ static const union { unsigned char bytes[4]; uint32_t value; } endianness = { { 0, 1, 2, 3 } };
1005
+ static const uint32_t littleendian = 0x03020100;
1006
+ ctx->total = 0;
1007
+ ctx->ihv[0] = 0x67452301;
1008
+ ctx->ihv[1] = 0xEFCDAB89;
1009
+ ctx->ihv[2] = 0x98BADCFE;
1010
+ ctx->ihv[3] = 0x10325476;
1011
+ ctx->ihv[4] = 0xC3D2E1F0;
1012
+ ctx->found_collision = 0;
1013
+ ctx->safe_hash = 1;
1014
+ ctx->ubc_check = 1;
1015
+ ctx->detect_coll = 1;
1016
+ ctx->reduced_round_coll = 0;
1017
+ ctx->bigendian = (endianness.value != littleendian);
1018
+ ctx->callback = NULL;
1019
+ }
1020
+
1021
+ void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
1022
+ {
1023
+ if (safehash)
1024
+ ctx->safe_hash = 1;
1025
+ else
1026
+ ctx->safe_hash = 0;
1027
+ }
1028
+
1029
+
1030
+ void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
1031
+ {
1032
+ if (ubc_check)
1033
+ ctx->ubc_check = 1;
1034
+ else
1035
+ ctx->ubc_check = 0;
1036
+ }
1037
+
1038
+ void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
1039
+ {
1040
+ if (detect_coll)
1041
+ ctx->detect_coll = 1;
1042
+ else
1043
+ ctx->detect_coll = 0;
1044
+ }
1045
+
1046
+ void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
1047
+ {
1048
+ if (reduced_round_coll)
1049
+ ctx->reduced_round_coll = 1;
1050
+ else
1051
+ ctx->reduced_round_coll = 0;
1052
+ }
1053
+
1054
+ void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback)
1055
+ {
1056
+ ctx->callback = callback;
1057
+ }
1058
+
1059
+ void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, unsigned len)
1060
+ {
1061
+ unsigned left, fill;
1062
+ if (len == 0)
1063
+ return;
1064
+
1065
+ left = ctx->total & 63;
1066
+ fill = 64 - left;
1067
+
1068
+ if (left && len >= fill)
1069
+ {
1070
+ ctx->total += fill;
1071
+ memcpy(ctx->buffer + left, buf, fill);
1072
+ if (!ctx->bigendian)
1073
+ swap_bytes((uint32_t*)(ctx->buffer));
1074
+ sha1_process(ctx, (uint32_t*)(ctx->buffer));
1075
+ buf += fill;
1076
+ len -= fill;
1077
+ left = 0;
1078
+ }
1079
+ while (len >= 64)
1080
+ {
1081
+ ctx->total += 64;
1082
+ if (!ctx->bigendian)
1083
+ {
1084
+ memcpy(ctx->buffer, buf, 64);
1085
+ swap_bytes((uint32_t*)(ctx->buffer));
1086
+ sha1_process(ctx, (uint32_t*)(ctx->buffer));
1087
+ }
1088
+ else
1089
+ sha1_process(ctx, (uint32_t*)(buf));
1090
+ buf += 64;
1091
+ len -= 64;
1092
+ }
1093
+ if (len > 0)
1094
+ {
1095
+ ctx->total += len;
1096
+ memcpy(ctx->buffer + left, buf, len);
1097
+ }
1098
+ }
1099
+
1100
+ static const unsigned char sha1_padding[64] =
1101
+ {
1102
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1103
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1104
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1105
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1106
+ };
1107
+
1108
+ int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx)
1109
+ {
1110
+ uint32_t last = ctx->total & 63;
1111
+ uint32_t padn = (last < 56) ? (56 - last) : (120 - last);
1112
+ uint64_t total;
1113
+ SHA1DCUpdate(ctx, (const char*)(sha1_padding), padn);
1114
+
1115
+ total = ctx->total - padn;
1116
+ total <<= 3;
1117
+ ctx->buffer[56] = (unsigned char)(total >> 56);
1118
+ ctx->buffer[57] = (unsigned char)(total >> 48);
1119
+ ctx->buffer[58] = (unsigned char)(total >> 40);
1120
+ ctx->buffer[59] = (unsigned char)(total >> 32);
1121
+ ctx->buffer[60] = (unsigned char)(total >> 24);
1122
+ ctx->buffer[61] = (unsigned char)(total >> 16);
1123
+ ctx->buffer[62] = (unsigned char)(total >> 8);
1124
+ ctx->buffer[63] = (unsigned char)(total);
1125
+ if (!ctx->bigendian)
1126
+ swap_bytes((uint32_t*)(ctx->buffer));
1127
+ sha1_process(ctx, (uint32_t*)(ctx->buffer));
1128
+ output[0] = (unsigned char)(ctx->ihv[0] >> 24);
1129
+ output[1] = (unsigned char)(ctx->ihv[0] >> 16);
1130
+ output[2] = (unsigned char)(ctx->ihv[0] >> 8);
1131
+ output[3] = (unsigned char)(ctx->ihv[0]);
1132
+ output[4] = (unsigned char)(ctx->ihv[1] >> 24);
1133
+ output[5] = (unsigned char)(ctx->ihv[1] >> 16);
1134
+ output[6] = (unsigned char)(ctx->ihv[1] >> 8);
1135
+ output[7] = (unsigned char)(ctx->ihv[1]);
1136
+ output[8] = (unsigned char)(ctx->ihv[2] >> 24);
1137
+ output[9] = (unsigned char)(ctx->ihv[2] >> 16);
1138
+ output[10] = (unsigned char)(ctx->ihv[2] >> 8);
1139
+ output[11] = (unsigned char)(ctx->ihv[2]);
1140
+ output[12] = (unsigned char)(ctx->ihv[3] >> 24);
1141
+ output[13] = (unsigned char)(ctx->ihv[3] >> 16);
1142
+ output[14] = (unsigned char)(ctx->ihv[3] >> 8);
1143
+ output[15] = (unsigned char)(ctx->ihv[3]);
1144
+ output[16] = (unsigned char)(ctx->ihv[4] >> 24);
1145
+ output[17] = (unsigned char)(ctx->ihv[4] >> 16);
1146
+ output[18] = (unsigned char)(ctx->ihv[4] >> 8);
1147
+ output[19] = (unsigned char)(ctx->ihv[4]);
1148
+ return ctx->found_collision;
1149
+ }