All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
@ 2024-05-15 15:02 Jarkko Sakkinen
  2024-05-16  4:14 ` Herbert Xu
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jarkko Sakkinen @ 2024-05-15 15:02 UTC (permalink / raw)
  To: Herbert Xu
  Cc: linux-integrity, Jarkko Sakkinen, James Prestwood,
	David S. Miller, open list:CRYPTO API, open list

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>

Cc: James Prestwood <prestwoj@gmail.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
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

diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c
index cd501195f34a..ea162ccf28ec 100644
--- a/crypto/rsa-pkcs1pad.c
+++ b/crypto/rsa-pkcs1pad.c
@@ -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;
diff --git a/include/crypto/rsa-pkcs1pad.h b/include/crypto/rsa-pkcs1pad.h
new file mode 100644
index 000000000000..32c7453ff644
--- /dev/null
+++ b/include/crypto/rsa-pkcs1pad.h
@@ -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 */
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
  2024-05-15 15:02 [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Jarkko Sakkinen
@ 2024-05-16  4:14 ` Herbert Xu
  2024-05-16  8:32   ` Jarkko Sakkinen
  2024-05-16  5:24 ` kernel test robot
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2024-05-16  4:14 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: linux-integrity, James Prestwood, David S. Miller,
	open list:CRYPTO API, open list

On Wed, May 15, 2024 at 06:02:10PM +0300, Jarkko Sakkinen wrote:
> 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>
> 
> Cc: James Prestwood <prestwoj@gmail.com>
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
> 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

Please provide a link to the patch that will make use of this.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
  2024-05-15 15:02 [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Jarkko Sakkinen
  2024-05-16  4:14 ` Herbert Xu
@ 2024-05-16  5:24 ` kernel test robot
  2024-05-16  6:56 ` kernel test robot
  2024-05-16 10:01 ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2024-05-16  5:24 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: llvm, oe-kbuild-all

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/202405161355.B776iHbb-lkp@intel.com/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/202405161355.B776iHbb-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405161355.B776iHbb-lkp@intel.com/

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  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
  2024-05-15 15:02 [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Jarkko Sakkinen
  2024-05-16  4:14 ` Herbert Xu
  2024-05-16  5:24 ` kernel test robot
@ 2024-05-16  6:56 ` kernel test robot
  2024-05-16 10:01 ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2024-05-16  6:56 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: oe-kbuild-all

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/202405161409.ij6nBora-lkp@intel.com/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/202405161409.ij6nBora-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405161409.ij6nBora-lkp@intel.com/

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
  2024-05-16  4:14 ` Herbert Xu
@ 2024-05-16  8:32   ` Jarkko Sakkinen
  0 siblings, 0 replies; 6+ messages in thread
From: Jarkko Sakkinen @ 2024-05-16  8:32 UTC (permalink / raw)
  To: Herbert Xu
  Cc: linux-integrity, James Prestwood, David S. Miller,
	open list:CRYPTO API, open list

On Thu May 16, 2024 at 7:14 AM EEST, Herbert Xu wrote:
> On Wed, May 15, 2024 at 06:02:10PM +0300, Jarkko Sakkinen wrote:
> > 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>
> > 
> > Cc: James Prestwood <prestwoj@gmail.com>
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> > 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
>
> 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/20200518172704.29608-18-prestwoj@gmail.com/

TPM2_RSA_Decrypt is exactly textbook RSA so it partially needs
the code from kernel's RSA implementation.

BR, Jarkko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup()
  2024-05-15 15:02 [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Jarkko Sakkinen
                   ` (2 preceding siblings ...)
  2024-05-16  6:56 ` kernel test robot
@ 2024-05-16 10:01 ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2024-05-16 10:01 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: oe-kbuild-all

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/202405161744.nLqphdgo-lkp@intel.com/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/202405161744.nLqphdgo-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405161744.nLqphdgo-lkp@intel.com/

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	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-16 10:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-15 15:02 [PATCH v2] crypto: rsa-pkcs1pad: export rsa1_asn_lookup() Jarkko Sakkinen
2024-05-16  4:14 ` Herbert Xu
2024-05-16  8:32   ` Jarkko Sakkinen
2024-05-16  5:24 ` kernel test robot
2024-05-16  6:56 ` kernel test robot
2024-05-16 10:01 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.