2727
2828#define LRW_BLOCK_SIZE 16
2929
30- struct priv {
30+ struct lrw_tfm_ctx {
3131 struct crypto_skcipher * child ;
3232
3333 /*
@@ -49,12 +49,12 @@ struct priv {
4949 be128 mulinc [128 ];
5050};
5151
52- struct rctx {
52+ struct lrw_request_ctx {
5353 be128 t ;
5454 struct skcipher_request subreq ;
5555};
5656
57- static inline void setbit128_bbe (void * b , int bit )
57+ static inline void lrw_setbit128_bbe (void * b , int bit )
5858{
5959 __set_bit (bit ^ (0x80 -
6060#ifdef __BIG_ENDIAN
@@ -65,10 +65,10 @@ static inline void setbit128_bbe(void *b, int bit)
6565 ), b );
6666}
6767
68- static int setkey (struct crypto_skcipher * parent , const u8 * key ,
69- unsigned int keylen )
68+ static int lrw_setkey (struct crypto_skcipher * parent , const u8 * key ,
69+ unsigned int keylen )
7070{
71- struct priv * ctx = crypto_skcipher_ctx (parent );
71+ struct lrw_tfm_ctx * ctx = crypto_skcipher_ctx (parent );
7272 struct crypto_skcipher * child = ctx -> child ;
7373 int err , bsize = LRW_BLOCK_SIZE ;
7474 const u8 * tweak = key + keylen - bsize ;
@@ -92,7 +92,7 @@ static int setkey(struct crypto_skcipher *parent, const u8 *key,
9292
9393 /* initialize optimization table */
9494 for (i = 0 ; i < 128 ; i ++ ) {
95- setbit128_bbe (& tmp , i );
95+ lrw_setbit128_bbe (& tmp , i );
9696 ctx -> mulinc [i ] = tmp ;
9797 gf128mul_64k_bbe (& ctx -> mulinc [i ], ctx -> table );
9898 }
@@ -108,10 +108,10 @@ static int setkey(struct crypto_skcipher *parent, const u8 *key,
108108 * For example:
109109 *
110110 * u32 counter[4] = { 0xFFFFFFFF, 0x1, 0x0, 0x0 };
111- * int i = next_index (&counter);
111+ * int i = lrw_next_index (&counter);
112112 * // i == 33, counter == { 0x0, 0x2, 0x0, 0x0 }
113113 */
114- static int next_index (u32 * counter )
114+ static int lrw_next_index (u32 * counter )
115115{
116116 int i , res = 0 ;
117117
@@ -135,14 +135,14 @@ static int next_index(u32 *counter)
135135 * We compute the tweak masks twice (both before and after the ECB encryption or
136136 * decryption) to avoid having to allocate a temporary buffer and/or make
137137 * mutliple calls to the 'ecb(..)' instance, which usually would be slower than
138- * just doing the next_index () calls again.
138+ * just doing the lrw_next_index () calls again.
139139 */
140- static int xor_tweak (struct skcipher_request * req , bool second_pass )
140+ static int lrw_xor_tweak (struct skcipher_request * req , bool second_pass )
141141{
142142 const int bs = LRW_BLOCK_SIZE ;
143143 struct crypto_skcipher * tfm = crypto_skcipher_reqtfm (req );
144- struct priv * ctx = crypto_skcipher_ctx (tfm );
145- struct rctx * rctx = skcipher_request_ctx (req );
144+ const struct lrw_tfm_ctx * ctx = crypto_skcipher_ctx (tfm );
145+ struct lrw_request_ctx * rctx = skcipher_request_ctx (req );
146146 be128 t = rctx -> t ;
147147 struct skcipher_walk w ;
148148 __be32 * iv ;
@@ -178,7 +178,8 @@ static int xor_tweak(struct skcipher_request *req, bool second_pass)
178178
179179 /* T <- I*Key2, using the optimization
180180 * discussed in the specification */
181- be128_xor (& t , & t , & ctx -> mulinc [next_index (counter )]);
181+ be128_xor (& t , & t ,
182+ & ctx -> mulinc [lrw_next_index (counter )]);
182183 } while ((avail -= bs ) >= bs );
183184
184185 if (second_pass && w .nbytes == w .total ) {
@@ -194,38 +195,40 @@ static int xor_tweak(struct skcipher_request *req, bool second_pass)
194195 return err ;
195196}
196197
197- static int xor_tweak_pre (struct skcipher_request * req )
198+ static int lrw_xor_tweak_pre (struct skcipher_request * req )
198199{
199- return xor_tweak (req , false);
200+ return lrw_xor_tweak (req , false);
200201}
201202
202- static int xor_tweak_post (struct skcipher_request * req )
203+ static int lrw_xor_tweak_post (struct skcipher_request * req )
203204{
204- return xor_tweak (req , true);
205+ return lrw_xor_tweak (req , true);
205206}
206207
207- static void crypt_done (struct crypto_async_request * areq , int err )
208+ static void lrw_crypt_done (struct crypto_async_request * areq , int err )
208209{
209210 struct skcipher_request * req = areq -> data ;
210211
211212 if (!err ) {
212- struct rctx * rctx = skcipher_request_ctx (req );
213+ struct lrw_request_ctx * rctx = skcipher_request_ctx (req );
213214
214215 rctx -> subreq .base .flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP ;
215- err = xor_tweak_post (req );
216+ err = lrw_xor_tweak_post (req );
216217 }
217218
218219 skcipher_request_complete (req , err );
219220}
220221
221- static void init_crypt (struct skcipher_request * req )
222+ static void lrw_init_crypt (struct skcipher_request * req )
222223{
223- struct priv * ctx = crypto_skcipher_ctx (crypto_skcipher_reqtfm (req ));
224- struct rctx * rctx = skcipher_request_ctx (req );
224+ const struct lrw_tfm_ctx * ctx =
225+ crypto_skcipher_ctx (crypto_skcipher_reqtfm (req ));
226+ struct lrw_request_ctx * rctx = skcipher_request_ctx (req );
225227 struct skcipher_request * subreq = & rctx -> subreq ;
226228
227229 skcipher_request_set_tfm (subreq , ctx -> child );
228- skcipher_request_set_callback (subreq , req -> base .flags , crypt_done , req );
230+ skcipher_request_set_callback (subreq , req -> base .flags , lrw_crypt_done ,
231+ req );
229232 /* pass req->iv as IV (will be used by xor_tweak, ECB will ignore it) */
230233 skcipher_request_set_crypt (subreq , req -> dst , req -> dst ,
231234 req -> cryptlen , req -> iv );
@@ -237,33 +240,33 @@ static void init_crypt(struct skcipher_request *req)
237240 gf128mul_64k_bbe (& rctx -> t , ctx -> table );
238241}
239242
240- static int encrypt (struct skcipher_request * req )
243+ static int lrw_encrypt (struct skcipher_request * req )
241244{
242- struct rctx * rctx = skcipher_request_ctx (req );
245+ struct lrw_request_ctx * rctx = skcipher_request_ctx (req );
243246 struct skcipher_request * subreq = & rctx -> subreq ;
244247
245- init_crypt (req );
246- return xor_tweak_pre (req ) ?:
248+ lrw_init_crypt (req );
249+ return lrw_xor_tweak_pre (req ) ?:
247250 crypto_skcipher_encrypt (subreq ) ?:
248- xor_tweak_post (req );
251+ lrw_xor_tweak_post (req );
249252}
250253
251- static int decrypt (struct skcipher_request * req )
254+ static int lrw_decrypt (struct skcipher_request * req )
252255{
253- struct rctx * rctx = skcipher_request_ctx (req );
256+ struct lrw_request_ctx * rctx = skcipher_request_ctx (req );
254257 struct skcipher_request * subreq = & rctx -> subreq ;
255258
256- init_crypt (req );
257- return xor_tweak_pre (req ) ?:
259+ lrw_init_crypt (req );
260+ return lrw_xor_tweak_pre (req ) ?:
258261 crypto_skcipher_decrypt (subreq ) ?:
259- xor_tweak_post (req );
262+ lrw_xor_tweak_post (req );
260263}
261264
262- static int init_tfm (struct crypto_skcipher * tfm )
265+ static int lrw_init_tfm (struct crypto_skcipher * tfm )
263266{
264267 struct skcipher_instance * inst = skcipher_alg_instance (tfm );
265268 struct crypto_skcipher_spawn * spawn = skcipher_instance_ctx (inst );
266- struct priv * ctx = crypto_skcipher_ctx (tfm );
269+ struct lrw_tfm_ctx * ctx = crypto_skcipher_ctx (tfm );
267270 struct crypto_skcipher * cipher ;
268271
269272 cipher = crypto_spawn_skcipher (spawn );
@@ -273,27 +276,27 @@ static int init_tfm(struct crypto_skcipher *tfm)
273276 ctx -> child = cipher ;
274277
275278 crypto_skcipher_set_reqsize (tfm , crypto_skcipher_reqsize (cipher ) +
276- sizeof (struct rctx ));
279+ sizeof (struct lrw_request_ctx ));
277280
278281 return 0 ;
279282}
280283
281- static void exit_tfm (struct crypto_skcipher * tfm )
284+ static void lrw_exit_tfm (struct crypto_skcipher * tfm )
282285{
283- struct priv * ctx = crypto_skcipher_ctx (tfm );
286+ struct lrw_tfm_ctx * ctx = crypto_skcipher_ctx (tfm );
284287
285288 if (ctx -> table )
286289 gf128mul_free_64k (ctx -> table );
287290 crypto_free_skcipher (ctx -> child );
288291}
289292
290- static void crypto_lrw_free (struct skcipher_instance * inst )
293+ static void lrw_free_instance (struct skcipher_instance * inst )
291294{
292295 crypto_drop_skcipher (skcipher_instance_ctx (inst ));
293296 kfree (inst );
294297}
295298
296- static int create (struct crypto_template * tmpl , struct rtattr * * tb )
299+ static int lrw_create (struct crypto_template * tmpl , struct rtattr * * tb )
297300{
298301 struct crypto_skcipher_spawn * spawn ;
299302 struct skcipher_instance * inst ;
@@ -384,43 +387,43 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
384387 inst -> alg .max_keysize = crypto_skcipher_alg_max_keysize (alg ) +
385388 LRW_BLOCK_SIZE ;
386389
387- inst -> alg .base .cra_ctxsize = sizeof (struct priv );
390+ inst -> alg .base .cra_ctxsize = sizeof (struct lrw_tfm_ctx );
388391
389- inst -> alg .init = init_tfm ;
390- inst -> alg .exit = exit_tfm ;
392+ inst -> alg .init = lrw_init_tfm ;
393+ inst -> alg .exit = lrw_exit_tfm ;
391394
392- inst -> alg .setkey = setkey ;
393- inst -> alg .encrypt = encrypt ;
394- inst -> alg .decrypt = decrypt ;
395+ inst -> alg .setkey = lrw_setkey ;
396+ inst -> alg .encrypt = lrw_encrypt ;
397+ inst -> alg .decrypt = lrw_decrypt ;
395398
396- inst -> free = crypto_lrw_free ;
399+ inst -> free = lrw_free_instance ;
397400
398401 err = skcipher_register_instance (tmpl , inst );
399402 if (err ) {
400403err_free_inst :
401- crypto_lrw_free (inst );
404+ lrw_free_instance (inst );
402405 }
403406 return err ;
404407}
405408
406- static struct crypto_template crypto_tmpl = {
409+ static struct crypto_template lrw_tmpl = {
407410 .name = "lrw" ,
408- .create = create ,
411+ .create = lrw_create ,
409412 .module = THIS_MODULE ,
410413};
411414
412- static int __init crypto_module_init (void )
415+ static int __init lrw_module_init (void )
413416{
414- return crypto_register_template (& crypto_tmpl );
417+ return crypto_register_template (& lrw_tmpl );
415418}
416419
417- static void __exit crypto_module_exit (void )
420+ static void __exit lrw_module_exit (void )
418421{
419- crypto_unregister_template (& crypto_tmpl );
422+ crypto_unregister_template (& lrw_tmpl );
420423}
421424
422- subsys_initcall (crypto_module_init );
423- module_exit (crypto_module_exit );
425+ subsys_initcall (lrw_module_init );
426+ module_exit (lrw_module_exit );
424427
425428MODULE_LICENSE ("GPL" );
426429MODULE_DESCRIPTION ("LRW block cipher mode" );
0 commit comments