Protocol version 1.2 integrations
[silc.git] / lib / silccrypt / silcpkcs.h
index 43d602aafc6ec8b6913728106ba9d60df90dfe26..d9497309729b4b37112b365dd55163732d74dc4c 100644 (file)
@@ -92,6 +92,7 @@ typedef struct SilcPKCSObjectStruct {
  * SOURCE
  */
 typedef struct {
+  SilcUInt16 pk_type;          /* Public key type (SilcSKEPKType) */
   SilcUInt32 len;
   char *name;
   char *identifier;
@@ -399,7 +400,8 @@ const char *silc_pkcs_get_name(SilcPKCS pkcs);
  *
  * DESCRIPTION
  *
- *    Returns SILC style public key.
+ *    Returns SILC style public key.  The caller must free the returned
+ *    data.
  *
  ***/
 unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
@@ -413,7 +415,8 @@ unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
  *
  * DESCRIPTION
  *
- *    Returns SILC style private key.
+ *    Returns SILC style private key.  The caller must free the returned
+ *    data and SHOULD zero the memory area before freeing.
  *
  ***/
 unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
@@ -732,8 +735,9 @@ silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
  *
  * SYNOPSIS
  *
- *    bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
- *                                    SilcPublicKey *public_key);
+ *    bool silc_pkcs_public_key_decode(unsigned char *data,
+ *                                     SilcUInt32 data_len,
+ *                                     SilcPublicKey *public_key);
  *
  * DESCRIPTION
  *
@@ -744,6 +748,41 @@ silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
 bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
                                 SilcPublicKey *public_key);
 
+/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
+ *
+ * DESCRIPTION
+ *
+ *    Encodes the Public Key Payload from the public key indicated by
+ *    `public_key' of type of `pk_type'.  The type is SilcSKEPKType.
+ *    Returns the encoded payload buffer.
+ *
+ ***/
+SilcBuffer silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
+
+/****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
+ *
+ * SYNOPSIS
+ *
+ *    bool
+ *    silc_pkcs_public_key_payload_decode(unsigned char *data,
+ *                                        SilcUInt32 data_len,
+ *                                        SilcPublicKey *public_key);
+ *
+ * DESCRIPTION
+ *
+ *    Decodes Public Key Payload from `data' of `data_len' bytes in length
+ *    data buffer into `public_key' pointer. Returns FALSE if the payload
+ *    cannot be decoded.
+ *
+ ***/
+bool silc_pkcs_public_key_payload_decode(unsigned char *data,
+                                        SilcUInt32 data_len,
+                                        SilcPublicKey *public_key);
+
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_compare
  *
  * SYNOPSIS
@@ -848,7 +887,8 @@ bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
  *
  * DESCRIPTION
  *
- *    Saves public key into file. Returns FALSE on error.
+ *    Saves public key into file.  The public key is already encoded as
+ *    data when calling this function.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
@@ -860,38 +900,23 @@ bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
  * SYNOPSIS
  *
  *    bool silc_pkcs_save_private_key(char *filename,
- *                                   SilcPrivateKey private_key,
- *                                   unsigned char *passphrase,
- *                                   SilcUInt32 encoding);
+ *                                   SilcPrivateKey private_key,
+ *                                    unsigned char *passphrase,
+ *                                    SilcUInt32 passphrase_len,
+ *                                    SilcUInt32 encoding);
  *
  * DESCRIPTION
  *
- *    Saves private key into file. Returns FALSE on error.
+ *    Saves private key into file.  The private key is encrypted into
+ *    the file with the `passphrase' as a key.  The encryption algorithm
+ *    is AES with 256 bit key in CBC mode.  Returns FALSE on error.
  *
  ***/
 bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key, 
                                unsigned char *passphrase,
+                               SilcUInt32 passphrase_len,
                                SilcUInt32 encoding);
 
-/****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key_data
- *
- * SYNOPSIS
- *
- *    bool silc_pkcs_save_private_key_data(char *filename, unsigned char *data,
- *                                        SilcUInt32 data_len,
- *                                        unsigned char *passphrase,
- *                                        SilcUInt32 encoding);
- *
- * DESCRIPTION
- *
- *    Saves private key into file. Returns FALSE on error.
- *
- ***/
-bool silc_pkcs_save_private_key_data(char *filename, unsigned char *data, 
-                                    SilcUInt32 data_len,
-                                    unsigned char *passphrase,
-                                    SilcUInt32 encoding);
-
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
  *
  * SYNOPSIS
@@ -913,16 +938,21 @@ bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
  * SYNOPSIS
  *
  *    bool silc_pkcs_load_private_key(char *filename,
- *                                   SilcPrivateKey *private_key,
- *                                   SilcUInt32 encoding);
+ *                                    SilcPrivateKey *private_key,
+ *                                    unsigned char *passphrase,
+ *                                    SilcUInt32 passphrase_len,
+ *                                    SilcUInt32 encoding);
  *
  * DESCRIPTION
  *
  *    Load private key from file and allocates new private key. Returns TRUE
- *    if loading was successful.
+ *    if loading was successful. The `passphrase' is used as decryption
+ *    key of the private key file.
  *
  ***/
 bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
+                               unsigned char *passphrase,
+                               SilcUInt32 passphrase_len,
                                SilcUInt32 encoding);
 
 #endif /* SILCPKCS_H */