Skip to content

Commit 332f884

Browse files
committed
[CRYPTO] ablkcipher: Add distinct ABLKCIPHER type
Up until now we have ablkcipher algorithms have been identified as type BLKCIPHER with the ASYNC bit set. This is suboptimal because ablkcipher refers to two things. On the one hand it refers to the top-level ablkcipher interface with requests. On the other hand it refers to and algorithm type underneath. As it is you cannot request a synchronous block cipher algorithm with the ablkcipher interface on top. This is a problem because we want to be able to eventually phase out the blkcipher top-level interface. This patch fixes this by making ABLKCIPHER its own type, just as we have distinct types for HASH and DIGEST. The type it associated with the algorithm implementation only. Which top-level interface is used for synchronous block ciphers is then determined by the mask that's used. If it's a specific mask then the old blkcipher interface is given, otherwise we go with the new ablkcipher interface. Signed-off-by: Herbert Xu <[email protected]>
1 parent 86f578d commit 332f884

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

crypto/authenc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
292292
goto out_put_auth;
293293

294294
enc = crypto_attr_alg(tb[3], CRYPTO_ALG_TYPE_BLKCIPHER,
295-
CRYPTO_ALG_TYPE_MASK);
295+
CRYPTO_ALG_TYPE_BLKCIPHER_MASK);
296296
inst = ERR_PTR(PTR_ERR(enc));
297297
if (IS_ERR(enc))
298298
goto out_put_auth;

crypto/blkcipher.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,8 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
433433
struct blkcipher_alg *cipher = &alg->cra_blkcipher;
434434
unsigned int len = alg->cra_ctxsize;
435435

436-
type ^= CRYPTO_ALG_ASYNC;
437-
mask &= CRYPTO_ALG_ASYNC;
438-
if ((type & mask) && cipher->ivsize) {
436+
if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK &&
437+
cipher->ivsize) {
439438
len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
440439
len += cipher->ivsize;
441440
}
@@ -482,9 +481,7 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
482481
if (alg->ivsize > PAGE_SIZE / 8)
483482
return -EINVAL;
484483

485-
type ^= CRYPTO_ALG_ASYNC;
486-
mask &= CRYPTO_ALG_ASYNC;
487-
if (type & mask)
484+
if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK)
488485
return crypto_init_blkcipher_ops_sync(tfm);
489486
else
490487
return crypto_init_blkcipher_ops_async(tfm);

crypto/cryptd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
228228
struct crypto_alg *alg;
229229

230230
alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
231-
CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
231+
CRYPTO_ALG_TYPE_MASK);
232232
if (IS_ERR(alg))
233233
return ERR_PTR(PTR_ERR(alg));
234234

235235
inst = cryptd_alloc_instance(alg, state);
236236
if (IS_ERR(inst))
237237
goto out_put_alg;
238238

239-
inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC;
239+
inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
240240
inst->alg.cra_type = &crypto_ablkcipher_type;
241241

242242
inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize;

drivers/crypto/hifn_795x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2361,7 +2361,7 @@ static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t)
23612361
snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name);
23622362

23632363
alg->alg.cra_priority = 300;
2364-
alg->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC;
2364+
alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
23652365
alg->alg.cra_blocksize = t->bsize;
23662366
alg->alg.cra_ctxsize = sizeof(struct hifn_context);
23672367
alg->alg.cra_alignmask = 15;

include/crypto/algapi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher(
191191
struct crypto_spawn *spawn)
192192
{
193193
u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
194-
u32 mask = CRYPTO_ALG_TYPE_MASK;
194+
u32 mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
195195

196196
return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
197197
}
@@ -200,7 +200,7 @@ static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
200200
struct crypto_spawn *spawn)
201201
{
202202
u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
203-
u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
203+
u32 mask = CRYPTO_ALG_TYPE_MASK;
204204

205205
return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
206206
}

include/linux/crypto.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
#define CRYPTO_ALG_TYPE_DIGEST 0x00000002
3434
#define CRYPTO_ALG_TYPE_HASH 0x00000003
3535
#define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
36-
#define CRYPTO_ALG_TYPE_COMPRESS 0x00000005
37-
#define CRYPTO_ALG_TYPE_AEAD 0x00000006
36+
#define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005
37+
#define CRYPTO_ALG_TYPE_COMPRESS 0x00000008
38+
#define CRYPTO_ALG_TYPE_AEAD 0x00000009
3839

3940
#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
41+
#define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
4042

4143
#define CRYPTO_ALG_LARVAL 0x00000010
4244
#define CRYPTO_ALG_DEAD 0x00000020
@@ -530,7 +532,7 @@ static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
530532
{
531533
type &= ~CRYPTO_ALG_TYPE_MASK;
532534
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
533-
mask |= CRYPTO_ALG_TYPE_MASK;
535+
mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
534536

535537
return __crypto_ablkcipher_cast(
536538
crypto_alloc_base(alg_name, type, mask));
@@ -552,7 +554,7 @@ static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
552554
{
553555
type &= ~CRYPTO_ALG_TYPE_MASK;
554556
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
555-
mask |= CRYPTO_ALG_TYPE_MASK;
557+
mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
556558

557559
return crypto_has_alg(alg_name, type, mask);
558560
}
@@ -841,9 +843,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast(
841843
static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
842844
const char *alg_name, u32 type, u32 mask)
843845
{
844-
type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
846+
type &= ~CRYPTO_ALG_TYPE_MASK;
845847
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
846-
mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
848+
mask |= CRYPTO_ALG_TYPE_MASK;
847849

848850
return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
849851
}
@@ -861,9 +863,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
861863

862864
static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
863865
{
864-
type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
866+
type &= ~CRYPTO_ALG_TYPE_MASK;
865867
type |= CRYPTO_ALG_TYPE_BLKCIPHER;
866-
mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
868+
mask |= CRYPTO_ALG_TYPE_MASK;
867869

868870
return crypto_has_alg(alg_name, type, mask);
869871
}

0 commit comments

Comments
 (0)