svn rev #21796: trunk/src/ lib/crypto/arcfour/ lib/crypto/dk/ lib/crypto/hash_provider/ ...

raeburn@MIT.EDU raeburn at MIT.EDU
Mon Jan 26 14:06:27 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=21796
Commit By: raeburn
Log Message:
Use 16/32-bit big/little-endian store functions in more places.


Changed Files:
U   trunk/src/lib/crypto/arcfour/arcfour.c
U   trunk/src/lib/crypto/dk/checksum.c
U   trunk/src/lib/crypto/dk/dk_aead.c
U   trunk/src/lib/crypto/dk/dk_decrypt.c
U   trunk/src/lib/crypto/dk/dk_encrypt.c
U   trunk/src/lib/crypto/hash_provider/hash_crc32.c
U   trunk/src/lib/crypto/hash_provider/hash_sha1.c
U   trunk/src/lib/crypto/keyhash_provider/hmac_md5.c
U   trunk/src/lib/crypto/keyhash_provider/md5_hmac.c
U   trunk/src/lib/crypto/yarrow/yhash.h
U   trunk/src/lib/gssapi/generic/gssapiP_generic.h
U   trunk/src/lib/gssapi/krb5/k5seal.c
U   trunk/src/lib/gssapi/krb5/k5sealiov.c
U   trunk/src/lib/gssapi/krb5/k5unseal.c
U   trunk/src/lib/gssapi/krb5/k5unsealiov.c
U   trunk/src/lib/gssapi/krb5/util_crypt.c
U   trunk/src/lib/gssapi/krb5/util_seqnum.c
U   trunk/src/lib/gssapi/mechglue/g_glue.c
U   trunk/src/lib/krb5/krb/chpw.c
U   trunk/src/lib/krb5/os/mk_faddr.c
U   trunk/src/tests/gss-threads/gss-misc.c
Modified: trunk/src/lib/crypto/arcfour/arcfour.c
===================================================================
--- trunk/src/lib/crypto/arcfour/arcfour.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/arcfour/arcfour.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -254,16 +254,10 @@
   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)

Modified: trunk/src/lib/crypto/dk/checksum.c
===================================================================
--- trunk/src/lib/crypto/dk/checksum.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/dk/checksum.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -75,10 +75,7 @@
     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 @@
     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;
 

Modified: trunk/src/lib/crypto/dk/dk_aead.c
===================================================================
--- trunk/src/lib/crypto/dk/dk_aead.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/dk/dk_aead.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
     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 @@
     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;
 

Modified: trunk/src/lib/crypto/dk/dk_decrypt.c
===================================================================
--- trunk/src/lib/crypto/dk/dk_decrypt.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/dk/dk_decrypt.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -119,10 +119,7 @@
     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;
 

Modified: trunk/src/lib/crypto/dk/dk_encrypt.c
===================================================================
--- trunk/src/lib/crypto/dk/dk_encrypt.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/dk/dk_encrypt.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -99,10 +99,7 @@
     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 @@
     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;
 

Modified: trunk/src/lib/crypto/hash_provider/hash_crc32.c
===================================================================
--- trunk/src/lib/crypto/hash_provider/hash_crc32.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/hash_provider/hash_crc32.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -44,11 +44,7 @@
 	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);
 }
 

Modified: trunk/src/lib/crypto/hash_provider/hash_sha1.c
===================================================================
--- trunk/src/lib/crypto/hash_provider/hash_sha1.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/hash_provider/hash_sha1.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -44,10 +44,7 @@
     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);

Modified: trunk/src/lib/crypto/keyhash_provider/hmac_md5.c
===================================================================
--- trunk/src/lib/crypto/keyhash_provider/hmac_md5.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/keyhash_provider/hmac_md5.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
 
   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 @@
 
   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 @@
   k5_hmac_md5_hash_iov,
   NULL  /*checksum  again */
 };
-

Modified: trunk/src/lib/crypto/keyhash_provider/md5_hmac.c
===================================================================
--- trunk/src/lib/crypto/keyhash_provider/md5_hmac.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/keyhash_provider/md5_hmac.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
   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);

Modified: trunk/src/lib/crypto/yarrow/yhash.h
===================================================================
--- trunk/src/lib/crypto/yarrow/yhash.h	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/crypto/yarrow/yhash.h	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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)
 
 

Modified: trunk/src/lib/gssapi/generic/gssapiP_generic.h
===================================================================
--- trunk/src/lib/gssapi/generic/gssapiP_generic.h	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/generic/gssapiP_generic.h	2009-01-26 19:06:21 UTC (rev 21796)
@@ -59,27 +59,19 @@
    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)               \

Modified: trunk/src/lib/gssapi/krb5/k5seal.c
===================================================================
--- trunk/src/lib/gssapi/krb5/k5seal.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/k5seal.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -121,13 +121,11 @@
     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 @@
             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)
             {

Modified: trunk/src/lib/gssapi/krb5/k5sealiov.c
===================================================================
--- trunk/src/lib/gssapi/krb5/k5sealiov.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/k5sealiov.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
     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 @@
             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)

Modified: trunk/src/lib/gssapi/krb5/k5unseal.c
===================================================================
--- trunk/src/lib/gssapi/krb5/k5unseal.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/k5unseal.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -175,10 +175,7 @@
                 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)
                 {

Modified: trunk/src/lib/gssapi/krb5/k5unsealiov.c
===================================================================
--- trunk/src/lib/gssapi/krb5/k5unsealiov.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/k5unsealiov.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
                 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) {

Modified: trunk/src/lib/gssapi/krb5/util_crypt.c
===================================================================
--- trunk/src/lib/gssapi/krb5/util_crypt.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/util_crypt.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -317,10 +317,8 @@
         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 @@
         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;

Modified: trunk/src/lib/gssapi/krb5/util_seqnum.c
===================================================================
--- trunk/src/lib/gssapi/krb5/util_seqnum.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/krb5/util_seqnum.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
     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 @@
 
     }
 
-    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));
 }
 

Modified: trunk/src/lib/gssapi/mechglue/g_glue.c
===================================================================
--- trunk/src/lib/gssapi/mechglue/g_glue.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/gssapi/mechglue/g_glue.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -407,8 +407,8 @@
 
     /* 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 @@
     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);

Modified: trunk/src/lib/krb5/krb/chpw.c
===================================================================
--- trunk/src/lib/krb5/krb/chpw.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/krb5/krb/chpw.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -43,8 +43,8 @@
 
     /* 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 @@
 
     /* 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 @@
     ** 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;

Modified: trunk/src/lib/krb5/os/mk_faddr.c
===================================================================
--- trunk/src/lib/krb5/os/mk_faddr.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/lib/krb5/os/mk_faddr.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -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 @@
     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);

Modified: trunk/src/tests/gss-threads/gss-misc.c
===================================================================
--- trunk/src/tests/gss-threads/gss-misc.c	2009-01-26 16:20:41 UTC (rev 21795)
+++ trunk/src/tests/gss-threads/gss-misc.c	2009-01-26 19:06:21 UTC (rev 21796)
@@ -73,6 +73,8 @@
 
 #include <gssapi/gssapi_generic.h>
 #include "gss-misc.h"
+/* for store_32_be */
+#include "k5-platform.h"
 
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -175,11 +177,7 @@
      }
      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");




More information about the cvs-krb5 mailing list