Added encryptio boolena indicator to silc_cipher_set_key.
[silc.git] / lib / silccrypt / silcpk.c
index 0de35d6a57f7cb78425a6c5781bbc5ef1db259e6..7e7c234e72681cd6355c0e6b69aec9e51cf37215 100644 (file)
@@ -370,6 +370,10 @@ SilcBool silc_pkcs_silc_import_public_key(unsigned char *key,
   if (ret == -1)
     goto err;
 
+  /* Backwards compatibility */
+  if (totlen == key_len)
+    totlen -= 4;
+
   if (totlen + 4 != key_len)
     goto err;
 
@@ -816,7 +820,7 @@ SilcBool silc_pkcs_silc_import_private_key_file(unsigned char *filedata,
   /* Check file magic */
   SILC_GET32_MSB(magic, filedata);
   if (magic != SILC_PKCS_PRIVATE_KEY_MAGIC) {
-    SILC_LOG_ERROR(("Private key does not have correct magic"));
+    SILC_LOG_DEBUG(("Private key does not have correct magic"));
     return FALSE;
   }
 
@@ -859,7 +863,7 @@ SilcBool silc_pkcs_silc_import_private_key_file(unsigned char *filedata,
   silc_hash_final(sha1, keymat + 16);
 
   /* Set the key to the cipher */
-  silc_cipher_set_key(aes, keymat, 256);
+  silc_cipher_set_key(aes, keymat, 256, FALSE);
 
   /* First, verify the MAC of the private key data */
   mac_len = silc_hmac_len(sha1hmac);
@@ -971,7 +975,6 @@ SilcBool silc_pkcs_silc_import_private_key(unsigned char *key,
     /* Parse the RSA SILC private key */
     SilcBufferStruct k;
     SilcMPInt n, e, d, dp, dq, qp, p, q;
-    SilcMPInt version;
     unsigned char *tmp;
     SilcUInt32 len, ver;
 
@@ -1147,12 +1150,10 @@ SilcBool silc_pkcs_silc_import_private_key(unsigned char *key,
     }
 
     /* Encode to PKCS #1 format */
-    silc_mp_init(&version);
-    silc_mp_set_ui(&version, 0);
     memset(&alg_key, 0, sizeof(alg_key));
     if (!silc_asn1_encode(asn1, &alg_key,
                          SILC_ASN1_SEQUENCE,
-                           SILC_ASN1_INT(&version),
+                           SILC_ASN1_SHORT_INT(0),
                            SILC_ASN1_INT(&n),
                            SILC_ASN1_INT(&e),
                            SILC_ASN1_INT(&d),
@@ -1164,7 +1165,6 @@ SilcBool silc_pkcs_silc_import_private_key(unsigned char *key,
                          SILC_ASN1_END, SILC_ASN1_END))
       goto err;
 
-    silc_mp_uninit(&version);
     silc_mp_uninit(&n);
     silc_mp_uninit(&e);
     silc_mp_uninit(&e);
@@ -1275,7 +1275,7 @@ silc_pkcs_silc_export_private_key_file(void *private_key,
   silc_hash_final(sha1, keymat + 16);
 
   /* Set the key to the cipher */
-  silc_cipher_set_key(aes, keymat, 256);
+  silc_cipher_set_key(aes, keymat, 256, TRUE);
 
   /* Encode the buffer to be encrypted.  Add padding to it too, at least
      block size of the cipher. */