Fossil SCM

Remove the #if'd out, pre-hardened SHA1 code. It's been dead code for nearly a decade.

stephan 2026-10-16 12:47 UTC trunk
Commit c54604f830cbfd0b15bf85747e90659f6023891e4978fb090d08525c114908ff
2 files changed +2 -200 -7
+2 -200
--- src/sha1.c
+++ src/sha1.c
@@ -29,12 +29,10 @@
2929
** https://github.com/cr-marcstevens/sha1collisiondetection
3030
**
3131
** Downloaded on 2017-03-01 then repackaged to work with Fossil
3232
** and makeheaders.
3333
*/
34
-#if FOSSIL_HARDENED_SHA1
35
-
3634
#if INTERFACE
3735
typedef void(*collision_block_callback)(uint64_t, const uint32_t*,
3836
const uint32_t*, const uint32_t*, const uint32_t*);
3937
struct SHA1_CTX {
4038
uint64_t total;
@@ -52,216 +50,20 @@
5250
uint32_t ihv2[5];
5351
uint32_t m1[80];
5452
uint32_t m2[80];
5553
uint32_t states[80][5];
5654
};
57
-#endif
55
+
5856
void SHA1DCInit(SHA1_CTX*);
5957
void SHA1DCUpdate(SHA1_CTX*, const unsigned char*, unsigned);
6058
int SHA1DCFinal(unsigned char[20], SHA1_CTX*);
6159
6260
#define SHA1Context SHA1_CTX
6361
#define SHA1Init SHA1DCInit
6462
#define SHA1Update SHA1DCUpdate
6563
#define SHA1Final SHA1DCFinal
66
-
67
-/*
68
-** SHA1 Implementation #2: use the SHA1 algorithm built into SSL
69
-*/
70
-#elif defined(FOSSIL_ENABLE_SSL)
71
-
72
-# include <openssl/sha.h>
73
-# define SHA1Context SHA_CTX
74
-# define SHA1Init SHA1_Init
75
-# define SHA1Update SHA1_Update
76
-# define SHA1Final SHA1_Final
77
-
78
-/*
79
-** SHA1 Implementation #3: If none of the previous two SHA1
80
-** algorithms work, there is this built-in. This built-in was the
81
-** original implementation used by Fossil.
82
-*/
83
-#else
84
-/*
85
-** The SHA1 implementation below is adapted from:
86
-**
87
-** $NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $
88
-** $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $
89
-**
90
-** SHA-1 in C
91
-** By Steve Reid <[email protected]>
92
-** 100% Public Domain
93
-*/
94
-typedef struct SHA1Context SHA1Context;
95
-struct SHA1Context {
96
- unsigned int state[5];
97
- unsigned int count[2];
98
- unsigned char buffer[64];
99
-};
100
-
101
-/*
102
- * blk0() and blk() perform the initial expand.
103
- * I got the idea of expanding during the round function from SSLeay
104
- *
105
- * blk0le() for little-endian and blk0be() for big-endian.
106
- */
107
-#define SHA_ROT(x,l,r) ((x) << (l) | (x) >> (r))
108
-#define rol(x,k) SHA_ROT(x,k,32-(k))
109
-#define ror(x,k) SHA_ROT(x,32-(k),k)
110
-#define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
111
- |(rol(block[i],8)&0x00FF00FF))
112
-#define blk0be(i) block[i]
113
-#define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
114
- ^block[(i+2)&15]^block[i&15],1))
115
-
116
-/*
117
- * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
118
- *
119
- * Rl0() for little-endian and Rb0() for big-endian. Endianness is
120
- * determined at run-time.
121
- */
122
-#define Rl0(v,w,x,y,z,i) \
123
- z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
124
-#define Rb0(v,w,x,y,z,i) \
125
- z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
126
-#define R1(v,w,x,y,z,i) \
127
- z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
128
-#define R2(v,w,x,y,z,i) \
129
- z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
130
-#define R3(v,w,x,y,z,i) \
131
- z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
132
-#define R4(v,w,x,y,z,i) \
133
- z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
134
-
135
-/*
136
- * Hash a single 512-bit block. This is the core of the algorithm.
137
- */
138
-#define a qq[0]
139
-#define b qq[1]
140
-#define c qq[2]
141
-#define d qq[3]
142
-#define e qq[4]
143
-
144
-void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
145
-{
146
- unsigned int qq[5]; /* a, b, c, d, e; */
147
- static int one = 1;
148
- unsigned int block[16];
149
- memcpy(block, buffer, 64);
150
- memcpy(qq,state,5*sizeof(unsigned int));
151
-
152
- /* Copy context->state[] to working vars */
153
- /*
154
- a = state[0];
155
- b = state[1];
156
- c = state[2];
157
- d = state[3];
158
- e = state[4];
159
- */
160
-
161
- /* 4 rounds of 20 operations each. Loop unrolled. */
162
- if( 1 == *(unsigned char*)&one ){
163
- Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
164
- Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
165
- Rl0(c,d,e,a,b, 8); Rl0(b,c,d,e,a, 9); Rl0(a,b,c,d,e,10); Rl0(e,a,b,c,d,11);
166
- Rl0(d,e,a,b,c,12); Rl0(c,d,e,a,b,13); Rl0(b,c,d,e,a,14); Rl0(a,b,c,d,e,15);
167
- }else{
168
- Rb0(a,b,c,d,e, 0); Rb0(e,a,b,c,d, 1); Rb0(d,e,a,b,c, 2); Rb0(c,d,e,a,b, 3);
169
- Rb0(b,c,d,e,a, 4); Rb0(a,b,c,d,e, 5); Rb0(e,a,b,c,d, 6); Rb0(d,e,a,b,c, 7);
170
- Rb0(c,d,e,a,b, 8); Rb0(b,c,d,e,a, 9); Rb0(a,b,c,d,e,10); Rb0(e,a,b,c,d,11);
171
- Rb0(d,e,a,b,c,12); Rb0(c,d,e,a,b,13); Rb0(b,c,d,e,a,14); Rb0(a,b,c,d,e,15);
172
- }
173
- R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
174
- R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
175
- R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
176
- R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
177
- R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
178
- R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
179
- R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
180
- R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
181
- R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
182
- R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
183
- R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
184
- R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
185
- R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
186
- R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
187
- R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
188
- R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
189
-
190
- /* Add the working vars back into context.state[] */
191
- state[0] += a;
192
- state[1] += b;
193
- state[2] += c;
194
- state[3] += d;
195
- state[4] += e;
196
-}
197
-
198
-
199
-/*
200
- * SHA1Init - Initialize new context
201
- */
202
-static void SHA1Init(SHA1Context *context){
203
- /* SHA1 initialization constants */
204
- context->state[0] = 0x67452301;
205
- context->state[1] = 0xEFCDAB89;
206
- context->state[2] = 0x98BADCFE;
207
- context->state[3] = 0x10325476;
208
- context->state[4] = 0xC3D2E1F0;
209
- context->count[0] = context->count[1] = 0;
210
-}
211
-
212
-
213
-/*
214
- * Run your data through this.
215
- */
216
-static void SHA1Update(
217
- SHA1Context *context,
218
- const unsigned char *data,
219
- unsigned int len
220
-){
221
- unsigned int i, j;
222
-
223
- j = context->count[0];
224
- if ((context->count[0] += len << 3) < j)
225
- context->count[1] += (len>>29)+1;
226
- j = (j >> 3) & 63;
227
- if ((j + len) > 63) {
228
- (void)memcpy(&context->buffer[j], data, (i = 64-j));
229
- SHA1Transform(context->state, context->buffer);
230
- for ( ; i + 63 < len; i += 64)
231
- SHA1Transform(context->state, &data[i]);
232
- j = 0;
233
- } else {
234
- i = 0;
235
- }
236
- (void)memcpy(&context->buffer[j], &data[i], len - i);
237
-}
238
-
239
-
240
-/*
241
- * Add padding and return the message digest.
242
- */
243
-static void SHA1Final(unsigned char *digest, SHA1Context *context){
244
- unsigned int i;
245
- unsigned char finalcount[8];
246
-
247
- for (i = 0; i < 8; i++) {
248
- finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
249
- >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
250
- }
251
- SHA1Update(context, (const unsigned char *)"\200", 1);
252
- while ((context->count[0] & 504) != 448)
253
- SHA1Update(context, (const unsigned char *)"\0", 1);
254
- SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
255
-
256
- if (digest) {
257
- for (i = 0; i < 20; i++)
258
- digest[i] = (unsigned char)
259
- ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
260
- }
261
-}
262
-#endif /* Built-in SHA1 implementation */
64
+#endif
26365
26466
/*
26567
** Convert a digest into base-16. digest should be declared as
26668
** "unsigned char digest[20]" in the calling function. The SHA1
26769
** digest is stored in the first 20 bytes. zBuf should
26870
--- src/sha1.c
+++ src/sha1.c
@@ -29,12 +29,10 @@
29 ** https://github.com/cr-marcstevens/sha1collisiondetection
30 **
31 ** Downloaded on 2017-03-01 then repackaged to work with Fossil
32 ** and makeheaders.
33 */
34 #if FOSSIL_HARDENED_SHA1
35
36 #if INTERFACE
37 typedef void(*collision_block_callback)(uint64_t, const uint32_t*,
38 const uint32_t*, const uint32_t*, const uint32_t*);
39 struct SHA1_CTX {
40 uint64_t total;
@@ -52,216 +50,20 @@
52 uint32_t ihv2[5];
53 uint32_t m1[80];
54 uint32_t m2[80];
55 uint32_t states[80][5];
56 };
57 #endif
58 void SHA1DCInit(SHA1_CTX*);
59 void SHA1DCUpdate(SHA1_CTX*, const unsigned char*, unsigned);
60 int SHA1DCFinal(unsigned char[20], SHA1_CTX*);
61
62 #define SHA1Context SHA1_CTX
63 #define SHA1Init SHA1DCInit
64 #define SHA1Update SHA1DCUpdate
65 #define SHA1Final SHA1DCFinal
66
67 /*
68 ** SHA1 Implementation #2: use the SHA1 algorithm built into SSL
69 */
70 #elif defined(FOSSIL_ENABLE_SSL)
71
72 # include <openssl/sha.h>
73 # define SHA1Context SHA_CTX
74 # define SHA1Init SHA1_Init
75 # define SHA1Update SHA1_Update
76 # define SHA1Final SHA1_Final
77
78 /*
79 ** SHA1 Implementation #3: If none of the previous two SHA1
80 ** algorithms work, there is this built-in. This built-in was the
81 ** original implementation used by Fossil.
82 */
83 #else
84 /*
85 ** The SHA1 implementation below is adapted from:
86 **
87 ** $NetBSD: sha1.c,v 1.6 2009/11/06 20:31:18 joerg Exp $
88 ** $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $
89 **
90 ** SHA-1 in C
91 ** By Steve Reid <[email protected]>
92 ** 100% Public Domain
93 */
94 typedef struct SHA1Context SHA1Context;
95 struct SHA1Context {
96 unsigned int state[5];
97 unsigned int count[2];
98 unsigned char buffer[64];
99 };
100
101 /*
102 * blk0() and blk() perform the initial expand.
103 * I got the idea of expanding during the round function from SSLeay
104 *
105 * blk0le() for little-endian and blk0be() for big-endian.
106 */
107 #define SHA_ROT(x,l,r) ((x) << (l) | (x) >> (r))
108 #define rol(x,k) SHA_ROT(x,k,32-(k))
109 #define ror(x,k) SHA_ROT(x,32-(k),k)
110 #define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
111 |(rol(block[i],8)&0x00FF00FF))
112 #define blk0be(i) block[i]
113 #define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
114 ^block[(i+2)&15]^block[i&15],1))
115
116 /*
117 * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
118 *
119 * Rl0() for little-endian and Rb0() for big-endian. Endianness is
120 * determined at run-time.
121 */
122 #define Rl0(v,w,x,y,z,i) \
123 z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
124 #define Rb0(v,w,x,y,z,i) \
125 z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
126 #define R1(v,w,x,y,z,i) \
127 z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
128 #define R2(v,w,x,y,z,i) \
129 z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
130 #define R3(v,w,x,y,z,i) \
131 z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
132 #define R4(v,w,x,y,z,i) \
133 z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
134
135 /*
136 * Hash a single 512-bit block. This is the core of the algorithm.
137 */
138 #define a qq[0]
139 #define b qq[1]
140 #define c qq[2]
141 #define d qq[3]
142 #define e qq[4]
143
144 void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
145 {
146 unsigned int qq[5]; /* a, b, c, d, e; */
147 static int one = 1;
148 unsigned int block[16];
149 memcpy(block, buffer, 64);
150 memcpy(qq,state,5*sizeof(unsigned int));
151
152 /* Copy context->state[] to working vars */
153 /*
154 a = state[0];
155 b = state[1];
156 c = state[2];
157 d = state[3];
158 e = state[4];
159 */
160
161 /* 4 rounds of 20 operations each. Loop unrolled. */
162 if( 1 == *(unsigned char*)&one ){
163 Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
164 Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
165 Rl0(c,d,e,a,b, 8); Rl0(b,c,d,e,a, 9); Rl0(a,b,c,d,e,10); Rl0(e,a,b,c,d,11);
166 Rl0(d,e,a,b,c,12); Rl0(c,d,e,a,b,13); Rl0(b,c,d,e,a,14); Rl0(a,b,c,d,e,15);
167 }else{
168 Rb0(a,b,c,d,e, 0); Rb0(e,a,b,c,d, 1); Rb0(d,e,a,b,c, 2); Rb0(c,d,e,a,b, 3);
169 Rb0(b,c,d,e,a, 4); Rb0(a,b,c,d,e, 5); Rb0(e,a,b,c,d, 6); Rb0(d,e,a,b,c, 7);
170 Rb0(c,d,e,a,b, 8); Rb0(b,c,d,e,a, 9); Rb0(a,b,c,d,e,10); Rb0(e,a,b,c,d,11);
171 Rb0(d,e,a,b,c,12); Rb0(c,d,e,a,b,13); Rb0(b,c,d,e,a,14); Rb0(a,b,c,d,e,15);
172 }
173 R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
174 R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
175 R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
176 R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
177 R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
178 R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
179 R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
180 R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
181 R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
182 R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
183 R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
184 R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
185 R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
186 R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
187 R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
188 R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
189
190 /* Add the working vars back into context.state[] */
191 state[0] += a;
192 state[1] += b;
193 state[2] += c;
194 state[3] += d;
195 state[4] += e;
196 }
197
198
199 /*
200 * SHA1Init - Initialize new context
201 */
202 static void SHA1Init(SHA1Context *context){
203 /* SHA1 initialization constants */
204 context->state[0] = 0x67452301;
205 context->state[1] = 0xEFCDAB89;
206 context->state[2] = 0x98BADCFE;
207 context->state[3] = 0x10325476;
208 context->state[4] = 0xC3D2E1F0;
209 context->count[0] = context->count[1] = 0;
210 }
211
212
213 /*
214 * Run your data through this.
215 */
216 static void SHA1Update(
217 SHA1Context *context,
218 const unsigned char *data,
219 unsigned int len
220 ){
221 unsigned int i, j;
222
223 j = context->count[0];
224 if ((context->count[0] += len << 3) < j)
225 context->count[1] += (len>>29)+1;
226 j = (j >> 3) & 63;
227 if ((j + len) > 63) {
228 (void)memcpy(&context->buffer[j], data, (i = 64-j));
229 SHA1Transform(context->state, context->buffer);
230 for ( ; i + 63 < len; i += 64)
231 SHA1Transform(context->state, &data[i]);
232 j = 0;
233 } else {
234 i = 0;
235 }
236 (void)memcpy(&context->buffer[j], &data[i], len - i);
237 }
238
239
240 /*
241 * Add padding and return the message digest.
242 */
243 static void SHA1Final(unsigned char *digest, SHA1Context *context){
244 unsigned int i;
245 unsigned char finalcount[8];
246
247 for (i = 0; i < 8; i++) {
248 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
249 >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
250 }
251 SHA1Update(context, (const unsigned char *)"\200", 1);
252 while ((context->count[0] & 504) != 448)
253 SHA1Update(context, (const unsigned char *)"\0", 1);
254 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
255
256 if (digest) {
257 for (i = 0; i < 20; i++)
258 digest[i] = (unsigned char)
259 ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
260 }
261 }
262 #endif /* Built-in SHA1 implementation */
263
264 /*
265 ** Convert a digest into base-16. digest should be declared as
266 ** "unsigned char digest[20]" in the calling function. The SHA1
267 ** digest is stored in the first 20 bytes. zBuf should
268
--- src/sha1.c
+++ src/sha1.c
@@ -29,12 +29,10 @@
29 ** https://github.com/cr-marcstevens/sha1collisiondetection
30 **
31 ** Downloaded on 2017-03-01 then repackaged to work with Fossil
32 ** and makeheaders.
33 */
 
 
34 #if INTERFACE
35 typedef void(*collision_block_callback)(uint64_t, const uint32_t*,
36 const uint32_t*, const uint32_t*, const uint32_t*);
37 struct SHA1_CTX {
38 uint64_t total;
@@ -52,216 +50,20 @@
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 #define SHA1Context SHA1_CTX
61 #define SHA1Init SHA1DCInit
62 #define SHA1Update SHA1DCUpdate
63 #define SHA1Final SHA1DCFinal
64 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
66 /*
67 ** Convert a digest into base-16. digest should be declared as
68 ** "unsigned char digest[20]" in the calling function. The SHA1
69 ** digest is stored in the first 20 bytes. zBuf should
70
--- src/sha1hard.c
+++ src/sha1hard.c
@@ -15,11 +15,10 @@
1515
** completely different hash. The authors claim that the chance of
1616
** a false-positive is vanishingly small.
1717
*/
1818
/*MAKEHEADERS-STOP*/
1919
#include "config.h"
20
-#if FOSSIL_HARDENED_SHA1 /* Only do this code if requested */
2120
/*************** File: lib/sha1.c ****************/
2221
/***
2322
* Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow ([email protected])
2423
* Distributed under the MIT Software License.
2524
* See accompanying file LICENSE.txt or copy at
@@ -1412,11 +1411,10 @@
14121411
/* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */
14131412
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])
14141413
|| (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]))
14151414
{
14161415
ctx->found_collision = 1;
1417
- /* TODO: call callback */
14181416
if (ctx->callback != NULL)
14191417
ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2);
14201418
14211419
if (ctx->safe_hash)
14221420
{
@@ -1428,14 +1426,10 @@
14281426
}
14291427
}
14301428
}
14311429
}
14321430
}
1433
-
1434
-
1435
-
1436
-
14371431
14381432
void swap_bytes(uint32_t val[16])
14391433
{
14401434
unsigned i;
14411435
for (i = 0; i < 16; ++i)
@@ -1591,6 +1585,5 @@
15911585
output[17] = (unsigned char)(ctx->ihv[4] >> 16);
15921586
output[18] = (unsigned char)(ctx->ihv[4] >> 8);
15931587
output[19] = (unsigned char)(ctx->ihv[4]);
15941588
return ctx->found_collision;
15951589
}
1596
-#endif /* FOSSIL_HARDENED_SHA1 */
15971590
--- src/sha1hard.c
+++ src/sha1hard.c
@@ -15,11 +15,10 @@
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 #if FOSSIL_HARDENED_SHA1 /* Only do this code if requested */
21 /*************** File: lib/sha1.c ****************/
22 /***
23 * Copyright 2017 Marc Stevens <[email protected]>, Dan Shumow ([email protected])
24 * Distributed under the MIT Software License.
25 * See accompanying file LICENSE.txt or copy at
@@ -1412,11 +1411,10 @@
1412 /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */
1413 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])
1414 || (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]))
1415 {
1416 ctx->found_collision = 1;
1417 /* TODO: call callback */
1418 if (ctx->callback != NULL)
1419 ctx->callback(ctx->total - 64, ctx->ihv1, ctx->ihv2, ctx->m1, ctx->m2);
1420
1421 if (ctx->safe_hash)
1422 {
@@ -1428,14 +1426,10 @@
1428 }
1429 }
1430 }
1431 }
1432 }
1433
1434
1435
1436
1437
1438 void swap_bytes(uint32_t val[16])
1439 {
1440 unsigned i;
1441 for (i = 0; i < 16; ++i)
@@ -1591,6 +1585,5 @@
1591 output[17] = (unsigned char)(ctx->ihv[4] >> 16);
1592 output[18] = (unsigned char)(ctx->ihv[4] >> 8);
1593 output[19] = (unsigned char)(ctx->ihv[4]);
1594 return ctx->found_collision;
1595 }
1596 #endif /* FOSSIL_HARDENED_SHA1 */
1597
--- src/sha1hard.c
+++ src/sha1hard.c
@@ -15,11 +15,10 @@
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
@@ -1412,11 +1411,10 @@
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 {
@@ -1428,14 +1426,10 @@
1426 }
1427 }
1428 }
1429 }
1430 }
 
 
 
 
1431
1432 void swap_bytes(uint32_t val[16])
1433 {
1434 unsigned i;
1435 for (i = 0; i < 16; ++i)
@@ -1591,6 +1585,5 @@
1585 output[17] = (unsigned char)(ctx->ihv[4] >> 16);
1586 output[18] = (unsigned char)(ctx->ihv[4] >> 8);
1587 output[19] = (unsigned char)(ctx->ihv[4]);
1588 return ctx->found_collision;
1589 }
 
1590

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button