Fossil SCM

Fix MD5 function (actually: byteReverse) for ARM processors. If OpenSSL is available, use their MD5 impl. Exchange SHA1Final() method parameters, being compatible with OpenSSL.

jan.nijtmans 2017-02-24 14:52 trunk
Commit b88ef030a6aacd9e667404f87247be6b64c65e78
3 files changed +1 -1 +15 -1 +7 -7
+1 -1
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -750,11 +750,11 @@
750750
** Returns non-zero if files that may be binary should be used with external
751751
** diff programs.
752752
*/
753753
int diff_include_binary_files(void){
754754
const char* zArgIncludeBinary = find_option("diff-binary", 0, 1);
755
-
755
+
756756
/* Command line argument have priority on settings */
757757
if( zArgIncludeBinary ){
758758
return is_truth(zArgIncludeBinary);
759759
}else{
760760
return db_get_boolean("diff-binary", 1);
761761
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -750,11 +750,11 @@
750 ** Returns non-zero if files that may be binary should be used with external
751 ** diff programs.
752 */
753 int diff_include_binary_files(void){
754 const char* zArgIncludeBinary = find_option("diff-binary", 0, 1);
755
756 /* Command line argument have priority on settings */
757 if( zArgIncludeBinary ){
758 return is_truth(zArgIncludeBinary);
759 }else{
760 return db_get_boolean("diff-binary", 1);
761
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -750,11 +750,11 @@
750 ** Returns non-zero if files that may be binary should be used with external
751 ** diff programs.
752 */
753 int diff_include_binary_files(void){
754 const char* zArgIncludeBinary = find_option("diff-binary", 0, 1);
755
756 /* Command line argument have priority on settings */
757 if( zArgIncludeBinary ){
758 return is_truth(zArgIncludeBinary);
759 }else{
760 return db_get_boolean("diff-binary", 1);
761
+15 -1
--- src/md5.c
+++ src/md5.c
@@ -22,10 +22,20 @@
2222
#include <string.h>
2323
#include <stdio.h>
2424
#include <sqlite3.h>
2525
#include "md5.h"
2626
27
+#ifdef FOSSIL_ENABLE_SSL
28
+
29
+# include <openssl/md5.h>
30
+# define MD5Context MD5_CTX
31
+# define MD5Init MD5_Init
32
+# define MD5Update MD5_Update
33
+# define MD5Final MD5_Final
34
+
35
+#else
36
+
2737
/*
2838
* If compiled on a machine that doesn't have a 32-bit integer,
2939
* you just set "uint32" to the appropriate datatype for an
3040
* unsigned 32-bit integer. For example:
3141
*
@@ -42,11 +52,14 @@
4252
uint32 bits[2];
4353
unsigned char in[64];
4454
};
4555
typedef struct Context MD5Context;
4656
47
-#if defined(__i386__) || defined(__x86_64__) || defined(_WIN32)
57
+#if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
58
+ defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
59
+ defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
60
+ defined(__arm__) || defined(_WIN32)
4861
# define byteReverse(A,B)
4962
#else
5063
/*
5164
* Convert an array of integers to little-endian.
5265
* Note: this code is a no-op on little-endian machines.
@@ -266,10 +279,11 @@
266279
MD5Transform(ctx->buf, (uint32 *)ctx->in);
267280
byteReverse((unsigned char *)ctx->buf, 4);
268281
memcpy(digest, ctx->buf, 16);
269282
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
270283
}
284
+#endif
271285
272286
/*
273287
** Convert a digest into base-16. digest should be declared as
274288
** "unsigned char digest[16]" in the calling function. The MD5
275289
** digest is stored in the first 16 bytes. zBuf should
276290
--- src/md5.c
+++ src/md5.c
@@ -22,10 +22,20 @@
22 #include <string.h>
23 #include <stdio.h>
24 #include <sqlite3.h>
25 #include "md5.h"
26
 
 
 
 
 
 
 
 
 
 
27 /*
28 * If compiled on a machine that doesn't have a 32-bit integer,
29 * you just set "uint32" to the appropriate datatype for an
30 * unsigned 32-bit integer. For example:
31 *
@@ -42,11 +52,14 @@
42 uint32 bits[2];
43 unsigned char in[64];
44 };
45 typedef struct Context MD5Context;
46
47 #if defined(__i386__) || defined(__x86_64__) || defined(_WIN32)
 
 
 
48 # define byteReverse(A,B)
49 #else
50 /*
51 * Convert an array of integers to little-endian.
52 * Note: this code is a no-op on little-endian machines.
@@ -266,10 +279,11 @@
266 MD5Transform(ctx->buf, (uint32 *)ctx->in);
267 byteReverse((unsigned char *)ctx->buf, 4);
268 memcpy(digest, ctx->buf, 16);
269 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
270 }
 
271
272 /*
273 ** Convert a digest into base-16. digest should be declared as
274 ** "unsigned char digest[16]" in the calling function. The MD5
275 ** digest is stored in the first 16 bytes. zBuf should
276
--- src/md5.c
+++ src/md5.c
@@ -22,10 +22,20 @@
22 #include <string.h>
23 #include <stdio.h>
24 #include <sqlite3.h>
25 #include "md5.h"
26
27 #ifdef FOSSIL_ENABLE_SSL
28
29 # include <openssl/md5.h>
30 # define MD5Context MD5_CTX
31 # define MD5Init MD5_Init
32 # define MD5Update MD5_Update
33 # define MD5Final MD5_Final
34
35 #else
36
37 /*
38 * If compiled on a machine that doesn't have a 32-bit integer,
39 * you just set "uint32" to the appropriate datatype for an
40 * unsigned 32-bit integer. For example:
41 *
@@ -42,11 +52,14 @@
52 uint32 bits[2];
53 unsigned char in[64];
54 };
55 typedef struct Context MD5Context;
56
57 #if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
58 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
59 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
60 defined(__arm__) || defined(_WIN32)
61 # define byteReverse(A,B)
62 #else
63 /*
64 * Convert an array of integers to little-endian.
65 * Note: this code is a no-op on little-endian machines.
@@ -266,10 +279,11 @@
279 MD5Transform(ctx->buf, (uint32 *)ctx->in);
280 byteReverse((unsigned char *)ctx->buf, 4);
281 memcpy(digest, ctx->buf, 16);
282 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
283 }
284 #endif
285
286 /*
287 ** Convert a digest into base-16. digest should be declared as
288 ** "unsigned char digest[16]" in the calling function. The MD5
289 ** digest is stored in the first 16 bytes. zBuf should
290
+7 -7
--- src/sha1.c
+++ src/sha1.c
@@ -9,11 +9,11 @@
99
1010
# include <openssl/sha.h>
1111
# define SHA1Context SHA_CTX
1212
# define SHA1Init SHA1_Init
1313
# define SHA1Update SHA1_Update
14
-# define SHA1Final(a,b) SHA1_Final(b,a)
14
+# define SHA1Final SHA1_Final
1515
1616
#else
1717
1818
/*
1919
** The SHA1 implementation below is adapted from:
@@ -188,11 +188,11 @@
188188
189189
190190
/*
191191
* Add padding and return the message digest.
192192
*/
193
-static void SHA1Final(SHA1Context *context, unsigned char digest[20]){
193
+static void SHA1Final(unsigned char *digest, SHA1Context *context){
194194
unsigned int i;
195195
unsigned char finalcount[8];
196196
197197
for (i = 0; i < 8; i++) {
198198
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
@@ -268,11 +268,11 @@
268268
*/
269269
char *sha1sum_finish(Blob *pOut){
270270
unsigned char zResult[20];
271271
static char zOut[41];
272272
sha1sum_step_text(0,0);
273
- SHA1Final(&incrCtx, zResult);
273
+ SHA1Final(zResult, &incrCtx);
274274
incrInit = 0;
275275
DigestToBase16(zResult, zOut);
276276
if( pOut ){
277277
blob_zero(pOut);
278278
blob_append(pOut, zOut, 40);
@@ -316,11 +316,11 @@
316316
SHA1Update(&ctx, (unsigned char*)zBuf, (unsigned)n);
317317
}
318318
fclose(in);
319319
blob_zero(pCksum);
320320
blob_resize(pCksum, 40);
321
- SHA1Final(&ctx, zResult);
321
+ SHA1Final(zResult, &ctx);
322322
DigestToBase16(zResult, blob_buffer(pCksum));
323323
return 0;
324324
}
325325
326326
/*
@@ -340,11 +340,11 @@
340340
blob_reset(pCksum);
341341
}else{
342342
blob_zero(pCksum);
343343
}
344344
blob_resize(pCksum, 40);
345
- SHA1Final(&ctx, zResult);
345
+ SHA1Final(zResult, &ctx);
346346
DigestToBase16(zResult, blob_buffer(pCksum));
347347
return 0;
348348
}
349349
350350
/*
@@ -356,11 +356,11 @@
356356
unsigned char zResult[20];
357357
char zDigest[41];
358358
359359
SHA1Init(&ctx);
360360
SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
361
- SHA1Final(&ctx, zResult);
361
+ SHA1Final(zResult, &ctx);
362362
DigestToBase16(zResult, zDigest);
363363
return mprintf("%s", zDigest);
364364
}
365365
366366
/*
@@ -407,11 +407,11 @@
407407
SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
408408
SHA1Update(&ctx, (unsigned char*)"/", 1);
409409
SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
410410
SHA1Update(&ctx, (unsigned char*)"/", 1);
411411
SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
412
- SHA1Final(&ctx, zResult);
412
+ SHA1Final(zResult, &ctx);
413413
DigestToBase16(zResult, zDigest);
414414
return mprintf("%s", zDigest);
415415
}
416416
417417
/*
418418
--- src/sha1.c
+++ src/sha1.c
@@ -9,11 +9,11 @@
9
10 # include <openssl/sha.h>
11 # define SHA1Context SHA_CTX
12 # define SHA1Init SHA1_Init
13 # define SHA1Update SHA1_Update
14 # define SHA1Final(a,b) SHA1_Final(b,a)
15
16 #else
17
18 /*
19 ** The SHA1 implementation below is adapted from:
@@ -188,11 +188,11 @@
188
189
190 /*
191 * Add padding and return the message digest.
192 */
193 static void SHA1Final(SHA1Context *context, unsigned char digest[20]){
194 unsigned int i;
195 unsigned char finalcount[8];
196
197 for (i = 0; i < 8; i++) {
198 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
@@ -268,11 +268,11 @@
268 */
269 char *sha1sum_finish(Blob *pOut){
270 unsigned char zResult[20];
271 static char zOut[41];
272 sha1sum_step_text(0,0);
273 SHA1Final(&incrCtx, zResult);
274 incrInit = 0;
275 DigestToBase16(zResult, zOut);
276 if( pOut ){
277 blob_zero(pOut);
278 blob_append(pOut, zOut, 40);
@@ -316,11 +316,11 @@
316 SHA1Update(&ctx, (unsigned char*)zBuf, (unsigned)n);
317 }
318 fclose(in);
319 blob_zero(pCksum);
320 blob_resize(pCksum, 40);
321 SHA1Final(&ctx, zResult);
322 DigestToBase16(zResult, blob_buffer(pCksum));
323 return 0;
324 }
325
326 /*
@@ -340,11 +340,11 @@
340 blob_reset(pCksum);
341 }else{
342 blob_zero(pCksum);
343 }
344 blob_resize(pCksum, 40);
345 SHA1Final(&ctx, zResult);
346 DigestToBase16(zResult, blob_buffer(pCksum));
347 return 0;
348 }
349
350 /*
@@ -356,11 +356,11 @@
356 unsigned char zResult[20];
357 char zDigest[41];
358
359 SHA1Init(&ctx);
360 SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
361 SHA1Final(&ctx, zResult);
362 DigestToBase16(zResult, zDigest);
363 return mprintf("%s", zDigest);
364 }
365
366 /*
@@ -407,11 +407,11 @@
407 SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
408 SHA1Update(&ctx, (unsigned char*)"/", 1);
409 SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
410 SHA1Update(&ctx, (unsigned char*)"/", 1);
411 SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
412 SHA1Final(&ctx, zResult);
413 DigestToBase16(zResult, zDigest);
414 return mprintf("%s", zDigest);
415 }
416
417 /*
418
--- src/sha1.c
+++ src/sha1.c
@@ -9,11 +9,11 @@
9
10 # include <openssl/sha.h>
11 # define SHA1Context SHA_CTX
12 # define SHA1Init SHA1_Init
13 # define SHA1Update SHA1_Update
14 # define SHA1Final SHA1_Final
15
16 #else
17
18 /*
19 ** The SHA1 implementation below is adapted from:
@@ -188,11 +188,11 @@
188
189
190 /*
191 * Add padding and return the message digest.
192 */
193 static void SHA1Final(unsigned char *digest, SHA1Context *context){
194 unsigned int i;
195 unsigned char finalcount[8];
196
197 for (i = 0; i < 8; i++) {
198 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
@@ -268,11 +268,11 @@
268 */
269 char *sha1sum_finish(Blob *pOut){
270 unsigned char zResult[20];
271 static char zOut[41];
272 sha1sum_step_text(0,0);
273 SHA1Final(zResult, &incrCtx);
274 incrInit = 0;
275 DigestToBase16(zResult, zOut);
276 if( pOut ){
277 blob_zero(pOut);
278 blob_append(pOut, zOut, 40);
@@ -316,11 +316,11 @@
316 SHA1Update(&ctx, (unsigned char*)zBuf, (unsigned)n);
317 }
318 fclose(in);
319 blob_zero(pCksum);
320 blob_resize(pCksum, 40);
321 SHA1Final(zResult, &ctx);
322 DigestToBase16(zResult, blob_buffer(pCksum));
323 return 0;
324 }
325
326 /*
@@ -340,11 +340,11 @@
340 blob_reset(pCksum);
341 }else{
342 blob_zero(pCksum);
343 }
344 blob_resize(pCksum, 40);
345 SHA1Final(zResult, &ctx);
346 DigestToBase16(zResult, blob_buffer(pCksum));
347 return 0;
348 }
349
350 /*
@@ -356,11 +356,11 @@
356 unsigned char zResult[20];
357 char zDigest[41];
358
359 SHA1Init(&ctx);
360 SHA1Update(&ctx, (unsigned const char*)zIn, strlen(zIn));
361 SHA1Final(zResult, &ctx);
362 DigestToBase16(zResult, zDigest);
363 return mprintf("%s", zDigest);
364 }
365
366 /*
@@ -407,11 +407,11 @@
407 SHA1Update(&ctx, (unsigned char*)zProjCode, strlen(zProjCode));
408 SHA1Update(&ctx, (unsigned char*)"/", 1);
409 SHA1Update(&ctx, (unsigned char*)zLogin, strlen(zLogin));
410 SHA1Update(&ctx, (unsigned char*)"/", 1);
411 SHA1Update(&ctx, (unsigned const char*)zPw, strlen(zPw));
412 SHA1Final(zResult, &ctx);
413 DigestToBase16(zResult, zDigest);
414 return mprintf("%s", zDigest);
415 }
416
417 /*
418

Keyboard Shortcuts

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