Skip to contentSkip to conversation

KEYS: asymmetric: Fix ECDSA use via keyctl uapi

PATCH In review Denis Kenzior 3 participants 3 messages Aug 26, 2022 – Jan 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KEYS: asymmetric: Fix ECDSA use via keyctl uapi

When support for ECDSA keys was added, constraints for data & signature sizes were never updated. This makes it impossible to use such keys via keyctl API from userspace.

Update constraint on max_data_size to 64 bytes in order to support SHA512-based signatures. Also update the signature length constraints per ECDSA signature encoding described in RFC 5480.

Fixes 299f561a6693 ("x509: Add support for parsing x509 certs with ECDSA keys")

---

Version History:

v2: Update patch description according to Jarkko's comments. No functional code changes.

 crypto/asymmetric_keys/public_key.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/public_key.c +22 -2
index 2f8352e88860..eca5671ad3f2 100644
@@ -186,8 +186,28 @@ static int software_key_query(const struct kernel_pkey_params *params,
 
 	len = crypto_akcipher_maxsize(tfm);
 	info->key_size = len * 8;
-	info->max_data_size = len;
-	info->max_sig_size = len;
+
+	if (strncmp(pkey->pkey_algo, "ecdsa", 5) == 0) {
+		/*
+		 * ECDSA key sizes are much smaller than RSA, and thus could
+		 * operate on (hashed) inputs that are larger than key size.
+		 * For example SHA384-hashed input used with secp256r1
+		 * based keys.  Set max_data_size to be at least as large as
+		 * the largest supported hash size (SHA512)
+		 */
+		info->max_data_size = 64;
+
+		/*
+		 * Verify takes ECDSA-Sig (described in RFC 5480) as input,
+		 * which is actually 2 'key_size'-bit integers encoded in
+		 * ASN.1.  Account for the ASN.1 encoding overhead here.
+		 */
+		info->max_sig_size = 2 * (len + 3) + 2;
+	} else {
+		info->max_data_size = len;
+		info->max_sig_size = len;
+	}
+
 	info->max_enc_size = len;
 	info->max_dec_size = len;
 	info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Denis Kenzior

When support for ECDSA keys was added, constraints for data & signature sizes were never updated. This makes it impossible to use such keys via keyctl API from userspace.

Update constraint on max_data_size to 64 bytes in order to support SHA512-based signatures. Also update the signature length constraints per ECDSA signature encoding described in RFC 5480.

Fixes 299f561a6693 ("x509: Add support for parsing x509 certs with ECDSA keys")
Quoted 45 lines

---

Version History:

v2: Update patch description according to Jarkko's comments. No functional code changes.

  crypto/asymmetric_keys/public_key.c | 24 ++++++++++++++++++++++--
  1 file changed, 22 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/public_key.c +22 -2
index 2f8352e88860..eca5671ad3f2 100644
@@ -186,8 +186,28 @@ static int software_key_query(const struct kernel_pkey_params *params,
 
  	len = crypto_akcipher_maxsize(tfm);
  	info->key_size = len * 8;
-	info->max_data_size = len;
-	info->max_sig_size = len;
+
+	if (strncmp(pkey->pkey_algo, "ecdsa", 5) == 0) {
+		/*
+		 * ECDSA key sizes are much smaller than RSA, and thus could
+		 * operate on (hashed) inputs that are larger than key size.
+		 * For example SHA384-hashed input used with secp256r1
+		 * based keys.  Set max_data_size to be at least as large as
+		 * the largest supported hash size (SHA512)
+		 */
+		info->max_data_size = 64;
+
+		/*
+		 * Verify takes ECDSA-Sig (described in RFC 5480) as input,
+		 * which is actually 2 'key_size'-bit integers encoded in
+		 * ASN.1.  Account for the ASN.1 encoding overhead here.
+		 */
+		info->max_sig_size = 2 * (len + 3) + 2;
+	} else {
+		info->max_data_size = len;
+		info->max_sig_size = len;
+	}
+
  	info->max_enc_size = len;
  	info->max_dec_size = len;
  	info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |
#2 lore raw
In reply to Denis Kenzior

Hi

What's the hold-up with this patch? I would really appreciate if someone could take a look at it and move it along to finally enable iwd to connect to networks using ECDSA certificates (my eduroam network for example).

Michael

------- Original Message -------

Quoted 71 lines · Denis Kenzior

When support for ECDSA keys was added, constraints for data & signature sizes were never updated. This makes it impossible to use such keys via keyctl API from userspace.

Update constraint on max_data_size to 64 bytes in order to support SHA512-based signatures. Also update the signature length constraints per ECDSA signature encoding described in RFC 5480.

Fixes 299f561a6693 ("x509: Add support for parsing x509 certs with ECDSA keys")

---

Version History:

v2: Update patch description according to Jarkko's comments. No functional code changes.

crypto/asymmetric_keys/public_key.c | 24 ++++++++++++++++++++++--

1 file changed, 22 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/public_key.c +22 -2
index 2f8352e88860..eca5671ad3f2 100644
@@ -186,8 +186,28 @@ static int software_key_query(const struct kernel_pkey_params *params,
 
 len = crypto_akcipher_maxsize(tfm);
 info->key_size = len * 8;
 
- info->max_data_size = len;
 
- info->max_sig_size = len;
 
+
+ if (strncmp(pkey->pkey_algo, "ecdsa", 5) == 0) {
 
+ /*
+ * ECDSA key sizes are much smaller than RSA, and thus could
+ * operate on (hashed) inputs that are larger than key size.
+ * For example SHA384-hashed input used with secp256r1
+ * based keys. Set max_data_size to be at least as large as
+ * the largest supported hash size (SHA512)
+ */
+ info->max_data_size = 64;
 
+
+ /*
+ * Verify takes ECDSA-Sig (described in RFC 5480) as input,
+ * which is actually 2 'key_size'-bit integers encoded in
+ * ASN.1. Account for the ASN.1 encoding overhead here.
+ */
+ info->max_sig_size = 2 * (len + 3) + 2;
 
+ } else {
+ info->max_data_size = len;
 
+ info->max_sig_size = len;
 
+ }
+

info->max_enc_size = len;

info->max_dec_size = len;

info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |

--
2.35.1