p11-kit/0008-Add-support-for-CKM_DH_PKCS_DERIVE.patch
2024-02-28 21:54:07 +08:00

95 lines
3.2 KiB
Diff

From 25c7661eb8ae1f60aa0d1d995ac4addc456d33b9 Mon Sep 17 00:00:00 2001
From: Ingo Franzki <ifranzki@linux.ibm.com>
Date: Fri, 8 Apr 2022 13:38:44 +0200
Subject: [PATCH 08/11] Add support for CKM_DH_PKCS_DERIVE
It takes the the public value of the other party as mechanism parameter.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
---
p11-kit/rpc-message.c | 41 +++++++++++++++++++++++++++++++++++++++++
p11-kit/rpc-message.h | 11 +++++++++++
2 files changed, 52 insertions(+)
diff --git a/p11-kit/rpc-message.c b/p11-kit/rpc-message.c
index 5159d98..c3f1dbb 100644
--- a/p11-kit/rpc-message.c
+++ b/p11-kit/rpc-message.c
@@ -1678,6 +1678,46 @@ p11_rpc_buffer_get_mac_general_mechanism_value (p11_buffer *buffer,
return true;
}
+void
+p11_rpc_buffer_add_dh_pkcs_derive_mechanism_value (p11_buffer *buffer,
+ const void *value,
+ CK_ULONG value_length)
+{
+ /* Mechanism parameter is public value of the other party */
+ if (value_length == 0) {
+ p11_buffer_fail (buffer);
+ return;
+ }
+
+ p11_rpc_buffer_add_byte_array (buffer,
+ (unsigned char *)value,
+ value_length);
+}
+
+bool
+p11_rpc_buffer_get_dh_pkcs_derive_mechanism_value (p11_buffer *buffer,
+ size_t *offset,
+ void *value,
+ CK_ULONG *value_length)
+{
+ const unsigned char *data;
+ size_t len;
+
+ if (!p11_rpc_buffer_get_byte_array (buffer, offset, &data, &len))
+ return false;
+
+ if (len == 0)
+ return false;
+
+ if (value)
+ memcpy (value, data, len);
+
+ if (value_length)
+ *value_length = len;
+
+ return true;
+}
+
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_SHA1_RSA_PKCS_PSS, p11_rpc_buffer_add_rsa_pkcs_pss_mechanism_value, p11_rpc_buffer_get_rsa_pkcs_pss_mechanism_value },
@@ -1716,6 +1756,7 @@ static p11_rpc_mechanism_serializer p11_rpc_mechanism_serializers[] = {
{ CKM_AES_CMAC_GENERAL, p11_rpc_buffer_add_mac_general_mechanism_value, p11_rpc_buffer_get_mac_general_mechanism_value },
{ CKM_DES3_MAC_GENERAL, p11_rpc_buffer_add_mac_general_mechanism_value, p11_rpc_buffer_get_mac_general_mechanism_value },
{ CKM_DES3_CMAC_GENERAL, p11_rpc_buffer_add_mac_general_mechanism_value, p11_rpc_buffer_get_mac_general_mechanism_value },
+ { CKM_DH_PKCS_DERIVE, p11_rpc_buffer_add_dh_pkcs_derive_mechanism_value, p11_rpc_buffer_get_dh_pkcs_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 5ae09e5..6c8eaf3 100644
--- a/p11-kit/rpc-message.h
+++ b/p11-kit/rpc-message.h
@@ -531,4 +531,15 @@ bool p11_rpc_buffer_get_mac_general_mechanism_value
void *value,
CK_ULONG *value_length);
+void p11_rpc_buffer_add_dh_pkcs_derive_mechanism_value
+ (p11_buffer *buffer,
+ const void *value,
+ CK_ULONG value_length);
+
+bool p11_rpc_buffer_get_dh_pkcs_derive_mechanism_value
+ (p11_buffer *buffer,
+ size_t *offset,
+ void *value,
+ CK_ULONG *value_length);
+
#endif /* _RPC_MESSAGE_H */
--
2.38.1