From owner-svn-soc-all@FreeBSD.ORG Sat Sep 7 12:34:06 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5CA57E2F for ; Sat, 7 Sep 2013 12:34:06 +0000 (UTC) (envelope-from def@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 492D62E2A for ; Sat, 7 Sep 2013 12:34:06 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r87CY6Ko059038 for ; Sat, 7 Sep 2013 12:34:06 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r87CY6Ol059016 for svn-soc-all@FreeBSD.org; Sat, 7 Sep 2013 12:34:06 GMT (envelope-from def@FreeBSD.org) Date: Sat, 7 Sep 2013 12:34:06 GMT Message-Id: <201309071234.r87CY6Ol059016@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257074 - soc2013/def/crashdump-head/sys/crypto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Sep 2013 12:34:06 -0000 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 #include +#ifdef _KERNEL +#include +#else +#include +#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 #include #include -#include - -#ifdef _KERNEL -#include -#else -#include -#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;