Skip to content

Commit c7fc059

Browse files
committed
[CRYPTO] api: Added cra_init/cra_exit
This patch adds the hooks cra_init/cra_exit which are called during a tfm's construction and destruction respectively. This will be used by the instances to allocate child tfm's. For now this lets us get rid of the coa_init/coa_exit functions which are used for exactly that purpose (unlike the dia_init function which is called for each transaction). In fact the coa_exit path is currently buggy as it may get called twice when an error is encountered during initialisation. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 110bf1c commit c7fc059

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

‎crypto/api.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,16 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
188188
if (crypto_init_flags(tfm, flags))
189189
goto out_free_tfm;
190190

191-
if (crypto_init_ops(tfm)) {
192-
crypto_exit_ops(tfm);
191+
if (crypto_init_ops(tfm))
193192
goto out_free_tfm;
194-
}
193+
194+
if (alg->cra_init && alg->cra_init(tfm))
195+
goto cra_init_failed;
195196

196197
goto out;
197198

199+
cra_init_failed:
200+
crypto_exit_ops(tfm);
198201
out_free_tfm:
199202
kfree(tfm);
200203
tfm = NULL;
@@ -215,6 +218,8 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
215218
alg = tfm->__crt_alg;
216219
size = sizeof(*tfm) + alg->cra_ctxsize;
217220

221+
if (alg->cra_exit)
222+
alg->cra_exit(tfm);
218223
crypto_exit_ops(tfm);
219224
crypto_alg_put(alg);
220225
memset(tfm, 0, size);

‎crypto/compress.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,14 @@ int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags)
4141

4242
int crypto_init_compress_ops(struct crypto_tfm *tfm)
4343
{
44-
int ret = 0;
4544
struct compress_tfm *ops = &tfm->crt_compress;
46-
47-
ret = tfm->__crt_alg->cra_compress.coa_init(tfm);
48-
if (ret)
49-
goto out;
5045

5146
ops->cot_compress = crypto_compress;
5247
ops->cot_decompress = crypto_decompress;
5348

54-
out:
55-
return ret;
49+
return 0;
5650
}
5751

5852
void crypto_exit_compress_ops(struct crypto_tfm *tfm)
5953
{
60-
tfm->__crt_alg->cra_compress.coa_exit(tfm);
6154
}

‎crypto/deflate.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ static struct crypto_alg alg = {
201201
.cra_ctxsize = sizeof(struct deflate_ctx),
202202
.cra_module = THIS_MODULE,
203203
.cra_list = LIST_HEAD_INIT(alg.cra_list),
204+
.cra_init = deflate_init,
205+
.cra_exit = deflate_exit,
204206
.cra_u = { .compress = {
205-
.coa_init = deflate_init,
206-
.coa_exit = deflate_exit,
207207
.coa_compress = deflate_compress,
208208
.coa_decompress = deflate_decompress } }
209209
};

‎include/linux/crypto.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ struct digest_alg {
109109
};
110110

111111
struct compress_alg {
112-
int (*coa_init)(struct crypto_tfm *tfm);
113-
void (*coa_exit)(struct crypto_tfm *tfm);
114112
int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
115113
unsigned int slen, u8 *dst, unsigned int *dlen);
116114
int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
@@ -138,6 +136,9 @@ struct crypto_alg {
138136
struct digest_alg digest;
139137
struct compress_alg compress;
140138
} cra_u;
139+
140+
int (*cra_init)(struct crypto_tfm *tfm);
141+
void (*cra_exit)(struct crypto_tfm *tfm);
141142

142143
struct module *cra_module;
143144
};

0 commit comments

Comments
 (0)