diff options
author | miod <> | 2016-11-08 20:20:06 +0000 |
---|---|---|
committer | miod <> | 2016-11-08 20:20:06 +0000 |
commit | acfc5dfa14919694cee5af74f2d461fc9cc191a3 (patch) | |
tree | aa9ae30923a5f7352297f4204cd55d42e936ae5c | |
parent | 5605f577187336e02b609bad906ab42478c7340a (diff) | |
download | openbsd-acfc5dfa14919694cee5af74f2d461fc9cc191a3.tar.gz openbsd-acfc5dfa14919694cee5af74f2d461fc9cc191a3.tar.bz2 openbsd-acfc5dfa14919694cee5af74f2d461fc9cc191a3.zip |
Use more homogeneous types and avoid a possible right shift by 32 in
lh_strhash().
ok guenther@
-rw-r--r-- | src/lib/libcrypto/lhash/lhash.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c index f4994f7471..ac6cc43ea5 100644 --- a/src/lib/libcrypto/lhash/lhash.c +++ b/src/lib/libcrypto/lhash/lhash.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: lhash.c,v 1.17 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: lhash.c,v 1.18 2016/11/08 20:20:06 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -431,29 +431,23 @@ unsigned long | |||
431 | lh_strhash(const char *c) | 431 | lh_strhash(const char *c) |
432 | { | 432 | { |
433 | unsigned long ret = 0; | 433 | unsigned long ret = 0; |
434 | long n; | 434 | unsigned long n, v; |
435 | unsigned long v; | 435 | unsigned int r; |
436 | int r; | 436 | |
437 | 437 | if (c == NULL || *c == '\0') | |
438 | if ((c == NULL) || (*c == '\0')) | 438 | return ret; |
439 | return (ret); | ||
440 | /* | ||
441 | unsigned char b[16]; | ||
442 | MD5(c,strlen(c),b); | ||
443 | return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24)); | ||
444 | */ | ||
445 | 439 | ||
446 | n = 0x100; | 440 | n = 0x100; |
447 | while (*c) { | 441 | while (*c) { |
448 | v = n | (*c); | 442 | v = n | *c; |
449 | n += 0x100; | 443 | n += 0x100; |
450 | r = (int)((v >> 2) ^ v) & 0x0f; | 444 | if ((r = ((v >> 2) ^ v) & 0x0f) != 0) |
451 | ret = (ret << r)|(ret >> (32 - r)); | 445 | ret = (ret << r) | (ret >> (32 - r)); |
452 | ret &= 0xFFFFFFFFL; | 446 | ret &= 0xFFFFFFFFUL; |
453 | ret ^= v * v; | 447 | ret ^= v * v; |
454 | c++; | 448 | c++; |
455 | } | 449 | } |
456 | return ((ret >> 16) ^ ret); | 450 | return (ret >> 16) ^ ret; |
457 | } | 451 | } |
458 | 452 | ||
459 | unsigned long | 453 | unsigned long |