Skip to contentSkip to conversation

crypto: use get/put_endian helpers

PATCH In review Harvey Harrison 1 participant 1 message May 29, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/37 crypto: use get/put_endian helpers

---
 crypto/ccm.c         |    6 +++---
 crypto/crc32c.c      |    6 +++---
 crypto/ctr.c         |    3 +--
 crypto/lrw.c         |    2 +-
 crypto/michael_mic.c |    4 ++--
 5 files changed, 10 insertions(+), 11 deletions(-)
crypto/ccm.c +3 -3
index 7cf7e5a..54638a7 100644
@@ -150,11 +150,11 @@ static int format_adata(u8 *adata, unsigned int a)
 	 * RFC 3610 and NIST Special Publication 800-38C
 	 */
 	if (a < 65280) {
-		*(__be16 *)adata = cpu_to_be16(a);
+		put_be16(a, (__be16 *)adata);
 		len = 2;
 	} else  {
-		*(__be16 *)adata = cpu_to_be16(0xfffe);
-		*(__be32 *)&adata[2] = cpu_to_be32(a);
+		put_be16(0xfffe, (__be16 *)adata);
+		put_be32(a, (__be32 *)&adata[2]);
 		len = 6;
 	}
 
crypto/crc32c.c +3 -3
index 0dcf64a..a1c3f8a 100644
@@ -52,7 +52,7 @@ static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key,
 		tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
 		return -EINVAL;
 	}
-	mctx->key = le32_to_cpu(*(__le32 *)key);
+	mctx->key = get_le32((__le32 *)key);
 	return 0;
 }
 
@@ -67,8 +67,8 @@ static void chksum_update(struct crypto_tfm *tfm, const u8 *data,
 static void chksum_final(struct crypto_tfm *tfm, u8 *out)
 {
 	struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
-	
-	*(__le32 *)out = ~cpu_to_le32(mctx->crc);
+
+	put_le32(~mctx->crc, (__le32 *)out);
 }
 
 static int crc32c_cra_init(struct crypto_tfm *tfm)
crypto/ctr.c +1 -2
index 2d7425f..5105d07 100644
@@ -285,8 +285,7 @@ static int crypto_rfc3686_crypt(struct blkcipher_desc *desc,
 	memcpy(iv + CTR_RFC3686_NONCE_SIZE, info, CTR_RFC3686_IV_SIZE);
 
 	/* initialize counter portion of counter block */
-	*(__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE) =
-		cpu_to_be32(1);
+	put_be32(1, (__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE));
 
 	desc->tfm = child;
 	desc->info = iv;
crypto/lrw.c +1 -1
index 8ef664e..42a4533 100644
@@ -111,7 +111,7 @@ static inline int get_index128(be128 *block)
 	__be32 *p = (__be32 *) block;
 
 	for (p += 3, x = 0; x < 128; p--, x += 32) {
-		u32 val = be32_to_cpup(p);
+		u32 val = get_be32(p);
 
 		if (!~val)
 			continue;
crypto/michael_mic.c +2 -2
index 9e917b8..8aab62f 100644
@@ -71,7 +71,7 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data,
 			return;
 
 		src = (const __le32 *)mctx->pending;
-		mctx->l ^= le32_to_cpup(src);
+		mctx->l ^= get_le32(src);
 		michael_block(mctx->l, mctx->r);
 		mctx->pending_len = 0;
 	}
@@ -79,7 +79,7 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data,
 	src = (const __le32 *)data;
 
 	while (len >= 4) {
-		mctx->l ^= le32_to_cpup(src++);
+		mctx->l ^= get_le32(src++);
 		michael_block(mctx->l, mctx->r);
 		len -= 4;
 	}
Signature · 1 line
1.5.6.rc0.277.g804cf