Merge branch 'topic/mm-fixes' of git://208.110.73.182/silc into silc.1.1.branch
[silc.git] / lib / silccrypt / silcpkcs.h
index f0dfca17a306080053fddd768c506b06a1f742b3..0c746bef062b1c0935d05094277758cd2a96bbf1 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2006 Pekka Riikonen
+  Copyright (C) 1997 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -42,8 +42,7 @@ typedef struct SilcPKCSObjectStruct SilcPKCSObject;
  *
  * DESCRIPTION
  *
- *    Public key cryptosystem types.  These are defined by the SILC
- *    Key Exchange protocol.
+ *    Supported public key cryptosystem types.
  *
  * SOURCE
  */
@@ -71,7 +70,7 @@ typedef enum {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcPublicKeyStruct {
   const SilcPKCSObject *pkcs;  /* PKCS */
   void *public_key;            /* PKCS specific public key */
 } *SilcPublicKey;
@@ -89,7 +88,7 @@ typedef struct {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcPrivateKeyStruct {
   const SilcPKCSObject *pkcs;  /* PKCS */
   void *private_key;           /* PKCS specific private key */
 } *SilcPrivateKey;
@@ -129,10 +128,10 @@ typedef struct {
                           void **ret_public_key,
                           void **ret_private_key);
 
-  /* Public key routines */
-  SilcBool (*import_public_key)(unsigned char *key,
-                               SilcUInt32 key_len,
-                               void **ret_public_key);
+  /* Public key routines. */
+  int (*import_public_key)(unsigned char *key,
+                          SilcUInt32 key_len,
+                          void **ret_public_key);
   unsigned char *(*export_public_key)(void *public_key,
                                      SilcUInt32 *ret_len);
   SilcUInt32 (*public_key_bitlen)(void *public_key);
@@ -141,9 +140,9 @@ typedef struct {
   void (*public_key_free)(void *public_key);
 
   /* Private key routines */
-  SilcBool (*import_private_key)(unsigned char *key,
-                                SilcUInt32 key_len,
-                                void **ret_private_key);
+  int (*import_private_key)(unsigned char *key,
+                           SilcUInt32 key_len,
+                           void **ret_private_key);
   unsigned char *(*export_private_key)(void *private_key,
                                       SilcUInt32 *ret_len);
   SilcUInt32 (*private_key_bitlen)(void *public_key);
@@ -155,7 +154,8 @@ typedef struct {
                      SilcUInt32 src_len,
                      unsigned char *dst,
                      SilcUInt32 dst_size,
-                     SilcUInt32 *ret_dst_len);
+                     SilcUInt32 *ret_dst_len,
+                     SilcRng rng);
   SilcBool (*decrypt)(void *private_key,
                      unsigned char *src,
                      SilcUInt32 src_len,
@@ -170,6 +170,7 @@ typedef struct {
                   unsigned char *signature,
                   SilcUInt32 signature_size,
                   SilcUInt32 *ret_signature_len,
+                  SilcBool compute_hash,
                   SilcHash hash);
   SilcBool (*verify)(void *public_key,
                     unsigned char *signature,
@@ -195,10 +196,11 @@ struct SilcPKCSObjectStruct {
                                     SilcPKCSFileEncoding encoding,
                                     void **ret_public_key);
 
-  /* Imports from public key binary data */
-  SilcBool (*import_public_key)(unsigned char *key,
-                               SilcUInt32 key_len,
-                               void **ret_public_key);
+  /* Imports from public key binary data.  Returns the amount of bytes
+     imported from `key' or 0 on error. */
+  int (*import_public_key)(unsigned char *key,
+                          SilcUInt32 key_len,
+                          void **ret_public_key);
 
   /* Exports public key to file */
   unsigned char *(*export_public_key_file)(void *public_key,
@@ -231,10 +233,11 @@ struct SilcPKCSObjectStruct {
                                      SilcPKCSFileEncoding encoding,
                                      void **ret_private_key);
 
-  /* Imports from private key binary data */
-  SilcBool (*import_private_key)(unsigned char *key,
-                                SilcUInt32 key_len,
-                                void **ret_private_key);
+  /* Imports from private key binary data.  Returns the amount of bytes
+     imported from `key' or 0 on error. */
+  int (*import_private_key)(unsigned char *key,
+                           SilcUInt32 key_len,
+                           void **ret_private_key);
 
   /* Exports private key to file */
   unsigned char *(*export_private_key_file)(void *private_key,
@@ -260,7 +263,8 @@ struct SilcPKCSObjectStruct {
                      SilcUInt32 src_len,
                      unsigned char *dst,
                      SilcUInt32 dst_size,
-                     SilcUInt32 *ret_dst_len);
+                     SilcUInt32 *ret_dst_len,
+                     SilcRng rng);
   SilcBool (*decrypt)(void *private_key,
                      unsigned char *src,
                      SilcUInt32 src_len,
@@ -275,6 +279,7 @@ struct SilcPKCSObjectStruct {
                   unsigned char *signature,
                   SilcUInt32 signature_size,
                   SilcUInt32 *ret_signature_len,
+                  SilcBool compute_hash,
                   SilcHash hash);
   SilcBool (*verify)(void *public_key,
                     unsigned char *signature,
@@ -284,8 +289,8 @@ struct SilcPKCSObjectStruct {
                     SilcHash hash);
 };
 
-/* Marks for all PKCS in silc. This can be used in silc_pkcs_unregister
-   to unregister all PKCS at once. */
+/* Marks for all PKCS in. This can be used in silc_pkcs_unregister to
+   unregister all PKCS at once. */
 #define SILC_ALL_PKCS ((SilcPKCSObject *)1)
 #define SILC_ALL_PKCS_ALG ((SilcPKCSAlgorithm *)1)
 
@@ -656,7 +661,7 @@ void silc_pkcs_private_key_free(SilcPrivateKey private_key);
 SilcBool silc_pkcs_encrypt(SilcPublicKey public_key,
                           unsigned char *src, SilcUInt32 src_len,
                           unsigned char *dst, SilcUInt32 dst_size,
-                          SilcUInt32 *dst_len);
+                          SilcUInt32 *dst_len, SilcRng rng);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
  *
@@ -684,18 +689,21 @@ SilcBool silc_pkcs_decrypt(SilcPrivateKey private_key,
  *    SilcBool silc_pkcs_sign(SilcPrivateKey private_key,
  *                            unsigned char *src, SilcUInt32 src_len,
  *                            unsigned char *dst, SilcUInt32 dst_size,
- *                            SilcUInt32 *dst_len, SilcHash hash);
+ *                            SilcUInt32 *dst_len, SilcBool compute_hash,
+ *                            SilcHash hash);
  *
  * DESCRIPTION
  *
  *    Generates signature with the private key.  Returns FALSE on error.
- *    If `hash' is non-NULL the `src' will be hashed before signing.
+ *    If `compute_hash' is TRUE the `hash' will be used to compute a
+ *    digest over the `src'.  The `hash' must always be valid.
  *
  ***/
 SilcBool silc_pkcs_sign(SilcPrivateKey private_key,
                        unsigned char *src, SilcUInt32 src_len,
                        unsigned char *dst, SilcUInt32 dst_size,
-                       SilcUInt32 *dst_len, SilcHash hash);
+                       SilcUInt32 *dst_len, SilcBool compute_hash,
+                       SilcHash hash);
 
 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
  *