socsvn commit: r257074 - soc2013/def/crashdump-head/sys/crypto

def at FreeBSD.org def at FreeBSD.org
Sat Sep 7 12:34:06 UTC 2013


Author: def
Date: Sat Sep  7 12:34:06 2013
New Revision: 257074
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257074

Log:
  Roll back XTS implementation to r255309.

Modified:
  soc2013/def/crashdump-head/sys/crypto/xts.c
  soc2013/def/crashdump-head/sys/crypto/xts.h

Modified: soc2013/def/crashdump-head/sys/crypto/xts.c
==============================================================================
--- soc2013/def/crashdump-head/sys/crypto/xts.c	Sat Sep  7 11:41:52 2013	(r257073)
+++ soc2013/def/crashdump-head/sys/crypto/xts.c	Sat Sep  7 12:34:06 2013	(r257074)
@@ -32,6 +32,12 @@
 #include <sys/endian.h>
 #include <crypto/xts.h>
 
+#ifdef _KERNEL
+#include <sys/libkern.h>
+#else
+#include <string.h>
+#endif
+
 void
 xts_aes_keysetup(struct xts_ctx *ctx, const uint8_t *key, uint32_t keybits)
 {
@@ -57,7 +63,42 @@
 	.pa_id 		= XTS_ALG_AES,
 };
 
-void
+static __inline void
+xor128(void *dst, const void *src1, const void *src2)
+{
+	const uint64_t *s1 = (const uint64_t *)src1;
+	const uint64_t *s2 = (const uint64_t *)src2;
+	uint64_t *d = (uint64_t *)dst;
+
+	d[0] = s1[0] ^ s2[0];
+	d[1] = s1[1] ^ s2[1];
+}
+
+static __inline int
+shl128(uint64_t *d, const uint64_t *s)
+{
+	int c0, c1;
+
+	c0 = s[0] & (1ULL << 63) ? 1 : 0;
+	c1 = s[1] & (1ULL << 63) ? 1 : 0;
+	d[0] = s[0] << 1;
+	d[1] = s[1] << 1 | c0;
+
+	return (c1);
+}
+
+static __inline void
+gf_mul128(uint64_t *dst, const uint64_t *src)
+{
+	static const uint8_t gf_128_fdbk = 0x87;
+	int carry;
+
+	carry = shl128(dst, src);
+	if (carry != 0)
+		((uint8_t *)dst)[0] ^= gf_128_fdbk;
+}
+
+static __inline void
 xts_fullblock(algop_crypt_t *data_crypt, const struct xts_ctx *data_ctx,
     uint64_t *tweak, const uint8_t *src, uint8_t *dst)
 {
@@ -67,7 +108,7 @@
 	gf_mul128(tweak, tweak);
 }
 
-void
+static __inline void
 xts_lastblock(algop_crypt_t *data_crypt, const struct xts_ctx *data_ctx,
     uint64_t *tweak, const uint8_t *src, uint8_t *dst, int len)
 {
@@ -83,7 +124,7 @@
 	xor128(dst, dst, tweak);
 }
 
-void
+static __inline void
 xts_start(const struct xts_alg *alg, const struct xts_ctx *tweak_ctx,
     uint64_t *tweak, uint64_t sector, const uint8_t *xtweak)
 {
@@ -97,46 +138,40 @@
 void
 xts_block_encrypt(const struct xts_alg *alg,
     const struct xts_ctx *tweak_ctx, const struct xts_ctx *data_ctx,
-    uint64_t sector, const uint8_t *xtweak, uint64_t *alpha_j,
-    int len, const uint8_t *src, uint8_t *dst)
+    uint64_t sector, const uint8_t *xtweak, int len,
+    const uint8_t *src, uint8_t *dst)
 {
 	uint64_t tweak[XTS_BLK_BYTES / 8];
 
-	if (alpha_j == NULL) {
-		xts_start(alg, tweak_ctx, tweak, sector, xtweak);
-		alpha_j = tweak;
-	}
+	xts_start(alg, tweak_ctx, tweak, sector, xtweak);
 
 	while (len >= XTS_BLK_BYTES) {
-		xts_fullblock(alg->pa_encrypt, data_ctx, alpha_j, src, dst);
+		xts_fullblock(alg->pa_encrypt, data_ctx, tweak, src, dst);
 		dst += XTS_BLK_BYTES;
 		src += XTS_BLK_BYTES;
 		len -= XTS_BLK_BYTES;
 	}
 
 	if (len != 0)
-		xts_lastblock(alg->pa_encrypt, data_ctx, alpha_j, src, dst, len);
+		xts_lastblock(alg->pa_encrypt, data_ctx, tweak, src, dst, len);
 }
 
 void
 xts_block_decrypt(const struct xts_alg *alg,
     const struct xts_ctx *tweak_ctx, const struct xts_ctx *data_ctx,
-    uint64_t sector, const uint8_t *xtweak, uint64_t *alpha_j,
-    int len, const uint8_t *src, uint8_t *dst)
+    uint64_t sector, const uint8_t *xtweak, int len,
+    const uint8_t *src, uint8_t *dst)
 {
 	uint64_t tweak[XTS_BLK_BYTES / 8];
 	uint64_t prevtweak[XTS_BLK_BYTES / 8];
 
-	if (alpha_j == NULL) {
-		xts_start(alg, tweak_ctx, tweak, sector, xtweak);
-		alpha_j = tweak;
-	}
+	xts_start(alg, tweak_ctx, tweak, sector, xtweak);
 
 	if ((len & XTS_BLK_MASK) != 0)
 		len -= XTS_BLK_BYTES;
 
 	while (len >= XTS_BLK_BYTES) {
-		xts_fullblock(alg->pa_decrypt, data_ctx, alpha_j, src, dst);
+		xts_fullblock(alg->pa_decrypt, data_ctx, tweak, src, dst);
 		dst += XTS_BLK_BYTES;
 		src += XTS_BLK_BYTES;
 		len -= XTS_BLK_BYTES;
@@ -144,10 +179,10 @@
 
 	if (len != 0) {
 		len += XTS_BLK_BYTES;
-		prevtweak[0] = alpha_j[0];
-		prevtweak[1] = alpha_j[1];
-		gf_mul128(alpha_j, alpha_j);
-		xts_fullblock(alg->pa_decrypt, data_ctx, alpha_j, src, dst);
+		prevtweak[0] = tweak[0];
+		prevtweak[1] = tweak[1];
+		gf_mul128(tweak, tweak);
+		xts_fullblock(alg->pa_decrypt, data_ctx, tweak, src, dst);
 		dst += XTS_BLK_BYTES;
 		src += XTS_BLK_BYTES;
 		len -= XTS_BLK_BYTES;

Modified: soc2013/def/crashdump-head/sys/crypto/xts.h
==============================================================================
--- soc2013/def/crashdump-head/sys/crypto/xts.h	Sat Sep  7 11:41:52 2013	(r257073)
+++ soc2013/def/crashdump-head/sys/crypto/xts.h	Sat Sep  7 12:34:06 2013	(r257074)
@@ -32,13 +32,6 @@
 #include <crypto/camellia/camellia.h>
 #include <crypto/rijndael/rijndael.h>
 #include <crypto/hmac/hmac.h>
-#include <sys/endian.h>
-
-#ifdef _KERNEL
-#include <sys/libkern.h>
-#else
-#include <string.h>
-#endif
 
 #define	XTS_BLK_BYTES		16
 #define	XTS_BLK_MASK		(XTS_BLK_BYTES - 1)
@@ -65,59 +58,15 @@
 	int			pa_id;
 };
 
-static __inline void
-xor128(void *dst, const void *src1, const void *src2)
-{
-	const uint64_t *s1 = (const uint64_t *)src1;
-	const uint64_t *s2 = (const uint64_t *)src2;
-	uint64_t *d = (uint64_t *)dst;
-
-	d[0] = s1[0] ^ s2[0];
-	d[1] = s1[1] ^ s2[1];
-}
-
-static __inline int
-shl128(uint64_t *d, const uint64_t *s)
-{
-	int c0, c1;
-
-	c0 = s[0] & (1ULL << 63) ? 1 : 0;
-	c1 = s[1] & (1ULL << 63) ? 1 : 0;
-	d[0] = s[0] << 1;
-	d[1] = s[1] << 1 | c0;
-
-	return (c1);
-}
-
-static __inline void
-gf_mul128(uint64_t *dst, const uint64_t *src)
-{
-	static const uint8_t gf_128_fdbk = 0x87;
-	int carry;
-
-	carry = shl128(dst, src);
-	if (carry != 0)
-		((uint8_t *)dst)[0] ^= gf_128_fdbk;
-}
-
-void	xts_fullblock(algop_crypt_t *data_crypt, const struct xts_ctx *data_ctx,
-	    uint64_t *tweak, const uint8_t *src, uint8_t *dst);
-
-void	xts_lastblock(algop_crypt_t *data_crypt, const struct xts_ctx *data_ctx,
-	    uint64_t *tweak, const uint8_t *src, uint8_t *dst, int len);
-
-void	xts_start(const struct xts_alg *alg, const struct xts_ctx *tweak_ctx,
-	    uint64_t *tweak, uint64_t sector, const uint8_t *xtweak);
-
 void	xts_block_encrypt(const struct xts_alg *alg,
 	    const struct xts_ctx *tweak_ctx, const struct xts_ctx *data_ctx,
-	    uint64_t sector, const uint8_t *xtweak, uint64_t *alpha_j,
-	    int len, const uint8_t *src, uint8_t *dst);
+	    uint64_t sector, const uint8_t *xtweak, int len,
+	    const uint8_t *src, uint8_t *dst);
 
 void	xts_block_decrypt(const struct xts_alg *alg,
 	    const struct xts_ctx *tweak_ctx, const struct xts_ctx *data_ctx,
-	    uint64_t sector, const uint8_t *xtweak, uint64_t *alpha_j,
-	    int len, const uint8_t *src, uint8_t *dst);
+	    uint64_t sector, const uint8_t *xtweak, int len,
+	    const uint8_t *src, uint8_t *dst);
 
 algop_crypt_t		xts_aes_encrypt;
 algop_crypt_t		xts_aes_decrypt;


More information about the svn-soc-all mailing list