136 lines
4.6 KiB
Diff
136 lines
4.6 KiB
Diff
From d23b8a60a1944a9e25d5e47ead16185a39111b51 Mon Sep 17 00:00:00 2001
|
|
From: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
Date: Thu, 7 Apr 2022 17:10:53 +0200
|
|
Subject: [PATCH 02/11] Add support for serializing CK_ECDH1_DERIVE_PARAMS mech
|
|
param
|
|
|
|
Used by CKM_ECDH1_DERIVE, CKM_IBM_EC_X25519 and CKM_IBM_EC_X448.
|
|
|
|
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
|
|
---
|
|
p11-kit/rpc-message.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
|
|
p11-kit/rpc-message.h | 11 ++++++
|
|
2 files changed, 89 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/p11-kit/rpc-message.c b/p11-kit/rpc-message.c
|
|
index 0923224..d842df0 100644
|
|
--- a/p11-kit/rpc-message.c
|
|
+++ b/p11-kit/rpc-message.c
|
|
@@ -1428,6 +1428,80 @@ p11_rpc_buffer_get_rsa_pkcs_oaep_mechanism_value (p11_buffer *buffer,
|
|
return true;
|
|
}
|
|
|
|
+void
|
|
+p11_rpc_buffer_add_ecdh1_derive_mechanism_value (p11_buffer *buffer,
|
|
+ const void *value,
|
|
+ CK_ULONG value_length)
|
|
+{
|
|
+ CK_ECDH1_DERIVE_PARAMS params;
|
|
+
|
|
+ /* Check if value can be converted to CK_ECDH1_DERIVE_PARAMS. */
|
|
+ if (value_length != sizeof (CK_ECDH1_DERIVE_PARAMS)) {
|
|
+ p11_buffer_fail (buffer);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ memcpy (¶ms, value, value_length);
|
|
+
|
|
+ /* Check if params.kdf can be converted to uint64_t. */
|
|
+ if (params.kdf > UINT64_MAX) {
|
|
+ p11_buffer_fail (buffer);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ p11_rpc_buffer_add_uint64 (buffer, params.kdf);
|
|
+
|
|
+ /* parmas.shared_data can only be an array of CK_BYTE or
|
|
+ * NULL */
|
|
+ p11_rpc_buffer_add_byte_array (buffer,
|
|
+ (unsigned char *)params.shared_data,
|
|
+ params.shared_data_len);
|
|
+
|
|
+ /* parmas.public_data can only be an array of CK_BYTE or
|
|
+ * NULL */
|
|
+ p11_rpc_buffer_add_byte_array (buffer,
|
|
+ (unsigned char *)params.public_data,
|
|
+ params.public_data_len);
|
|
+}
|
|
+
|
|
+bool
|
|
+p11_rpc_buffer_get_ecdh1_derive_mechanism_value (p11_buffer *buffer,
|
|
+ size_t *offset,
|
|
+ void *value,
|
|
+ CK_ULONG *value_length)
|
|
+{
|
|
+ uint64_t val;
|
|
+ const unsigned char *data1, *data2;
|
|
+ size_t len1, len2;
|
|
+
|
|
+ if (!p11_rpc_buffer_get_uint64 (buffer, offset, &val))
|
|
+ return false;
|
|
+
|
|
+ if (!p11_rpc_buffer_get_byte_array (buffer, offset, &data1, &len1))
|
|
+ return false;
|
|
+
|
|
+ if (!p11_rpc_buffer_get_byte_array (buffer, offset, &data2, &len2))
|
|
+ return false;
|
|
+
|
|
+
|
|
+ if (value) {
|
|
+ CK_ECDH1_DERIVE_PARAMS params;
|
|
+
|
|
+ params.kdf = val;
|
|
+ params.shared_data = (void *) data1;
|
|
+ params.shared_data_len = len1;
|
|
+ params.public_data = (void *) data2;
|
|
+ params.public_data_len = len2;
|
|
+
|
|
+ memcpy (value, ¶ms, sizeof (CK_ECDH1_DERIVE_PARAMS));
|
|
+ }
|
|
+
|
|
+ if (value_length)
|
|
+ *value_length = sizeof (CK_ECDH1_DERIVE_PARAMS);
|
|
+
|
|
+ return true;
|
|
+}
|
|
+
|
|
void
|
|
p11_rpc_buffer_add_ibm_attrbound_wrap_mechanism_value (p11_buffer *buffer,
|
|
const void *value,
|
|
@@ -1480,7 +1554,10 @@ p11_rpc_buffer_get_ibm_attrbound_wrap_mechanism_value (p11_buffer *buffer,
|
|
static p11_rpc_mechanism_serializer p11_rpc_mechanism_serializers[] = {
|
|
{ CKM_RSA_PKCS_PSS, p11_rpc_buffer_add_rsa_pkcs_pss_mechanism_value, p11_rpc_buffer_get_rsa_pkcs_pss_mechanism_value },
|
|
{ CKM_RSA_PKCS_OAEP, p11_rpc_buffer_add_rsa_pkcs_oaep_mechanism_value, p11_rpc_buffer_get_rsa_pkcs_oaep_mechanism_value },
|
|
- { CKM_IBM_ATTRIBUTEBOUND_WRAP, p11_rpc_buffer_add_ibm_attrbound_wrap_mechanism_value, p11_rpc_buffer_get_ibm_attrbound_wrap_mechanism_value }
|
|
+ { CKM_ECDH1_DERIVE, p11_rpc_buffer_add_ecdh1_derive_mechanism_value, p11_rpc_buffer_get_ecdh1_derive_mechanism_value },
|
|
+ { CKM_IBM_ATTRIBUTEBOUND_WRAP, p11_rpc_buffer_add_ibm_attrbound_wrap_mechanism_value, p11_rpc_buffer_get_ibm_attrbound_wrap_mechanism_value },
|
|
+ { CKM_IBM_EC_X25519, p11_rpc_buffer_add_ecdh1_derive_mechanism_value, p11_rpc_buffer_get_ecdh1_derive_mechanism_value },
|
|
+ { CKM_IBM_EC_X448, p11_rpc_buffer_add_ecdh1_derive_mechanism_value, p11_rpc_buffer_get_ecdh1_derive_mechanism_value },
|
|
};
|
|
|
|
static p11_rpc_mechanism_serializer p11_rpc_byte_array_mechanism_serializer = {
|
|
diff --git a/p11-kit/rpc-message.h b/p11-kit/rpc-message.h
|
|
index eec2927..66f512d 100644
|
|
--- a/p11-kit/rpc-message.h
|
|
+++ b/p11-kit/rpc-message.h
|
|
@@ -480,6 +480,17 @@ bool p11_rpc_buffer_get_rsa_pkcs_oaep_mechanism_value
|
|
void *value,
|
|
CK_ULONG *value_length);
|
|
|
|
+void p11_rpc_buffer_add_ecdh1_derive_mechanism_value
|
|
+ (p11_buffer *buffer,
|
|
+ const void *value,
|
|
+ CK_ULONG value_length);
|
|
+
|
|
+bool p11_rpc_buffer_get_ecdh1_derive_mechanism_value
|
|
+ (p11_buffer *buffer,
|
|
+ size_t *offset,
|
|
+ void *value,
|
|
+ CK_ULONG *value_length);
|
|
+
|
|
void p11_rpc_buffer_add_ibm_attrbound_wrap_mechanism_value
|
|
(p11_buffer *buffer,
|
|
const void *value,
|
|
--
|
|
2.38.1
|
|
|