if (params->length != 4)
return KRB5_ERR_BAD_S2K_PARAMS;
/* The first two need casts in case 'int' is 16 bits. */
- iter_count = (((unsigned long)p[0] << 24)
- | ((unsigned long)p[1] << 16)
- | (p[2] << 8)
- | (p[3]));
+ iter_count = load_32_be(p);
if (iter_count == 0) {
iter_count = (1L << 16) << 16;
if (((iter_count >> 16) >> 16) != 1)
ms_usage=krb5int_arcfour_translate_usage(usage);
if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) {
strncpy(salt.data, l40, salt.length);
- salt.data[10]=ms_usage & 0xff;
- salt.data[11]=(ms_usage >> 8) & 0xff;
- salt.data[12]=(ms_usage >> 16) & 0xff;
- salt.data[13]=(ms_usage >> 24) & 0xff;
+ store_32_le(ms_usage, salt.data+10);
} else {
salt.length=4;
- salt.data[0]=ms_usage & 0xff;
- salt.data[1]=(ms_usage >> 8) & 0xff;
- salt.data[2]=(ms_usage >> 16) & 0xff;
- salt.data[3]=(ms_usage >> 24) & 0xff;
+ store_32_le(ms_usage, salt.data);
}
krb5_hmac(hash, key, 1, &salt, &d1);
* the right, while D0 gets 16 from the left and 12 from the
* right. The code knows which bits go where.
*/
- tmp = ((unsigned DES_INT32)(*(k)++)) << 24;
- tmp |= ((unsigned DES_INT32)(*(k)++)) << 16;
- tmp |= ((unsigned DES_INT32)(*(k)++)) << 8;
- tmp |= (unsigned DES_INT32)(*(k)++); /* left part of key */
+ tmp = load_32_be(k), k += 4;
+
c = PC1_CL[(tmp >> 29) & 0x7]
| (PC1_CL[(tmp >> 21) & 0x7] << 1)
| (PC1_CL[(tmp >> 13) & 0x7] << 2)
| (PC1_DL[(tmp >> 9) & 0xf] << 2)
| (PC1_DL[(tmp >> 1) & 0xf] << 3);
- tmp = ((unsigned DES_INT32)(*(k)++)) << 24;
- tmp |= ((unsigned DES_INT32)(*(k)++)) << 16;
- tmp |= ((unsigned DES_INT32)(*(k)++)) << 8;
- tmp |= (unsigned DES_INT32)(*(k)++); /* right part of key */
+ tmp = load_32_be(k), k += 4;
+
c |= PC1_CR[(tmp >> 28) & 0xf]
| (PC1_CR[(tmp >> 20) & 0xf] << 1)
| (PC1_CR[(tmp >> 12) & 0xf] << 2)
/* transform if necessary */
if (mdi == 0x40) {
- for (i = 0, ii = 0; i < 16; i++, ii += 4)
- in[i] = (((krb5_ui_4)mdContext->in[ii+3]) << 24) |
- (((krb5_ui_4)mdContext->in[ii+2]) << 16) |
- (((krb5_ui_4)mdContext->in[ii+1]) << 8) |
- ((krb5_ui_4)mdContext->in[ii]);
+ for (i = 0, ii = 0; i < 16; i++, ii += 4) {
+ in[i] = load_32_le(mdContext->in+ii);
+ }
Transform (mdContext->buf, in);
mdi = 0;
}
/* append length in bits and transform */
for (i = 0, ii = 0; i < 14; i++, ii += 4)
- in[i] = (((krb5_ui_4)mdContext->in[ii+3]) << 24) |
- (((krb5_ui_4)mdContext->in[ii+2]) << 16) |
- (((krb5_ui_4)mdContext->in[ii+1]) << 8) |
- ((krb5_ui_4)mdContext->in[ii]);
+ in[i] = load_32_le(mdContext->in+ii);
Transform (mdContext->buf, in);
/* store buffer in digest */
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
- mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
- mdContext->digest[ii+1] =
- (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
- mdContext->digest[ii+2] =
- (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
- mdContext->digest[ii+3] =
- (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+ store_32_le(mdContext->buf[i], mdContext->digest+ii);
}
}
/* transform if necessary */
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; i++, ii += 4)
- in[i] = (((krb5_ui_4)mdContext->in[ii+3]) << 24) |
- (((krb5_ui_4)mdContext->in[ii+2]) << 16) |
- (((krb5_ui_4)mdContext->in[ii+1]) << 8) |
- ((krb5_ui_4)mdContext->in[ii]);
+ in[i] = load_32_le(mdContext->in+ii);
Transform (mdContext->buf, in);
mdi = 0;
}
/* append length in bits and transform */
for (i = 0, ii = 0; i < 14; i++, ii += 4)
- in[i] = (((krb5_ui_4)mdContext->in[ii+3]) << 24) |
- (((krb5_ui_4)mdContext->in[ii+2]) << 16) |
- (((krb5_ui_4)mdContext->in[ii+1]) << 8) |
- ((krb5_ui_4)mdContext->in[ii]);
+ in[i] = load_32_le(mdContext->in+ii);
Transform (mdContext->buf, in);
/* store buffer in digest */
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
- mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
- mdContext->digest[ii+1] =
- (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
- mdContext->digest[ii+2] =
- (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
- mdContext->digest[ii+3] =
- (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+ store_32_le(mdContext->buf[i], mdContext->digest+ii);
}
}
#endif
/* Compute U_1. */
- ibytes[3] = i & 0xff;
- ibytes[2] = (i >> 8) & 0xff;
- ibytes[1] = (i >> 16) & 0xff;
- ibytes[0] = (i >> 24) & 0xff;
+ store_32_be(i, ibytes);
tlen = salt->length;
memcpy(u_tmp2, salt->data, tlen);
count = 0;
break; /* out of while loop */
}
- *lp = (SHS_LONG) *buffer++ << 24;
- *lp |= (SHS_LONG) *buffer++ << 16;
- *lp |= (SHS_LONG) *buffer++ << 8;
- *lp++ |= (SHS_LONG) *buffer++;
+ *lp++ = load_32_be(buffer);
+ buffer += 4;
count -= 4;
}
if (canfill) {
while (count >= SHS_DATASIZE) {
lp = shsInfo->data;
while (lp < shsInfo->data + 16) {
- *lp = ((SHS_LONG) *buffer++) << 24;
- *lp |= ((SHS_LONG) *buffer++) << 16;
- *lp |= ((SHS_LONG) *buffer++) << 8;
- *lp++ |= (SHS_LONG) *buffer++;
+ *lp++ = load_32_be(buffer);
+ buffer += 4;
}
SHSTransform(shsInfo->digest, shsInfo->data);
count -= SHS_DATASIZE;
if (count > 0) {
lp = shsInfo->data;
while (count > 4) {
- *lp = ((SHS_LONG) *buffer++) << 24;
- *lp |= ((SHS_LONG) *buffer++) << 16;
- *lp |= ((SHS_LONG) *buffer++) << 8;
- *lp++ |= (SHS_LONG) *buffer++;
+ *lp++ = load_32_be(buffer);
+ buffer += 4;
count -= 4;
}
*lp = 0;