2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-12-05 16:09:34 +00:00
|
|
|
/*
|
|
|
|
* RSA padding templates.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <crypto/algapi.h>
|
|
|
|
#include <crypto/akcipher.h>
|
|
|
|
#include <crypto/internal/akcipher.h>
|
2019-01-10 20:17:53 +00:00
|
|
|
#include <crypto/internal/rsa.h>
|
2015-12-05 16:09:34 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/random.h>
|
2020-08-19 11:58:20 +00:00
|
|
|
#include <linux/scatterlist.h>
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
struct pkcs1pad_ctx {
|
|
|
|
struct crypto_akcipher *child;
|
|
|
|
unsigned int key_size;
|
|
|
|
};
|
|
|
|
|
2016-03-03 21:49:26 +00:00
|
|
|
struct pkcs1pad_inst_ctx {
|
|
|
|
struct crypto_akcipher_spawn spawn;
|
|
|
|
};
|
|
|
|
|
2015-12-05 16:09:34 +00:00
|
|
|
struct pkcs1pad_request {
|
2016-06-29 11:32:24 +00:00
|
|
|
struct scatterlist in_sg[2], out_sg[1];
|
2015-12-05 16:09:34 +00:00
|
|
|
uint8_t *in_buf, *out_buf;
|
2016-07-15 03:39:18 +00:00
|
|
|
struct akcipher_request child_req;
|
2015-12-05 16:09:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int pkcs1pad_set_pub_key(struct crypto_akcipher *tfm, const void *key,
|
|
|
|
unsigned int keylen)
|
|
|
|
{
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
2016-06-29 11:32:27 +00:00
|
|
|
|
2024-09-10 14:30:15 +00:00
|
|
|
return rsa_set_key(ctx->child, &ctx->key_size, RSA_PUB, key, keylen);
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_set_priv_key(struct crypto_akcipher *tfm, const void *key,
|
|
|
|
unsigned int keylen)
|
|
|
|
{
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
|
2024-09-10 14:30:15 +00:00
|
|
|
return rsa_set_key(ctx->child, &ctx->key_size, RSA_PRIV, key, keylen);
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 07:18:16 +00:00
|
|
|
static unsigned int pkcs1pad_get_max_size(struct crypto_akcipher *tfm)
|
2015-12-05 16:09:34 +00:00
|
|
|
{
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
|
|
|
|
/*
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
* The maximum destination buffer size for the encrypt operation
|
2015-12-05 16:09:34 +00:00
|
|
|
* will be the same as for RSA, even though it's smaller for
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
* decrypt.
|
2015-12-05 16:09:34 +00:00
|
|
|
*/
|
|
|
|
|
2017-05-25 07:18:16 +00:00
|
|
|
return ctx->key_size;
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pkcs1pad_sg_set_buf(struct scatterlist *sg, void *buf, size_t len,
|
|
|
|
struct scatterlist *next)
|
|
|
|
{
|
2016-06-29 11:32:24 +00:00
|
|
|
int nsegs = next ? 2 : 1;
|
|
|
|
|
|
|
|
sg_init_table(sg, nsegs);
|
|
|
|
sg_set_buf(sg, buf, len);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
if (next)
|
|
|
|
sg_chain(sg, nsegs, next);
|
|
|
|
}
|
|
|
|
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
static int pkcs1pad_encrypt_complete(struct akcipher_request *req, int err)
|
2015-12-05 16:09:34 +00:00
|
|
|
{
|
|
|
|
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req);
|
2016-06-29 11:32:28 +00:00
|
|
|
unsigned int pad_len;
|
|
|
|
unsigned int len;
|
|
|
|
u8 *out_buf;
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
len = req_ctx->child_req.dst_len;
|
|
|
|
pad_len = ctx->key_size - len;
|
|
|
|
|
|
|
|
/* Four billion to one */
|
|
|
|
if (likely(!pad_len))
|
|
|
|
goto out;
|
|
|
|
|
2023-01-23 10:08:56 +00:00
|
|
|
out_buf = kzalloc(ctx->key_size, GFP_ATOMIC);
|
2016-06-29 11:32:28 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
if (!out_buf)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sg_copy_to_buffer(req->dst, sg_nents_for_len(req->dst, len),
|
|
|
|
out_buf + pad_len, len);
|
|
|
|
sg_copy_from_buffer(req->dst,
|
|
|
|
sg_nents_for_len(req->dst, ctx->key_size),
|
|
|
|
out_buf, ctx->key_size);
|
2020-08-07 06:18:13 +00:00
|
|
|
kfree_sensitive(out_buf);
|
2016-06-29 11:32:28 +00:00
|
|
|
|
|
|
|
out:
|
2015-12-05 16:09:34 +00:00
|
|
|
req->dst_len = ctx->key_size;
|
|
|
|
|
|
|
|
kfree(req_ctx->in_buf);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
static void pkcs1pad_encrypt_complete_cb(void *data, int err)
|
2015-12-05 16:09:34 +00:00
|
|
|
{
|
2023-02-08 05:58:44 +00:00
|
|
|
struct akcipher_request *req = data;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
if (err == -EINPROGRESS)
|
2023-01-31 08:02:04 +00:00
|
|
|
goto out;
|
|
|
|
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
err = pkcs1pad_encrypt_complete(req, err);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
2023-01-31 08:02:04 +00:00
|
|
|
out:
|
|
|
|
akcipher_request_complete(req, err);
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_encrypt(struct akcipher_request *req)
|
|
|
|
{
|
|
|
|
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req);
|
|
|
|
int err;
|
|
|
|
unsigned int i, ps_end;
|
|
|
|
|
|
|
|
if (!ctx->key_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (req->src_len > ctx->key_size - 11)
|
|
|
|
return -EOVERFLOW;
|
|
|
|
|
|
|
|
if (req->dst_len < ctx->key_size) {
|
|
|
|
req->dst_len = ctx->key_size;
|
|
|
|
return -EOVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
req_ctx->in_buf = kmalloc(ctx->key_size - 1 - req->src_len,
|
2016-06-29 11:32:26 +00:00
|
|
|
GFP_KERNEL);
|
2015-12-05 16:09:34 +00:00
|
|
|
if (!req_ctx->in_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ps_end = ctx->key_size - req->src_len - 2;
|
|
|
|
req_ctx->in_buf[0] = 0x02;
|
|
|
|
for (i = 1; i < ps_end; i++)
|
2022-10-10 02:44:02 +00:00
|
|
|
req_ctx->in_buf[i] = get_random_u32_inclusive(1, 255);
|
2015-12-05 16:09:34 +00:00
|
|
|
req_ctx->in_buf[ps_end] = 0x00;
|
|
|
|
|
|
|
|
pkcs1pad_sg_set_buf(req_ctx->in_sg, req_ctx->in_buf,
|
|
|
|
ctx->key_size - 1 - req->src_len, req->src);
|
|
|
|
|
|
|
|
akcipher_request_set_tfm(&req_ctx->child_req, ctx->child);
|
|
|
|
akcipher_request_set_callback(&req_ctx->child_req, req->base.flags,
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
pkcs1pad_encrypt_complete_cb, req);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
2016-06-29 11:32:28 +00:00
|
|
|
/* Reuse output buffer */
|
|
|
|
akcipher_request_set_crypt(&req_ctx->child_req, req_ctx->in_sg,
|
|
|
|
req->dst, ctx->key_size - 1, req->dst_len);
|
|
|
|
|
2015-12-05 16:09:34 +00:00
|
|
|
err = crypto_akcipher_encrypt(&req_ctx->child_req);
|
2017-10-18 07:00:36 +00:00
|
|
|
if (err != -EINPROGRESS && err != -EBUSY)
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
return pkcs1pad_encrypt_complete(req, err);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_decrypt_complete(struct akcipher_request *req, int err)
|
|
|
|
{
|
|
|
|
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req);
|
2016-09-22 09:04:57 +00:00
|
|
|
unsigned int dst_len;
|
2015-12-05 16:09:34 +00:00
|
|
|
unsigned int pos;
|
2016-09-22 09:04:57 +00:00
|
|
|
u8 *out_buf;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto done;
|
|
|
|
|
2016-09-22 09:04:57 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
dst_len = req_ctx->child_req.dst_len;
|
|
|
|
if (dst_len < ctx->key_size - 1)
|
2015-12-05 16:09:34 +00:00
|
|
|
goto done;
|
2016-09-22 09:04:57 +00:00
|
|
|
|
|
|
|
out_buf = req_ctx->out_buf;
|
|
|
|
if (dst_len == ctx->key_size) {
|
|
|
|
if (out_buf[0] != 0x00)
|
|
|
|
/* Decrypted value had no leading 0 byte */
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dst_len--;
|
|
|
|
out_buf++;
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 09:04:57 +00:00
|
|
|
if (out_buf[0] != 0x02)
|
2015-12-05 16:09:34 +00:00
|
|
|
goto done;
|
2016-09-22 09:04:57 +00:00
|
|
|
|
|
|
|
for (pos = 1; pos < dst_len; pos++)
|
|
|
|
if (out_buf[pos] == 0x00)
|
2015-12-05 16:09:34 +00:00
|
|
|
break;
|
2016-09-22 09:04:57 +00:00
|
|
|
if (pos < 9 || pos == dst_len)
|
2015-12-05 16:09:34 +00:00
|
|
|
goto done;
|
|
|
|
pos++;
|
|
|
|
|
2016-09-22 09:04:57 +00:00
|
|
|
err = 0;
|
|
|
|
|
|
|
|
if (req->dst_len < dst_len - pos)
|
2015-12-05 16:09:34 +00:00
|
|
|
err = -EOVERFLOW;
|
2016-09-22 09:04:57 +00:00
|
|
|
req->dst_len = dst_len - pos;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
if (!err)
|
|
|
|
sg_copy_from_buffer(req->dst,
|
|
|
|
sg_nents_for_len(req->dst, req->dst_len),
|
2016-09-22 09:04:57 +00:00
|
|
|
out_buf + pos, req->dst_len);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
done:
|
2020-08-07 06:18:13 +00:00
|
|
|
kfree_sensitive(req_ctx->out_buf);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-02-08 05:58:44 +00:00
|
|
|
static void pkcs1pad_decrypt_complete_cb(void *data, int err)
|
2015-12-05 16:09:34 +00:00
|
|
|
{
|
2023-02-08 05:58:44 +00:00
|
|
|
struct akcipher_request *req = data;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
if (err == -EINPROGRESS)
|
2023-01-31 08:02:04 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = pkcs1pad_decrypt_complete(req, err);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
2023-01-31 08:02:04 +00:00
|
|
|
out:
|
|
|
|
akcipher_request_complete(req, err);
|
2015-12-05 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_decrypt(struct akcipher_request *req)
|
|
|
|
{
|
|
|
|
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
struct pkcs1pad_request *req_ctx = akcipher_request_ctx(req);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!ctx->key_size || req->src_len != ctx->key_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-29 11:32:26 +00:00
|
|
|
req_ctx->out_buf = kmalloc(ctx->key_size, GFP_KERNEL);
|
2015-12-05 16:09:34 +00:00
|
|
|
if (!req_ctx->out_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pkcs1pad_sg_set_buf(req_ctx->out_sg, req_ctx->out_buf,
|
2016-04-06 21:42:32 +00:00
|
|
|
ctx->key_size, NULL);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
akcipher_request_set_tfm(&req_ctx->child_req, ctx->child);
|
|
|
|
akcipher_request_set_callback(&req_ctx->child_req, req->base.flags,
|
|
|
|
pkcs1pad_decrypt_complete_cb, req);
|
|
|
|
|
2016-06-29 11:32:28 +00:00
|
|
|
/* Reuse input buffer, output to a new buffer */
|
|
|
|
akcipher_request_set_crypt(&req_ctx->child_req, req->src,
|
|
|
|
req_ctx->out_sg, req->src_len,
|
|
|
|
ctx->key_size);
|
|
|
|
|
2015-12-05 16:09:34 +00:00
|
|
|
err = crypto_akcipher_decrypt(&req_ctx->child_req);
|
2017-10-18 07:00:36 +00:00
|
|
|
if (err != -EINPROGRESS && err != -EBUSY)
|
2015-12-05 16:09:34 +00:00
|
|
|
return pkcs1pad_decrypt_complete(req, err);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_init_tfm(struct crypto_akcipher *tfm)
|
|
|
|
{
|
|
|
|
struct akcipher_instance *inst = akcipher_alg_instance(tfm);
|
2016-03-03 21:49:26 +00:00
|
|
|
struct pkcs1pad_inst_ctx *ictx = akcipher_instance_ctx(inst);
|
2015-12-05 16:09:34 +00:00
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
struct crypto_akcipher *child_tfm;
|
|
|
|
|
2016-06-29 11:32:23 +00:00
|
|
|
child_tfm = crypto_spawn_akcipher(&ictx->spawn);
|
2015-12-05 16:09:34 +00:00
|
|
|
if (IS_ERR(child_tfm))
|
|
|
|
return PTR_ERR(child_tfm);
|
|
|
|
|
|
|
|
ctx->child = child_tfm;
|
2022-11-22 05:53:38 +00:00
|
|
|
|
|
|
|
akcipher_set_reqsize(tfm, sizeof(struct pkcs1pad_request) +
|
|
|
|
crypto_akcipher_reqsize(child_tfm));
|
|
|
|
|
2015-12-05 16:09:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pkcs1pad_exit_tfm(struct crypto_akcipher *tfm)
|
|
|
|
{
|
|
|
|
struct pkcs1pad_ctx *ctx = akcipher_tfm_ctx(tfm);
|
|
|
|
|
|
|
|
crypto_free_akcipher(ctx->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pkcs1pad_free(struct akcipher_instance *inst)
|
|
|
|
{
|
2016-03-03 21:49:26 +00:00
|
|
|
struct pkcs1pad_inst_ctx *ctx = akcipher_instance_ctx(inst);
|
|
|
|
struct crypto_akcipher_spawn *spawn = &ctx->spawn;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
crypto_drop_akcipher(spawn);
|
|
|
|
kfree(inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb)
|
|
|
|
{
|
2020-01-03 03:58:47 +00:00
|
|
|
u32 mask;
|
2015-12-05 16:09:34 +00:00
|
|
|
struct akcipher_instance *inst;
|
2016-03-03 21:49:26 +00:00
|
|
|
struct pkcs1pad_inst_ctx *ctx;
|
2015-12-05 16:09:34 +00:00
|
|
|
struct akcipher_alg *rsa_alg;
|
|
|
|
int err;
|
|
|
|
|
2020-07-10 06:20:38 +00:00
|
|
|
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AKCIPHER, &mask);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2020-01-03 03:58:47 +00:00
|
|
|
|
2016-03-03 21:49:26 +00:00
|
|
|
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
2015-12-05 16:09:34 +00:00
|
|
|
if (!inst)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-03-03 21:49:26 +00:00
|
|
|
ctx = akcipher_instance_ctx(inst);
|
|
|
|
|
2020-02-26 04:59:23 +00:00
|
|
|
err = crypto_grab_akcipher(&ctx->spawn, akcipher_crypto_instance(inst),
|
|
|
|
crypto_attr_alg_name(tb[1]), 0, mask);
|
2015-12-05 16:09:34 +00:00
|
|
|
if (err)
|
2020-02-26 04:59:23 +00:00
|
|
|
goto err_free_inst;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
2020-02-26 04:59:23 +00:00
|
|
|
rsa_alg = crypto_spawn_akcipher_alg(&ctx->spawn);
|
2015-12-05 16:09:34 +00:00
|
|
|
|
2022-01-19 00:13:02 +00:00
|
|
|
if (strcmp(rsa_alg->base.cra_name, "rsa") != 0) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_free_inst;
|
|
|
|
}
|
|
|
|
|
2015-12-05 16:09:34 +00:00
|
|
|
err = -ENAMETOOLONG;
|
crypto: rsassa-pkcs1 - Migrate to sig_alg backend
A sig_alg backend has just been introduced with the intent of moving all
asymmetric sign/verify algorithms to it one by one.
Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
rsassa-pkcs1.c which uses the new backend.
Consequently there are now two templates which build on the "rsa"
akcipher_alg:
* The existing "pkcs1pad" template, which is instantiated as an
akcipher_instance and retains the encrypt/decrypt operations of
RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
* The new "pkcs1" template, which is instantiated as a sig_instance
and contains the sign/verify operations of RSASSA-PKCS1-v1_5
(RFC 8017 sec 8.2).
In a separate step, rsa-pkcs1pad.c could optionally be renamed to
rsaes-pkcs1.c for clarity. Additional "oaep" and "pss" templates
could be added for RSAES-OAEP and RSASSA-PSS.
Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
without specifying a hash algorithm. That makes sense if the transform
is only used for encrypt/decrypt and continues to be supported. But for
sign/verify, such transforms previously did not insert the Full Hash
Prefix into the padding. The resulting message encoding was incompliant
with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
From here on in, it is no longer allowed to allocate a transform without
specifying a hash algorithm if the transform is used for sign/verify
operations. This simplifies the code because the insertion of the Full
Hash Prefix is no longer optional, so various "if (digest_info)" clauses
can be removed.
There has been a previous attempt to forbid transform allocation without
specifying a hash algorithm, namely by commit c0d20d22e0ad ("crypto:
rsa-pkcs1pad - Require hash to be present"). It had to be rolled back
with commit b3a8c8a5ebb5 ("crypto: rsa-pkcs1pad: Allow hash to be
optional [ver #2]"), presumably because it broke allocation of a
transform which was solely used for encrypt/decrypt, not sign/verify.
Avoid such breakage by allowing transform allocation for encrypt/decrypt
with and without specifying a hash algorithm (and simply ignoring the
hash algorithm in the former case).
So again, specifying a hash algorithm is now mandatory for sign/verify,
but optional and ignored for encrypt/decrypt.
The new sig_alg API uses kernel buffers instead of sglists, which
avoids the overhead of copying signature and digest from sglists back
into kernel buffers. rsassa-pkcs1.c is thus simplified quite a bit.
sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
may be asynchronous. So await the result of the akcipher_alg, similar
to crypto_akcipher_sync_{en,de}crypt().
As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
adhere to the spec language in RFC 9580. Otherwise keep the code
unmodified wherever possible to ease reviewing and bisecting. Leave
several simplification and hardening opportunities to separate commits.
rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
clause for kfree_sensitive() is introduced herein as a byproduct.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-10 14:30:16 +00:00
|
|
|
if (snprintf(inst->alg.base.cra_name,
|
|
|
|
CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)",
|
|
|
|
rsa_alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
|
|
|
|
goto err_free_inst;
|
|
|
|
|
|
|
|
if (snprintf(inst->alg.base.cra_driver_name,
|
|
|
|
CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)",
|
|
|
|
rsa_alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
|
|
|
goto err_free_inst;
|
2015-12-05 16:09:34 +00:00
|
|
|
|
|
|
|
inst->alg.base.cra_priority = rsa_alg->base.cra_priority;
|
|
|
|
inst->alg.base.cra_ctxsize = sizeof(struct pkcs1pad_ctx);
|
|
|
|
|
|
|
|
inst->alg.init = pkcs1pad_init_tfm;
|
|
|
|
inst->alg.exit = pkcs1pad_exit_tfm;
|
|
|
|
|
|
|
|
inst->alg.encrypt = pkcs1pad_encrypt;
|
|
|
|
inst->alg.decrypt = pkcs1pad_decrypt;
|
|
|
|
inst->alg.set_pub_key = pkcs1pad_set_pub_key;
|
|
|
|
inst->alg.set_priv_key = pkcs1pad_set_priv_key;
|
|
|
|
inst->alg.max_size = pkcs1pad_get_max_size;
|
|
|
|
|
|
|
|
inst->free = pkcs1pad_free;
|
|
|
|
|
|
|
|
err = akcipher_register_instance(tmpl, inst);
|
2020-02-26 04:59:23 +00:00
|
|
|
if (err) {
|
|
|
|
err_free_inst:
|
|
|
|
pkcs1pad_free(inst);
|
|
|
|
}
|
2015-12-05 16:09:34 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct crypto_template rsa_pkcs1pad_tmpl = {
|
|
|
|
.name = "pkcs1pad",
|
|
|
|
.create = pkcs1pad_create,
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
};
|
2023-10-16 05:57:30 +00:00
|
|
|
|
|
|
|
MODULE_ALIAS_CRYPTO("pkcs1pad");
|