crypto: chacha20 - Add a four block SSSE3 variant for x86_64
[firefly-linux-kernel-4.4.55.git] / arch / x86 / crypto / chacha20_glue.c
index 250de401d28f5de477887fea6af077cde5f0a67c..4d677c3eb7bd1610a6b3e902a6288d7ac23ca4f6 100644 (file)
 #define CHACHA20_STATE_ALIGN 16
 
 asmlinkage void chacha20_block_xor_ssse3(u32 *state, u8 *dst, const u8 *src);
+asmlinkage void chacha20_4block_xor_ssse3(u32 *state, u8 *dst, const u8 *src);
 
 static void chacha20_dosimd(u32 *state, u8 *dst, const u8 *src,
                            unsigned int bytes)
 {
        u8 buf[CHACHA20_BLOCK_SIZE];
 
+       while (bytes >= CHACHA20_BLOCK_SIZE * 4) {
+               chacha20_4block_xor_ssse3(state, dst, src);
+               bytes -= CHACHA20_BLOCK_SIZE * 4;
+               src += CHACHA20_BLOCK_SIZE * 4;
+               dst += CHACHA20_BLOCK_SIZE * 4;
+               state[12] += 4;
+       }
        while (bytes >= CHACHA20_BLOCK_SIZE) {
                chacha20_block_xor_ssse3(state, dst, src);
                bytes -= CHACHA20_BLOCK_SIZE;