Fossil SCM

Attempt to preserve more of the randomness generated by MD5.

andybradford 2025-10-01 05:33 md5-color-hash
Commit f9d361804e3ced90832bb46e6aedb5f8a7d0389fbb211a4abc6873986c41fac7
1 file changed +9 -1
+9 -1
--- src/color.c
+++ src/color.c
@@ -297,17 +297,25 @@
297297
/*
298298
** Compute a hash on a branch or user name
299299
*/
300300
static unsigned int hash_of_name(const char *z){
301301
unsigned int h = 0;
302
+ unsigned char c;
303
+ int l = 0;
302304
int i;
303305
const char *zHash;
304306
md5sum_init();
305307
md5sum_step_text(z, -1);
306308
zHash = md5sum_finish(0);
307309
for( i=0; zHash[i]; i++ ){
308
- h += zHash[i] << i;
310
+ c = (i%2)==0 ? zHash[i] << 4 : zHash[i];
311
+ if( ((i/8)%2)==0 ) {
312
+ h += c << (24 - (l * 8));
313
+ }else{
314
+ h ^= c << (24 - (l * 8));
315
+ }
316
+ l = (l + 1) % 4;
309317
}
310318
return h;
311319
}
312320
313321
/*
314322
--- src/color.c
+++ src/color.c
@@ -297,17 +297,25 @@
297 /*
298 ** Compute a hash on a branch or user name
299 */
300 static unsigned int hash_of_name(const char *z){
301 unsigned int h = 0;
 
 
302 int i;
303 const char *zHash;
304 md5sum_init();
305 md5sum_step_text(z, -1);
306 zHash = md5sum_finish(0);
307 for( i=0; zHash[i]; i++ ){
308 h += zHash[i] << i;
 
 
 
 
 
 
309 }
310 return h;
311 }
312
313 /*
314
--- src/color.c
+++ src/color.c
@@ -297,17 +297,25 @@
297 /*
298 ** Compute a hash on a branch or user name
299 */
300 static unsigned int hash_of_name(const char *z){
301 unsigned int h = 0;
302 unsigned char c;
303 int l = 0;
304 int i;
305 const char *zHash;
306 md5sum_init();
307 md5sum_step_text(z, -1);
308 zHash = md5sum_finish(0);
309 for( i=0; zHash[i]; i++ ){
310 c = (i%2)==0 ? zHash[i] << 4 : zHash[i];
311 if( ((i/8)%2)==0 ) {
312 h += c << (24 - (l * 8));
313 }else{
314 h ^= c << (24 - (l * 8));
315 }
316 l = (l + 1) % 4;
317 }
318 return h;
319 }
320
321 /*
322

Keyboard Shortcuts

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