Skip to content

Commit 507e07e

Browse files
committed
There is a signedness bug in Openwall gen_salt code that pgcrypto uses.
This makes the salt space for md5 and xdes algorithms a lot smaller than it should be. Marko Kreen
1 parent 9259526 commit 507e07e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

contrib/pgcrypto/crypt-gensalt.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ _crypt_gensalt_extended_rn(unsigned long count,
6262
output[2] = _crypt_itoa64[(count >> 6) & 0x3f];
6363
output[3] = _crypt_itoa64[(count >> 12) & 0x3f];
6464
output[4] = _crypt_itoa64[(count >> 18) & 0x3f];
65-
value = (unsigned long) input[0] |
66-
((unsigned long) input[1] << 8) |
67-
((unsigned long) input[2] << 16);
65+
value = (unsigned long)(unsigned char) input[0] |
66+
((unsigned long)(unsigned char) input[1] << 8) |
67+
((unsigned long)(unsigned char) input[2] << 16);
6868
output[5] = _crypt_itoa64[value & 0x3f];
6969
output[6] = _crypt_itoa64[(value >> 6) & 0x3f];
7070
output[7] = _crypt_itoa64[(value >> 12) & 0x3f];
@@ -90,9 +90,9 @@ _crypt_gensalt_md5_rn(unsigned long count,
9090
output[0] = '$';
9191
output[1] = '1';
9292
output[2] = '$';
93-
value = (unsigned long) input[0] |
94-
((unsigned long) input[1] << 8) |
95-
((unsigned long) input[2] << 16);
93+
value = (unsigned long)(unsigned char) input[0] |
94+
((unsigned long)(unsigned char) input[1] << 8) |
95+
((unsigned long)(unsigned char) input[2] << 16);
9696
output[3] = _crypt_itoa64[value & 0x3f];
9797
output[4] = _crypt_itoa64[(value >> 6) & 0x3f];
9898
output[5] = _crypt_itoa64[(value >> 12) & 0x3f];
@@ -101,9 +101,9 @@ _crypt_gensalt_md5_rn(unsigned long count,
101101

102102
if (size >= 6 && output_size >= 3 + 4 + 4 + 1)
103103
{
104-
value = (unsigned long) input[3] |
105-
((unsigned long) input[4] << 8) |
106-
((unsigned long) input[5] << 16);
104+
value = (unsigned long)(unsigned char) input[3] |
105+
((unsigned long)(unsigned char) input[4] << 8) |
106+
((unsigned long)(unsigned char) input[5] << 16);
107107
output[7] = _crypt_itoa64[value & 0x3f];
108108
output[8] = _crypt_itoa64[(value >> 6) & 0x3f];
109109
output[9] = _crypt_itoa64[(value >> 12) & 0x3f];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy