1616 * operations.
1717 */
1818
19- #include <crypto/algapi.h>
19+ #include <asm/cpu_device_id.h>
20+ #include <asm/fpu/api.h>
2021#include <crypto/internal/hash.h>
21- #include <crypto/internal/simd.h>
2222#include <crypto/polyval.h>
23- #include <linux/ crypto.h>
24- #include <linux/init .h>
23+ #include <crypto/utils .h>
24+ #include <linux/errno .h>
2525#include <linux/kernel.h>
2626#include <linux/module.h>
27- #include <asm/cpu_device_id.h>
28- #include <asm/simd.h>
27+ #include <linux/string.h>
2928
3029#define POLYVAL_ALIGN 16
3130#define POLYVAL_ALIGN_ATTR __aligned(POLYVAL_ALIGN)
@@ -42,7 +41,6 @@ struct polyval_tfm_ctx {
4241
4342struct polyval_desc_ctx {
4443 u8 buffer [POLYVAL_BLOCK_SIZE ];
45- u32 bytes ;
4644};
4745
4846asmlinkage void clmul_polyval_update (const struct polyval_tfm_ctx * keys ,
@@ -57,25 +55,16 @@ static inline struct polyval_tfm_ctx *polyval_tfm_ctx(struct crypto_shash *tfm)
5755static void internal_polyval_update (const struct polyval_tfm_ctx * keys ,
5856 const u8 * in , size_t nblocks , u8 * accumulator )
5957{
60- if (likely (crypto_simd_usable ())) {
61- kernel_fpu_begin ();
62- clmul_polyval_update (keys , in , nblocks , accumulator );
63- kernel_fpu_end ();
64- } else {
65- polyval_update_non4k (keys -> key_powers [NUM_KEY_POWERS - 1 ], in ,
66- nblocks , accumulator );
67- }
58+ kernel_fpu_begin ();
59+ clmul_polyval_update (keys , in , nblocks , accumulator );
60+ kernel_fpu_end ();
6861}
6962
7063static void internal_polyval_mul (u8 * op1 , const u8 * op2 )
7164{
72- if (likely (crypto_simd_usable ())) {
73- kernel_fpu_begin ();
74- clmul_polyval_mul (op1 , op2 );
75- kernel_fpu_end ();
76- } else {
77- polyval_mul_non4k (op1 , op2 );
78- }
65+ kernel_fpu_begin ();
66+ clmul_polyval_mul (op1 , op2 );
67+ kernel_fpu_end ();
7968}
8069
8170static int polyval_x86_setkey (struct crypto_shash * tfm ,
@@ -112,49 +101,27 @@ static int polyval_x86_update(struct shash_desc *desc,
112101{
113102 struct polyval_desc_ctx * dctx = shash_desc_ctx (desc );
114103 const struct polyval_tfm_ctx * tctx = polyval_tfm_ctx (desc -> tfm );
115- u8 * pos ;
116104 unsigned int nblocks ;
117- unsigned int n ;
118-
119- if (dctx -> bytes ) {
120- n = min (srclen , dctx -> bytes );
121- pos = dctx -> buffer + POLYVAL_BLOCK_SIZE - dctx -> bytes ;
122-
123- dctx -> bytes -= n ;
124- srclen -= n ;
125-
126- while (n -- )
127- * pos ++ ^= * src ++ ;
128105
129- if (!dctx -> bytes )
130- internal_polyval_mul (dctx -> buffer ,
131- tctx -> key_powers [NUM_KEY_POWERS - 1 ]);
132- }
133-
134- while (srclen >= POLYVAL_BLOCK_SIZE ) {
106+ do {
135107 /* Allow rescheduling every 4K bytes. */
136108 nblocks = min (srclen , 4096U ) / POLYVAL_BLOCK_SIZE ;
137109 internal_polyval_update (tctx , src , nblocks , dctx -> buffer );
138110 srclen -= nblocks * POLYVAL_BLOCK_SIZE ;
139111 src += nblocks * POLYVAL_BLOCK_SIZE ;
140- }
112+ } while ( srclen >= POLYVAL_BLOCK_SIZE );
141113
142- if (srclen ) {
143- dctx -> bytes = POLYVAL_BLOCK_SIZE - srclen ;
144- pos = dctx -> buffer ;
145- while (srclen -- )
146- * pos ++ ^= * src ++ ;
147- }
148-
149- return 0 ;
114+ return srclen ;
150115}
151116
152- static int polyval_x86_final (struct shash_desc * desc , u8 * dst )
117+ static int polyval_x86_finup (struct shash_desc * desc , const u8 * src ,
118+ unsigned int len , u8 * dst )
153119{
154120 struct polyval_desc_ctx * dctx = shash_desc_ctx (desc );
155121 const struct polyval_tfm_ctx * tctx = polyval_tfm_ctx (desc -> tfm );
156122
157- if (dctx -> bytes ) {
123+ if (len ) {
124+ crypto_xor (dctx -> buffer , src , len );
158125 internal_polyval_mul (dctx -> buffer ,
159126 tctx -> key_powers [NUM_KEY_POWERS - 1 ]);
160127 }
@@ -168,13 +135,14 @@ static struct shash_alg polyval_alg = {
168135 .digestsize = POLYVAL_DIGEST_SIZE ,
169136 .init = polyval_x86_init ,
170137 .update = polyval_x86_update ,
171- .final = polyval_x86_final ,
138+ .finup = polyval_x86_finup ,
172139 .setkey = polyval_x86_setkey ,
173140 .descsize = sizeof (struct polyval_desc_ctx ),
174141 .base = {
175142 .cra_name = "polyval" ,
176143 .cra_driver_name = "polyval-clmulni" ,
177144 .cra_priority = 200 ,
145+ .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY ,
178146 .cra_blocksize = POLYVAL_BLOCK_SIZE ,
179147 .cra_ctxsize = POLYVAL_CTX_SIZE ,
180148 .cra_module = THIS_MODULE ,
0 commit comments