Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* gf128mul.c - GF(2^128) multiplication functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2003, Dr Brian Gladman, Worcester, UK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2006, Rik Snel <rsnel@cube.dyndns.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Based on Dr Brian Gladman's (GPL'd) work published at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * http://gladman.plushost.co.uk/oldsite/cryptography_technology/index.php
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * See the original copyright notice below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * under the terms of the GNU General Public License as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Software Foundation; either version 2 of the License, or (at your option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  Copyright (c) 2003, Dr Brian Gladman, Worcester, UK.   All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  LICENSE TERMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  The free distribution and use of this software in both source and binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  form is allowed (with or without changes) provided that:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)    1. distributions of this source code include the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)       notice, this list of conditions and the following disclaimer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)    2. distributions in binary form include the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)       notice, this list of conditions and the following disclaimer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)       in the documentation and/or other associated materials;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)    3. the copyright holder's name is not used to endorse products
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)       built using this software without specific written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  ALTERNATIVELY, provided that this notice is retained in full, this product
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  may be distributed under the terms of the GNU General Public License (GPL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  in which case the provisions of the GPL apply INSTEAD OF those given above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  DISCLAIMER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  This software is provided 'as is' with no explicit or implied warranties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  in respect of its properties, including, but not limited to, correctness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  and/or fitness for purpose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  Issue 31/01/2006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  This file provides fast multiplication in GF(2^128) as required by several
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  cryptographic authentication modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <crypto/gf128mul.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define gf128mul_dat(q) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	q(0x00), q(0x01), q(0x02), q(0x03), q(0x04), q(0x05), q(0x06), q(0x07),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	q(0x08), q(0x09), q(0x0a), q(0x0b), q(0x0c), q(0x0d), q(0x0e), q(0x0f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	q(0x10), q(0x11), q(0x12), q(0x13), q(0x14), q(0x15), q(0x16), q(0x17),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	q(0x18), q(0x19), q(0x1a), q(0x1b), q(0x1c), q(0x1d), q(0x1e), q(0x1f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	q(0x20), q(0x21), q(0x22), q(0x23), q(0x24), q(0x25), q(0x26), q(0x27),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	q(0x28), q(0x29), q(0x2a), q(0x2b), q(0x2c), q(0x2d), q(0x2e), q(0x2f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	q(0x30), q(0x31), q(0x32), q(0x33), q(0x34), q(0x35), q(0x36), q(0x37),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	q(0x38), q(0x39), q(0x3a), q(0x3b), q(0x3c), q(0x3d), q(0x3e), q(0x3f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	q(0x40), q(0x41), q(0x42), q(0x43), q(0x44), q(0x45), q(0x46), q(0x47),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	q(0x48), q(0x49), q(0x4a), q(0x4b), q(0x4c), q(0x4d), q(0x4e), q(0x4f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	q(0x50), q(0x51), q(0x52), q(0x53), q(0x54), q(0x55), q(0x56), q(0x57),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	q(0x58), q(0x59), q(0x5a), q(0x5b), q(0x5c), q(0x5d), q(0x5e), q(0x5f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	q(0x60), q(0x61), q(0x62), q(0x63), q(0x64), q(0x65), q(0x66), q(0x67),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	q(0x68), q(0x69), q(0x6a), q(0x6b), q(0x6c), q(0x6d), q(0x6e), q(0x6f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	q(0x70), q(0x71), q(0x72), q(0x73), q(0x74), q(0x75), q(0x76), q(0x77),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	q(0x78), q(0x79), q(0x7a), q(0x7b), q(0x7c), q(0x7d), q(0x7e), q(0x7f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	q(0x80), q(0x81), q(0x82), q(0x83), q(0x84), q(0x85), q(0x86), q(0x87),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	q(0x88), q(0x89), q(0x8a), q(0x8b), q(0x8c), q(0x8d), q(0x8e), q(0x8f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	q(0x90), q(0x91), q(0x92), q(0x93), q(0x94), q(0x95), q(0x96), q(0x97),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	q(0x98), q(0x99), q(0x9a), q(0x9b), q(0x9c), q(0x9d), q(0x9e), q(0x9f),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	q(0xa0), q(0xa1), q(0xa2), q(0xa3), q(0xa4), q(0xa5), q(0xa6), q(0xa7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	q(0xa8), q(0xa9), q(0xaa), q(0xab), q(0xac), q(0xad), q(0xae), q(0xaf),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	q(0xb0), q(0xb1), q(0xb2), q(0xb3), q(0xb4), q(0xb5), q(0xb6), q(0xb7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	q(0xb8), q(0xb9), q(0xba), q(0xbb), q(0xbc), q(0xbd), q(0xbe), q(0xbf),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	q(0xc0), q(0xc1), q(0xc2), q(0xc3), q(0xc4), q(0xc5), q(0xc6), q(0xc7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	q(0xc8), q(0xc9), q(0xca), q(0xcb), q(0xcc), q(0xcd), q(0xce), q(0xcf),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	q(0xd0), q(0xd1), q(0xd2), q(0xd3), q(0xd4), q(0xd5), q(0xd6), q(0xd7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	q(0xd8), q(0xd9), q(0xda), q(0xdb), q(0xdc), q(0xdd), q(0xde), q(0xdf),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	q(0xe0), q(0xe1), q(0xe2), q(0xe3), q(0xe4), q(0xe5), q(0xe6), q(0xe7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	q(0xe8), q(0xe9), q(0xea), q(0xeb), q(0xec), q(0xed), q(0xee), q(0xef),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	q(0xf0), q(0xf1), q(0xf2), q(0xf3), q(0xf4), q(0xf5), q(0xf6), q(0xf7),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	q(0xf8), q(0xf9), q(0xfa), q(0xfb), q(0xfc), q(0xfd), q(0xfe), q(0xff) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * Given a value i in 0..255 as the byte overflow when a field element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * in GF(2^128) is multiplied by x^8, the following macro returns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * 16-bit value that must be XOR-ed into the low-degree end of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * product to reduce it modulo the polynomial x^128 + x^7 + x^2 + x + 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * There are two versions of the macro, and hence two tables: one for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * the "be" convention where the highest-order bit is the coefficient of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * the highest-degree polynomial term, and one for the "le" convention
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * where the highest-order bit is the coefficient of the lowest-degree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * polynomial term.  In both cases the values are stored in CPU byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * endianness such that the coefficients are ordered consistently across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * bytes, i.e. in the "be" table bits 15..0 of the stored value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * correspond to the coefficients of x^15..x^0, and in the "le" table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * bits 15..0 correspond to the coefficients of x^0..x^15.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Therefore, provided that the appropriate byte endianness conversions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * are done by the multiplication functions (and these must be in place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * anyway to support both little endian and big endian CPUs), the "be"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * table can be used for multiplications of both "bbe" and "ble"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * elements, and the "le" table can be used for multiplications of both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * "lle" and "lbe" elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define xda_be(i) ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	(i & 0x80 ? 0x4380 : 0) ^ (i & 0x40 ? 0x21c0 : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	(i & 0x20 ? 0x10e0 : 0) ^ (i & 0x10 ? 0x0870 : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	(i & 0x08 ? 0x0438 : 0) ^ (i & 0x04 ? 0x021c : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	(i & 0x02 ? 0x010e : 0) ^ (i & 0x01 ? 0x0087 : 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define xda_le(i) ( \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	(i & 0x80 ? 0xe100 : 0) ^ (i & 0x40 ? 0x7080 : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	(i & 0x20 ? 0x3840 : 0) ^ (i & 0x10 ? 0x1c20 : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	(i & 0x08 ? 0x0e10 : 0) ^ (i & 0x04 ? 0x0708 : 0) ^ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	(i & 0x02 ? 0x0384 : 0) ^ (i & 0x01 ? 0x01c2 : 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static const u16 gf128mul_table_le[256] = gf128mul_dat(xda_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static const u16 gf128mul_table_be[256] = gf128mul_dat(xda_be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * The following functions multiply a field element by x^8 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * the polynomial field representation.  They use 64-bit word operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * to gain speed but compensate for machine endianness and hence work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * correctly on both styles of machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void gf128mul_x8_lle(be128 *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	u64 a = be64_to_cpu(x->a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	u64 b = be64_to_cpu(x->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u64 _tt = gf128mul_table_le[b & 0xff];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	x->b = cpu_to_be64((b >> 8) | (a << 56));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	x->a = cpu_to_be64((a >> 8) ^ (_tt << 48));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void gf128mul_x8_bbe(be128 *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	u64 a = be64_to_cpu(x->a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	u64 b = be64_to_cpu(x->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	u64 _tt = gf128mul_table_be[a >> 56];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	x->a = cpu_to_be64((a << 8) | (b >> 56));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	x->b = cpu_to_be64((b << 8) ^ _tt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void gf128mul_x8_ble(le128 *r, const le128 *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	u64 a = le64_to_cpu(x->a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	u64 b = le64_to_cpu(x->b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u64 _tt = gf128mul_table_be[a >> 56];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	r->a = cpu_to_le64((a << 8) | (b >> 56));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	r->b = cpu_to_le64((b << 8) ^ _tt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) EXPORT_SYMBOL(gf128mul_x8_ble);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) void gf128mul_lle(be128 *r, const be128 *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	be128 p[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	p[0] = *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	for (i = 0; i < 7; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		gf128mul_x_lle(&p[i + 1], &p[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	memset(r, 0, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	for (i = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		u8 ch = ((u8 *)b)[15 - i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (ch & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			be128_xor(r, r, &p[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if (ch & 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			be128_xor(r, r, &p[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (ch & 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			be128_xor(r, r, &p[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (ch & 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			be128_xor(r, r, &p[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (ch & 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			be128_xor(r, r, &p[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (ch & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			be128_xor(r, r, &p[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (ch & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			be128_xor(r, r, &p[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (ch & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			be128_xor(r, r, &p[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (++i >= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		gf128mul_x8_lle(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) EXPORT_SYMBOL(gf128mul_lle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void gf128mul_bbe(be128 *r, const be128 *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	be128 p[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	p[0] = *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	for (i = 0; i < 7; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		gf128mul_x_bbe(&p[i + 1], &p[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	memset(r, 0, sizeof(*r));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	for (i = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		u8 ch = ((u8 *)b)[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (ch & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			be128_xor(r, r, &p[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (ch & 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			be128_xor(r, r, &p[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (ch & 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			be128_xor(r, r, &p[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (ch & 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			be128_xor(r, r, &p[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (ch & 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			be128_xor(r, r, &p[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (ch & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			be128_xor(r, r, &p[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (ch & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			be128_xor(r, r, &p[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (ch & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			be128_xor(r, r, &p[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (++i >= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		gf128mul_x8_bbe(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) EXPORT_SYMBOL(gf128mul_bbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*      This version uses 64k bytes of table space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)     A 16 byte buffer has to be multiplied by a 16 byte key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)     value in GF(2^128).  If we consider a GF(2^128) value in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)     the buffer's lowest byte, we can construct a table of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)     the 256 16 byte values that result from the 256 values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)     of this byte.  This requires 4096 bytes. But we also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)     need tables for each of the 16 higher bytes in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)     buffer as well, which makes 64 kbytes in total.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* additional explanation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * t[0][BYTE] contains g*BYTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * t[1][BYTE] contains g*x^8*BYTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *  ..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * t[15][BYTE] contains g*x^120*BYTE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct gf128mul_64k *gf128mul_init_64k_bbe(const be128 *g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct gf128mul_64k *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	t = kzalloc(sizeof(*t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	for (i = 0; i < 16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		t->t[i] = kzalloc(sizeof(*t->t[i]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		if (!t->t[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			gf128mul_free_64k(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			t = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	t->t[0]->t[1] = *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	for (j = 1; j <= 64; j <<= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		gf128mul_x_bbe(&t->t[0]->t[j + j], &t->t[0]->t[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	for (i = 0;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		for (j = 2; j < 256; j += j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			for (k = 1; k < j; ++k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				be128_xor(&t->t[i]->t[j + k],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 					  &t->t[i]->t[j], &t->t[i]->t[k]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (++i >= 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		for (j = 128; j > 0; j >>= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			t->t[i]->t[j] = t->t[i - 1]->t[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			gf128mul_x8_bbe(&t->t[i]->t[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) EXPORT_SYMBOL(gf128mul_init_64k_bbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) void gf128mul_free_64k(struct gf128mul_64k *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	for (i = 0; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		kfree_sensitive(t->t[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	kfree_sensitive(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) EXPORT_SYMBOL(gf128mul_free_64k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void gf128mul_64k_bbe(be128 *a, const struct gf128mul_64k *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	u8 *ap = (u8 *)a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	be128 r[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	*r = t->t[0]->t[ap[15]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	for (i = 1; i < 16; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		be128_xor(r, r, &t->t[i]->t[ap[15 - i]]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	*a = *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) EXPORT_SYMBOL(gf128mul_64k_bbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /*      This version uses 4k bytes of table space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)     A 16 byte buffer has to be multiplied by a 16 byte key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)     value in GF(2^128).  If we consider a GF(2^128) value in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)     single byte, we can construct a table of the 256 16 byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)     values that result from the 256 values of this byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)     This requires 4096 bytes. If we take the highest byte in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)     the buffer and use this table to get the result, we then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)     have to multiply by x^120 to get the final value. For the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)     next highest byte the result has to be multiplied by x^112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)     and so on. But we can do this by accumulating the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)     in an accumulator starting with the result for the top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)     byte.  We repeatedly multiply the accumulator value by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)     x^8 and then add in (i.e. xor) the 16 bytes of the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)     lower byte in the buffer, stopping when we reach the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)     lowest byte. This requires a 4096 byte table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct gf128mul_4k *gf128mul_init_4k_lle(const be128 *g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct gf128mul_4k *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	int j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	t = kzalloc(sizeof(*t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	t->t[128] = *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	for (j = 64; j > 0; j >>= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		gf128mul_x_lle(&t->t[j], &t->t[j+j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	for (j = 2; j < 256; j += j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		for (k = 1; k < j; ++k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			be128_xor(&t->t[j + k], &t->t[j], &t->t[k]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) EXPORT_SYMBOL(gf128mul_init_4k_lle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct gf128mul_4k *gf128mul_init_4k_bbe(const be128 *g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct gf128mul_4k *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	int j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	t = kzalloc(sizeof(*t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	t->t[1] = *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	for (j = 1; j <= 64; j <<= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		gf128mul_x_bbe(&t->t[j + j], &t->t[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	for (j = 2; j < 256; j += j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		for (k = 1; k < j; ++k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			be128_xor(&t->t[j + k], &t->t[j], &t->t[k]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) EXPORT_SYMBOL(gf128mul_init_4k_bbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) void gf128mul_4k_lle(be128 *a, const struct gf128mul_4k *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	u8 *ap = (u8 *)a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	be128 r[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	int i = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	*r = t->t[ap[15]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	while (i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		gf128mul_x8_lle(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		be128_xor(r, r, &t->t[ap[i]]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	*a = *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) EXPORT_SYMBOL(gf128mul_4k_lle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) void gf128mul_4k_bbe(be128 *a, const struct gf128mul_4k *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	u8 *ap = (u8 *)a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	be128 r[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	*r = t->t[ap[0]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	while (++i < 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		gf128mul_x8_bbe(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		be128_xor(r, r, &t->t[ap[i]]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	*a = *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) EXPORT_SYMBOL(gf128mul_4k_bbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) MODULE_DESCRIPTION("Functions for multiplying elements of GF(2^128)");