Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2005 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
*
* DESCRIPTION
*
- * Public key cryptosystem types. These are defined by the SILC
- * Key Exchange protocol.
+ * Supported public key cryptosystem types.
*
* SOURCE
*/
*
* SOURCE
*/
-typedef struct {
+typedef struct SilcPublicKeyStruct {
const SilcPKCSObject *pkcs; /* PKCS */
void *public_key; /* PKCS specific public key */
} *SilcPublicKey;
*
* SOURCE
*/
-typedef struct {
+typedef struct SilcPrivateKeyStruct {
const SilcPKCSObject *pkcs; /* PKCS */
void *private_key; /* PKCS specific private key */
} *SilcPrivateKey;
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);
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);
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,
unsigned char *signature,
SilcUInt32 signature_size,
SilcUInt32 *ret_signature_len,
+ SilcBool compute_hash,
SilcHash hash);
SilcBool (*verify)(void *public_key,
unsigned char *signature,
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,
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,
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,
unsigned char *signature,
SilcUInt32 signature_size,
SilcUInt32 *ret_signature_len,
+ SilcBool compute_hash,
SilcHash hash);
SilcBool (*verify)(void *public_key,
unsigned char *signature,
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)
*
* SYNOPSIS
*
- * const SilcPKCSObject *silc_pkcs_get_pkcs(SilcPublicKey public_key);
+ * const SilcPKCSObject *silc_pkcs_get_pkcs(void *key);
*
* DESCRIPTION
*
- * Returns the PKCS object from `public_key'.
+ * Returns the PKCS object from `key', which may be SilcPublicKey or
+ * SilcPrivateKey pointer.
*
***/
-const SilcPKCSObject *silc_pkcs_get_pkcs(SilcPublicKey public_key);
+const SilcPKCSObject *silc_pkcs_get_pkcs(void *key);
/****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_algorithm
*
* SYNOPSIS
*
- * const SilcPKCSObject *silc_pkcs_get_algorithm(SilcPublicKey public_key);
+ * const SilcPKCSAlgorithm *silc_pkcs_get_algorithm(void *key);
*
* DESCRIPTION
*
- * Returns the PKCS algorithm object from `public_key'.
+ * Returns the PKCS algorithm object from `key', which may be SilcPublicKey
+ * or SilcPrivateKey pointer.
*
***/
-const SilcPKCSAlgorithm *silc_pkcs_get_algorithm(SilcPublicKey public_key);
+const SilcPKCSAlgorithm *silc_pkcs_get_algorithm(void *key);
/****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
*
* SYNOPSIS
*
- * const char *silc_pkcs_get_name(SilcPublicKey public_key)
+ * const char *silc_pkcs_get_name(void *key);
*
* DESCRIPTION
*
- * Returns PKCS algorithm name from the public key.
+ * Returns PKCS algorithm name from the `key', which may be SilcPublicKey
+ * or SilcPrivateKey pointer.
*
***/
-const char *silc_pkcs_get_name(SilcPublicKey public_key);
+const char *silc_pkcs_get_name(void *key);
/****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_type
*
* SYNOPSIS
*
- * SilcPKCSType silc_pkcs_get_type(SilcPublicKey public_key);
+ * SilcPKCSType silc_pkcs_get_type(void *key);
*
* DESCRIPTION
*
- * Returns PKCS type from the public key.
+ * Returns PKCS type from the `key', which may be SilcPublicKey or
+ * SilcPrivateKey pointer.
*
***/
-SilcPKCSType silc_pkcs_get_type(SilcPublicKey public_key);
+SilcPKCSType silc_pkcs_get_type(void *key);
/****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_context
*
*
* DESCRIPTION
*
- * Returns the key length in bits from the public key.
+ * Returns the key length in bits from the private key.
*
***/
SilcUInt32 silc_pkcs_private_key_get_len(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
*
* 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
*