summaryrefslogtreecommitdiffstats
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2017-07-24 06:28:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-08-03 21:27:05 -0400
commita7c391f04fe3259fb0417d71fec78ae28f25780e (patch)
treeae138006abd68d231231dbea641ea1cb46e43dff /crypto/algapi.c
parent9a42e4eed3fcd7ba8dff6622384cd08bfe5ef707 (diff)
crypto: algapi - use separate dst and src operands for __crypto_xor()
In preparation of introducing crypto_xor_cpy(), which will use separate operands for input and output, modify the __crypto_xor() implementation, which it will share with the existing crypto_xor(), which provides the actual functionality when not using the inline version. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index e4cc7615a139..aa699ff6c876 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -975,13 +975,15 @@ void crypto_inc(u8 *a, unsigned int size)
975} 975}
976EXPORT_SYMBOL_GPL(crypto_inc); 976EXPORT_SYMBOL_GPL(crypto_inc);
977 977
978void __crypto_xor(u8 *dst, const u8 *src, unsigned int len) 978void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int len)
979{ 979{
980 int relalign = 0; 980 int relalign = 0;
981 981
982 if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { 982 if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
983 int size = sizeof(unsigned long); 983 int size = sizeof(unsigned long);
984 int d = ((unsigned long)dst ^ (unsigned long)src) & (size - 1); 984 int d = (((unsigned long)dst ^ (unsigned long)src1) |
985 ((unsigned long)dst ^ (unsigned long)src2)) &
986 (size - 1);
985 987
986 relalign = d ? 1 << __ffs(d) : size; 988 relalign = d ? 1 << __ffs(d) : size;
987 989
@@ -992,34 +994,37 @@ void __crypto_xor(u8 *dst, const u8 *src, unsigned int len)
992 * process the remainder of the input using optimal strides. 994 * process the remainder of the input using optimal strides.
993 */ 995 */
994 while (((unsigned long)dst & (relalign - 1)) && len > 0) { 996 while (((unsigned long)dst & (relalign - 1)) && len > 0) {
995 *dst++ ^= *src++; 997 *dst++ = *src1++ ^ *src2++;
996 len--; 998 len--;
997 } 999 }
998 } 1000 }
999 1001
1000 while (IS_ENABLED(CONFIG_64BIT) && len >= 8 && !(relalign & 7)) { 1002 while (IS_ENABLED(CONFIG_64BIT) && len >= 8 && !(relalign & 7)) {
1001 *(u64 *)dst ^= *(u64 *)src; 1003 *(u64 *)dst = *(u64 *)src1 ^ *(u64 *)src2;
1002 dst += 8; 1004 dst += 8;
1003 src += 8; 1005 src1 += 8;
1006 src2 += 8;
1004 len -= 8; 1007 len -= 8;
1005 } 1008 }
1006 1009
1007 while (len >= 4 && !(relalign & 3)) { 1010 while (len >= 4 && !(relalign & 3)) {
1008 *(u32 *)dst ^= *(u32 *)src; 1011 *(u32 *)dst = *(u32 *)src1 ^ *(u32 *)src2;
1009 dst += 4; 1012 dst += 4;
1010 src += 4; 1013 src1 += 4;
1014 src2 += 4;
1011 len -= 4; 1015 len -= 4;
1012 } 1016 }
1013 1017
1014 while (len >= 2 && !(relalign & 1)) { 1018 while (len >= 2 && !(relalign & 1)) {
1015 *(u16 *)dst ^= *(u16 *)src; 1019 *(u16 *)dst = *(u16 *)src1 ^ *(u16 *)src2;
1016 dst += 2; 1020 dst += 2;
1017 src += 2; 1021 src1 += 2;
1022 src2 += 2;
1018 len -= 2; 1023 len -= 2;
1019 } 1024 }
1020 1025
1021 while (len--) 1026 while (len--)
1022 *dst++ ^= *src++; 1027 *dst++ = *src1++ ^ *src2++;
1023} 1028}
1024EXPORT_SYMBOL_GPL(__crypto_xor); 1029EXPORT_SYMBOL_GPL(__crypto_xor);
1025 1030