1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Accelerated GHASH implementation with Intel PCLMULQDQ-NI
4 * instructions. This file contains accelerated part of ghash
5 * implementation. More information about PCLMULQDQ can be found at:
7 * http://software.intel.com/en-us/articles/carry-less-multiplication-and-its-usage-for-computing-the-gcm-mode/
9 * Copyright (c) 2009 Intel Corp.
10 * Author: Huang Ying <ying.huang@intel.com>
16 #include <linux/linkage.h>
18 #include <asm/frame.h>
20 .section .rodata.cst16.bswap_mask, "aM", @progbits, 16
23 .octa 0x000102030405060708090a0b0c0d0e0f
36 * __clmul_gf128mul_ble: internal ABI
39 * SHASH: operand2, hash_key << 1 mod poly
41 * DATA: operand1 * operand2 mod poly
47 SYM_FUNC_START_LOCAL(__clmul_gf128mul_ble)
49 pshufd $0b01001110, DATA, T2
50 pshufd $0b01001110, SHASH, T3
54 PCLMULQDQ 0x00 SHASH DATA # DATA = a0 * b0
55 PCLMULQDQ 0x11 SHASH T1 # T1 = a1 * b1
56 PCLMULQDQ 0x00 T3 T2 # T2 = (a1 + a0) * (b1 + b0)
58 pxor T1, T2 # T2 = a0 * b1 + a1 * b0
64 pxor T2, T1 # <T1:DATA> is result of
65 # carry-less multiplication
67 # first phase of the reduction
80 # second phase of the reduction
90 SYM_FUNC_END(__clmul_gf128mul_ble)
92 /* void clmul_ghash_mul(char *dst, const u128 *shash) */
93 SYM_FUNC_START(clmul_ghash_mul)
97 movaps .Lbswap_mask, BSWAP
99 call __clmul_gf128mul_ble
100 PSHUFB_XMM BSWAP DATA
104 SYM_FUNC_END(clmul_ghash_mul)
107 * void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
108 * const u128 *shash);
110 SYM_FUNC_START(clmul_ghash_update)
113 jb .Lupdate_just_ret # check length
114 movaps .Lbswap_mask, BSWAP
117 PSHUFB_XMM BSWAP DATA
123 call __clmul_gf128mul_ble
128 PSHUFB_XMM BSWAP DATA
133 SYM_FUNC_END(clmul_ghash_update)