2 * Accelerated GHASH implementation with Intel PCLMULQDQ-NI
3 * instructions. This file contains accelerated part of ghash
4 * implementation. More information about PCLMULQDQ can be found at:
6 * http://software.intel.com/en-us/articles/carry-less-multiplication-and-its-usage-for-computing-the-gcm-mode/
8 * Copyright (c) 2009 Intel Corp.
9 * Author: Huang Ying <ying.huang@intel.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as published
16 * by the Free Software Foundation.
19 #include <linux/linkage.h>
26 .octa 0x000102030405060708090a0b0c0d0e0f
28 .octa 0xc2000000000000000000000000000001
30 .octa 0x00000001000000000000000000000001
43 * __clmul_gf128mul_ble: internal ABI
46 * SHASH: operand2, hash_key << 1 mod poly
48 * DATA: operand1 * operand2 mod poly
56 pshufd $0b01001110, DATA, T2
57 pshufd $0b01001110, SHASH, T3
61 PCLMULQDQ 0x00 SHASH DATA # DATA = a0 * b0
62 PCLMULQDQ 0x11 SHASH T1 # T1 = a1 * b1
63 PCLMULQDQ 0x00 T3 T2 # T2 = (a1 + a0) * (b1 + b0)
65 pxor T1, T2 # T2 = a0 * b1 + a1 * b0
71 pxor T2, T1 # <T1:DATA> is result of
72 # carry-less multiplication
74 # first phase of the reduction
87 # second phase of the reduction
98 /* void clmul_ghash_mul(char *dst, const be128 *shash) */
99 ENTRY(clmul_ghash_mul)
102 movaps .Lbswap_mask, BSWAP
103 PSHUFB_XMM BSWAP DATA
104 call __clmul_gf128mul_ble
105 PSHUFB_XMM BSWAP DATA
110 * void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
111 * const be128 *shash);
113 ENTRY(clmul_ghash_update)
115 jb .Lupdate_just_ret # check length
116 movaps .Lbswap_mask, BSWAP
119 PSHUFB_XMM BSWAP DATA
125 call __clmul_gf128mul_ble
130 PSHUFB_XMM BSWAP DATA
136 * void clmul_ghash_setkey(be128 *shash, const u8 *key);
138 * Calculate hash_key << 1 mod poly
140 ENTRY(clmul_ghash_setkey)
141 movaps .Lbswap_mask, BSWAP
143 PSHUFB_XMM BSWAP %xmm0
152 pshufd $0b00100100, %xmm2, %xmm1
153 pcmpeqd .Ltwo_one, %xmm1