Fossil SCM
Update src/sha1hard.c to match the current upstream implementation, which LLM analysis assures us is faster. The only local changes applied were minor formatting, add 'static' to a few functions, and remove those which fail the resulting 'defined but not used' warning. This change requires stdint.h: C99 but unsupported by MSC until mid-2000-teens, so this might not build with an ancient MSC. Passes tests with rebuild, test-integrity, and this check-in.
Commit
d243deba6a63cf4e2b0c58fe153505153dbdf26df75b2647b0d01ad511d88efe
Parent
c54604f830cbfd0…
2 files changed
+1
-3
+185
-352
+1
-3
| --- src/sha1.c | ||
| +++ src/sha1.c | ||
| @@ -16,13 +16,11 @@ | ||
| 16 | 16 | ******************************************************************************* |
| 17 | 17 | ** |
| 18 | 18 | ** This implementation of SHA1. |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | -#include <sys/types.h> | |
| 22 | 21 | #include "sha1.h" |
| 23 | - | |
| 24 | 22 | |
| 25 | 23 | /* |
| 26 | 24 | ** SHA1 Implementation #1 is the hardened SHA1 implementation by |
| 27 | 25 | ** Marc Stevens. Code obtained from GitHub |
| 28 | 26 | ** |
| @@ -36,11 +34,10 @@ | ||
| 36 | 34 | const uint32_t*, const uint32_t*, const uint32_t*); |
| 37 | 35 | struct SHA1_CTX { |
| 38 | 36 | uint64_t total; |
| 39 | 37 | uint32_t ihv[5]; |
| 40 | 38 | unsigned char buffer[64]; |
| 41 | - int bigendian; | |
| 42 | 39 | int found_collision; |
| 43 | 40 | int safe_hash; |
| 44 | 41 | int detect_coll; |
| 45 | 42 | int ubc_check; |
| 46 | 43 | int reduced_round_coll; |
| @@ -50,10 +47,11 @@ | ||
| 50 | 47 | uint32_t ihv2[5]; |
| 51 | 48 | uint32_t m1[80]; |
| 52 | 49 | uint32_t m2[80]; |
| 53 | 50 | uint32_t states[80][5]; |
| 54 | 51 | }; |
| 52 | +typedef struct SHA1_CTX SHA1_CTX; | |
| 55 | 53 | |
| 56 | 54 | void SHA1DCInit(SHA1_CTX*); |
| 57 | 55 | void SHA1DCUpdate(SHA1_CTX*, const unsigned char*, unsigned); |
| 58 | 56 | int SHA1DCFinal(unsigned char[20], SHA1_CTX*); |
| 59 | 57 | |
| 60 | 58 |
| --- src/sha1.c | |
| +++ src/sha1.c | |
| @@ -16,13 +16,11 @@ | |
| 16 | ******************************************************************************* |
| 17 | ** |
| 18 | ** This implementation of SHA1. |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include <sys/types.h> |
| 22 | #include "sha1.h" |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | ** SHA1 Implementation #1 is the hardened SHA1 implementation by |
| 27 | ** Marc Stevens. Code obtained from GitHub |
| 28 | ** |
| @@ -36,11 +34,10 @@ | |
| 36 | const uint32_t*, const uint32_t*, const uint32_t*); |
| 37 | struct SHA1_CTX { |
| 38 | uint64_t total; |
| 39 | uint32_t ihv[5]; |
| 40 | unsigned char buffer[64]; |
| 41 | int bigendian; |
| 42 | int found_collision; |
| 43 | int safe_hash; |
| 44 | int detect_coll; |
| 45 | int ubc_check; |
| 46 | int reduced_round_coll; |
| @@ -50,10 +47,11 @@ | |
| 50 | uint32_t ihv2[5]; |
| 51 | uint32_t m1[80]; |
| 52 | uint32_t m2[80]; |
| 53 | uint32_t states[80][5]; |
| 54 | }; |
| 55 | |
| 56 | void SHA1DCInit(SHA1_CTX*); |
| 57 | void SHA1DCUpdate(SHA1_CTX*, const unsigned char*, unsigned); |
| 58 | int SHA1DCFinal(unsigned char[20], SHA1_CTX*); |
| 59 | |
| 60 |
| --- src/sha1.c | |
| +++ src/sha1.c | |
| @@ -16,13 +16,11 @@ | |
| 16 | ******************************************************************************* |
| 17 | ** |
| 18 | ** This implementation of SHA1. |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include "sha1.h" |
| 22 | |
| 23 | /* |
| 24 | ** SHA1 Implementation #1 is the hardened SHA1 implementation by |
| 25 | ** Marc Stevens. Code obtained from GitHub |
| 26 | ** |
| @@ -36,11 +34,10 @@ | |
| 34 | const uint32_t*, const uint32_t*, const uint32_t*); |
| 35 | struct SHA1_CTX { |
| 36 | uint64_t total; |
| 37 | uint32_t ihv[5]; |
| 38 | unsigned char buffer[64]; |
| 39 | int found_collision; |
| 40 | int safe_hash; |
| 41 | int detect_coll; |
| 42 | int ubc_check; |
| 43 | int reduced_round_coll; |
| @@ -50,10 +47,11 @@ | |
| 47 | uint32_t ihv2[5]; |
| 48 | uint32_t m1[80]; |
| 49 | uint32_t m2[80]; |
| 50 | uint32_t states[80][5]; |
| 51 | }; |
| 52 | typedef struct SHA1_CTX SHA1_CTX; |
| 53 | |
| 54 | void SHA1DCInit(SHA1_CTX*); |
| 55 | void SHA1DCUpdate(SHA1_CTX*, const unsigned char*, unsigned); |
| 56 | int SHA1DCFinal(unsigned char[20], SHA1_CTX*); |
| 57 | |
| 58 |
+185
-352
| --- src/sha1hard.c | ||
| +++ src/sha1hard.c | ||
| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | ** The code in this file is the concatenation of several files |
| 3 | 3 | ** copied out of |
| 4 | 4 | ** |
| 5 | 5 | ** https://github.com/cr-marcstevens/sha1collisiondetection |
| 6 | 6 | ** |
| 7 | -** The copy was made on 2017-03-01. Some minor formatting changes | |
| 8 | -** were made but otherwise the code is unchanged. All | |
| 9 | -** original copyright claims are preserved. | |
| 7 | +** The copy was made on 2017-03-01 (updated 2026-10-16). Some minor | |
| 8 | +** formatting changes were made but otherwise the code is unchanged. | |
| 9 | +** All original copyright claims are preserved. | |
| 10 | 10 | ** |
| 11 | 11 | ** The code here implements a version of the SHA1 hash function that |
| 12 | 12 | ** is not vulnerable to crypto-analysis based attacks. If an input |
| 13 | 13 | ** is detected that looks like it might have been the result of a |
| 14 | 14 | ** crypto-analysis attack, then the hash is perturbed to generate a |
| @@ -15,10 +15,12 @@ | ||
| 15 | 15 | ** completely different hash. The authors claim that the chance of |
| 16 | 16 | ** a false-positive is vanishingly small. |
| 17 | 17 | */ |
| 18 | 18 | /*MAKEHEADERS-STOP*/ |
| 19 | 19 | #include "config.h" |
| 20 | +#include "sha1.h" | |
| 21 | + | |
| 20 | 22 | /*************** File: lib/sha1.c ****************/ |
| 21 | 23 | /*** |
| 22 | 24 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow ([email protected]) |
| 23 | 25 | * Distributed under the MIT Software License. |
| 24 | 26 | * See accompanying file LICENSE.txt or copy at |
| @@ -65,94 +67,70 @@ | ||
| 65 | 67 | #define DVMASKSIZE 1 |
| 66 | 68 | typedef struct { int dvType; int dvK; int dvB; int testt; int maski; int maskb; uint32_t dm[80]; } dv_info_t; |
| 67 | 69 | #define DOSTORESTATE58 |
| 68 | 70 | #define DOSTORESTATE65 |
| 69 | 71 | typedef void(*sha1_recompression_type)(uint32_t*, uint32_t*, const uint32_t*, const uint32_t*); |
| 70 | -void sha1_message_expansion(uint32_t W[80]); | |
| 71 | -void sha1_compression(uint32_t ihv[5], const uint32_t m[16]); | |
| 72 | -void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]); | |
| 73 | -void sha1_compression_states(uint32_t ihv[5], const uint32_t W[80], uint32_t states[80][5]); | |
| 74 | -extern sha1_recompression_type sha1_recompression_step[80]; | |
| 75 | -typedef void(*collision_block_callback)(uint64_t, const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*); | |
| 76 | -typedef struct { | |
| 77 | - uint64_t total; | |
| 78 | - uint32_t ihv[5]; | |
| 79 | - unsigned char buffer[64]; | |
| 80 | - int bigendian; | |
| 81 | - int found_collision; | |
| 82 | - int safe_hash; | |
| 83 | - int detect_coll; | |
| 84 | - int ubc_check; | |
| 85 | - int reduced_round_coll; | |
| 86 | - collision_block_callback callback; | |
| 87 | - | |
| 88 | - uint32_t ihv1[5]; | |
| 89 | - uint32_t ihv2[5]; | |
| 90 | - uint32_t m1[80]; | |
| 91 | - uint32_t m2[80]; | |
| 92 | - uint32_t states[80][5]; | |
| 93 | -} SHA1_CTX; | |
| 94 | 72 | |
| 95 | 73 | /******************** File: lib/ubc_check.c **************************/ |
| 96 | 74 | /*** |
| 97 | 75 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow <[email protected]> |
| 98 | 76 | * Distributed under the MIT Software License. |
| 99 | 77 | * See accompanying file LICENSE.txt or copy at |
| 100 | 78 | * https://opensource.org/licenses/MIT |
| 101 | 79 | ***/ |
| 102 | 80 | |
| 103 | -/* | |
| 104 | -** this file was generated by the 'parse_bitrel' program in the tools section | |
| 105 | -** using the data files from directory 'tools/data/3565' | |
| 106 | -** | |
| 107 | -** sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check | |
| 108 | -** dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) | |
| 109 | -** dm[80] is the expanded message block XOR-difference defined by the DV | |
| 110 | -** testt is the step to do the recompression from for collision detection | |
| 111 | -** maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check | |
| 112 | -** | |
| 113 | -** ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs | |
| 114 | -** it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met | |
| 115 | -** thus one needs to do the recompression check for each DV that has its bit set | |
| 116 | -** | |
| 117 | -** ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded | |
| 118 | -** a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c | |
| 119 | -** ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section | |
| 120 | -*/ | |
| 121 | - | |
| 122 | -static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; | |
| 123 | -static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; | |
| 124 | -static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; | |
| 125 | -static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; | |
| 126 | -static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; | |
| 127 | -static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; | |
| 128 | -static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; | |
| 129 | -static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; | |
| 130 | -static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; | |
| 131 | -static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; | |
| 132 | -static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; | |
| 133 | -static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; | |
| 134 | -static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; | |
| 135 | -static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; | |
| 136 | -static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; | |
| 137 | -static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; | |
| 138 | -static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; | |
| 139 | -static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; | |
| 140 | -static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; | |
| 141 | -static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; | |
| 142 | -static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; | |
| 143 | -static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; | |
| 144 | -static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; | |
| 145 | -static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; | |
| 146 | -static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; | |
| 147 | -static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; | |
| 148 | -static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; | |
| 149 | -static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; | |
| 150 | -static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; | |
| 151 | -static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; | |
| 152 | -static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; | |
| 153 | -static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; | |
| 81 | +// this file was generated by the 'parse_bitrel' program in the tools section | |
| 82 | +// using the data files from directory 'tools/data/3565' | |
| 83 | +// | |
| 84 | +// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check | |
| 85 | +// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) | |
| 86 | +// dm[80] is the expanded message block XOR-difference defined by the DV | |
| 87 | +// testt is the step to do the recompression from for collision detection | |
| 88 | +// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check | |
| 89 | +// | |
| 90 | +// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs | |
| 91 | +// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met | |
| 92 | +// thus one needs to do the recompression check for each DV that has its bit set | |
| 93 | +// | |
| 94 | +// ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded | |
| 95 | +// a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c | |
| 96 | +// ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section | |
| 97 | + | |
| 98 | +#include <stdint.h> | |
| 99 | + | |
| 100 | +static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; | |
| 101 | +static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; | |
| 102 | +static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; | |
| 103 | +static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; | |
| 104 | +static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; | |
| 105 | +static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; | |
| 106 | +static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; | |
| 107 | +static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; | |
| 108 | +static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; | |
| 109 | +static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; | |
| 110 | +static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; | |
| 111 | +static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; | |
| 112 | +static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; | |
| 113 | +static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; | |
| 114 | +static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; | |
| 115 | +static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; | |
| 116 | +static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; | |
| 117 | +static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; | |
| 118 | +static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; | |
| 119 | +static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; | |
| 120 | +static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; | |
| 121 | +static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; | |
| 122 | +static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; | |
| 123 | +static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; | |
| 124 | +static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; | |
| 125 | +static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; | |
| 126 | +static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; | |
| 127 | +static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; | |
| 128 | +static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; | |
| 129 | +static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; | |
| 130 | +static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; | |
| 131 | +static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; | |
| 154 | 132 | |
| 155 | 133 | dv_info_t sha1_dvs[] = |
| 156 | 134 | { |
| 157 | 135 | {1,43,0,58,0,0, { 0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161,0x80000599 } } |
| 158 | 136 | , {1,44,0,58,0,1, { 0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161 } } |
| @@ -186,11 +164,12 @@ | ||
| 186 | 164 | , {2,54,0,65,0,29, { 0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107 } } |
| 187 | 165 | , {2,55,0,65,0,30, { 0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b } } |
| 188 | 166 | , {2,56,0,65,0,31, { 0x2600001a,0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046 } } |
| 189 | 167 | , {0,0,0,0,0,0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} |
| 190 | 168 | }; |
| 191 | -void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) | |
| 169 | + | |
| 170 | +static void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) | |
| 192 | 171 | { |
| 193 | 172 | uint32_t mask = ~((uint32_t)(0)); |
| 194 | 173 | mask &= (((((W[44]^W[45])>>29)&1)-1) | ~(DV_I_48_0_bit|DV_I_51_0_bit|DV_I_52_0_bit|DV_II_45_0_bit|DV_II_46_0_bit|DV_II_50_0_bit|DV_II_51_0_bit)); |
| 195 | 174 | mask &= (((((W[49]^W[50])>>29)&1)-1) | ~(DV_I_46_0_bit|DV_II_45_0_bit|DV_II_50_0_bit|DV_II_51_0_bit|DV_II_55_0_bit|DV_II_56_0_bit)); |
| 196 | 175 | mask &= (((((W[48]^W[49])>>29)&1)-1) | ~(DV_I_45_0_bit|DV_I_52_0_bit|DV_II_49_0_bit|DV_II_50_0_bit|DV_II_54_0_bit|DV_II_55_0_bit)); |
| @@ -454,17 +433,29 @@ | ||
| 454 | 433 | dvmask[0]=mask; |
| 455 | 434 | } |
| 456 | 435 | /******************** End Of File: lib/ubc_check.c *******************/ |
| 457 | 436 | /******************** Continue with: lib/sha1.c **********************/ |
| 458 | 437 | |
| 459 | - | |
| 460 | 438 | #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n)))) |
| 461 | 439 | #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n)))) |
| 462 | 440 | |
| 441 | +#define sha1_bswap32(x) \ | |
| 442 | + {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);} | |
| 443 | + | |
| 444 | +#define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1)) | |
| 445 | + | |
| 446 | +#if defined(BIGENDIAN) | |
| 447 | + #define sha1_load(m, t) (m[t]) | |
| 448 | +#else | |
| 449 | + #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); } | |
| 450 | +#endif /*define(BIGENDIAN)*/ | |
| 451 | + | |
| 452 | +#define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x | |
| 453 | + | |
| 463 | 454 | #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d)))) |
| 464 | 455 | #define sha1_f2(b,c,d) ((b)^(c)^(d)) |
| 465 | -#define sha1_f3(b,c,d) (((b) & ((c)|(d))) | ((c)&(d))) | |
| 456 | +#define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c)))) | |
| 466 | 457 | #define sha1_f4(b,c,d) ((b)^(c)^(d)) |
| 467 | 458 | |
| 468 | 459 | #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ |
| 469 | 460 | { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); } |
| 470 | 461 | #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ |
| @@ -480,124 +471,30 @@ | ||
| 480 | 471 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; } |
| 481 | 472 | #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ |
| 482 | 473 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; } |
| 483 | 474 | #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ |
| 484 | 475 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; } |
| 476 | + | |
| 477 | +#define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \ | |
| 478 | + {sha1_load(m, t, temp); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_right(b, 2);} | |
| 479 | + | |
| 480 | +#define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \ | |
| 481 | + {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_right(b, 2); } | |
| 482 | + | |
| 483 | +#define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \ | |
| 484 | + {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1; b = rotate_right(b, 2); } | |
| 485 | + | |
| 486 | +#define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \ | |
| 487 | + {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC; b = rotate_right(b, 2); } | |
| 488 | + | |
| 489 | +#define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \ | |
| 490 | + {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6; b = rotate_right(b, 2); } | |
| 491 | + | |
| 485 | 492 | |
| 486 | 493 | #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; |
| 487 | 494 | |
| 488 | - | |
| 489 | - | |
| 490 | -void sha1_message_expansion(uint32_t W[80]) | |
| 491 | -{ | |
| 492 | - unsigned i; | |
| 493 | - for (i = 16; i < 80; ++i) | |
| 494 | - W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); | |
| 495 | -} | |
| 496 | - | |
| 497 | -void sha1_compression(uint32_t ihv[5], const uint32_t m[16]) | |
| 498 | -{ | |
| 499 | - uint32_t W[80]; | |
| 500 | - uint32_t a,b,c,d,e; | |
| 501 | - unsigned i; | |
| 502 | - | |
| 503 | - memcpy(W, m, 16 * 4); | |
| 504 | - for (i = 16; i < 80; ++i) | |
| 505 | - W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); | |
| 506 | - | |
| 507 | - a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4]; | |
| 508 | - | |
| 509 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); | |
| 510 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); | |
| 511 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); | |
| 512 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); | |
| 513 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); | |
| 514 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); | |
| 515 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); | |
| 516 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); | |
| 517 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); | |
| 518 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); | |
| 519 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); | |
| 520 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); | |
| 521 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); | |
| 522 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); | |
| 523 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); | |
| 524 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); | |
| 525 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); | |
| 526 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); | |
| 527 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); | |
| 528 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); | |
| 529 | - | |
| 530 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); | |
| 531 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); | |
| 532 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); | |
| 533 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); | |
| 534 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); | |
| 535 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); | |
| 536 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); | |
| 537 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); | |
| 538 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); | |
| 539 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); | |
| 540 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); | |
| 541 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); | |
| 542 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); | |
| 543 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); | |
| 544 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); | |
| 545 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); | |
| 546 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); | |
| 547 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); | |
| 548 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); | |
| 549 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); | |
| 550 | - | |
| 551 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); | |
| 552 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); | |
| 553 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); | |
| 554 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); | |
| 555 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); | |
| 556 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); | |
| 557 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); | |
| 558 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); | |
| 559 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); | |
| 560 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); | |
| 561 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); | |
| 562 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); | |
| 563 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); | |
| 564 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); | |
| 565 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); | |
| 566 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); | |
| 567 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); | |
| 568 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); | |
| 569 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); | |
| 570 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); | |
| 571 | - | |
| 572 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); | |
| 573 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); | |
| 574 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); | |
| 575 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); | |
| 576 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); | |
| 577 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); | |
| 578 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); | |
| 579 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); | |
| 580 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); | |
| 581 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); | |
| 582 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); | |
| 583 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); | |
| 584 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); | |
| 585 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); | |
| 586 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); | |
| 587 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); | |
| 588 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); | |
| 589 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); | |
| 590 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); | |
| 591 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); | |
| 592 | - | |
| 593 | - ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; | |
| 594 | -} | |
| 595 | - | |
| 596 | - | |
| 597 | - | |
| 598 | -void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) | |
| 495 | +static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) | |
| 599 | 496 | { |
| 600 | 497 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 601 | 498 | |
| 602 | 499 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); |
| 603 | 500 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); |
| @@ -684,422 +581,422 @@ | ||
| 684 | 581 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); |
| 685 | 582 | |
| 686 | 583 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 687 | 584 | } |
| 688 | 585 | |
| 689 | - | |
| 690 | - | |
| 691 | -void sha1_compression_states(uint32_t ihv[5], const uint32_t W[80], uint32_t states[80][5]) | |
| 586 | +static void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], | |
| 587 | + uint32_t W[80], uint32_t states[80][5]) | |
| 692 | 588 | { |
| 693 | 589 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 590 | + uint32_t temp; | |
| 694 | 591 | |
| 695 | 592 | #ifdef DOSTORESTATE00 |
| 696 | 593 | SHA1_STORE_STATE(0) |
| 697 | 594 | #endif |
| 698 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); | |
| 595 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp); | |
| 699 | 596 | |
| 700 | 597 | #ifdef DOSTORESTATE01 |
| 701 | 598 | SHA1_STORE_STATE(1) |
| 702 | 599 | #endif |
| 703 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); | |
| 600 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp); | |
| 704 | 601 | |
| 705 | 602 | #ifdef DOSTORESTATE02 |
| 706 | 603 | SHA1_STORE_STATE(2) |
| 707 | 604 | #endif |
| 708 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); | |
| 605 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp); | |
| 709 | 606 | |
| 710 | 607 | #ifdef DOSTORESTATE03 |
| 711 | 608 | SHA1_STORE_STATE(3) |
| 712 | 609 | #endif |
| 713 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); | |
| 610 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp); | |
| 714 | 611 | |
| 715 | 612 | #ifdef DOSTORESTATE04 |
| 716 | 613 | SHA1_STORE_STATE(4) |
| 717 | 614 | #endif |
| 718 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); | |
| 615 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp); | |
| 719 | 616 | |
| 720 | 617 | #ifdef DOSTORESTATE05 |
| 721 | 618 | SHA1_STORE_STATE(5) |
| 722 | 619 | #endif |
| 723 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); | |
| 620 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp); | |
| 724 | 621 | |
| 725 | 622 | #ifdef DOSTORESTATE06 |
| 726 | 623 | SHA1_STORE_STATE(6) |
| 727 | 624 | #endif |
| 728 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); | |
| 625 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp); | |
| 729 | 626 | |
| 730 | 627 | #ifdef DOSTORESTATE07 |
| 731 | 628 | SHA1_STORE_STATE(7) |
| 732 | 629 | #endif |
| 733 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); | |
| 630 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp); | |
| 734 | 631 | |
| 735 | 632 | #ifdef DOSTORESTATE08 |
| 736 | 633 | SHA1_STORE_STATE(8) |
| 737 | 634 | #endif |
| 738 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); | |
| 635 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp); | |
| 739 | 636 | |
| 740 | 637 | #ifdef DOSTORESTATE09 |
| 741 | 638 | SHA1_STORE_STATE(9) |
| 742 | 639 | #endif |
| 743 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); | |
| 640 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp); | |
| 744 | 641 | |
| 745 | 642 | #ifdef DOSTORESTATE10 |
| 746 | 643 | SHA1_STORE_STATE(10) |
| 747 | 644 | #endif |
| 748 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); | |
| 645 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp); | |
| 749 | 646 | |
| 750 | 647 | #ifdef DOSTORESTATE11 |
| 751 | 648 | SHA1_STORE_STATE(11) |
| 752 | 649 | #endif |
| 753 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); | |
| 650 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp); | |
| 754 | 651 | |
| 755 | 652 | #ifdef DOSTORESTATE12 |
| 756 | 653 | SHA1_STORE_STATE(12) |
| 757 | 654 | #endif |
| 758 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); | |
| 655 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp); | |
| 759 | 656 | |
| 760 | 657 | #ifdef DOSTORESTATE13 |
| 761 | 658 | SHA1_STORE_STATE(13) |
| 762 | 659 | #endif |
| 763 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); | |
| 660 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp); | |
| 764 | 661 | |
| 765 | 662 | #ifdef DOSTORESTATE14 |
| 766 | 663 | SHA1_STORE_STATE(14) |
| 767 | 664 | #endif |
| 768 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); | |
| 665 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp); | |
| 769 | 666 | |
| 770 | 667 | #ifdef DOSTORESTATE15 |
| 771 | 668 | SHA1_STORE_STATE(15) |
| 772 | 669 | #endif |
| 773 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); | |
| 670 | + SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp); | |
| 774 | 671 | |
| 775 | 672 | #ifdef DOSTORESTATE16 |
| 776 | 673 | SHA1_STORE_STATE(16) |
| 777 | 674 | #endif |
| 778 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); | |
| 675 | + SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp); | |
| 779 | 676 | |
| 780 | 677 | #ifdef DOSTORESTATE17 |
| 781 | 678 | SHA1_STORE_STATE(17) |
| 782 | 679 | #endif |
| 783 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); | |
| 680 | + SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp); | |
| 784 | 681 | |
| 785 | 682 | #ifdef DOSTORESTATE18 |
| 786 | 683 | SHA1_STORE_STATE(18) |
| 787 | 684 | #endif |
| 788 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); | |
| 685 | + SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp); | |
| 789 | 686 | |
| 790 | 687 | #ifdef DOSTORESTATE19 |
| 791 | 688 | SHA1_STORE_STATE(19) |
| 792 | 689 | #endif |
| 793 | - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); | |
| 690 | + SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp); | |
| 794 | 691 | |
| 795 | 692 | |
| 796 | 693 | |
| 797 | 694 | #ifdef DOSTORESTATE20 |
| 798 | 695 | SHA1_STORE_STATE(20) |
| 799 | 696 | #endif |
| 800 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); | |
| 697 | + SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp); | |
| 801 | 698 | |
| 802 | 699 | #ifdef DOSTORESTATE21 |
| 803 | 700 | SHA1_STORE_STATE(21) |
| 804 | 701 | #endif |
| 805 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); | |
| 702 | + SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp); | |
| 806 | 703 | |
| 807 | 704 | #ifdef DOSTORESTATE22 |
| 808 | 705 | SHA1_STORE_STATE(22) |
| 809 | 706 | #endif |
| 810 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); | |
| 707 | + SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp); | |
| 811 | 708 | |
| 812 | 709 | #ifdef DOSTORESTATE23 |
| 813 | 710 | SHA1_STORE_STATE(23) |
| 814 | 711 | #endif |
| 815 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); | |
| 712 | + SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp); | |
| 816 | 713 | |
| 817 | 714 | #ifdef DOSTORESTATE24 |
| 818 | 715 | SHA1_STORE_STATE(24) |
| 819 | 716 | #endif |
| 820 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); | |
| 717 | + SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp); | |
| 821 | 718 | |
| 822 | 719 | #ifdef DOSTORESTATE25 |
| 823 | 720 | SHA1_STORE_STATE(25) |
| 824 | 721 | #endif |
| 825 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); | |
| 722 | + SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp); | |
| 826 | 723 | |
| 827 | 724 | #ifdef DOSTORESTATE26 |
| 828 | 725 | SHA1_STORE_STATE(26) |
| 829 | 726 | #endif |
| 830 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); | |
| 727 | + SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp); | |
| 831 | 728 | |
| 832 | 729 | #ifdef DOSTORESTATE27 |
| 833 | 730 | SHA1_STORE_STATE(27) |
| 834 | 731 | #endif |
| 835 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); | |
| 732 | + SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp); | |
| 836 | 733 | |
| 837 | 734 | #ifdef DOSTORESTATE28 |
| 838 | 735 | SHA1_STORE_STATE(28) |
| 839 | 736 | #endif |
| 840 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); | |
| 737 | + SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp); | |
| 841 | 738 | |
| 842 | 739 | #ifdef DOSTORESTATE29 |
| 843 | 740 | SHA1_STORE_STATE(29) |
| 844 | 741 | #endif |
| 845 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); | |
| 742 | + SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp); | |
| 846 | 743 | |
| 847 | 744 | #ifdef DOSTORESTATE30 |
| 848 | 745 | SHA1_STORE_STATE(30) |
| 849 | 746 | #endif |
| 850 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); | |
| 747 | + SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp); | |
| 851 | 748 | |
| 852 | 749 | #ifdef DOSTORESTATE31 |
| 853 | 750 | SHA1_STORE_STATE(31) |
| 854 | 751 | #endif |
| 855 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); | |
| 752 | + SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp); | |
| 856 | 753 | |
| 857 | 754 | #ifdef DOSTORESTATE32 |
| 858 | 755 | SHA1_STORE_STATE(32) |
| 859 | 756 | #endif |
| 860 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); | |
| 757 | + SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp); | |
| 861 | 758 | |
| 862 | 759 | #ifdef DOSTORESTATE33 |
| 863 | 760 | SHA1_STORE_STATE(33) |
| 864 | 761 | #endif |
| 865 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); | |
| 762 | + SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp); | |
| 866 | 763 | |
| 867 | 764 | #ifdef DOSTORESTATE34 |
| 868 | 765 | SHA1_STORE_STATE(34) |
| 869 | 766 | #endif |
| 870 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); | |
| 767 | + SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp); | |
| 871 | 768 | |
| 872 | 769 | #ifdef DOSTORESTATE35 |
| 873 | 770 | SHA1_STORE_STATE(35) |
| 874 | 771 | #endif |
| 875 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); | |
| 772 | + SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp); | |
| 876 | 773 | |
| 877 | 774 | #ifdef DOSTORESTATE36 |
| 878 | 775 | SHA1_STORE_STATE(36) |
| 879 | 776 | #endif |
| 880 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); | |
| 777 | + SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp); | |
| 881 | 778 | |
| 882 | 779 | #ifdef DOSTORESTATE37 |
| 883 | 780 | SHA1_STORE_STATE(37) |
| 884 | 781 | #endif |
| 885 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); | |
| 782 | + SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp); | |
| 886 | 783 | |
| 887 | 784 | #ifdef DOSTORESTATE38 |
| 888 | 785 | SHA1_STORE_STATE(38) |
| 889 | 786 | #endif |
| 890 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); | |
| 787 | + SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp); | |
| 891 | 788 | |
| 892 | 789 | #ifdef DOSTORESTATE39 |
| 893 | 790 | SHA1_STORE_STATE(39) |
| 894 | 791 | #endif |
| 895 | - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); | |
| 792 | + SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp); | |
| 896 | 793 | |
| 897 | 794 | |
| 898 | 795 | |
| 899 | 796 | #ifdef DOSTORESTATE40 |
| 900 | 797 | SHA1_STORE_STATE(40) |
| 901 | 798 | #endif |
| 902 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); | |
| 799 | + SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp); | |
| 903 | 800 | |
| 904 | 801 | #ifdef DOSTORESTATE41 |
| 905 | 802 | SHA1_STORE_STATE(41) |
| 906 | 803 | #endif |
| 907 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); | |
| 804 | + SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp); | |
| 908 | 805 | |
| 909 | 806 | #ifdef DOSTORESTATE42 |
| 910 | 807 | SHA1_STORE_STATE(42) |
| 911 | 808 | #endif |
| 912 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); | |
| 809 | + SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp); | |
| 913 | 810 | |
| 914 | 811 | #ifdef DOSTORESTATE43 |
| 915 | 812 | SHA1_STORE_STATE(43) |
| 916 | 813 | #endif |
| 917 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); | |
| 814 | + SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp); | |
| 918 | 815 | |
| 919 | 816 | #ifdef DOSTORESTATE44 |
| 920 | 817 | SHA1_STORE_STATE(44) |
| 921 | 818 | #endif |
| 922 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); | |
| 819 | + SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp); | |
| 923 | 820 | |
| 924 | 821 | #ifdef DOSTORESTATE45 |
| 925 | 822 | SHA1_STORE_STATE(45) |
| 926 | 823 | #endif |
| 927 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); | |
| 824 | + SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp); | |
| 928 | 825 | |
| 929 | 826 | #ifdef DOSTORESTATE46 |
| 930 | 827 | SHA1_STORE_STATE(46) |
| 931 | 828 | #endif |
| 932 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); | |
| 829 | + SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp); | |
| 933 | 830 | |
| 934 | 831 | #ifdef DOSTORESTATE47 |
| 935 | 832 | SHA1_STORE_STATE(47) |
| 936 | 833 | #endif |
| 937 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); | |
| 834 | + SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp); | |
| 938 | 835 | |
| 939 | 836 | #ifdef DOSTORESTATE48 |
| 940 | 837 | SHA1_STORE_STATE(48) |
| 941 | 838 | #endif |
| 942 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); | |
| 839 | + SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp); | |
| 943 | 840 | |
| 944 | 841 | #ifdef DOSTORESTATE49 |
| 945 | 842 | SHA1_STORE_STATE(49) |
| 946 | 843 | #endif |
| 947 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); | |
| 844 | + SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp); | |
| 948 | 845 | |
| 949 | 846 | #ifdef DOSTORESTATE50 |
| 950 | 847 | SHA1_STORE_STATE(50) |
| 951 | 848 | #endif |
| 952 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); | |
| 849 | + SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp); | |
| 953 | 850 | |
| 954 | 851 | #ifdef DOSTORESTATE51 |
| 955 | 852 | SHA1_STORE_STATE(51) |
| 956 | 853 | #endif |
| 957 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); | |
| 854 | + SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp); | |
| 958 | 855 | |
| 959 | 856 | #ifdef DOSTORESTATE52 |
| 960 | 857 | SHA1_STORE_STATE(52) |
| 961 | 858 | #endif |
| 962 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); | |
| 859 | + SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp); | |
| 963 | 860 | |
| 964 | 861 | #ifdef DOSTORESTATE53 |
| 965 | 862 | SHA1_STORE_STATE(53) |
| 966 | 863 | #endif |
| 967 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); | |
| 864 | + SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp); | |
| 968 | 865 | |
| 969 | 866 | #ifdef DOSTORESTATE54 |
| 970 | 867 | SHA1_STORE_STATE(54) |
| 971 | 868 | #endif |
| 972 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); | |
| 869 | + SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp); | |
| 973 | 870 | |
| 974 | 871 | #ifdef DOSTORESTATE55 |
| 975 | 872 | SHA1_STORE_STATE(55) |
| 976 | 873 | #endif |
| 977 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); | |
| 874 | + SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp); | |
| 978 | 875 | |
| 979 | 876 | #ifdef DOSTORESTATE56 |
| 980 | 877 | SHA1_STORE_STATE(56) |
| 981 | 878 | #endif |
| 982 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); | |
| 879 | + SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp); | |
| 983 | 880 | |
| 984 | 881 | #ifdef DOSTORESTATE57 |
| 985 | 882 | SHA1_STORE_STATE(57) |
| 986 | 883 | #endif |
| 987 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); | |
| 884 | + SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp); | |
| 988 | 885 | |
| 989 | 886 | #ifdef DOSTORESTATE58 |
| 990 | 887 | SHA1_STORE_STATE(58) |
| 991 | 888 | #endif |
| 992 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); | |
| 889 | + SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp); | |
| 993 | 890 | |
| 994 | 891 | #ifdef DOSTORESTATE59 |
| 995 | 892 | SHA1_STORE_STATE(59) |
| 996 | 893 | #endif |
| 997 | - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); | |
| 894 | + SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp); | |
| 998 | 895 | |
| 999 | 896 | |
| 1000 | 897 | |
| 1001 | 898 | |
| 1002 | 899 | #ifdef DOSTORESTATE60 |
| 1003 | 900 | SHA1_STORE_STATE(60) |
| 1004 | 901 | #endif |
| 1005 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); | |
| 902 | + SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp); | |
| 1006 | 903 | |
| 1007 | 904 | #ifdef DOSTORESTATE61 |
| 1008 | 905 | SHA1_STORE_STATE(61) |
| 1009 | 906 | #endif |
| 1010 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); | |
| 907 | + SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp); | |
| 1011 | 908 | |
| 1012 | 909 | #ifdef DOSTORESTATE62 |
| 1013 | 910 | SHA1_STORE_STATE(62) |
| 1014 | 911 | #endif |
| 1015 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); | |
| 912 | + SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp); | |
| 1016 | 913 | |
| 1017 | 914 | #ifdef DOSTORESTATE63 |
| 1018 | 915 | SHA1_STORE_STATE(63) |
| 1019 | 916 | #endif |
| 1020 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); | |
| 917 | + SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp); | |
| 1021 | 918 | |
| 1022 | 919 | #ifdef DOSTORESTATE64 |
| 1023 | 920 | SHA1_STORE_STATE(64) |
| 1024 | 921 | #endif |
| 1025 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); | |
| 922 | + SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp); | |
| 1026 | 923 | |
| 1027 | 924 | #ifdef DOSTORESTATE65 |
| 1028 | 925 | SHA1_STORE_STATE(65) |
| 1029 | 926 | #endif |
| 1030 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); | |
| 927 | + SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp); | |
| 1031 | 928 | |
| 1032 | 929 | #ifdef DOSTORESTATE66 |
| 1033 | 930 | SHA1_STORE_STATE(66) |
| 1034 | 931 | #endif |
| 1035 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); | |
| 932 | + SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp); | |
| 1036 | 933 | |
| 1037 | 934 | #ifdef DOSTORESTATE67 |
| 1038 | 935 | SHA1_STORE_STATE(67) |
| 1039 | 936 | #endif |
| 1040 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); | |
| 937 | + SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp); | |
| 1041 | 938 | |
| 1042 | 939 | #ifdef DOSTORESTATE68 |
| 1043 | 940 | SHA1_STORE_STATE(68) |
| 1044 | 941 | #endif |
| 1045 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); | |
| 942 | + SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp); | |
| 1046 | 943 | |
| 1047 | 944 | #ifdef DOSTORESTATE69 |
| 1048 | 945 | SHA1_STORE_STATE(69) |
| 1049 | 946 | #endif |
| 1050 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); | |
| 947 | + SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp); | |
| 1051 | 948 | |
| 1052 | 949 | #ifdef DOSTORESTATE70 |
| 1053 | 950 | SHA1_STORE_STATE(70) |
| 1054 | 951 | #endif |
| 1055 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); | |
| 952 | + SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp); | |
| 1056 | 953 | |
| 1057 | 954 | #ifdef DOSTORESTATE71 |
| 1058 | 955 | SHA1_STORE_STATE(71) |
| 1059 | 956 | #endif |
| 1060 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); | |
| 957 | + SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp); | |
| 1061 | 958 | |
| 1062 | 959 | #ifdef DOSTORESTATE72 |
| 1063 | 960 | SHA1_STORE_STATE(72) |
| 1064 | 961 | #endif |
| 1065 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); | |
| 962 | + SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp); | |
| 1066 | 963 | |
| 1067 | 964 | #ifdef DOSTORESTATE73 |
| 1068 | 965 | SHA1_STORE_STATE(73) |
| 1069 | 966 | #endif |
| 1070 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); | |
| 967 | + SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp); | |
| 1071 | 968 | |
| 1072 | 969 | #ifdef DOSTORESTATE74 |
| 1073 | 970 | SHA1_STORE_STATE(74) |
| 1074 | 971 | #endif |
| 1075 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); | |
| 972 | + SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp); | |
| 1076 | 973 | |
| 1077 | 974 | #ifdef DOSTORESTATE75 |
| 1078 | 975 | SHA1_STORE_STATE(75) |
| 1079 | 976 | #endif |
| 1080 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); | |
| 977 | + SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp); | |
| 1081 | 978 | |
| 1082 | 979 | #ifdef DOSTORESTATE76 |
| 1083 | 980 | SHA1_STORE_STATE(76) |
| 1084 | 981 | #endif |
| 1085 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); | |
| 982 | + SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp); | |
| 1086 | 983 | |
| 1087 | 984 | #ifdef DOSTORESTATE77 |
| 1088 | 985 | SHA1_STORE_STATE(77) |
| 1089 | 986 | #endif |
| 1090 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); | |
| 987 | + SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp); | |
| 1091 | 988 | |
| 1092 | 989 | #ifdef DOSTORESTATE78 |
| 1093 | 990 | SHA1_STORE_STATE(78) |
| 1094 | 991 | #endif |
| 1095 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); | |
| 992 | + SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp); | |
| 1096 | 993 | |
| 1097 | 994 | #ifdef DOSTORESTATE79 |
| 1098 | 995 | SHA1_STORE_STATE(79) |
| 1099 | 996 | #endif |
| 1100 | - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); | |
| 997 | + SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp); | |
| 1101 | 998 | |
| 1102 | 999 | |
| 1103 | 1000 | |
| 1104 | 1001 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 1105 | 1002 | } |
| @@ -1362,11 +1259,11 @@ | ||
| 1362 | 1259 | SHA1_RECOMPRESS(76) |
| 1363 | 1260 | SHA1_RECOMPRESS(77) |
| 1364 | 1261 | SHA1_RECOMPRESS(78) |
| 1365 | 1262 | SHA1_RECOMPRESS(79) |
| 1366 | 1263 | |
| 1367 | -sha1_recompression_type sha1_recompression_step[80] = | |
| 1264 | +static const sha1_recompression_type sha1_recompression_step[80] = | |
| 1368 | 1265 | { |
| 1369 | 1266 | 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, |
| 1370 | 1267 | 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, |
| 1371 | 1268 | 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, |
| 1372 | 1269 | 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, |
| @@ -1374,15 +1271,11 @@ | ||
| 1374 | 1271 | 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, |
| 1375 | 1272 | 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, |
| 1376 | 1273 | 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, |
| 1377 | 1274 | }; |
| 1378 | 1275 | |
| 1379 | - | |
| 1380 | - | |
| 1381 | - | |
| 1382 | - | |
| 1383 | -void sha1_process(SHA1_CTX* ctx, const uint32_t block[16]) | |
| 1276 | +static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16]) | |
| 1384 | 1277 | { |
| 1385 | 1278 | unsigned i, j; |
| 1386 | 1279 | uint32_t ubc_dv_mask[DVMASKSIZE]; |
| 1387 | 1280 | uint32_t ihvtmp[5]; |
| 1388 | 1281 | for (i=0; i < DVMASKSIZE; ++i) |
| @@ -1390,31 +1283,33 @@ | ||
| 1390 | 1283 | ctx->ihv1[0] = ctx->ihv[0]; |
| 1391 | 1284 | ctx->ihv1[1] = ctx->ihv[1]; |
| 1392 | 1285 | ctx->ihv1[2] = ctx->ihv[2]; |
| 1393 | 1286 | ctx->ihv1[3] = ctx->ihv[3]; |
| 1394 | 1287 | ctx->ihv1[4] = ctx->ihv[4]; |
| 1395 | - memcpy(ctx->m1, block, 64); | |
| 1396 | - sha1_message_expansion(ctx->m1); | |
| 1397 | - if (ctx->detect_coll && ctx->ubc_check) | |
| 1398 | - { | |
| 1399 | - ubc_check(ctx->m1, ubc_dv_mask); | |
| 1400 | - } | |
| 1401 | - sha1_compression_states(ctx->ihv, ctx->m1, ctx->states); | |
| 1288 | + | |
| 1289 | + sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states); | |
| 1290 | + | |
| 1402 | 1291 | if (ctx->detect_coll) |
| 1403 | 1292 | { |
| 1293 | + if (ctx->ubc_check) | |
| 1294 | + { | |
| 1295 | + ubc_check(ctx->m1, ubc_dv_mask); | |
| 1296 | + } | |
| 1297 | + | |
| 1404 | 1298 | for (i = 0; sha1_dvs[i].dvType != 0; ++i) |
| 1405 | 1299 | { |
| 1406 | 1300 | if ((0 == ctx->ubc_check) || (((uint32_t)(1) << sha1_dvs[i].maskb) & ubc_dv_mask[sha1_dvs[i].maski])) |
| 1407 | 1301 | { |
| 1408 | 1302 | for (j = 0; j < 80; ++j) |
| 1409 | 1303 | ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; |
| 1410 | 1304 | (sha1_recompression_step[sha1_dvs[i].testt])(ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); |
| 1411 | - /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */ | |
| 1305 | + // to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 | |
| 1412 | 1306 | 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]) |
| 1413 | 1307 | || (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])) |
| 1414 | 1308 | { |
| 1415 | 1309 | ctx->found_collision = 1; |
| 1310 | + | |
| 1416 | 1311 | if (ctx->callback != NULL) |
| 1417 | 1312 | ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2); |
| 1418 | 1313 | |
| 1419 | 1314 | if (ctx->safe_hash) |
| 1420 | 1315 | { |
| @@ -1427,24 +1322,12 @@ | ||
| 1427 | 1322 | } |
| 1428 | 1323 | } |
| 1429 | 1324 | } |
| 1430 | 1325 | } |
| 1431 | 1326 | |
| 1432 | -void swap_bytes(uint32_t val[16]) | |
| 1433 | -{ | |
| 1434 | - unsigned i; | |
| 1435 | - for (i = 0; i < 16; ++i) | |
| 1436 | - { | |
| 1437 | - val[i] = ((val[i] << 8) & 0xFF00FF00) | ((val[i] >> 8) & 0xFF00FF); | |
| 1438 | - val[i] = (val[i] << 16) | (val[i] >> 16); | |
| 1439 | - } | |
| 1440 | -} | |
| 1441 | - | |
| 1442 | 1327 | void SHA1DCInit(SHA1_CTX* ctx) |
| 1443 | 1328 | { |
| 1444 | - static const union { unsigned char bytes[4]; uint32_t value; } endianness = { { 0, 1, 2, 3 } }; | |
| 1445 | - static const uint32_t littleendian = 0x03020100; | |
| 1446 | 1329 | ctx->total = 0; |
| 1447 | 1330 | ctx->ihv[0] = 0x67452301; |
| 1448 | 1331 | ctx->ihv[1] = 0xEFCDAB89; |
| 1449 | 1332 | ctx->ihv[2] = 0x98BADCFE; |
| 1450 | 1333 | ctx->ihv[3] = 0x10325476; |
| @@ -1452,52 +1335,13 @@ | ||
| 1452 | 1335 | ctx->found_collision = 0; |
| 1453 | 1336 | ctx->safe_hash = 1; |
| 1454 | 1337 | ctx->ubc_check = 1; |
| 1455 | 1338 | ctx->detect_coll = 1; |
| 1456 | 1339 | ctx->reduced_round_coll = 0; |
| 1457 | - ctx->bigendian = (endianness.value != littleendian); | |
| 1458 | 1340 | ctx->callback = NULL; |
| 1459 | 1341 | } |
| 1460 | 1342 | |
| 1461 | -void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash) | |
| 1462 | -{ | |
| 1463 | - if (safehash) | |
| 1464 | - ctx->safe_hash = 1; | |
| 1465 | - else | |
| 1466 | - ctx->safe_hash = 0; | |
| 1467 | -} | |
| 1468 | - | |
| 1469 | - | |
| 1470 | -void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check) | |
| 1471 | -{ | |
| 1472 | - if (ubc_check) | |
| 1473 | - ctx->ubc_check = 1; | |
| 1474 | - else | |
| 1475 | - ctx->ubc_check = 0; | |
| 1476 | -} | |
| 1477 | - | |
| 1478 | -void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll) | |
| 1479 | -{ | |
| 1480 | - if (detect_coll) | |
| 1481 | - ctx->detect_coll = 1; | |
| 1482 | - else | |
| 1483 | - ctx->detect_coll = 0; | |
| 1484 | -} | |
| 1485 | - | |
| 1486 | -void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll) | |
| 1487 | -{ | |
| 1488 | - if (reduced_round_coll) | |
| 1489 | - ctx->reduced_round_coll = 1; | |
| 1490 | - else | |
| 1491 | - ctx->reduced_round_coll = 0; | |
| 1492 | -} | |
| 1493 | - | |
| 1494 | -void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback) | |
| 1495 | -{ | |
| 1496 | - ctx->callback = callback; | |
| 1497 | -} | |
| 1498 | - | |
| 1499 | 1343 | void SHA1DCUpdate(SHA1_CTX* ctx, const unsigned char* buf, unsigned len) |
| 1500 | 1344 | { |
| 1501 | 1345 | unsigned left, fill; |
| 1502 | 1346 | if (len == 0) |
| 1503 | 1347 | return; |
| @@ -1507,28 +1351,19 @@ | ||
| 1507 | 1351 | |
| 1508 | 1352 | if (left && len >= fill) |
| 1509 | 1353 | { |
| 1510 | 1354 | ctx->total += fill; |
| 1511 | 1355 | memcpy(ctx->buffer + left, buf, fill); |
| 1512 | - if (!ctx->bigendian) | |
| 1513 | - swap_bytes((uint32_t*)(ctx->buffer)); | |
| 1514 | 1356 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1515 | 1357 | buf += fill; |
| 1516 | 1358 | len -= fill; |
| 1517 | 1359 | left = 0; |
| 1518 | 1360 | } |
| 1519 | 1361 | while (len >= 64) |
| 1520 | 1362 | { |
| 1521 | 1363 | ctx->total += 64; |
| 1522 | - if (!ctx->bigendian) | |
| 1523 | - { | |
| 1524 | - memcpy(ctx->buffer, buf, 64); | |
| 1525 | - swap_bytes((uint32_t*)(ctx->buffer)); | |
| 1526 | - sha1_process(ctx, (uint32_t*)(ctx->buffer)); | |
| 1527 | - } | |
| 1528 | - else | |
| 1529 | - sha1_process(ctx, (uint32_t*)(buf)); | |
| 1364 | + sha1_process(ctx, (uint32_t*)(buf)); | |
| 1530 | 1365 | buf += 64; |
| 1531 | 1366 | len -= 64; |
| 1532 | 1367 | } |
| 1533 | 1368 | if (len > 0) |
| 1534 | 1369 | { |
| @@ -1560,12 +1395,10 @@ | ||
| 1560 | 1395 | ctx->buffer[59] = (unsigned char)(total >> 32); |
| 1561 | 1396 | ctx->buffer[60] = (unsigned char)(total >> 24); |
| 1562 | 1397 | ctx->buffer[61] = (unsigned char)(total >> 16); |
| 1563 | 1398 | ctx->buffer[62] = (unsigned char)(total >> 8); |
| 1564 | 1399 | ctx->buffer[63] = (unsigned char)(total); |
| 1565 | - if (!ctx->bigendian) | |
| 1566 | - swap_bytes((uint32_t*)(ctx->buffer)); | |
| 1567 | 1400 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1568 | 1401 | output[0] = (unsigned char)(ctx->ihv[0] >> 24); |
| 1569 | 1402 | output[1] = (unsigned char)(ctx->ihv[0] >> 16); |
| 1570 | 1403 | output[2] = (unsigned char)(ctx->ihv[0] >> 8); |
| 1571 | 1404 | output[3] = (unsigned char)(ctx->ihv[0]); |
| 1572 | 1405 |
| --- src/sha1hard.c | |
| +++ src/sha1hard.c | |
| @@ -2,13 +2,13 @@ | |
| 2 | ** The code in this file is the concatenation of several files |
| 3 | ** copied out of |
| 4 | ** |
| 5 | ** https://github.com/cr-marcstevens/sha1collisiondetection |
| 6 | ** |
| 7 | ** The copy was made on 2017-03-01. Some minor formatting changes |
| 8 | ** were made but otherwise the code is unchanged. All |
| 9 | ** original copyright claims are preserved. |
| 10 | ** |
| 11 | ** The code here implements a version of the SHA1 hash function that |
| 12 | ** is not vulnerable to crypto-analysis based attacks. If an input |
| 13 | ** is detected that looks like it might have been the result of a |
| 14 | ** crypto-analysis attack, then the hash is perturbed to generate a |
| @@ -15,10 +15,12 @@ | |
| 15 | ** completely different hash. The authors claim that the chance of |
| 16 | ** a false-positive is vanishingly small. |
| 17 | */ |
| 18 | /*MAKEHEADERS-STOP*/ |
| 19 | #include "config.h" |
| 20 | /*************** File: lib/sha1.c ****************/ |
| 21 | /*** |
| 22 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow ([email protected]) |
| 23 | * Distributed under the MIT Software License. |
| 24 | * See accompanying file LICENSE.txt or copy at |
| @@ -65,94 +67,70 @@ | |
| 65 | #define DVMASKSIZE 1 |
| 66 | typedef struct { int dvType; int dvK; int dvB; int testt; int maski; int maskb; uint32_t dm[80]; } dv_info_t; |
| 67 | #define DOSTORESTATE58 |
| 68 | #define DOSTORESTATE65 |
| 69 | typedef void(*sha1_recompression_type)(uint32_t*, uint32_t*, const uint32_t*, const uint32_t*); |
| 70 | void sha1_message_expansion(uint32_t W[80]); |
| 71 | void sha1_compression(uint32_t ihv[5], const uint32_t m[16]); |
| 72 | void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]); |
| 73 | void sha1_compression_states(uint32_t ihv[5], const uint32_t W[80], uint32_t states[80][5]); |
| 74 | extern sha1_recompression_type sha1_recompression_step[80]; |
| 75 | typedef void(*collision_block_callback)(uint64_t, const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*); |
| 76 | typedef struct { |
| 77 | uint64_t total; |
| 78 | uint32_t ihv[5]; |
| 79 | unsigned char buffer[64]; |
| 80 | int bigendian; |
| 81 | int found_collision; |
| 82 | int safe_hash; |
| 83 | int detect_coll; |
| 84 | int ubc_check; |
| 85 | int reduced_round_coll; |
| 86 | collision_block_callback callback; |
| 87 | |
| 88 | uint32_t ihv1[5]; |
| 89 | uint32_t ihv2[5]; |
| 90 | uint32_t m1[80]; |
| 91 | uint32_t m2[80]; |
| 92 | uint32_t states[80][5]; |
| 93 | } SHA1_CTX; |
| 94 | |
| 95 | /******************** File: lib/ubc_check.c **************************/ |
| 96 | /*** |
| 97 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow <[email protected]> |
| 98 | * Distributed under the MIT Software License. |
| 99 | * See accompanying file LICENSE.txt or copy at |
| 100 | * https://opensource.org/licenses/MIT |
| 101 | ***/ |
| 102 | |
| 103 | /* |
| 104 | ** this file was generated by the 'parse_bitrel' program in the tools section |
| 105 | ** using the data files from directory 'tools/data/3565' |
| 106 | ** |
| 107 | ** sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check |
| 108 | ** dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) |
| 109 | ** dm[80] is the expanded message block XOR-difference defined by the DV |
| 110 | ** testt is the step to do the recompression from for collision detection |
| 111 | ** maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check |
| 112 | ** |
| 113 | ** ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs |
| 114 | ** it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met |
| 115 | ** thus one needs to do the recompression check for each DV that has its bit set |
| 116 | ** |
| 117 | ** ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded |
| 118 | ** a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c |
| 119 | ** ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section |
| 120 | */ |
| 121 | |
| 122 | static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; |
| 123 | static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; |
| 124 | static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; |
| 125 | static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; |
| 126 | static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; |
| 127 | static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; |
| 128 | static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; |
| 129 | static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; |
| 130 | static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; |
| 131 | static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; |
| 132 | static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; |
| 133 | static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; |
| 134 | static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; |
| 135 | static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; |
| 136 | static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; |
| 137 | static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; |
| 138 | static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; |
| 139 | static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; |
| 140 | static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; |
| 141 | static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; |
| 142 | static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; |
| 143 | static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; |
| 144 | static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; |
| 145 | static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; |
| 146 | static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; |
| 147 | static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; |
| 148 | static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; |
| 149 | static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; |
| 150 | static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; |
| 151 | static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; |
| 152 | static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; |
| 153 | static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; |
| 154 | |
| 155 | dv_info_t sha1_dvs[] = |
| 156 | { |
| 157 | {1,43,0,58,0,0, { 0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161,0x80000599 } } |
| 158 | , {1,44,0,58,0,1, { 0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161 } } |
| @@ -186,11 +164,12 @@ | |
| 186 | , {2,54,0,65,0,29, { 0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107 } } |
| 187 | , {2,55,0,65,0,30, { 0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b } } |
| 188 | , {2,56,0,65,0,31, { 0x2600001a,0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046 } } |
| 189 | , {0,0,0,0,0,0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} |
| 190 | }; |
| 191 | void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) |
| 192 | { |
| 193 | uint32_t mask = ~((uint32_t)(0)); |
| 194 | mask &= (((((W[44]^W[45])>>29)&1)-1) | ~(DV_I_48_0_bit|DV_I_51_0_bit|DV_I_52_0_bit|DV_II_45_0_bit|DV_II_46_0_bit|DV_II_50_0_bit|DV_II_51_0_bit)); |
| 195 | mask &= (((((W[49]^W[50])>>29)&1)-1) | ~(DV_I_46_0_bit|DV_II_45_0_bit|DV_II_50_0_bit|DV_II_51_0_bit|DV_II_55_0_bit|DV_II_56_0_bit)); |
| 196 | mask &= (((((W[48]^W[49])>>29)&1)-1) | ~(DV_I_45_0_bit|DV_I_52_0_bit|DV_II_49_0_bit|DV_II_50_0_bit|DV_II_54_0_bit|DV_II_55_0_bit)); |
| @@ -454,17 +433,29 @@ | |
| 454 | dvmask[0]=mask; |
| 455 | } |
| 456 | /******************** End Of File: lib/ubc_check.c *******************/ |
| 457 | /******************** Continue with: lib/sha1.c **********************/ |
| 458 | |
| 459 | |
| 460 | #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n)))) |
| 461 | #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n)))) |
| 462 | |
| 463 | #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d)))) |
| 464 | #define sha1_f2(b,c,d) ((b)^(c)^(d)) |
| 465 | #define sha1_f3(b,c,d) (((b) & ((c)|(d))) | ((c)&(d))) |
| 466 | #define sha1_f4(b,c,d) ((b)^(c)^(d)) |
| 467 | |
| 468 | #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ |
| 469 | { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); } |
| 470 | #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ |
| @@ -480,124 +471,30 @@ | |
| 480 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; } |
| 481 | #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ |
| 482 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; } |
| 483 | #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ |
| 484 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; } |
| 485 | |
| 486 | #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; |
| 487 | |
| 488 | |
| 489 | |
| 490 | void sha1_message_expansion(uint32_t W[80]) |
| 491 | { |
| 492 | unsigned i; |
| 493 | for (i = 16; i < 80; ++i) |
| 494 | W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); |
| 495 | } |
| 496 | |
| 497 | void sha1_compression(uint32_t ihv[5], const uint32_t m[16]) |
| 498 | { |
| 499 | uint32_t W[80]; |
| 500 | uint32_t a,b,c,d,e; |
| 501 | unsigned i; |
| 502 | |
| 503 | memcpy(W, m, 16 * 4); |
| 504 | for (i = 16; i < 80; ++i) |
| 505 | W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); |
| 506 | |
| 507 | a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4]; |
| 508 | |
| 509 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); |
| 510 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); |
| 511 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); |
| 512 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); |
| 513 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); |
| 514 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); |
| 515 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); |
| 516 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); |
| 517 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); |
| 518 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); |
| 519 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); |
| 520 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); |
| 521 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); |
| 522 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); |
| 523 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); |
| 524 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); |
| 525 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); |
| 526 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); |
| 527 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); |
| 528 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); |
| 529 | |
| 530 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); |
| 531 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); |
| 532 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); |
| 533 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); |
| 534 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); |
| 535 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); |
| 536 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); |
| 537 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); |
| 538 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); |
| 539 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); |
| 540 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); |
| 541 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); |
| 542 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); |
| 543 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); |
| 544 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); |
| 545 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); |
| 546 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); |
| 547 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); |
| 548 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); |
| 549 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); |
| 550 | |
| 551 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); |
| 552 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); |
| 553 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); |
| 554 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); |
| 555 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); |
| 556 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); |
| 557 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); |
| 558 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); |
| 559 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); |
| 560 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); |
| 561 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); |
| 562 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); |
| 563 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); |
| 564 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); |
| 565 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); |
| 566 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); |
| 567 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); |
| 568 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); |
| 569 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); |
| 570 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); |
| 571 | |
| 572 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); |
| 573 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); |
| 574 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); |
| 575 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); |
| 576 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); |
| 577 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); |
| 578 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); |
| 579 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); |
| 580 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); |
| 581 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); |
| 582 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); |
| 583 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); |
| 584 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); |
| 585 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); |
| 586 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); |
| 587 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); |
| 588 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); |
| 589 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); |
| 590 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); |
| 591 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); |
| 592 | |
| 593 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | |
| 598 | void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) |
| 599 | { |
| 600 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 601 | |
| 602 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); |
| 603 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); |
| @@ -684,422 +581,422 @@ | |
| 684 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); |
| 685 | |
| 686 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | |
| 691 | void sha1_compression_states(uint32_t ihv[5], const uint32_t W[80], uint32_t states[80][5]) |
| 692 | { |
| 693 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 694 | |
| 695 | #ifdef DOSTORESTATE00 |
| 696 | SHA1_STORE_STATE(0) |
| 697 | #endif |
| 698 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); |
| 699 | |
| 700 | #ifdef DOSTORESTATE01 |
| 701 | SHA1_STORE_STATE(1) |
| 702 | #endif |
| 703 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); |
| 704 | |
| 705 | #ifdef DOSTORESTATE02 |
| 706 | SHA1_STORE_STATE(2) |
| 707 | #endif |
| 708 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); |
| 709 | |
| 710 | #ifdef DOSTORESTATE03 |
| 711 | SHA1_STORE_STATE(3) |
| 712 | #endif |
| 713 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); |
| 714 | |
| 715 | #ifdef DOSTORESTATE04 |
| 716 | SHA1_STORE_STATE(4) |
| 717 | #endif |
| 718 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); |
| 719 | |
| 720 | #ifdef DOSTORESTATE05 |
| 721 | SHA1_STORE_STATE(5) |
| 722 | #endif |
| 723 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); |
| 724 | |
| 725 | #ifdef DOSTORESTATE06 |
| 726 | SHA1_STORE_STATE(6) |
| 727 | #endif |
| 728 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); |
| 729 | |
| 730 | #ifdef DOSTORESTATE07 |
| 731 | SHA1_STORE_STATE(7) |
| 732 | #endif |
| 733 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); |
| 734 | |
| 735 | #ifdef DOSTORESTATE08 |
| 736 | SHA1_STORE_STATE(8) |
| 737 | #endif |
| 738 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); |
| 739 | |
| 740 | #ifdef DOSTORESTATE09 |
| 741 | SHA1_STORE_STATE(9) |
| 742 | #endif |
| 743 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); |
| 744 | |
| 745 | #ifdef DOSTORESTATE10 |
| 746 | SHA1_STORE_STATE(10) |
| 747 | #endif |
| 748 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); |
| 749 | |
| 750 | #ifdef DOSTORESTATE11 |
| 751 | SHA1_STORE_STATE(11) |
| 752 | #endif |
| 753 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); |
| 754 | |
| 755 | #ifdef DOSTORESTATE12 |
| 756 | SHA1_STORE_STATE(12) |
| 757 | #endif |
| 758 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); |
| 759 | |
| 760 | #ifdef DOSTORESTATE13 |
| 761 | SHA1_STORE_STATE(13) |
| 762 | #endif |
| 763 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); |
| 764 | |
| 765 | #ifdef DOSTORESTATE14 |
| 766 | SHA1_STORE_STATE(14) |
| 767 | #endif |
| 768 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); |
| 769 | |
| 770 | #ifdef DOSTORESTATE15 |
| 771 | SHA1_STORE_STATE(15) |
| 772 | #endif |
| 773 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); |
| 774 | |
| 775 | #ifdef DOSTORESTATE16 |
| 776 | SHA1_STORE_STATE(16) |
| 777 | #endif |
| 778 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); |
| 779 | |
| 780 | #ifdef DOSTORESTATE17 |
| 781 | SHA1_STORE_STATE(17) |
| 782 | #endif |
| 783 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); |
| 784 | |
| 785 | #ifdef DOSTORESTATE18 |
| 786 | SHA1_STORE_STATE(18) |
| 787 | #endif |
| 788 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); |
| 789 | |
| 790 | #ifdef DOSTORESTATE19 |
| 791 | SHA1_STORE_STATE(19) |
| 792 | #endif |
| 793 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); |
| 794 | |
| 795 | |
| 796 | |
| 797 | #ifdef DOSTORESTATE20 |
| 798 | SHA1_STORE_STATE(20) |
| 799 | #endif |
| 800 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); |
| 801 | |
| 802 | #ifdef DOSTORESTATE21 |
| 803 | SHA1_STORE_STATE(21) |
| 804 | #endif |
| 805 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); |
| 806 | |
| 807 | #ifdef DOSTORESTATE22 |
| 808 | SHA1_STORE_STATE(22) |
| 809 | #endif |
| 810 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); |
| 811 | |
| 812 | #ifdef DOSTORESTATE23 |
| 813 | SHA1_STORE_STATE(23) |
| 814 | #endif |
| 815 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); |
| 816 | |
| 817 | #ifdef DOSTORESTATE24 |
| 818 | SHA1_STORE_STATE(24) |
| 819 | #endif |
| 820 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); |
| 821 | |
| 822 | #ifdef DOSTORESTATE25 |
| 823 | SHA1_STORE_STATE(25) |
| 824 | #endif |
| 825 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); |
| 826 | |
| 827 | #ifdef DOSTORESTATE26 |
| 828 | SHA1_STORE_STATE(26) |
| 829 | #endif |
| 830 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); |
| 831 | |
| 832 | #ifdef DOSTORESTATE27 |
| 833 | SHA1_STORE_STATE(27) |
| 834 | #endif |
| 835 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); |
| 836 | |
| 837 | #ifdef DOSTORESTATE28 |
| 838 | SHA1_STORE_STATE(28) |
| 839 | #endif |
| 840 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); |
| 841 | |
| 842 | #ifdef DOSTORESTATE29 |
| 843 | SHA1_STORE_STATE(29) |
| 844 | #endif |
| 845 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); |
| 846 | |
| 847 | #ifdef DOSTORESTATE30 |
| 848 | SHA1_STORE_STATE(30) |
| 849 | #endif |
| 850 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); |
| 851 | |
| 852 | #ifdef DOSTORESTATE31 |
| 853 | SHA1_STORE_STATE(31) |
| 854 | #endif |
| 855 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); |
| 856 | |
| 857 | #ifdef DOSTORESTATE32 |
| 858 | SHA1_STORE_STATE(32) |
| 859 | #endif |
| 860 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); |
| 861 | |
| 862 | #ifdef DOSTORESTATE33 |
| 863 | SHA1_STORE_STATE(33) |
| 864 | #endif |
| 865 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); |
| 866 | |
| 867 | #ifdef DOSTORESTATE34 |
| 868 | SHA1_STORE_STATE(34) |
| 869 | #endif |
| 870 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); |
| 871 | |
| 872 | #ifdef DOSTORESTATE35 |
| 873 | SHA1_STORE_STATE(35) |
| 874 | #endif |
| 875 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); |
| 876 | |
| 877 | #ifdef DOSTORESTATE36 |
| 878 | SHA1_STORE_STATE(36) |
| 879 | #endif |
| 880 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); |
| 881 | |
| 882 | #ifdef DOSTORESTATE37 |
| 883 | SHA1_STORE_STATE(37) |
| 884 | #endif |
| 885 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); |
| 886 | |
| 887 | #ifdef DOSTORESTATE38 |
| 888 | SHA1_STORE_STATE(38) |
| 889 | #endif |
| 890 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); |
| 891 | |
| 892 | #ifdef DOSTORESTATE39 |
| 893 | SHA1_STORE_STATE(39) |
| 894 | #endif |
| 895 | HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); |
| 896 | |
| 897 | |
| 898 | |
| 899 | #ifdef DOSTORESTATE40 |
| 900 | SHA1_STORE_STATE(40) |
| 901 | #endif |
| 902 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); |
| 903 | |
| 904 | #ifdef DOSTORESTATE41 |
| 905 | SHA1_STORE_STATE(41) |
| 906 | #endif |
| 907 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); |
| 908 | |
| 909 | #ifdef DOSTORESTATE42 |
| 910 | SHA1_STORE_STATE(42) |
| 911 | #endif |
| 912 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); |
| 913 | |
| 914 | #ifdef DOSTORESTATE43 |
| 915 | SHA1_STORE_STATE(43) |
| 916 | #endif |
| 917 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); |
| 918 | |
| 919 | #ifdef DOSTORESTATE44 |
| 920 | SHA1_STORE_STATE(44) |
| 921 | #endif |
| 922 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); |
| 923 | |
| 924 | #ifdef DOSTORESTATE45 |
| 925 | SHA1_STORE_STATE(45) |
| 926 | #endif |
| 927 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); |
| 928 | |
| 929 | #ifdef DOSTORESTATE46 |
| 930 | SHA1_STORE_STATE(46) |
| 931 | #endif |
| 932 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); |
| 933 | |
| 934 | #ifdef DOSTORESTATE47 |
| 935 | SHA1_STORE_STATE(47) |
| 936 | #endif |
| 937 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); |
| 938 | |
| 939 | #ifdef DOSTORESTATE48 |
| 940 | SHA1_STORE_STATE(48) |
| 941 | #endif |
| 942 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); |
| 943 | |
| 944 | #ifdef DOSTORESTATE49 |
| 945 | SHA1_STORE_STATE(49) |
| 946 | #endif |
| 947 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); |
| 948 | |
| 949 | #ifdef DOSTORESTATE50 |
| 950 | SHA1_STORE_STATE(50) |
| 951 | #endif |
| 952 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); |
| 953 | |
| 954 | #ifdef DOSTORESTATE51 |
| 955 | SHA1_STORE_STATE(51) |
| 956 | #endif |
| 957 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); |
| 958 | |
| 959 | #ifdef DOSTORESTATE52 |
| 960 | SHA1_STORE_STATE(52) |
| 961 | #endif |
| 962 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); |
| 963 | |
| 964 | #ifdef DOSTORESTATE53 |
| 965 | SHA1_STORE_STATE(53) |
| 966 | #endif |
| 967 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); |
| 968 | |
| 969 | #ifdef DOSTORESTATE54 |
| 970 | SHA1_STORE_STATE(54) |
| 971 | #endif |
| 972 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); |
| 973 | |
| 974 | #ifdef DOSTORESTATE55 |
| 975 | SHA1_STORE_STATE(55) |
| 976 | #endif |
| 977 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); |
| 978 | |
| 979 | #ifdef DOSTORESTATE56 |
| 980 | SHA1_STORE_STATE(56) |
| 981 | #endif |
| 982 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); |
| 983 | |
| 984 | #ifdef DOSTORESTATE57 |
| 985 | SHA1_STORE_STATE(57) |
| 986 | #endif |
| 987 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); |
| 988 | |
| 989 | #ifdef DOSTORESTATE58 |
| 990 | SHA1_STORE_STATE(58) |
| 991 | #endif |
| 992 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); |
| 993 | |
| 994 | #ifdef DOSTORESTATE59 |
| 995 | SHA1_STORE_STATE(59) |
| 996 | #endif |
| 997 | HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | #ifdef DOSTORESTATE60 |
| 1003 | SHA1_STORE_STATE(60) |
| 1004 | #endif |
| 1005 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); |
| 1006 | |
| 1007 | #ifdef DOSTORESTATE61 |
| 1008 | SHA1_STORE_STATE(61) |
| 1009 | #endif |
| 1010 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); |
| 1011 | |
| 1012 | #ifdef DOSTORESTATE62 |
| 1013 | SHA1_STORE_STATE(62) |
| 1014 | #endif |
| 1015 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); |
| 1016 | |
| 1017 | #ifdef DOSTORESTATE63 |
| 1018 | SHA1_STORE_STATE(63) |
| 1019 | #endif |
| 1020 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); |
| 1021 | |
| 1022 | #ifdef DOSTORESTATE64 |
| 1023 | SHA1_STORE_STATE(64) |
| 1024 | #endif |
| 1025 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); |
| 1026 | |
| 1027 | #ifdef DOSTORESTATE65 |
| 1028 | SHA1_STORE_STATE(65) |
| 1029 | #endif |
| 1030 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); |
| 1031 | |
| 1032 | #ifdef DOSTORESTATE66 |
| 1033 | SHA1_STORE_STATE(66) |
| 1034 | #endif |
| 1035 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); |
| 1036 | |
| 1037 | #ifdef DOSTORESTATE67 |
| 1038 | SHA1_STORE_STATE(67) |
| 1039 | #endif |
| 1040 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); |
| 1041 | |
| 1042 | #ifdef DOSTORESTATE68 |
| 1043 | SHA1_STORE_STATE(68) |
| 1044 | #endif |
| 1045 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); |
| 1046 | |
| 1047 | #ifdef DOSTORESTATE69 |
| 1048 | SHA1_STORE_STATE(69) |
| 1049 | #endif |
| 1050 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); |
| 1051 | |
| 1052 | #ifdef DOSTORESTATE70 |
| 1053 | SHA1_STORE_STATE(70) |
| 1054 | #endif |
| 1055 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); |
| 1056 | |
| 1057 | #ifdef DOSTORESTATE71 |
| 1058 | SHA1_STORE_STATE(71) |
| 1059 | #endif |
| 1060 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); |
| 1061 | |
| 1062 | #ifdef DOSTORESTATE72 |
| 1063 | SHA1_STORE_STATE(72) |
| 1064 | #endif |
| 1065 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); |
| 1066 | |
| 1067 | #ifdef DOSTORESTATE73 |
| 1068 | SHA1_STORE_STATE(73) |
| 1069 | #endif |
| 1070 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); |
| 1071 | |
| 1072 | #ifdef DOSTORESTATE74 |
| 1073 | SHA1_STORE_STATE(74) |
| 1074 | #endif |
| 1075 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); |
| 1076 | |
| 1077 | #ifdef DOSTORESTATE75 |
| 1078 | SHA1_STORE_STATE(75) |
| 1079 | #endif |
| 1080 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); |
| 1081 | |
| 1082 | #ifdef DOSTORESTATE76 |
| 1083 | SHA1_STORE_STATE(76) |
| 1084 | #endif |
| 1085 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); |
| 1086 | |
| 1087 | #ifdef DOSTORESTATE77 |
| 1088 | SHA1_STORE_STATE(77) |
| 1089 | #endif |
| 1090 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); |
| 1091 | |
| 1092 | #ifdef DOSTORESTATE78 |
| 1093 | SHA1_STORE_STATE(78) |
| 1094 | #endif |
| 1095 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); |
| 1096 | |
| 1097 | #ifdef DOSTORESTATE79 |
| 1098 | SHA1_STORE_STATE(79) |
| 1099 | #endif |
| 1100 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 1105 | } |
| @@ -1362,11 +1259,11 @@ | |
| 1362 | SHA1_RECOMPRESS(76) |
| 1363 | SHA1_RECOMPRESS(77) |
| 1364 | SHA1_RECOMPRESS(78) |
| 1365 | SHA1_RECOMPRESS(79) |
| 1366 | |
| 1367 | sha1_recompression_type sha1_recompression_step[80] = |
| 1368 | { |
| 1369 | 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, |
| 1370 | 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, |
| 1371 | 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, |
| 1372 | 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, |
| @@ -1374,15 +1271,11 @@ | |
| 1374 | 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, |
| 1375 | 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, |
| 1376 | 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, |
| 1377 | }; |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | void sha1_process(SHA1_CTX* ctx, const uint32_t block[16]) |
| 1384 | { |
| 1385 | unsigned i, j; |
| 1386 | uint32_t ubc_dv_mask[DVMASKSIZE]; |
| 1387 | uint32_t ihvtmp[5]; |
| 1388 | for (i=0; i < DVMASKSIZE; ++i) |
| @@ -1390,31 +1283,33 @@ | |
| 1390 | ctx->ihv1[0] = ctx->ihv[0]; |
| 1391 | ctx->ihv1[1] = ctx->ihv[1]; |
| 1392 | ctx->ihv1[2] = ctx->ihv[2]; |
| 1393 | ctx->ihv1[3] = ctx->ihv[3]; |
| 1394 | ctx->ihv1[4] = ctx->ihv[4]; |
| 1395 | memcpy(ctx->m1, block, 64); |
| 1396 | sha1_message_expansion(ctx->m1); |
| 1397 | if (ctx->detect_coll && ctx->ubc_check) |
| 1398 | { |
| 1399 | ubc_check(ctx->m1, ubc_dv_mask); |
| 1400 | } |
| 1401 | sha1_compression_states(ctx->ihv, ctx->m1, ctx->states); |
| 1402 | if (ctx->detect_coll) |
| 1403 | { |
| 1404 | for (i = 0; sha1_dvs[i].dvType != 0; ++i) |
| 1405 | { |
| 1406 | if ((0 == ctx->ubc_check) || (((uint32_t)(1) << sha1_dvs[i].maskb) & ubc_dv_mask[sha1_dvs[i].maski])) |
| 1407 | { |
| 1408 | for (j = 0; j < 80; ++j) |
| 1409 | ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; |
| 1410 | (sha1_recompression_step[sha1_dvs[i].testt])(ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); |
| 1411 | /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */ |
| 1412 | 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]) |
| 1413 | || (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])) |
| 1414 | { |
| 1415 | ctx->found_collision = 1; |
| 1416 | if (ctx->callback != NULL) |
| 1417 | ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2); |
| 1418 | |
| 1419 | if (ctx->safe_hash) |
| 1420 | { |
| @@ -1427,24 +1322,12 @@ | |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | void swap_bytes(uint32_t val[16]) |
| 1433 | { |
| 1434 | unsigned i; |
| 1435 | for (i = 0; i < 16; ++i) |
| 1436 | { |
| 1437 | val[i] = ((val[i] << 8) & 0xFF00FF00) | ((val[i] >> 8) & 0xFF00FF); |
| 1438 | val[i] = (val[i] << 16) | (val[i] >> 16); |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | void SHA1DCInit(SHA1_CTX* ctx) |
| 1443 | { |
| 1444 | static const union { unsigned char bytes[4]; uint32_t value; } endianness = { { 0, 1, 2, 3 } }; |
| 1445 | static const uint32_t littleendian = 0x03020100; |
| 1446 | ctx->total = 0; |
| 1447 | ctx->ihv[0] = 0x67452301; |
| 1448 | ctx->ihv[1] = 0xEFCDAB89; |
| 1449 | ctx->ihv[2] = 0x98BADCFE; |
| 1450 | ctx->ihv[3] = 0x10325476; |
| @@ -1452,52 +1335,13 @@ | |
| 1452 | ctx->found_collision = 0; |
| 1453 | ctx->safe_hash = 1; |
| 1454 | ctx->ubc_check = 1; |
| 1455 | ctx->detect_coll = 1; |
| 1456 | ctx->reduced_round_coll = 0; |
| 1457 | ctx->bigendian = (endianness.value != littleendian); |
| 1458 | ctx->callback = NULL; |
| 1459 | } |
| 1460 | |
| 1461 | void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash) |
| 1462 | { |
| 1463 | if (safehash) |
| 1464 | ctx->safe_hash = 1; |
| 1465 | else |
| 1466 | ctx->safe_hash = 0; |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check) |
| 1471 | { |
| 1472 | if (ubc_check) |
| 1473 | ctx->ubc_check = 1; |
| 1474 | else |
| 1475 | ctx->ubc_check = 0; |
| 1476 | } |
| 1477 | |
| 1478 | void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll) |
| 1479 | { |
| 1480 | if (detect_coll) |
| 1481 | ctx->detect_coll = 1; |
| 1482 | else |
| 1483 | ctx->detect_coll = 0; |
| 1484 | } |
| 1485 | |
| 1486 | void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll) |
| 1487 | { |
| 1488 | if (reduced_round_coll) |
| 1489 | ctx->reduced_round_coll = 1; |
| 1490 | else |
| 1491 | ctx->reduced_round_coll = 0; |
| 1492 | } |
| 1493 | |
| 1494 | void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback) |
| 1495 | { |
| 1496 | ctx->callback = callback; |
| 1497 | } |
| 1498 | |
| 1499 | void SHA1DCUpdate(SHA1_CTX* ctx, const unsigned char* buf, unsigned len) |
| 1500 | { |
| 1501 | unsigned left, fill; |
| 1502 | if (len == 0) |
| 1503 | return; |
| @@ -1507,28 +1351,19 @@ | |
| 1507 | |
| 1508 | if (left && len >= fill) |
| 1509 | { |
| 1510 | ctx->total += fill; |
| 1511 | memcpy(ctx->buffer + left, buf, fill); |
| 1512 | if (!ctx->bigendian) |
| 1513 | swap_bytes((uint32_t*)(ctx->buffer)); |
| 1514 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1515 | buf += fill; |
| 1516 | len -= fill; |
| 1517 | left = 0; |
| 1518 | } |
| 1519 | while (len >= 64) |
| 1520 | { |
| 1521 | ctx->total += 64; |
| 1522 | if (!ctx->bigendian) |
| 1523 | { |
| 1524 | memcpy(ctx->buffer, buf, 64); |
| 1525 | swap_bytes((uint32_t*)(ctx->buffer)); |
| 1526 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1527 | } |
| 1528 | else |
| 1529 | sha1_process(ctx, (uint32_t*)(buf)); |
| 1530 | buf += 64; |
| 1531 | len -= 64; |
| 1532 | } |
| 1533 | if (len > 0) |
| 1534 | { |
| @@ -1560,12 +1395,10 @@ | |
| 1560 | ctx->buffer[59] = (unsigned char)(total >> 32); |
| 1561 | ctx->buffer[60] = (unsigned char)(total >> 24); |
| 1562 | ctx->buffer[61] = (unsigned char)(total >> 16); |
| 1563 | ctx->buffer[62] = (unsigned char)(total >> 8); |
| 1564 | ctx->buffer[63] = (unsigned char)(total); |
| 1565 | if (!ctx->bigendian) |
| 1566 | swap_bytes((uint32_t*)(ctx->buffer)); |
| 1567 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1568 | output[0] = (unsigned char)(ctx->ihv[0] >> 24); |
| 1569 | output[1] = (unsigned char)(ctx->ihv[0] >> 16); |
| 1570 | output[2] = (unsigned char)(ctx->ihv[0] >> 8); |
| 1571 | output[3] = (unsigned char)(ctx->ihv[0]); |
| 1572 |
| --- src/sha1hard.c | |
| +++ src/sha1hard.c | |
| @@ -2,13 +2,13 @@ | |
| 2 | ** The code in this file is the concatenation of several files |
| 3 | ** copied out of |
| 4 | ** |
| 5 | ** https://github.com/cr-marcstevens/sha1collisiondetection |
| 6 | ** |
| 7 | ** The copy was made on 2017-03-01 (updated 2026-10-16). Some minor |
| 8 | ** formatting changes were made but otherwise the code is unchanged. |
| 9 | ** All original copyright claims are preserved. |
| 10 | ** |
| 11 | ** The code here implements a version of the SHA1 hash function that |
| 12 | ** is not vulnerable to crypto-analysis based attacks. If an input |
| 13 | ** is detected that looks like it might have been the result of a |
| 14 | ** crypto-analysis attack, then the hash is perturbed to generate a |
| @@ -15,10 +15,12 @@ | |
| 15 | ** completely different hash. The authors claim that the chance of |
| 16 | ** a false-positive is vanishingly small. |
| 17 | */ |
| 18 | /*MAKEHEADERS-STOP*/ |
| 19 | #include "config.h" |
| 20 | #include "sha1.h" |
| 21 | |
| 22 | /*************** File: lib/sha1.c ****************/ |
| 23 | /*** |
| 24 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow ([email protected]) |
| 25 | * Distributed under the MIT Software License. |
| 26 | * See accompanying file LICENSE.txt or copy at |
| @@ -65,94 +67,70 @@ | |
| 67 | #define DVMASKSIZE 1 |
| 68 | typedef struct { int dvType; int dvK; int dvB; int testt; int maski; int maskb; uint32_t dm[80]; } dv_info_t; |
| 69 | #define DOSTORESTATE58 |
| 70 | #define DOSTORESTATE65 |
| 71 | typedef void(*sha1_recompression_type)(uint32_t*, uint32_t*, const uint32_t*, const uint32_t*); |
| 72 | |
| 73 | /******************** File: lib/ubc_check.c **************************/ |
| 74 | /*** |
| 75 | * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow <[email protected]> |
| 76 | * Distributed under the MIT Software License. |
| 77 | * See accompanying file LICENSE.txt or copy at |
| 78 | * https://opensource.org/licenses/MIT |
| 79 | ***/ |
| 80 | |
| 81 | // this file was generated by the 'parse_bitrel' program in the tools section |
| 82 | // using the data files from directory 'tools/data/3565' |
| 83 | // |
| 84 | // sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check |
| 85 | // dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) |
| 86 | // dm[80] is the expanded message block XOR-difference defined by the DV |
| 87 | // testt is the step to do the recompression from for collision detection |
| 88 | // maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check |
| 89 | // |
| 90 | // ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs |
| 91 | // it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met |
| 92 | // thus one needs to do the recompression check for each DV that has its bit set |
| 93 | // |
| 94 | // ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded |
| 95 | // a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c |
| 96 | // ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section |
| 97 | |
| 98 | #include <stdint.h> |
| 99 | |
| 100 | static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; |
| 101 | static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; |
| 102 | static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; |
| 103 | static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; |
| 104 | static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; |
| 105 | static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; |
| 106 | static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; |
| 107 | static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; |
| 108 | static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; |
| 109 | static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; |
| 110 | static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; |
| 111 | static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; |
| 112 | static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; |
| 113 | static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; |
| 114 | static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; |
| 115 | static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; |
| 116 | static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; |
| 117 | static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; |
| 118 | static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; |
| 119 | static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; |
| 120 | static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; |
| 121 | static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; |
| 122 | static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; |
| 123 | static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; |
| 124 | static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; |
| 125 | static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; |
| 126 | static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; |
| 127 | static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; |
| 128 | static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; |
| 129 | static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; |
| 130 | static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; |
| 131 | static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; |
| 132 | |
| 133 | dv_info_t sha1_dvs[] = |
| 134 | { |
| 135 | {1,43,0,58,0,0, { 0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161,0x80000599 } } |
| 136 | , {1,44,0,58,0,1, { 0xb4000008,0x08000000,0x9800000c,0xd8000010,0x08000010,0xb8000010,0x98000000,0x60000000,0x00000008,0xc0000000,0x90000014,0x10000010,0xb8000014,0x28000000,0x20000010,0x48000000,0x08000018,0x60000000,0x90000010,0xf0000010,0x90000008,0xc0000000,0x90000010,0xf0000010,0xb0000008,0x40000000,0x90000000,0xf0000010,0x90000018,0x60000000,0x90000010,0x90000010,0x90000000,0x80000000,0x00000010,0xa0000000,0x20000000,0xa0000000,0x20000010,0x00000000,0x20000010,0x20000000,0x00000010,0x20000000,0x00000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000040,0x40000002,0x80000004,0x80000080,0x80000006,0x00000049,0x00000103,0x80000009,0x80000012,0x80000202,0x00000018,0x00000164,0x00000408,0x800000e6,0x8000004c,0x00000803,0x80000161 } } |
| @@ -186,11 +164,12 @@ | |
| 164 | , {2,54,0,65,0,29, { 0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b,0x80000107 } } |
| 165 | , {2,55,0,65,0,30, { 0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046,0x4000004b } } |
| 166 | , {2,56,0,65,0,31, { 0x2600001a,0x00000010,0x0400001c,0xcc000014,0x0c000002,0xc0000010,0xb400001c,0x3c000004,0xbc00001a,0x20000010,0x2400001c,0xec000014,0x0c000002,0xc0000010,0xb400001c,0x2c000004,0xbc000018,0xb0000010,0x0000000c,0xb8000010,0x08000018,0x78000010,0x08000014,0x70000010,0xb800001c,0xe8000000,0xb0000004,0x58000010,0xb000000c,0x48000000,0xb0000000,0xb8000010,0x98000010,0xa0000000,0x00000000,0x00000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0x20000000,0x00000010,0x60000000,0x00000018,0xe0000000,0x90000000,0x30000010,0xb0000000,0x20000000,0x20000000,0xa0000000,0x00000010,0x80000000,0x20000000,0x20000000,0x20000000,0x80000000,0x00000010,0x00000000,0x20000010,0xa0000000,0x00000000,0x20000000,0x20000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000001,0x00000020,0x00000001,0x40000002,0x40000041,0x40000022,0x80000005,0xc0000082,0xc0000046 } } |
| 167 | , {0,0,0,0,0,0, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} |
| 168 | }; |
| 169 | |
| 170 | static void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) |
| 171 | { |
| 172 | uint32_t mask = ~((uint32_t)(0)); |
| 173 | mask &= (((((W[44]^W[45])>>29)&1)-1) | ~(DV_I_48_0_bit|DV_I_51_0_bit|DV_I_52_0_bit|DV_II_45_0_bit|DV_II_46_0_bit|DV_II_50_0_bit|DV_II_51_0_bit)); |
| 174 | mask &= (((((W[49]^W[50])>>29)&1)-1) | ~(DV_I_46_0_bit|DV_II_45_0_bit|DV_II_50_0_bit|DV_II_51_0_bit|DV_II_55_0_bit|DV_II_56_0_bit)); |
| 175 | mask &= (((((W[48]^W[49])>>29)&1)-1) | ~(DV_I_45_0_bit|DV_I_52_0_bit|DV_II_49_0_bit|DV_II_50_0_bit|DV_II_54_0_bit|DV_II_55_0_bit)); |
| @@ -454,17 +433,29 @@ | |
| 433 | dvmask[0]=mask; |
| 434 | } |
| 435 | /******************** End Of File: lib/ubc_check.c *******************/ |
| 436 | /******************** Continue with: lib/sha1.c **********************/ |
| 437 | |
| 438 | #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n)))) |
| 439 | #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n)))) |
| 440 | |
| 441 | #define sha1_bswap32(x) \ |
| 442 | {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);} |
| 443 | |
| 444 | #define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1)) |
| 445 | |
| 446 | #if defined(BIGENDIAN) |
| 447 | #define sha1_load(m, t) (m[t]) |
| 448 | #else |
| 449 | #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); } |
| 450 | #endif /*define(BIGENDIAN)*/ |
| 451 | |
| 452 | #define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x |
| 453 | |
| 454 | #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d)))) |
| 455 | #define sha1_f2(b,c,d) ((b)^(c)^(d)) |
| 456 | #define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c)))) |
| 457 | #define sha1_f4(b,c,d) ((b)^(c)^(d)) |
| 458 | |
| 459 | #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ |
| 460 | { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); } |
| 461 | #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ |
| @@ -480,124 +471,30 @@ | |
| 471 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; } |
| 472 | #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ |
| 473 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; } |
| 474 | #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ |
| 475 | { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; } |
| 476 | |
| 477 | #define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \ |
| 478 | {sha1_load(m, t, temp); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_right(b, 2);} |
| 479 | |
| 480 | #define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \ |
| 481 | {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_right(b, 2); } |
| 482 | |
| 483 | #define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \ |
| 484 | {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1; b = rotate_right(b, 2); } |
| 485 | |
| 486 | #define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \ |
| 487 | {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC; b = rotate_right(b, 2); } |
| 488 | |
| 489 | #define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \ |
| 490 | {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6; b = rotate_right(b, 2); } |
| 491 | |
| 492 | |
| 493 | #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; |
| 494 | |
| 495 | static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) |
| 496 | { |
| 497 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 498 | |
| 499 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); |
| 500 | HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); |
| @@ -684,422 +581,422 @@ | |
| 581 | HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); |
| 582 | |
| 583 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 584 | } |
| 585 | |
| 586 | static void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], |
| 587 | uint32_t W[80], uint32_t states[80][5]) |
| 588 | { |
| 589 | uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; |
| 590 | uint32_t temp; |
| 591 | |
| 592 | #ifdef DOSTORESTATE00 |
| 593 | SHA1_STORE_STATE(0) |
| 594 | #endif |
| 595 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp); |
| 596 | |
| 597 | #ifdef DOSTORESTATE01 |
| 598 | SHA1_STORE_STATE(1) |
| 599 | #endif |
| 600 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp); |
| 601 | |
| 602 | #ifdef DOSTORESTATE02 |
| 603 | SHA1_STORE_STATE(2) |
| 604 | #endif |
| 605 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp); |
| 606 | |
| 607 | #ifdef DOSTORESTATE03 |
| 608 | SHA1_STORE_STATE(3) |
| 609 | #endif |
| 610 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp); |
| 611 | |
| 612 | #ifdef DOSTORESTATE04 |
| 613 | SHA1_STORE_STATE(4) |
| 614 | #endif |
| 615 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp); |
| 616 | |
| 617 | #ifdef DOSTORESTATE05 |
| 618 | SHA1_STORE_STATE(5) |
| 619 | #endif |
| 620 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp); |
| 621 | |
| 622 | #ifdef DOSTORESTATE06 |
| 623 | SHA1_STORE_STATE(6) |
| 624 | #endif |
| 625 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp); |
| 626 | |
| 627 | #ifdef DOSTORESTATE07 |
| 628 | SHA1_STORE_STATE(7) |
| 629 | #endif |
| 630 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp); |
| 631 | |
| 632 | #ifdef DOSTORESTATE08 |
| 633 | SHA1_STORE_STATE(8) |
| 634 | #endif |
| 635 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp); |
| 636 | |
| 637 | #ifdef DOSTORESTATE09 |
| 638 | SHA1_STORE_STATE(9) |
| 639 | #endif |
| 640 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp); |
| 641 | |
| 642 | #ifdef DOSTORESTATE10 |
| 643 | SHA1_STORE_STATE(10) |
| 644 | #endif |
| 645 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp); |
| 646 | |
| 647 | #ifdef DOSTORESTATE11 |
| 648 | SHA1_STORE_STATE(11) |
| 649 | #endif |
| 650 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp); |
| 651 | |
| 652 | #ifdef DOSTORESTATE12 |
| 653 | SHA1_STORE_STATE(12) |
| 654 | #endif |
| 655 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp); |
| 656 | |
| 657 | #ifdef DOSTORESTATE13 |
| 658 | SHA1_STORE_STATE(13) |
| 659 | #endif |
| 660 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp); |
| 661 | |
| 662 | #ifdef DOSTORESTATE14 |
| 663 | SHA1_STORE_STATE(14) |
| 664 | #endif |
| 665 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp); |
| 666 | |
| 667 | #ifdef DOSTORESTATE15 |
| 668 | SHA1_STORE_STATE(15) |
| 669 | #endif |
| 670 | SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp); |
| 671 | |
| 672 | #ifdef DOSTORESTATE16 |
| 673 | SHA1_STORE_STATE(16) |
| 674 | #endif |
| 675 | SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp); |
| 676 | |
| 677 | #ifdef DOSTORESTATE17 |
| 678 | SHA1_STORE_STATE(17) |
| 679 | #endif |
| 680 | SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp); |
| 681 | |
| 682 | #ifdef DOSTORESTATE18 |
| 683 | SHA1_STORE_STATE(18) |
| 684 | #endif |
| 685 | SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp); |
| 686 | |
| 687 | #ifdef DOSTORESTATE19 |
| 688 | SHA1_STORE_STATE(19) |
| 689 | #endif |
| 690 | SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp); |
| 691 | |
| 692 | |
| 693 | |
| 694 | #ifdef DOSTORESTATE20 |
| 695 | SHA1_STORE_STATE(20) |
| 696 | #endif |
| 697 | SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp); |
| 698 | |
| 699 | #ifdef DOSTORESTATE21 |
| 700 | SHA1_STORE_STATE(21) |
| 701 | #endif |
| 702 | SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp); |
| 703 | |
| 704 | #ifdef DOSTORESTATE22 |
| 705 | SHA1_STORE_STATE(22) |
| 706 | #endif |
| 707 | SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp); |
| 708 | |
| 709 | #ifdef DOSTORESTATE23 |
| 710 | SHA1_STORE_STATE(23) |
| 711 | #endif |
| 712 | SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp); |
| 713 | |
| 714 | #ifdef DOSTORESTATE24 |
| 715 | SHA1_STORE_STATE(24) |
| 716 | #endif |
| 717 | SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp); |
| 718 | |
| 719 | #ifdef DOSTORESTATE25 |
| 720 | SHA1_STORE_STATE(25) |
| 721 | #endif |
| 722 | SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp); |
| 723 | |
| 724 | #ifdef DOSTORESTATE26 |
| 725 | SHA1_STORE_STATE(26) |
| 726 | #endif |
| 727 | SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp); |
| 728 | |
| 729 | #ifdef DOSTORESTATE27 |
| 730 | SHA1_STORE_STATE(27) |
| 731 | #endif |
| 732 | SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp); |
| 733 | |
| 734 | #ifdef DOSTORESTATE28 |
| 735 | SHA1_STORE_STATE(28) |
| 736 | #endif |
| 737 | SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp); |
| 738 | |
| 739 | #ifdef DOSTORESTATE29 |
| 740 | SHA1_STORE_STATE(29) |
| 741 | #endif |
| 742 | SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp); |
| 743 | |
| 744 | #ifdef DOSTORESTATE30 |
| 745 | SHA1_STORE_STATE(30) |
| 746 | #endif |
| 747 | SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp); |
| 748 | |
| 749 | #ifdef DOSTORESTATE31 |
| 750 | SHA1_STORE_STATE(31) |
| 751 | #endif |
| 752 | SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp); |
| 753 | |
| 754 | #ifdef DOSTORESTATE32 |
| 755 | SHA1_STORE_STATE(32) |
| 756 | #endif |
| 757 | SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp); |
| 758 | |
| 759 | #ifdef DOSTORESTATE33 |
| 760 | SHA1_STORE_STATE(33) |
| 761 | #endif |
| 762 | SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp); |
| 763 | |
| 764 | #ifdef DOSTORESTATE34 |
| 765 | SHA1_STORE_STATE(34) |
| 766 | #endif |
| 767 | SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp); |
| 768 | |
| 769 | #ifdef DOSTORESTATE35 |
| 770 | SHA1_STORE_STATE(35) |
| 771 | #endif |
| 772 | SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp); |
| 773 | |
| 774 | #ifdef DOSTORESTATE36 |
| 775 | SHA1_STORE_STATE(36) |
| 776 | #endif |
| 777 | SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp); |
| 778 | |
| 779 | #ifdef DOSTORESTATE37 |
| 780 | SHA1_STORE_STATE(37) |
| 781 | #endif |
| 782 | SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp); |
| 783 | |
| 784 | #ifdef DOSTORESTATE38 |
| 785 | SHA1_STORE_STATE(38) |
| 786 | #endif |
| 787 | SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp); |
| 788 | |
| 789 | #ifdef DOSTORESTATE39 |
| 790 | SHA1_STORE_STATE(39) |
| 791 | #endif |
| 792 | SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp); |
| 793 | |
| 794 | |
| 795 | |
| 796 | #ifdef DOSTORESTATE40 |
| 797 | SHA1_STORE_STATE(40) |
| 798 | #endif |
| 799 | SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp); |
| 800 | |
| 801 | #ifdef DOSTORESTATE41 |
| 802 | SHA1_STORE_STATE(41) |
| 803 | #endif |
| 804 | SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp); |
| 805 | |
| 806 | #ifdef DOSTORESTATE42 |
| 807 | SHA1_STORE_STATE(42) |
| 808 | #endif |
| 809 | SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp); |
| 810 | |
| 811 | #ifdef DOSTORESTATE43 |
| 812 | SHA1_STORE_STATE(43) |
| 813 | #endif |
| 814 | SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp); |
| 815 | |
| 816 | #ifdef DOSTORESTATE44 |
| 817 | SHA1_STORE_STATE(44) |
| 818 | #endif |
| 819 | SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp); |
| 820 | |
| 821 | #ifdef DOSTORESTATE45 |
| 822 | SHA1_STORE_STATE(45) |
| 823 | #endif |
| 824 | SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp); |
| 825 | |
| 826 | #ifdef DOSTORESTATE46 |
| 827 | SHA1_STORE_STATE(46) |
| 828 | #endif |
| 829 | SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp); |
| 830 | |
| 831 | #ifdef DOSTORESTATE47 |
| 832 | SHA1_STORE_STATE(47) |
| 833 | #endif |
| 834 | SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp); |
| 835 | |
| 836 | #ifdef DOSTORESTATE48 |
| 837 | SHA1_STORE_STATE(48) |
| 838 | #endif |
| 839 | SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp); |
| 840 | |
| 841 | #ifdef DOSTORESTATE49 |
| 842 | SHA1_STORE_STATE(49) |
| 843 | #endif |
| 844 | SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp); |
| 845 | |
| 846 | #ifdef DOSTORESTATE50 |
| 847 | SHA1_STORE_STATE(50) |
| 848 | #endif |
| 849 | SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp); |
| 850 | |
| 851 | #ifdef DOSTORESTATE51 |
| 852 | SHA1_STORE_STATE(51) |
| 853 | #endif |
| 854 | SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp); |
| 855 | |
| 856 | #ifdef DOSTORESTATE52 |
| 857 | SHA1_STORE_STATE(52) |
| 858 | #endif |
| 859 | SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp); |
| 860 | |
| 861 | #ifdef DOSTORESTATE53 |
| 862 | SHA1_STORE_STATE(53) |
| 863 | #endif |
| 864 | SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp); |
| 865 | |
| 866 | #ifdef DOSTORESTATE54 |
| 867 | SHA1_STORE_STATE(54) |
| 868 | #endif |
| 869 | SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp); |
| 870 | |
| 871 | #ifdef DOSTORESTATE55 |
| 872 | SHA1_STORE_STATE(55) |
| 873 | #endif |
| 874 | SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp); |
| 875 | |
| 876 | #ifdef DOSTORESTATE56 |
| 877 | SHA1_STORE_STATE(56) |
| 878 | #endif |
| 879 | SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp); |
| 880 | |
| 881 | #ifdef DOSTORESTATE57 |
| 882 | SHA1_STORE_STATE(57) |
| 883 | #endif |
| 884 | SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp); |
| 885 | |
| 886 | #ifdef DOSTORESTATE58 |
| 887 | SHA1_STORE_STATE(58) |
| 888 | #endif |
| 889 | SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp); |
| 890 | |
| 891 | #ifdef DOSTORESTATE59 |
| 892 | SHA1_STORE_STATE(59) |
| 893 | #endif |
| 894 | SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp); |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | #ifdef DOSTORESTATE60 |
| 900 | SHA1_STORE_STATE(60) |
| 901 | #endif |
| 902 | SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp); |
| 903 | |
| 904 | #ifdef DOSTORESTATE61 |
| 905 | SHA1_STORE_STATE(61) |
| 906 | #endif |
| 907 | SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp); |
| 908 | |
| 909 | #ifdef DOSTORESTATE62 |
| 910 | SHA1_STORE_STATE(62) |
| 911 | #endif |
| 912 | SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp); |
| 913 | |
| 914 | #ifdef DOSTORESTATE63 |
| 915 | SHA1_STORE_STATE(63) |
| 916 | #endif |
| 917 | SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp); |
| 918 | |
| 919 | #ifdef DOSTORESTATE64 |
| 920 | SHA1_STORE_STATE(64) |
| 921 | #endif |
| 922 | SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp); |
| 923 | |
| 924 | #ifdef DOSTORESTATE65 |
| 925 | SHA1_STORE_STATE(65) |
| 926 | #endif |
| 927 | SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp); |
| 928 | |
| 929 | #ifdef DOSTORESTATE66 |
| 930 | SHA1_STORE_STATE(66) |
| 931 | #endif |
| 932 | SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp); |
| 933 | |
| 934 | #ifdef DOSTORESTATE67 |
| 935 | SHA1_STORE_STATE(67) |
| 936 | #endif |
| 937 | SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp); |
| 938 | |
| 939 | #ifdef DOSTORESTATE68 |
| 940 | SHA1_STORE_STATE(68) |
| 941 | #endif |
| 942 | SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp); |
| 943 | |
| 944 | #ifdef DOSTORESTATE69 |
| 945 | SHA1_STORE_STATE(69) |
| 946 | #endif |
| 947 | SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp); |
| 948 | |
| 949 | #ifdef DOSTORESTATE70 |
| 950 | SHA1_STORE_STATE(70) |
| 951 | #endif |
| 952 | SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp); |
| 953 | |
| 954 | #ifdef DOSTORESTATE71 |
| 955 | SHA1_STORE_STATE(71) |
| 956 | #endif |
| 957 | SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp); |
| 958 | |
| 959 | #ifdef DOSTORESTATE72 |
| 960 | SHA1_STORE_STATE(72) |
| 961 | #endif |
| 962 | SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp); |
| 963 | |
| 964 | #ifdef DOSTORESTATE73 |
| 965 | SHA1_STORE_STATE(73) |
| 966 | #endif |
| 967 | SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp); |
| 968 | |
| 969 | #ifdef DOSTORESTATE74 |
| 970 | SHA1_STORE_STATE(74) |
| 971 | #endif |
| 972 | SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp); |
| 973 | |
| 974 | #ifdef DOSTORESTATE75 |
| 975 | SHA1_STORE_STATE(75) |
| 976 | #endif |
| 977 | SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp); |
| 978 | |
| 979 | #ifdef DOSTORESTATE76 |
| 980 | SHA1_STORE_STATE(76) |
| 981 | #endif |
| 982 | SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp); |
| 983 | |
| 984 | #ifdef DOSTORESTATE77 |
| 985 | SHA1_STORE_STATE(77) |
| 986 | #endif |
| 987 | SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp); |
| 988 | |
| 989 | #ifdef DOSTORESTATE78 |
| 990 | SHA1_STORE_STATE(78) |
| 991 | #endif |
| 992 | SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp); |
| 993 | |
| 994 | #ifdef DOSTORESTATE79 |
| 995 | SHA1_STORE_STATE(79) |
| 996 | #endif |
| 997 | SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp); |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e; |
| 1002 | } |
| @@ -1362,11 +1259,11 @@ | |
| 1259 | SHA1_RECOMPRESS(76) |
| 1260 | SHA1_RECOMPRESS(77) |
| 1261 | SHA1_RECOMPRESS(78) |
| 1262 | SHA1_RECOMPRESS(79) |
| 1263 | |
| 1264 | static const sha1_recompression_type sha1_recompression_step[80] = |
| 1265 | { |
| 1266 | 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, |
| 1267 | 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, |
| 1268 | 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, |
| 1269 | 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, |
| @@ -1374,15 +1271,11 @@ | |
| 1271 | 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, |
| 1272 | 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, |
| 1273 | 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, |
| 1274 | }; |
| 1275 | |
| 1276 | static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16]) |
| 1277 | { |
| 1278 | unsigned i, j; |
| 1279 | uint32_t ubc_dv_mask[DVMASKSIZE]; |
| 1280 | uint32_t ihvtmp[5]; |
| 1281 | for (i=0; i < DVMASKSIZE; ++i) |
| @@ -1390,31 +1283,33 @@ | |
| 1283 | ctx->ihv1[0] = ctx->ihv[0]; |
| 1284 | ctx->ihv1[1] = ctx->ihv[1]; |
| 1285 | ctx->ihv1[2] = ctx->ihv[2]; |
| 1286 | ctx->ihv1[3] = ctx->ihv[3]; |
| 1287 | ctx->ihv1[4] = ctx->ihv[4]; |
| 1288 | |
| 1289 | sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states); |
| 1290 | |
| 1291 | if (ctx->detect_coll) |
| 1292 | { |
| 1293 | if (ctx->ubc_check) |
| 1294 | { |
| 1295 | ubc_check(ctx->m1, ubc_dv_mask); |
| 1296 | } |
| 1297 | |
| 1298 | for (i = 0; sha1_dvs[i].dvType != 0; ++i) |
| 1299 | { |
| 1300 | if ((0 == ctx->ubc_check) || (((uint32_t)(1) << sha1_dvs[i].maskb) & ubc_dv_mask[sha1_dvs[i].maski])) |
| 1301 | { |
| 1302 | for (j = 0; j < 80; ++j) |
| 1303 | ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; |
| 1304 | (sha1_recompression_step[sha1_dvs[i].testt])(ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); |
| 1305 | // to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 |
| 1306 | 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]) |
| 1307 | || (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])) |
| 1308 | { |
| 1309 | ctx->found_collision = 1; |
| 1310 | |
| 1311 | if (ctx->callback != NULL) |
| 1312 | ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2); |
| 1313 | |
| 1314 | if (ctx->safe_hash) |
| 1315 | { |
| @@ -1427,24 +1322,12 @@ | |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | void SHA1DCInit(SHA1_CTX* ctx) |
| 1328 | { |
| 1329 | ctx->total = 0; |
| 1330 | ctx->ihv[0] = 0x67452301; |
| 1331 | ctx->ihv[1] = 0xEFCDAB89; |
| 1332 | ctx->ihv[2] = 0x98BADCFE; |
| 1333 | ctx->ihv[3] = 0x10325476; |
| @@ -1452,52 +1335,13 @@ | |
| 1335 | ctx->found_collision = 0; |
| 1336 | ctx->safe_hash = 1; |
| 1337 | ctx->ubc_check = 1; |
| 1338 | ctx->detect_coll = 1; |
| 1339 | ctx->reduced_round_coll = 0; |
| 1340 | ctx->callback = NULL; |
| 1341 | } |
| 1342 | |
| 1343 | void SHA1DCUpdate(SHA1_CTX* ctx, const unsigned char* buf, unsigned len) |
| 1344 | { |
| 1345 | unsigned left, fill; |
| 1346 | if (len == 0) |
| 1347 | return; |
| @@ -1507,28 +1351,19 @@ | |
| 1351 | |
| 1352 | if (left && len >= fill) |
| 1353 | { |
| 1354 | ctx->total += fill; |
| 1355 | memcpy(ctx->buffer + left, buf, fill); |
| 1356 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1357 | buf += fill; |
| 1358 | len -= fill; |
| 1359 | left = 0; |
| 1360 | } |
| 1361 | while (len >= 64) |
| 1362 | { |
| 1363 | ctx->total += 64; |
| 1364 | sha1_process(ctx, (uint32_t*)(buf)); |
| 1365 | buf += 64; |
| 1366 | len -= 64; |
| 1367 | } |
| 1368 | if (len > 0) |
| 1369 | { |
| @@ -1560,12 +1395,10 @@ | |
| 1395 | ctx->buffer[59] = (unsigned char)(total >> 32); |
| 1396 | ctx->buffer[60] = (unsigned char)(total >> 24); |
| 1397 | ctx->buffer[61] = (unsigned char)(total >> 16); |
| 1398 | ctx->buffer[62] = (unsigned char)(total >> 8); |
| 1399 | ctx->buffer[63] = (unsigned char)(total); |
| 1400 | sha1_process(ctx, (uint32_t*)(ctx->buffer)); |
| 1401 | output[0] = (unsigned char)(ctx->ihv[0] >> 24); |
| 1402 | output[1] = (unsigned char)(ctx->ihv[0] >> 16); |
| 1403 | output[2] = (unsigned char)(ctx->ihv[0] >> 8); |
| 1404 | output[3] = (unsigned char)(ctx->ihv[0]); |
| 1405 |