heimdal: Avoid overflow when performing bitwise shift operations

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
This commit is contained in:
Joseph Sutton
2021-07-14 16:04:48 +12:00
committed by Jeffrey Altman
parent bc37bf1afd
commit 1c93a6ff26
5 changed files with 36 additions and 21 deletions

View File

@@ -225,8 +225,14 @@ DES_set_key_unchecked(DES_cblock *key, DES_key_schedule *ks)
uint32_t *k = &ks->ks[0];
int i;
t1 = (*key)[0] << 24 | (*key)[1] << 16 | (*key)[2] << 8 | (*key)[3];
t2 = (*key)[4] << 24 | (*key)[5] << 16 | (*key)[6] << 8 | (*key)[7];
t1 = (uint32_t)((*key)[0]) << 24
| (uint32_t)((*key)[1]) << 16
| (uint32_t)((*key)[2]) << 8
| (*key)[3];
t2 = (uint32_t)((*key)[4]) << 24
| (uint32_t)((*key)[5]) << 16
| (uint32_t)((*key)[6]) << 8
| (*key)[7];
c = (pc1_c_3[(t1 >> (5 )) & 0x7] << 3)
| (pc1_c_3[(t1 >> (5 + 8 )) & 0x7] << 2)
@@ -325,14 +331,14 @@ DES_key_sched(DES_cblock *key, DES_key_schedule *ks)
static void
load(const unsigned char *b, uint32_t v[2])
{
v[0] = b[0] << 24;
v[0] |= b[1] << 16;
v[0] |= b[2] << 8;
v[0] |= b[3] << 0;
v[1] = b[4] << 24;
v[1] |= b[5] << 16;
v[1] |= b[6] << 8;
v[1] |= b[7] << 0;
v[0] = (uint32_t)(b[0]) << 24;
v[0] |= (uint32_t)(b[1]) << 16;
v[0] |= (uint32_t)(b[2]) << 8;
v[0] |= b[3];
v[1] = (uint32_t)(b[4]) << 24;
v[1] |= (uint32_t)(b[5]) << 16;
v[1] |= (uint32_t)(b[6]) << 8;
v[1] |= b[7];
}
static void