Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cr-marcstevens/sha1collisiondetection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Shumow <shumow@gmail.com>2017-05-24 01:43:45 +0300
committerDan Shumow <shumow@gmail.com>2017-05-24 01:43:45 +0300
commit2d662ff62e28b4841bce272f3cf206ce95aa3e1b (patch)
treebfb032638ecaab7283baefd2bebf2d0cc6232ddc
parentda5ca1eb4a7559cc591cb7b1f0cf58c1b1b1fd55 (diff)
Fixes bugs with SIMD implementation, now runs correctly under VS.
-rw-r--r--lib/sha1.c9
-rw-r--r--lib/simd/sha1_simd.c18
-rw-r--r--lib/simd/sha1_simd.h3
3 files changed, 20 insertions, 10 deletions
diff --git a/lib/sha1.c b/lib/sha1.c
index 23236a2..e2f232f 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -1627,7 +1627,6 @@ static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
#ifdef SHA1DC_HAVE_SIMD
if (ctx->ubc_check == 0 && ctx->simd > 0)
{
- fprintf(stderr, "calling simd code");
sha1_process_simd(ctx, block);
return;
}
@@ -1663,6 +1662,14 @@ static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
if ((0 == ((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])))
|| (ctx->reduced_round_coll && 0==((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]))))
{
+ /*
+ fprintf(stderr, "block offset: %d dv id: %d test step: %d\n", (uint32_t)(ctx->total - 64), i, sha1_dvs[i].testt);
+ fprintf(stderr, "ihvtmp[0] = 0x%08x ihvtmp[1] = 0x%08x ihvtmp[2] = 0x%08x ihvtmp[3] = 0x%08x ihvtmp[4] = 0x%08x\n", ihvtmp[0], ihvtmp[1], ihvtmp[2], ihvtmp[3], ihvtmp[4]);
+ fprintf(stderr, "ctx->ihv[0] = 0x%08x ctx->ihv[1] = 0x%08x ctx->ihv[2] = 0x%08x ctx->ihv[3] = 0x%08x ctx->ihv[4] = 0x%08x\n", ctx->ihv[0], ctx->ihv[1], ctx->ihv[2], ctx->ihv[3], ctx->ihv[4]);
+ fprintf(stderr, "ctx->ihv1[0] = 0x%08x ctx->ihv1[1] = 0x%08x ctx->ihv1[2] = 0x%08x ctx->ihv1[3] = 0x%08x ctx->ihv1[4] = 0x%08x\n", ctx->ihv1[0], ctx->ihv1[1], ctx->ihv1[2], ctx->ihv1[3], ctx->ihv1[4]);
+ fprintf(stderr, "ctx->ihv2[0] = 0x%08x ctx->ihv2[1] = 0x%08x ctx->ihv2[2] = 0x%08x ctx->ihv2[3] = 0x%08x ctx->ihv2[4] = 0x%08x\n", ctx->ihv2[0], ctx->ihv2[1], ctx->ihv2[2], ctx->ihv2[3], ctx->ihv2[4]);
+ */
+
ctx->found_collision = 1;
if (ctx->callback != NULL)
diff --git a/lib/simd/sha1_simd.c b/lib/simd/sha1_simd.c
index e69ffbc..7da5ff7 100644
--- a/lib/simd/sha1_simd.c
+++ b/lib/simd/sha1_simd.c
@@ -15,7 +15,12 @@
#include <stdio.h>
#if defined(SHA1DC_HAVE_MMX64) || defined(SHA1DC_HAVE_SSE128) || defined(SHA1DC_HAVE_AVX256) || defined(SHA1DC_HAVE_AVX512)
+#ifdef __GNUC__
#include <x86intrin.h>
+#elif _MSC_VER
+#include <intrin.h>
+#endif
+
static void sha1dc_cpuid(uint32_t level, uint32_t sublevel, uint32_t result[4])
{
#ifdef _MSC_VER
@@ -149,7 +154,6 @@ int SHA1DC_get_simd()
if (simd_index == simd_type_unknown)
{
initialize_simd();
- fprintf(stderr, "Detected SIMD: %i\n", (int)(simd_index));
}
return (int)simd_index;
@@ -320,16 +324,16 @@ void sha1_process_simd(SHA1_CTX* ctx, const uint32_t block[16])
{
sha1_apply_message_differences_simd(ctx->m1, &(sha1_dvs_interleaved.dm[0][i]), dme);
- sha1_load_state_to_simd(ctx->states[58-1], simd_states);
+ sha1_load_state_to_simd(ctx->states[58], simd_states);
sha1_recompress_fast_58_simd(simd_ihv_reduced, simd_ihv_full, dme, simd_states);
sha1_compare_digests_simd(ctx, simd_ihv_full, simd_ihv_reduced, &(check_results[i]));
}
- for (i = step_58_offset; i < SHA1DC_SIMD_END58; i += lane_cnt)
+ for (i = step_58_offset; i < SHA1DC_SIMD_END58; i++)
{
- ctx->found_collision |= (0 != check_results[i]);
+ ctx->found_collision |= (0 == check_results[i]);
}
step_65_offset = get_dv_table_offset_65();
@@ -338,16 +342,16 @@ void sha1_process_simd(SHA1_CTX* ctx, const uint32_t block[16])
{
sha1_apply_message_differences_simd(ctx->m1, &(sha1_dvs_interleaved.dm[0][i]), dme);
- sha1_load_state_to_simd(ctx->states[65-1], simd_states);
+ sha1_load_state_to_simd(ctx->states[65], simd_states);
sha1_recompress_fast_65_simd(simd_ihv_reduced, simd_ihv_full, dme, simd_states);
sha1_compare_digests_simd(ctx, simd_ihv_full, simd_ihv_reduced, &(check_results[i]));
}
- for (i = step_65_offset; i < SHA1DC_SIMD_END65; i += lane_cnt)
+ for (i = step_65_offset; i < SHA1DC_SIMD_END65; i++)
{
- ctx->found_collision |= (0 != check_results[i]);
+ ctx->found_collision |= (0 == check_results[i]);
}
}
}
diff --git a/lib/simd/sha1_simd.h b/lib/simd/sha1_simd.h
index 3662eb9..c01b4a4 100644
--- a/lib/simd/sha1_simd.h
+++ b/lib/simd/sha1_simd.h
@@ -69,8 +69,7 @@ typedef struct {
#define SHA1DC_AVX512 (0)
#endif
-#define SIMD_IMPLEMENTATION_CNT (SHA1DC_MMX64 + SHA1DC_SSE128 + SHA1DC_NEON128 + SHA1DC_AVX256 + SHA1DC_AVX512)
-
+#define SIMD_IMPLEMENTATION_CNT (5)