aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/credentials/keys/private_key.c43
-rw-r--r--src/libstrongswan/credentials/keys/private_key.h24
-rw-r--r--src/libstrongswan/credentials/keys/public_key.c24
-rw-r--r--src/libstrongswan/credentials/keys/public_key.h9
4 files changed, 97 insertions, 3 deletions
diff --git a/src/libstrongswan/credentials/keys/private_key.c b/src/libstrongswan/credentials/keys/private_key.c
index 0a01d0385..a334370a4 100644
--- a/src/libstrongswan/credentials/keys/private_key.c
+++ b/src/libstrongswan/credentials/keys/private_key.c
@@ -15,3 +15,46 @@
#include "private_key.h"
+/**
+ * See header.
+ */
+bool private_key_equals(private_key_t *this, private_key_t *other)
+{
+ key_encoding_type_t type;
+ chunk_t a, b;
+
+ if (this == other)
+ {
+ return TRUE;
+ }
+
+ for (type = 0; type < KEY_ENCODING_MAX; type++)
+ {
+ if (this->get_fingerprint(this, type, &a) &&
+ other->get_fingerprint(other, type, &b))
+ {
+ return chunk_equals(a, b);
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * See header.
+ */
+bool private_key_belongs_to(private_key_t *private, public_key_t *public)
+{
+ key_encoding_type_t type;
+ chunk_t a, b;
+
+ for (type = 0; type < KEY_ENCODING_MAX; type++)
+ {
+ if (private->get_fingerprint(private, type, &a) &&
+ public->get_fingerprint(public, type, &b))
+ {
+ return chunk_equals(a, b);
+ }
+ }
+ return FALSE;
+}
+
diff --git a/src/libstrongswan/credentials/keys/private_key.h b/src/libstrongswan/credentials/keys/private_key.h
index f38af8ff4..bbc77a8dc 100644
--- a/src/libstrongswan/credentials/keys/private_key.h
+++ b/src/libstrongswan/credentials/keys/private_key.h
@@ -112,9 +112,27 @@ struct private_key_t {
private_key_t* (*get_ref)(private_key_t *this);
/**
- * Decrease refcount, destroy private_key if no more references.
- */
- void (*destroy)(private_key_t *this);
+ * Decrease refcount, destroy private_key if no more references.
+ */
+ void (*destroy)(private_key_t *this);
};
+/**
+ * Generic private key equals() implementation, usable by implementors.
+ *
+ * @param this first key to compare
+ * @param other second key to compare
+ * @return TRUE if this is equal to other
+ */
+bool private_key_equals(private_key_t *this, private_key_t *other);
+
+/**
+ * Generic private key belongs_to() implementation, usable by implementors.
+ *
+ * @param this first key to compare
+ * @param other second key to compare
+ * @return TRUE if this is equal to other
+ */
+bool private_key_belongs_to(private_key_t *private, public_key_t *public);
+
#endif /** PRIVATE_KEY_H_ @}*/
diff --git a/src/libstrongswan/credentials/keys/public_key.c b/src/libstrongswan/credentials/keys/public_key.c
index a5f547038..4abaf4010 100644
--- a/src/libstrongswan/credentials/keys/public_key.c
+++ b/src/libstrongswan/credentials/keys/public_key.c
@@ -39,6 +39,30 @@ ENUM(signature_scheme_names, SIGN_UNKNOWN, SIGN_ECDSA_521,
"ECDSA-521",
);
+/**
+ * See header.
+ */
+bool public_key_equals(public_key_t *this, public_key_t *other)
+{
+ key_encoding_type_t type;
+ chunk_t a, b;
+
+ if (this == other)
+ {
+ return TRUE;
+ }
+
+ for (type = 0; type < KEY_ENCODING_MAX; type++)
+ {
+ if (this->get_fingerprint(this, type, &a) &&
+ other->get_fingerprint(other, type, &b))
+ {
+ return chunk_equals(a, b);
+ }
+ }
+ return FALSE;
+}
+
/*
* Defined in header.
*/
diff --git a/src/libstrongswan/credentials/keys/public_key.h b/src/libstrongswan/credentials/keys/public_key.h
index be5f3bde6..6cab37d2d 100644
--- a/src/libstrongswan/credentials/keys/public_key.h
+++ b/src/libstrongswan/credentials/keys/public_key.h
@@ -169,6 +169,15 @@ struct public_key_t {
};
/**
+ * Generic public key equals() implementation, usable by implementors.
+ *
+ * @param this first key to compare
+ * @param other second key to compare
+ * @return TRUE if this is equal to other
+ */
+bool public_key_equals(public_key_t *this, public_key_t *other);
+
+/**
* Conversion of ASN.1 signature or hash OID to signature scheme.
*
* @param oid ASN.1 OID