crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
Subsystems (3)
Jarkko Sakkinen
maintainerPATCH v2 1/1 crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
ASN.1 template is required for TPM2 asymmetric keys, as it needs to be piggy-packed with the input data before applying TPM2_RSA_Decrypt. This patch prepares crypto subsystem for the addition of those keys.
Later rsa_lookup_asn1() can be enabled in crypto/asymmetric_keys/Kconfig by:
depends on CRYPTO_RSA >= <TPM2 asymmetric keys>
---
v2:
- Fix typo in the kdoc.
- Export also the template struct.
--- crypto/rsa-pkcs1pad.c | 16 ++++++++++------ include/crypto/rsa-pkcs1pad.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/crypto/rsa-pkcs1pad.h
crypto/rsa-pkcs1pad.c +10 -6
@@ -7,6 +7,7 @@#include <crypto/algapi.h> #include <crypto/akcipher.h> +#include <crypto/rsa-pkcs1pad.h> #include <crypto/internal/akcipher.h> #include <crypto/internal/rsa.h> #include <linux/err.h>
@@ -79,11 +80,7 @@ static const u8 rsa_digest_info_sha3_512[] = {0x05 ,0x00 ,0x04 ,0x40 }; -static const struct rsa_asn1_template { - const char *name; - const u8 *data; - size_t size; -} rsa_asn1_templates[] = { +const struct rsa_asn1_template rsa_asn1_templates[] = { #define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) }_ (md5), _(sha1),
@@ -101,7 +98,13 @@ static const struct rsa_asn1_template { { NULL } }; -static const struct rsa_asn1_template *rsa_lookup_asn1 (const char *name) +/** +* rsa_lookup_asn1() - Lookup the ASN.1 digest info given the hash +* name: hash algorithm name +* +* Returns the ASN.1 digest info on success, and NULL on failure. +*/ +const struct rsa_asn1_template *rsa_lookup_asn1 (const char *name) {const struct rsa_asn1_template *p;
@@ -110,6 +113,7 @@ static const struct rsa_asn1_template *rsa_lookup_asn1(const char *name)return p;return NULL ; } +EXPORT_SYMBOL_GPL (rsa_lookup_asn1);struct pkcs1pad_ctx {struct crypto_akcipher *child;
include/crypto/rsa-pkcs1pad.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* RSA padding templates. +*/ + +#ifndef _CRYPTO_RSA_PKCS1PAD_H +#define _CRYPTO_RSA_PKCS1PAD_H + +/* +* Hash algorithm name to ASN.1 template mapping. +*/ +struct rsa_asn1_template { +const char *name; +const u8 *data; +size_t size; +}; + +const struct rsa_asn1_template *rsa_lookup_asn1 (const char *name); + +#endif /* _CRYPTO_RSA_PKCS1PAD_H */
Signature · 1 line
2.45.0
Herbert Xu
maintainerQuoted 15 lines · Jarkko Sakkinen
ASN.1 template is required for TPM2 asymmetric keys, as it needs to be piggy-packed with the input data before applying
TPM2_RSA_Decrypt. This patch prepares crypto subsystem for the addition of those keys.Later
rsa_lookup_asn1()can be enabled incrypto/asymmetric_keys/Kconfigby:depends on
CRYPTO_RSA>= <TPM2 asymmetric keys>Cc James Prestwood <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Fix typo in the kdoc.
- Export also the template struct.
Quoted 5 lines
--- crypto/rsa-pkcs1pad.c | 16 ++++++++++------ include/crypto/rsa-pkcs1pad.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/crypto/rsa-pkcs1pad.h
Please provide a link to the patch that will make use of this.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Jarkko Sakkinen
maintainerQuoted 22 lines · Herbert Xu
Quoted 15 lines · Jarkko Sakkinen
ASN.1 template is required for TPM2 asymmetric keys, as it needs to be piggy-packed with the input data before applying
TPM2_RSA_Decrypt. This patch prepares crypto subsystem for the addition of those keys.Later
rsa_lookup_asn1()can be enabled incrypto/asymmetric_keys/Kconfigby:depends on
CRYPTO_RSA>= <TPM2 asymmetric keys>Cc James Prestwood <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Fix typo in the kdoc.
- Export also the template struct.Quoted 5 lines
--- crypto/rsa-pkcs1pad.c | 16 ++++++++++------ include/crypto/rsa-pkcs1pad.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 include/crypto/rsa-pkcs1pad.h
Quoted 1 line
Please provide a link to the patch that will make use of this.
OK, fair enough. Will be part of the full patch set.
Overally I can say that this will be used to make textbook RSA to a proper RSA signature ASN.1 and appropriate padding. I.e. breath new life to this patch, which has duplicate code:
https://lore.kernel.org/all/[email protected]/
TPM2_RSA_Decrypt is exactly textbook RSA so it partially needs the code from kernel's RSA implementation.
BR, Jarkko
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Jarkko,
kernel test robot noticed the following build warnings:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v6.9 next-20240515] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jarkko-Sakkinen/crypto-rsa-pkcs1pad-export-rsa1_asn_lookup/20240515-230406 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20240515150213.32491-1-jarkko%40kernel.org patch subject: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() config: i386-buildonly-randconfig-002-20240516 (https://download.01.org/0day-ci/archive/20240516/[email protected]/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240516/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> crypto/rsa-pkcs1pad.c:108: warning: Function parameter or struct member 'name' not described in 'rsa_lookup_asn1'
vim +108 crypto/rsa-pkcs1pad.c
a49de377e051ea Tadeusz Struk 2016-03-03 100
446115366ec712 Jarkko Sakkinen 2024-05-15 101 /**
446115366ec712 Jarkko Sakkinen 2024-05-15 102 * rsa_lookup_asn1() - Lookup the ASN.1 digest info given the hash
446115366ec712 Jarkko Sakkinen 2024-05-15 103 * name: hash algorithm name
446115366ec712 Jarkko Sakkinen 2024-05-15 104 *
446115366ec712 Jarkko Sakkinen 2024-05-15 105 * Returns the ASN.1 digest info on success, and NULL on failure.
446115366ec712 Jarkko Sakkinen 2024-05-15 106 */
446115366ec712 Jarkko Sakkinen 2024-05-15 107 const struct rsa_asn1_template *rsa_lookup_asn1(const char *name)
a49de377e051ea Tadeusz Struk 2016-03-03 @108 {
a49de377e051ea Tadeusz Struk 2016-03-03 109 const struct rsa_asn1_template *p;
a49de377e051ea Tadeusz Struk 2016-03-03 110
a49de377e051ea Tadeusz Struk 2016-03-03 111 for (p = rsa_asn1_templates; p->name; p++)
a49de377e051ea Tadeusz Struk 2016-03-03 112 if (strcmp(name, p->name) == 0)
a49de377e051ea Tadeusz Struk 2016-03-03 113 return p;
a49de377e051ea Tadeusz Struk 2016-03-03 114 return NULL;
a49de377e051ea Tadeusz Struk 2016-03-03 115 }446115366ec712 Jarkko Sakkinen 2024-05-15 116 EXPORT_SYMBOL_GPL(rsa_lookup_asn1);a49de377e051ea Tadeusz Struk 2016-03-03 117
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Jarkko,
kernel test robot noticed the following build warnings:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v6.9 next-20240515] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jarkko-Sakkinen/crypto-rsa-pkcs1pad-export-rsa1_asn_lookup/20240515-230406 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20240515150213.32491-1-jarkko%40kernel.org patch subject: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() config: i386-randconfig-061-20240516 (https://download.01.org/0day-ci/archive/20240516/[email protected]/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240516/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> crypto/rsa-pkcs1pad.c:83:32: sparse: sparse: symbol 'rsa_asn1_templates' was not declared. Should it be static?
vim +/rsa_asn1_templates +83 crypto/rsa-pkcs1pad.c
82
> 83 const struct rsa_asn1_template rsa_asn1_templates[] = {
84 #define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) }
85 _(md5),
86 _(sha1),
87 _(rmd160),
88 _(sha256),
89 _(sha384),
90 _(sha512),
91 _(sha224),
92 #undef _
93 #define _(X) { "sha3-" #X, rsa_digest_info_sha3_##X, sizeof(rsa_digest_info_sha3_##X) }
94 _(256),
95 _(384),
96 _(512),
97 #undef _
98 { NULL }
99 };100
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Jarkko,
kernel test robot noticed the following build warnings:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v6.9 next-20240516] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jarkko-Sakkinen/crypto-rsa-pkcs1pad-export-rsa1_asn_lookup/20240515-230406 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20240515150213.32491-1-jarkko%40kernel.org patch subject: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() config: i386-randconfig-061-20240516 (https://download.01.org/0day-ci/archive/20240516/[email protected]/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240516/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> crypto/rsa-pkcs1pad.c:83:32: sparse: sparse: symbol 'rsa_asn1_templates' was not declared. Should it be static?
vim +/rsa_asn1_templates +83 crypto/rsa-pkcs1pad.c
82
> 83 const struct rsa_asn1_template rsa_asn1_templates[] = {
84 #define _(X) { #X, rsa_digest_info_##X, sizeof(rsa_digest_info_##X) }
85 _(md5),
86 _(sha1),
87 _(rmd160),
88 _(sha256),
89 _(sha384),
90 _(sha512),
91 _(sha224),
92 #undef _
93 #define _(X) { "sha3-" #X, rsa_digest_info_sha3_##X, sizeof(rsa_digest_info_sha3_##X) }
94 _(256),
95 _(384),
96 _(512),
97 #undef _
98 { NULL }
99 };100
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki