aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-05-02 18:53:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-02 18:53:46 -0400
commit5a0387a8a8efb90ae7fea1e2e5c62de3efa74691 (patch)
tree9e5bbbafe7fea01c843d86c7c3d40f29f962c474 /include/crypto
parent204f144c9fcac355843412b6ba1150086488a208 (diff)
parent929562b144783b9212625305eadcbbd800809643 (diff)
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu: "Here is the crypto update for 4.12: API: - Add batch registration for acomp/scomp - Change acomp testing to non-unique compressed result - Extend algorithm name limit to 128 bytes - Require setkey before accept(2) in algif_aead Algorithms: - Add support for deflate rfc1950 (zlib) Drivers: - Add accelerated crct10dif for powerpc - Add crc32 in stm32 - Add sha384/sha512 in ccp - Add 3des/gcm(aes) for v5 devices in ccp - Add Queue Interface (QI) backend support in caam - Add new Exynos RNG driver - Add ThunderX ZIP driver - Add driver for hardware random generator on MT7623 SoC" * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (101 commits) crypto: stm32 - Fix OF module alias information crypto: algif_aead - Require setkey before accept(2) crypto: scomp - add support for deflate rfc1950 (zlib) crypto: scomp - allow registration of multiple scomps crypto: ccp - Change ISR handler method for a v5 CCP crypto: ccp - Change ISR handler method for a v3 CCP crypto: crypto4xx - rename ce_ring_contol to ce_ring_control crypto: testmgr - Allow ecb(cipher_null) in FIPS mode Revert "crypto: arm64/sha - Add constant operand modifier to ASM_EXPORT" crypto: ccp - Disable interrupts early on unload crypto: ccp - Use only the relevant interrupt bits hwrng: mtk - Add driver for hardware random generator on MT7623 SoC dt-bindings: hwrng: Add Mediatek hardware random generator bindings crypto: crct10dif-vpmsum - Fix missing preempt_disable() crypto: testmgr - replace compression known answer test crypto: acomp - allow registration of multiple acomps hwrng: n2 - Use devm_kcalloc() in n2rng_probe() crypto: chcr - Fix error handling related to 'chcr_alloc_shash' padata: get_next is never NULL crypto: exynos - Add new Exynos RNG driver ...
Diffstat (limited to 'include/crypto')
-rw-r--r--include/crypto/gf128mul.h87
-rw-r--r--include/crypto/internal/acompress.h3
-rw-r--r--include/crypto/internal/scompress.h3
-rw-r--r--include/crypto/kpp.h6
-rw-r--r--include/crypto/xts.h2
5 files changed, 80 insertions, 21 deletions
diff --git a/include/crypto/gf128mul.h b/include/crypto/gf128mul.h
index 592d47e565a8..0977fb18ff68 100644
--- a/include/crypto/gf128mul.h
+++ b/include/crypto/gf128mul.h
@@ -43,12 +43,13 @@
43 --------------------------------------------------------------------------- 43 ---------------------------------------------------------------------------
44 Issue Date: 31/01/2006 44 Issue Date: 31/01/2006
45 45
46 An implementation of field multiplication in Galois Field GF(128) 46 An implementation of field multiplication in Galois Field GF(2^128)
47*/ 47*/
48 48
49#ifndef _CRYPTO_GF128MUL_H 49#ifndef _CRYPTO_GF128MUL_H
50#define _CRYPTO_GF128MUL_H 50#define _CRYPTO_GF128MUL_H
51 51
52#include <asm/byteorder.h>
52#include <crypto/b128ops.h> 53#include <crypto/b128ops.h>
53#include <linux/slab.h> 54#include <linux/slab.h>
54 55
@@ -65,7 +66,7 @@
65 * are left and the lsb's are right. char b[16] is an array and b[0] is 66 * are left and the lsb's are right. char b[16] is an array and b[0] is
66 * the first octet. 67 * the first octet.
67 * 68 *
68 * 80000000 00000000 00000000 00000000 .... 00000000 00000000 00000000 69 * 10000000 00000000 00000000 00000000 .... 00000000 00000000 00000000
69 * b[0] b[1] b[2] b[3] b[13] b[14] b[15] 70 * b[0] b[1] b[2] b[3] b[13] b[14] b[15]
70 * 71 *
71 * Every bit is a coefficient of some power of X. We can store the bits 72 * Every bit is a coefficient of some power of X. We can store the bits
@@ -85,15 +86,17 @@
85 * Both of the above formats are easy to implement on big-endian 86 * Both of the above formats are easy to implement on big-endian
86 * machines. 87 * machines.
87 * 88 *
88 * EME (which is patent encumbered) uses the ble format (bits are stored 89 * XTS and EME (the latter of which is patent encumbered) use the ble
89 * in big endian order and the bytes in little endian). The above buffer 90 * format (bits are stored in big endian order and the bytes in little
90 * represents X^7 in this case and the primitive polynomial is b[0] = 0x87. 91 * endian). The above buffer represents X^7 in this case and the
92 * primitive polynomial is b[0] = 0x87.
91 * 93 *
92 * The common machine word-size is smaller than 128 bits, so to make 94 * The common machine word-size is smaller than 128 bits, so to make
93 * an efficient implementation we must split into machine word sizes. 95 * an efficient implementation we must split into machine word sizes.
94 * This file uses one 32bit for the moment. Machine endianness comes into 96 * This implementation uses 64-bit words for the moment. Machine
95 * play. The lle format in relation to machine endianness is discussed 97 * endianness comes into play. The lle format in relation to machine
96 * below by the original author of gf128mul Dr Brian Gladman. 98 * endianness is discussed below by the original author of gf128mul Dr
99 * Brian Gladman.
97 * 100 *
98 * Let's look at the bbe and ble format on a little endian machine. 101 * Let's look at the bbe and ble format on a little endian machine.
99 * 102 *
@@ -127,10 +130,10 @@
127 * machines this will automatically aligned to wordsize and on a 64-bit 130 * machines this will automatically aligned to wordsize and on a 64-bit
128 * machine also. 131 * machine also.
129 */ 132 */
130/* Multiply a GF128 field element by x. Field elements are held in arrays 133/* Multiply a GF(2^128) field element by x. Field elements are
131 of bytes in which field bits 8n..8n + 7 are held in byte[n], with lower 134 held in arrays of bytes in which field bits 8n..8n + 7 are held in
132 indexed bits placed in the more numerically significant bit positions 135 byte[n], with lower indexed bits placed in the more numerically
133 within bytes. 136 significant bit positions within bytes.
134 137
135 On little endian machines the bit indexes translate into the bit 138 On little endian machines the bit indexes translate into the bit
136 positions within four 32-bit words in the following way 139 positions within four 32-bit words in the following way
@@ -161,8 +164,58 @@ void gf128mul_lle(be128 *a, const be128 *b);
161 164
162void gf128mul_bbe(be128 *a, const be128 *b); 165void gf128mul_bbe(be128 *a, const be128 *b);
163 166
164/* multiply by x in ble format, needed by XTS */ 167/*
165void gf128mul_x_ble(be128 *a, const be128 *b); 168 * The following functions multiply a field element by x in
169 * the polynomial field representation. They use 64-bit word operations
170 * to gain speed but compensate for machine endianness and hence work
171 * correctly on both styles of machine.
172 *
173 * They are defined here for performance.
174 */
175
176static inline u64 gf128mul_mask_from_bit(u64 x, int which)
177{
178 /* a constant-time version of 'x & ((u64)1 << which) ? (u64)-1 : 0' */
179 return ((s64)(x << (63 - which)) >> 63);
180}
181
182static inline void gf128mul_x_lle(be128 *r, const be128 *x)
183{
184 u64 a = be64_to_cpu(x->a);
185 u64 b = be64_to_cpu(x->b);
186
187 /* equivalent to gf128mul_table_le[(b << 7) & 0xff] << 48
188 * (see crypto/gf128mul.c): */
189 u64 _tt = gf128mul_mask_from_bit(b, 0) & ((u64)0xe1 << 56);
190
191 r->b = cpu_to_be64((b >> 1) | (a << 63));
192 r->a = cpu_to_be64((a >> 1) ^ _tt);
193}
194
195static inline void gf128mul_x_bbe(be128 *r, const be128 *x)
196{
197 u64 a = be64_to_cpu(x->a);
198 u64 b = be64_to_cpu(x->b);
199
200 /* equivalent to gf128mul_table_be[a >> 63] (see crypto/gf128mul.c): */
201 u64 _tt = gf128mul_mask_from_bit(a, 63) & 0x87;
202
203 r->a = cpu_to_be64((a << 1) | (b >> 63));
204 r->b = cpu_to_be64((b << 1) ^ _tt);
205}
206
207/* needed by XTS */
208static inline void gf128mul_x_ble(le128 *r, const le128 *x)
209{
210 u64 a = le64_to_cpu(x->a);
211 u64 b = le64_to_cpu(x->b);
212
213 /* equivalent to gf128mul_table_be[b >> 63] (see crypto/gf128mul.c): */
214 u64 _tt = gf128mul_mask_from_bit(a, 63) & 0x87;
215
216 r->a = cpu_to_le64((a << 1) | (b >> 63));
217 r->b = cpu_to_le64((b << 1) ^ _tt);
218}
166 219
167/* 4k table optimization */ 220/* 4k table optimization */
168 221
@@ -172,8 +225,8 @@ struct gf128mul_4k {
172 225
173struct gf128mul_4k *gf128mul_init_4k_lle(const be128 *g); 226struct gf128mul_4k *gf128mul_init_4k_lle(const be128 *g);
174struct gf128mul_4k *gf128mul_init_4k_bbe(const be128 *g); 227struct gf128mul_4k *gf128mul_init_4k_bbe(const be128 *g);
175void gf128mul_4k_lle(be128 *a, struct gf128mul_4k *t); 228void gf128mul_4k_lle(be128 *a, const struct gf128mul_4k *t);
176void gf128mul_4k_bbe(be128 *a, struct gf128mul_4k *t); 229void gf128mul_4k_bbe(be128 *a, const struct gf128mul_4k *t);
177 230
178static inline void gf128mul_free_4k(struct gf128mul_4k *t) 231static inline void gf128mul_free_4k(struct gf128mul_4k *t)
179{ 232{
@@ -194,6 +247,6 @@ struct gf128mul_64k {
194 */ 247 */
195struct gf128mul_64k *gf128mul_init_64k_bbe(const be128 *g); 248struct gf128mul_64k *gf128mul_init_64k_bbe(const be128 *g);
196void gf128mul_free_64k(struct gf128mul_64k *t); 249void gf128mul_free_64k(struct gf128mul_64k *t);
197void gf128mul_64k_bbe(be128 *a, struct gf128mul_64k *t); 250void gf128mul_64k_bbe(be128 *a, const struct gf128mul_64k *t);
198 251
199#endif /* _CRYPTO_GF128MUL_H */ 252#endif /* _CRYPTO_GF128MUL_H */
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index 1de2b5af12d7..51052f65cefc 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -78,4 +78,7 @@ int crypto_register_acomp(struct acomp_alg *alg);
78 */ 78 */
79int crypto_unregister_acomp(struct acomp_alg *alg); 79int crypto_unregister_acomp(struct acomp_alg *alg);
80 80
81int crypto_register_acomps(struct acomp_alg *algs, int count);
82void crypto_unregister_acomps(struct acomp_alg *algs, int count);
83
81#endif 84#endif
diff --git a/include/crypto/internal/scompress.h b/include/crypto/internal/scompress.h
index 3fda3c5655a0..ccad9b2c9bd6 100644
--- a/include/crypto/internal/scompress.h
+++ b/include/crypto/internal/scompress.h
@@ -133,4 +133,7 @@ int crypto_register_scomp(struct scomp_alg *alg);
133 */ 133 */
134int crypto_unregister_scomp(struct scomp_alg *alg); 134int crypto_unregister_scomp(struct scomp_alg *alg);
135 135
136int crypto_register_scomps(struct scomp_alg *algs, int count);
137void crypto_unregister_scomps(struct scomp_alg *algs, int count);
138
136#endif 139#endif
diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h
index 4307a2f2365f..ce8e1f79374b 100644
--- a/include/crypto/kpp.h
+++ b/include/crypto/kpp.h
@@ -74,7 +74,7 @@ struct crypto_kpp {
74 * @base: Common crypto API algorithm data structure 74 * @base: Common crypto API algorithm data structure
75 */ 75 */
76struct kpp_alg { 76struct kpp_alg {
77 int (*set_secret)(struct crypto_kpp *tfm, void *buffer, 77 int (*set_secret)(struct crypto_kpp *tfm, const void *buffer,
78 unsigned int len); 78 unsigned int len);
79 int (*generate_public_key)(struct kpp_request *req); 79 int (*generate_public_key)(struct kpp_request *req);
80 int (*compute_shared_secret)(struct kpp_request *req); 80 int (*compute_shared_secret)(struct kpp_request *req);
@@ -273,8 +273,8 @@ struct kpp_secret {
273 * 273 *
274 * Return: zero on success; error code in case of error 274 * Return: zero on success; error code in case of error
275 */ 275 */
276static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm, void *buffer, 276static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm,
277 unsigned int len) 277 const void *buffer, unsigned int len)
278{ 278{
279 struct kpp_alg *alg = crypto_kpp_alg(tfm); 279 struct kpp_alg *alg = crypto_kpp_alg(tfm);
280 280
diff --git a/include/crypto/xts.h b/include/crypto/xts.h
index 77b630672b2c..c0bde308b28a 100644
--- a/include/crypto/xts.h
+++ b/include/crypto/xts.h
@@ -11,7 +11,7 @@ struct blkcipher_desc;
11#define XTS_BLOCK_SIZE 16 11#define XTS_BLOCK_SIZE 16
12 12
13struct xts_crypt_req { 13struct xts_crypt_req {
14 be128 *tbuf; 14 le128 *tbuf;
15 unsigned int tbuflen; 15 unsigned int tbuflen;
16 16
17 void *tweak_ctx; 17 void *tweak_ctx;