From: Ken Raeburn Date: Mon, 26 Jan 2009 19:06:21 +0000 (+0000) Subject: Use 16/32-bit big/little-endian store functions in more places X-Git-Tag: krb5-1.7-alpha1~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ea9fc333289d70b9c9474770e276a23a693705d1;p=krb5.git Use 16/32-bit big/little-endian store functions in more places git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21796 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/arcfour/arcfour.c b/src/lib/crypto/arcfour/arcfour.c index 8c9e8e1a4..085c997ed 100644 --- a/src/lib/crypto/arcfour/arcfour.c +++ b/src/lib/crypto/arcfour/arcfour.c @@ -254,16 +254,10 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, ms_usage=krb5int_arcfour_translate_usage(usage); if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { strncpy(salt.data, krb5int_arcfour_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); } ret=krb5_hmac(hash, key, 1, &salt, &d1); if (ret) diff --git a/src/lib/crypto/dk/checksum.c b/src/lib/crypto/dk/checksum.c index b51319b2e..f4b18bf0c 100644 --- a/src/lib/crypto/dk/checksum.c +++ b/src/lib/crypto/dk/checksum.c @@ -75,10 +75,7 @@ krb5_dk_make_checksum(const struct krb5_hash_provider *hash, datain.data = (char *) constantdata; datain.length = K5CLENGTH; - datain.data[0] = (usage>>24)&0xff; - datain.data[1] = (usage>>16)&0xff; - datain.data[2] = (usage>>8)&0xff; - datain.data[3] = usage&0xff; + store_32_be(usage, constantdata); datain.data[4] = (char) 0x99; @@ -147,10 +144,7 @@ krb5int_dk_make_checksum_iov(const struct krb5_hash_provider *hash, datain.data = (char *) constantdata; datain.length = K5CLENGTH; - datain.data[0] = (usage>>24)&0xff; - datain.data[1] = (usage>>16)&0xff; - datain.data[2] = (usage>>8)&0xff; - datain.data[3] = usage&0xff; + store_32_be(usage, constantdata); datain.data[4] = (char) 0x99; diff --git a/src/lib/crypto/dk/dk_aead.c b/src/lib/crypto/dk/dk_aead.c index 8abf5af5f..e995f9ae6 100644 --- a/src/lib/crypto/dk/dk_aead.c +++ b/src/lib/crypto/dk/dk_aead.c @@ -1,7 +1,7 @@ /* * lib/crypto/dk/dk_aead.c * - * Copyright 2008 by the Massachusetts Institute of Technology. + * Copyright 2008, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -147,10 +147,7 @@ krb5int_dk_encrypt_iov(const struct krb5_aead_provider *aead, d1.data = (char *)constantdata; d1.length = K5CLENGTH; - d1.data[0] = (usage >> 24) & 0xFF; - d1.data[1] = (usage >> 16) & 0xFF; - d1.data[2] = (usage >> 8 ) & 0xFF; - d1.data[3] = (usage ) & 0xFF; + store_32_be(usage, constantdata); d1.data[4] = 0xAA; @@ -298,10 +295,7 @@ krb5int_dk_decrypt_iov(const struct krb5_aead_provider *aead, d1.data = (char *)constantdata; d1.length = K5CLENGTH; - d1.data[0] = (usage >> 24) & 0xFF; - d1.data[1] = (usage >> 16) & 0xFF; - d1.data[2] = (usage >> 8 ) & 0xFF; - d1.data[3] = (usage ) & 0xFF; + store_32_be(usage, constantdata); d1.data[4] = 0xAA; diff --git a/src/lib/crypto/dk/dk_decrypt.c b/src/lib/crypto/dk/dk_decrypt.c index c4397382a..c38c4d5bf 100644 --- a/src/lib/crypto/dk/dk_decrypt.c +++ b/src/lib/crypto/dk/dk_decrypt.c @@ -119,10 +119,7 @@ krb5_dk_decrypt_maybe_trunc_hmac(const struct krb5_enc_provider *enc, d1.data = (char *) constantdata; d1.length = K5CLENGTH; - d1.data[0] = (usage>>24)&0xff; - d1.data[1] = (usage>>16)&0xff; - d1.data[2] = (usage>>8)&0xff; - d1.data[3] = usage&0xff; + store_32_be(usage, constantdata); d1.data[4] = (char) 0xAA; diff --git a/src/lib/crypto/dk/dk_encrypt.c b/src/lib/crypto/dk/dk_encrypt.c index 750f43ffe..6596e53ce 100644 --- a/src/lib/crypto/dk/dk_encrypt.c +++ b/src/lib/crypto/dk/dk_encrypt.c @@ -99,10 +99,7 @@ krb5_dk_encrypt(const struct krb5_enc_provider *enc, d1.data = (char *) constantdata; d1.length = K5CLENGTH; - d1.data[0] = (usage>>24)&0xff; - d1.data[1] = (usage>>16)&0xff; - d1.data[2] = (usage>>8)&0xff; - d1.data[3] = usage&0xff; + store_32_be(usage, constantdata); d1.data[4] = (char) 0xAA; @@ -265,10 +262,7 @@ krb5int_aes_dk_encrypt(const struct krb5_enc_provider *enc, d1.data = (char *) constantdata; d1.length = K5CLENGTH; - d1.data[0] = (usage>>24)&0xff; - d1.data[1] = (usage>>16)&0xff; - d1.data[2] = (usage>>8)&0xff; - d1.data[3] = usage&0xff; + store_32_be(usage, constantdata); d1.data[4] = (char) 0xAA; diff --git a/src/lib/crypto/hash_provider/hash_crc32.c b/src/lib/crypto/hash_provider/hash_crc32.c index 1df182c49..ca2681067 100644 --- a/src/lib/crypto/hash_provider/hash_crc32.c +++ b/src/lib/crypto/hash_provider/hash_crc32.c @@ -44,11 +44,7 @@ k5_crc32_hash(unsigned int icount, const krb5_data *input, c ^= cn; } - output->data[0] = c&0xff; - output->data[1] = (c>>8)&0xff; - output->data[2] = (c>>16)&0xff; - output->data[3] = (c>>24)&0xff; - + store_32_le(c, output->data); return(0); } diff --git a/src/lib/crypto/hash_provider/hash_sha1.c b/src/lib/crypto/hash_provider/hash_sha1.c index cdb309867..ffc073cf1 100644 --- a/src/lib/crypto/hash_provider/hash_sha1.c +++ b/src/lib/crypto/hash_provider/hash_sha1.c @@ -44,10 +44,7 @@ k5_sha1_hash(unsigned int icount, const krb5_data *input, shsFinal(&ctx); for (i=0; i<(sizeof(ctx.digest)/sizeof(ctx.digest[0])); i++) { - output->data[i*4] = (ctx.digest[i]>>24)&0xff; - output->data[i*4+1] = (ctx.digest[i]>>16)&0xff; - output->data[i*4+2] = (ctx.digest[i]>>8)&0xff; - output->data[i*4+3] = ctx.digest[i]&0xff; + store_32_be(ctx.digest[i], &output->data[i*4]); } return(0); diff --git a/src/lib/crypto/keyhash_provider/hmac_md5.c b/src/lib/crypto/keyhash_provider/hmac_md5.c index 53da03ad4..34ce67169 100644 --- a/src/lib/crypto/keyhash_provider/hmac_md5.c +++ b/src/lib/crypto/keyhash_provider/hmac_md5.c @@ -1,7 +1,7 @@ /* * lib/crypto/keyhash_provider/hmac_md5.c * - * Copyright 2001 by the Massachusetts Institute of Technology. + * Copyright 2001, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -65,10 +65,7 @@ k5_hmac_md5_hash (const krb5_keyblock *key, krb5_keyusage usage, krb5_MD5Init (&ctx); ms_usage = krb5int_arcfour_translate_usage (usage); - t[0] = (ms_usage) & 0xff; - t[1] = (ms_usage>>8) & 0xff; - t[2] = (ms_usage >>16) & 0xff; - t[3] = (ms_usage>>24) & 0XFF; + store_32_le(ms_usage, t); krb5_MD5Update (&ctx, (unsigned char * ) &t, 4); krb5_MD5Update (&ctx, (unsigned char *) input-> data, (unsigned int) input->length ); @@ -116,10 +113,7 @@ k5_hmac_md5_hash_iov (const krb5_keyblock *key, krb5_keyusage usage, krb5_MD5Init (&ctx); ms_usage = krb5int_arcfour_translate_usage (usage); - t[0] = (ms_usage) & 0xff; - t[1] = (ms_usage>>8) & 0xff; - t[2] = (ms_usage >>16) & 0xff; - t[3] = (ms_usage>>24) & 0XFF; + store_32_le(ms_usage, t); krb5_MD5Update (&ctx, (unsigned char * ) &t, 4); for (i = 0; i < num_data; i++) { const krb5_crypto_iov *iov = &data[i]; @@ -148,4 +142,3 @@ const struct krb5_keyhash_provider krb5int_keyhash_hmac_md5 = { k5_hmac_md5_hash_iov, NULL /*checksum again */ }; - diff --git a/src/lib/crypto/keyhash_provider/md5_hmac.c b/src/lib/crypto/keyhash_provider/md5_hmac.c index e8aea745c..d05b97f00 100644 --- a/src/lib/crypto/keyhash_provider/md5_hmac.c +++ b/src/lib/crypto/keyhash_provider/md5_hmac.c @@ -1,7 +1,7 @@ /* * lib/crypto/keyhash_provider/md5_hmac.c * - * Copyright2001 by the Massachusetts Institute of Technology. + * Copyright 2001, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -45,11 +45,7 @@ k5_md5_hmac_hash (const krb5_keyblock *key, krb5_keyusage usage, krb5_MD5Init(&ctx); ms_usage = krb5int_arcfour_translate_usage (usage); - t[0] = (ms_usage >> 0) & 0xff; - t[1] = (ms_usage >> 8) & 0xff; - t[2] = (ms_usage >> 16) & 0xff; - t[3] = (ms_usage >> 24) & 0xff; - + store_32_le(ms_usage, t); krb5_MD5Update(&ctx, t, sizeof(t)); krb5_MD5Update(&ctx, (unsigned char *)input->data, input->length); krb5_MD5Final(&ctx); diff --git a/src/lib/crypto/yarrow/yhash.h b/src/lib/crypto/yarrow/yhash.h index aaa739fe1..ee4f03eb2 100644 --- a/src/lib/crypto/yarrow/yhash.h +++ b/src/lib/crypto/yarrow/yhash.h @@ -19,12 +19,8 @@ unsigned char *out2 = (void *)(tdigest); \ HASH_CTX *ctx = (x); \ shsFinal(ctx); \ -for (loopvar=0; loopvar<(sizeof(ctx->digest)/sizeof(ctx->digest[0])); loopvar++) { \ - out2[loopvar*4] = (ctx->digest[loopvar]>>24)&0xff; \ - out2[loopvar*4+1] = (ctx->digest[loopvar]>>16)&0xff; \ - out2[loopvar*4+2] = (ctx->digest[loopvar]>>8)&0xff; \ - out2[loopvar*4+3] = ctx->digest[loopvar]&0xff; \ -} \ + for (loopvar=0; loopvar<(sizeof(ctx->digest)/sizeof(ctx->digest[0])); loopvar++) \ + store_32_be(ctx->digest[loopvar], &out2[loopvar*4]); \ } while(0) diff --git a/src/lib/gssapi/generic/gssapiP_generic.h b/src/lib/gssapi/generic/gssapiP_generic.h index b84f69e6a..b684055c4 100644 --- a/src/lib/gssapi/generic/gssapiP_generic.h +++ b/src/lib/gssapi/generic/gssapiP_generic.h @@ -59,27 +59,19 @@ typedef UINT64_TYPE gssint_uint64; things */ #define TWRITE_INT(ptr, num, bigend) \ - (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \ - (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \ - (ptr)[2] = (char) ((bigend)?(((num)>>8)&0xff):(((num)>>16)&0xff)); \ - (ptr)[3] = (char) ((bigend)?((num)&0xff):((num)>>24)); \ + if (bigend) store_32_be(num, ptr); else store_32_le(num, ptr); \ (ptr) += 4; #define TWRITE_INT16(ptr, num, bigend) \ - (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \ - (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \ + if (bigend) store_16_be((num)>>16, ptr); else store_16_le(num, ptr); \ (ptr) += 2; -#define TREAD_INT(ptr, num, bigend) \ - (num) = (((ptr)[0]<<((bigend)?24: 0)) | \ - ((ptr)[1]<<((bigend)?16: 8)) | \ - ((ptr)[2]<<((bigend)? 8:16)) | \ - ((ptr)[3]<<((bigend)? 0:24))); \ +#define TREAD_INT(ptr, num, bigend) \ + (num) = ((bigend) ? load_32_be(ptr) : load_32_le(ptr)); \ (ptr) += 4; -#define TREAD_INT16(ptr, num, bigend) \ - (num) = (((ptr)[0]<<((bigend)?24: 0)) | \ - ((ptr)[1]<<((bigend)?16: 8))); \ +#define TREAD_INT16(ptr, num, bigend) \ + (num) = ((bigend) ? (load_16_be(ptr) << 16) : load_16_le(ptr)); \ (ptr) += 2; #define TWRITE_STR(ptr, str, len) \ diff --git a/src/lib/gssapi/krb5/k5seal.c b/src/lib/gssapi/krb5/k5seal.c index aba8d81d6..bff1ab185 100644 --- a/src/lib/gssapi/krb5/k5seal.c +++ b/src/lib/gssapi/krb5/k5seal.c @@ -121,13 +121,11 @@ make_seal_token_v1 (krb5_context context, g_make_token_header(oid, 14+cksum_size+tmsglen, &ptr, toktype); /* 0..1 SIGN_ALG */ - ptr[0] = signalg & 0xff; - ptr[1] = (signalg >> 8) & 0xff; + store_16_le(signalg, &ptr[0]); /* 2..3 SEAL_ALG or Filler */ if ((toktype == KG_TOK_SEAL_MSG) && do_encrypt) { - ptr[2] = sealalg & 0xff; - ptr[3] = (sealalg >> 8) & 0xff; + store_16_le(sealalg, &ptr[2]); } else { /* No seal */ ptr[2] = 0xff; @@ -260,10 +258,7 @@ make_seal_token_v1 (krb5_context context, unsigned char bigend_seqnum[4]; krb5_keyblock *enc_key; int i; - bigend_seqnum[0] = (*seqnum>>24) & 0xff; - bigend_seqnum[1] = (*seqnum>>16) & 0xff; - bigend_seqnum[2] = (*seqnum>>8) & 0xff; - bigend_seqnum[3] = *seqnum & 0xff; + store_32_be(seqnum, bigend_seqnum); code = krb5_copy_keyblock (context, enc, &enc_key); if (code) { diff --git a/src/lib/gssapi/krb5/k5sealiov.c b/src/lib/gssapi/krb5/k5sealiov.c index 1d0c57300..f4354a9f3 100644 --- a/src/lib/gssapi/krb5/k5sealiov.c +++ b/src/lib/gssapi/krb5/k5sealiov.c @@ -2,7 +2,7 @@ /* * lib/gssapi/krb5/k5sealiov.c * - * Copyright 2008 by the Massachusetts Institute of Technology. + * Copyright 2008, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -133,13 +133,11 @@ make_seal_token_v1_iov(krb5_context context, g_make_token_header(ctx->mech_used, 14 + ctx->cksum_size + tmsglen, &ptr, toktype); /* 0..1 SIGN_ALG */ - ptr[0] = (ctx->signalg ) & 0xFF; - ptr[1] = (ctx->signalg >> 8) & 0xFF; + store_16_le(ctx->signalg, &ptr[0]); /* 2..3 SEAL_ALG or Filler */ if (toktype == KG_TOK_WRAP_MSG && conf_req_flag) { - ptr[2] = (ctx->sealalg ) & 0xFF; - ptr[3] = (ctx->sealalg >> 8) & 0xFF; + store_16_le(ctx->sealalg, &ptr[2]); } else { /* No seal */ ptr[2] = 0xFF; @@ -226,10 +224,7 @@ make_seal_token_v1_iov(krb5_context context, krb5_keyblock *enc_key; size_t i; - bigend_seqnum[0] = (ctx->seq_send >> 24) & 0xFF; - bigend_seqnum[1] = (ctx->seq_send >> 16) & 0xFF; - bigend_seqnum[2] = (ctx->seq_send >> 8 ) & 0xFF; - bigend_seqnum[3] = (ctx->seq_send ) & 0xFF; + store_32_be(ctx->seq_send, bigend_seqnum); code = krb5_copy_keyblock(context, ctx->enc, &enc_key); if (code != 0) diff --git a/src/lib/gssapi/krb5/k5unseal.c b/src/lib/gssapi/krb5/k5unseal.c index 8020b15f3..f55180af8 100644 --- a/src/lib/gssapi/krb5/k5unseal.c +++ b/src/lib/gssapi/krb5/k5unseal.c @@ -175,10 +175,7 @@ kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, message_buffer, unsigned char bigend_seqnum[4]; krb5_keyblock *enc_key; int i; - bigend_seqnum[0] = (seqnum>>24) & 0xff; - bigend_seqnum[1] = (seqnum>>16) & 0xff; - bigend_seqnum[2] = (seqnum>>8) & 0xff; - bigend_seqnum[3] = seqnum & 0xff; + store_32_be(seqnum, bigend_seqnum); code = krb5_copy_keyblock (context, ctx->enc, &enc_key); if (code) { diff --git a/src/lib/gssapi/krb5/k5unsealiov.c b/src/lib/gssapi/krb5/k5unsealiov.c index 87a4b20f9..5d2bd1afa 100644 --- a/src/lib/gssapi/krb5/k5unsealiov.c +++ b/src/lib/gssapi/krb5/k5unsealiov.c @@ -2,7 +2,7 @@ /* * lib/gssapi/krb5/k5unsealiov.c * - * Copyright 2008 by the Massachusetts Institute of Technology. + * Copyright 2008, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -151,10 +151,7 @@ kg_unseal_v1_iov(krb5_context context, krb5_keyblock *enc_key; size_t i; - bigend_seqnum[0] = (seqnum >> 24) & 0xFF; - bigend_seqnum[1] = (seqnum >> 16) & 0xFF; - bigend_seqnum[2] = (seqnum >> 8 ) & 0xFF; - bigend_seqnum[3] = (seqnum ) & 0xFF; + store_32_be(seqnum, bigend_seqnum); code = krb5_copy_keyblock(context, ctx->enc, &enc_key); if (code != 0) { diff --git a/src/lib/gssapi/krb5/util_crypt.c b/src/lib/gssapi/krb5/util_crypt.c index db38e9eab..a8558a594 100644 --- a/src/lib/gssapi/krb5/util_crypt.c +++ b/src/lib/gssapi/krb5/util_crypt.c @@ -317,10 +317,8 @@ kg_arcfour_docrypt (const krb5_keyblock *longterm_key , int ms_usage, memcpy(t, kg_arcfour_l40, sizeof(kg_arcfour_l40)); i += sizeof(kg_arcfour_l40); } - t[i++] = ms_usage &0xff; - t[i++] = (ms_usage>>8) & 0xff; - t[i++] = (ms_usage>>16) & 0xff; - t[i++] = (ms_usage>>24) & 0xff; + store_32_le(ms_usage, &t[i]); + i += 4; input.data = (void *) &t; input.length = i; output.data = (void *) usage_key.contents; @@ -684,10 +682,8 @@ kg_arcfour_docrypt_iov (krb5_context context, memcpy(t, kg_arcfour_l40, sizeof(kg_arcfour_l40)); i += sizeof(kg_arcfour_l40); } - t[i++] = ms_usage &0xff; - t[i++] = (ms_usage>>8) & 0xff; - t[i++] = (ms_usage>>16) & 0xff; - t[i++] = (ms_usage>>24) & 0xff; + store_32_le(ms_usage, &t[i]); + i += 4; input.data = (void *) &t; input.length = i; output.data = (void *) usage_key.contents; diff --git a/src/lib/gssapi/krb5/util_seqnum.c b/src/lib/gssapi/krb5/util_seqnum.c index 372cb62a9..b91dd658c 100644 --- a/src/lib/gssapi/krb5/util_seqnum.c +++ b/src/lib/gssapi/krb5/util_seqnum.c @@ -1,6 +1,6 @@ /* -*- mode: c; indent-tabs-mode: nil -*- */ /* - * Copyright2001 by the Massachusetts Institute of Technology. + * Copyright 2001, 2009 by the Massachusetts Institute of Technology. * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -47,10 +47,7 @@ kg_make_seq_num(context, key, direction, seqnum, cksum, buf) if (key->enctype == ENCTYPE_ARCFOUR_HMAC || key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { /* Yes, Microsoft used big-endian sequence number.*/ - plain[0] = (seqnum>>24) & 0xff; - plain[1] = (seqnum>>16) & 0xff; - plain[2] = (seqnum>>8) & 0xff; - plain[3] = seqnum & 0xff; + store_32_be(seqnum, plain); return kg_arcfour_docrypt (key, 0, cksum, 8, &plain[0], 8, @@ -58,11 +55,7 @@ kg_make_seq_num(context, key, direction, seqnum, cksum, buf) } - plain[0] = (unsigned char) (seqnum&0xff); - plain[1] = (unsigned char) ((seqnum>>8)&0xff); - plain[2] = (unsigned char) ((seqnum>>16)&0xff); - plain[3] = (unsigned char) ((seqnum>>24)&0xff); - + store_32_le(seqnum, plain); return(kg_encrypt(context, key, KG_USAGE_SEQ, cksum, plain, buf, 8)); } diff --git a/src/lib/gssapi/mechglue/g_glue.c b/src/lib/gssapi/mechglue/g_glue.c index 8b4070eb4..5a8ea54b1 100644 --- a/src/lib/gssapi/mechglue/g_glue.c +++ b/src/lib/gssapi/mechglue/g_glue.c @@ -407,8 +407,8 @@ OM_uint32 gssint_export_internal_name(minor_status, mech_type, /* spec allows only 2 bytes for the mech oid length */ mechOidLen = mechOidDERLen + mechOidTagLen + mech_type->length; - *buf++ = (mechOidLen & 0xFF00) >> 8; - *buf++ = (mechOidLen & 0x00FF); + store_16_be(mechOidLen, buf); + buf += 2; /* * DER Encoding of mech OID contains OID Tag (0x06), length and @@ -427,10 +427,8 @@ OM_uint32 gssint_export_internal_name(minor_status, mech_type, buf += mech_type->length; /* spec designates the next 4 bytes for the name length */ - *buf++ = (dispName.length & 0xFF000000) >> 24; - *buf++ = (dispName.length & 0x00FF0000) >> 16; - *buf++ = (dispName.length & 0x0000FF00) >> 8; - *buf++ = (dispName.length & 0X000000FF); + store_32_be(dispName.length, buf); + buf += 4; /* for the final ingredient - add the name from gss_display_name */ (void) memcpy(buf, dispName.value, dispName.length); diff --git a/src/lib/krb5/krb/chpw.c b/src/lib/krb5/krb/chpw.c index 851a9ecdd..f5f68d562 100644 --- a/src/lib/krb5/krb/chpw.c +++ b/src/lib/krb5/krb/chpw.c @@ -43,8 +43,8 @@ krb5int_mk_chpw_req(krb5_context context, /* length */ - *ptr++ = (packet->length>> 8) & 0xff; - *ptr++ = packet->length & 0xff; + store_16_be(packet->length, ptr); + ptr += 2; /* version == 0x0001 big-endian */ @@ -53,8 +53,8 @@ krb5int_mk_chpw_req(krb5_context context, /* ap_req length, big-endian */ - *ptr++ = (ap_req->length>>8) & 0xff; - *ptr++ = ap_req->length & 0xff; + store_16_be(ap_req->length, ptr); + ptr += 2; /* ap-req data */ @@ -306,14 +306,14 @@ krb5int_mk_setpw_req(krb5_context context, ** build the packet - */ /* put in the length */ - *ptr++ = (packet->length>>8) & 0xff; - *ptr++ = packet->length & 0xff; + store_16_be(packet->length, ptr); + ptr += 2; /* put in the version */ *ptr++ = (char)0xff; *ptr++ = (char)0x80; /* the ap_req length is big endian */ - *ptr++ = (ap_req->length>>8) & 0xff; - *ptr++ = ap_req->length & 0xff; + store_16_be(ap_req->length, ptr); + ptr += 2; /* put in the request data */ memcpy(ptr, ap_req->data, ap_req->length); ptr += ap_req->length; diff --git a/src/lib/krb5/os/mk_faddr.c b/src/lib/krb5/os/mk_faddr.c index cd243c022..a5cc99a65 100644 --- a/src/lib/krb5/os/mk_faddr.c +++ b/src/lib/krb5/os/mk_faddr.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/full_ipadr.c * - * Copyright 1995 by the Massachusetts Institute of Technology. + * Copyright 1995, 2009 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -57,8 +57,8 @@ krb5_make_fulladdr(krb5_context context, krb5_address *kaddr, krb5_address *kpor tmp16 = kaddr->addrtype; *marshal++ = 0x00; *marshal++ = 0x00; - *marshal++ = (krb5_octet) (tmp16 & 0xff); - *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff); + store_16_le(tmp16, marshal); + marshal += 2; tmp32 = kaddr->length; store_32_le(tmp32, marshal); diff --git a/src/tests/gss-threads/gss-misc.c b/src/tests/gss-threads/gss-misc.c index 3016db220..27a8af6a5 100644 --- a/src/tests/gss-threads/gss-misc.c +++ b/src/tests/gss-threads/gss-misc.c @@ -73,6 +73,8 @@ static char *rcsid = "$Header$"; #include #include "gss-misc.h" +/* for store_32_be */ +#include "k5-platform.h" #ifdef HAVE_STDLIB_H #include @@ -175,11 +177,7 @@ int send_token(s, flags, tok) } if (tok->length > 0xffffffffUL) abort(); - lenbuf[0] = (tok->length >> 24) & 0xff; - lenbuf[1] = (tok->length >> 16) & 0xff; - lenbuf[2] = (tok->length >> 8) & 0xff; - lenbuf[3] = tok->length & 0xff; - + store_32_be(tok->length, lenbuf); ret = write_all(s, lenbuf, 4); if (ret < 0) { perror("sending token length");