updates
[silc.git] / lib / silccrypt / silcpkcs.c
index fe0e1c659fad862933b3c379da19cea0fa58121d..2f9699bb064bdeb51674a554f13b12f9c839d129 100644 (file)
@@ -152,8 +152,10 @@ bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs)
 
 void silc_pkcs_free(SilcPKCS pkcs)
 {
-  if (pkcs)
+  if (pkcs) {
+    pkcs->pkcs->clear_keys(pkcs->context);
     silc_free(pkcs->context);
+  }
   silc_free(pkcs);
 }
 
@@ -202,9 +204,9 @@ char *silc_pkcs_get_supported(void)
 
 /* Returns the length of the key */
 
-uint32 silc_pkcs_get_key_len(SilcPKCS self)
+uint32 silc_pkcs_get_key_len(SilcPKCS pkcs)
 {
-  return self->key_len;
+  return pkcs->key_len;
 }
 
 /* Returns SILC style public key */
@@ -721,6 +723,25 @@ int silc_pkcs_public_key_decode(unsigned char *data, uint32 data_len,
   return FALSE;
 }
 
+/* Compares two public keys and returns TRUE if they are same key, and
+   FALSE if they are not same. */
+
+bool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2)
+{
+  if (key1 == key2)
+    return TRUE;
+
+  if (key1->len == key2->len &&
+      key1->name && key2->name && key1->identifier && key2->identifier &&
+      !strcmp(key1->name, key2->name) &&
+      !strcmp(key1->identifier, key2->identifier) &&
+      !memcmp(key1->pk, key2->pk, key1->pk_len) &&
+      key1->pk_len == key2->pk_len)
+    return TRUE;
+
+  return FALSE;
+}
+
 /* Encodes SILC private key from SilcPrivateKey. Returns the encoded data. */
 
 unsigned char *
@@ -1018,6 +1039,10 @@ int silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
       break;
     case SILC_PKCS_FILE_PEM:
       data = silc_decode_pem(data, len, &len);
+      memset(old, 0, data_len);
+      silc_free(old);
+      old = data; 
+      data_len = len;
       break;
     }