aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/transforms
diff options
context:
space:
mode:
Diffstat (limited to 'Source/charon/transforms')
-rwxr-xr-xSource/charon/transforms/certificate.c1
-rw-r--r--Source/charon/transforms/rsa/rsa_private_key.c22
-rw-r--r--Source/charon/transforms/rsa/rsa_private_key.h8
3 files changed, 30 insertions, 1 deletions
diff --git a/Source/charon/transforms/certificate.c b/Source/charon/transforms/certificate.c
index e8ee61bb2..2c8f30bf3 100755
--- a/Source/charon/transforms/certificate.c
+++ b/Source/charon/transforms/certificate.c
@@ -145,7 +145,6 @@ static rsa_public_key_t *get_public_key(private_certificate_t *this)
return this->public_key->clone(this->public_key);
}
-
/**
* Implementation of certificate.destroy.
*/
diff --git a/Source/charon/transforms/rsa/rsa_private_key.c b/Source/charon/transforms/rsa/rsa_private_key.c
index 4da3baf7c..231aee962 100644
--- a/Source/charon/transforms/rsa/rsa_private_key.c
+++ b/Source/charon/transforms/rsa/rsa_private_key.c
@@ -155,6 +155,8 @@ static asn1_rule_t rsa_private_key_rules[] = {
{ASN1_END, 0, 0, 0},
};
+static private_rsa_private_key_t *rsa_private_key_create_empty();
+
/**
* Implementation of private_rsa_private_key_t.compute_prime.
*/
@@ -389,6 +391,25 @@ bool belongs_to(private_rsa_private_key_t *this, rsa_public_key_t *public)
return FALSE;
}
+/**
+ * Implementation of rsa_private_key.clone.
+ */
+static rsa_private_key_t* _clone(private_rsa_private_key_t *this)
+{
+ private_rsa_private_key_t *clone = rsa_private_key_create_empty();
+
+ mpz_init_set(clone->n, this->n);
+ mpz_init_set(clone->e, this->e);
+ mpz_init_set(clone->p, this->p);
+ mpz_init_set(clone->q, this->q);
+ mpz_init_set(clone->d, this->d);
+ mpz_init_set(clone->exp1, this->exp1);
+ mpz_init_set(clone->exp2, this->exp2);
+ mpz_init_set(clone->coeff, this->coeff);
+ clone->k = this->k;
+
+ return &clone->public;
+}
/**
* Implementation of rsa_private_key.destroy.
@@ -419,6 +440,7 @@ static private_rsa_private_key_t *rsa_private_key_create_empty()
this->public.save_key = (status_t (*) (rsa_private_key_t*,char*))save_key;
this->public.get_public_key = (rsa_public_key_t *(*) (rsa_private_key_t*))get_public_key;
this->public.belongs_to = (bool (*) (rsa_private_key_t*,rsa_public_key_t*))belongs_to;
+ this->public.clone = (rsa_private_key_t*(*)(rsa_private_key_t*))_clone;
this->public.destroy = (void (*) (rsa_private_key_t*))destroy;
/* private functions */
diff --git a/Source/charon/transforms/rsa/rsa_private_key.h b/Source/charon/transforms/rsa/rsa_private_key.h
index ffbe419f5..3ca760042 100644
--- a/Source/charon/transforms/rsa/rsa_private_key.h
+++ b/Source/charon/transforms/rsa/rsa_private_key.h
@@ -126,6 +126,14 @@ struct rsa_private_key_t {
bool (*belongs_to) (rsa_private_key_t *this, rsa_public_key_t *public);
/**
+ * @brief Clone the private key.
+ *
+ * @param this private key to clone
+ * @return clone of this
+ */
+ rsa_private_key_t *(*clone) (rsa_private_key_t *this);
+
+ /**
* @brief Destroys the private key.
*
* @param this private key to destroy