27
27
#include <asm/cpu_device_id.h>
28
28
#include <asm/simd.h>
29
29
30
+ #define POLYVAL_ALIGN 16
31
+ #define POLYVAL_ALIGN_ATTR __aligned(POLYVAL_ALIGN)
32
+ #define POLYVAL_ALIGN_EXTRA ((POLYVAL_ALIGN - 1) & ~(CRYPTO_MINALIGN - 1))
33
+ #define POLYVAL_CTX_SIZE (sizeof(struct polyval_tfm_ctx) + POLYVAL_ALIGN_EXTRA)
30
34
#define NUM_KEY_POWERS 8
31
35
32
36
struct polyval_tfm_ctx {
33
37
/*
34
38
* These powers must be in the order h^8, ..., h^1.
35
39
*/
36
- u8 key_powers [NUM_KEY_POWERS ][POLYVAL_BLOCK_SIZE ];
40
+ u8 key_powers [NUM_KEY_POWERS ][POLYVAL_BLOCK_SIZE ] POLYVAL_ALIGN_ATTR ;
37
41
};
38
42
39
43
struct polyval_desc_ctx {
@@ -45,6 +49,11 @@ asmlinkage void clmul_polyval_update(const struct polyval_tfm_ctx *keys,
45
49
const u8 * in , size_t nblocks , u8 * accumulator );
46
50
asmlinkage void clmul_polyval_mul (u8 * op1 , const u8 * op2 );
47
51
52
+ static inline struct polyval_tfm_ctx * polyval_tfm_ctx (struct crypto_shash * tfm )
53
+ {
54
+ return PTR_ALIGN (crypto_shash_ctx (tfm ), POLYVAL_ALIGN );
55
+ }
56
+
48
57
static void internal_polyval_update (const struct polyval_tfm_ctx * keys ,
49
58
const u8 * in , size_t nblocks , u8 * accumulator )
50
59
{
@@ -72,7 +81,7 @@ static void internal_polyval_mul(u8 *op1, const u8 *op2)
72
81
static int polyval_x86_setkey (struct crypto_shash * tfm ,
73
82
const u8 * key , unsigned int keylen )
74
83
{
75
- struct polyval_tfm_ctx * tctx = crypto_shash_ctx (tfm );
84
+ struct polyval_tfm_ctx * tctx = polyval_tfm_ctx (tfm );
76
85
int i ;
77
86
78
87
if (keylen != POLYVAL_BLOCK_SIZE )
@@ -102,7 +111,7 @@ static int polyval_x86_update(struct shash_desc *desc,
102
111
const u8 * src , unsigned int srclen )
103
112
{
104
113
struct polyval_desc_ctx * dctx = shash_desc_ctx (desc );
105
- const struct polyval_tfm_ctx * tctx = crypto_shash_ctx (desc -> tfm );
114
+ const struct polyval_tfm_ctx * tctx = polyval_tfm_ctx (desc -> tfm );
106
115
u8 * pos ;
107
116
unsigned int nblocks ;
108
117
unsigned int n ;
@@ -143,7 +152,7 @@ static int polyval_x86_update(struct shash_desc *desc,
143
152
static int polyval_x86_final (struct shash_desc * desc , u8 * dst )
144
153
{
145
154
struct polyval_desc_ctx * dctx = shash_desc_ctx (desc );
146
- const struct polyval_tfm_ctx * tctx = crypto_shash_ctx (desc -> tfm );
155
+ const struct polyval_tfm_ctx * tctx = polyval_tfm_ctx (desc -> tfm );
147
156
148
157
if (dctx -> bytes ) {
149
158
internal_polyval_mul (dctx -> buffer ,
@@ -167,7 +176,7 @@ static struct shash_alg polyval_alg = {
167
176
.cra_driver_name = "polyval-clmulni" ,
168
177
.cra_priority = 200 ,
169
178
.cra_blocksize = POLYVAL_BLOCK_SIZE ,
170
- .cra_ctxsize = sizeof ( struct polyval_tfm_ctx ) ,
179
+ .cra_ctxsize = POLYVAL_CTX_SIZE ,
171
180
.cra_module = THIS_MODULE ,
172
181
},
173
182
};
0 commit comments