5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2003 - 2005 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silccrypt/SILC PKCS1 Interface
24 * This interface implements the PKCS#1 standard block encoding and decoding
25 * routines. It is used as part of RSA implementation to perform PKCS#1
26 * RSA operations. The routines encode and decode the data for RSA operations
27 * such as digital signatures and their verification, and encryption and
35 /****d* silccrypt/SilcPKCS1API/SilcPkcs1BlockType
39 * typedef enum { ... } SilcPkcs1BlockType
43 * Defines the PKCS#1 block types that define how the blcok is encoded
44 * for different RSA operations.
49 SILC_PKCS1_BT_PRV0 = 0x00, /* Private key BT 0 */
50 SILC_PKCS1_BT_PRV1 = 0x01, /* Private key BT 1 (use this always) */
51 SILC_PKCS1_BT_PUB = 0x02, /* Public key BT */
55 /****f* silccrypt/SilcPKCS1API/silc_pkcs1_encode
59 * SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
60 * const unsigned char *data,
61 * SilcUInt32 data_len,
62 * unsigned char *dest_data,
63 * SilcUInt32 dest_data_size,
68 * Encodes PKCS#1 data block from the `data' according to the block type
69 * indicated by `bt'. When encoding signatures the `bt' must be
70 * SILC_PKCS1_BT_PRV1 and when encoding encryption blocks the `bt' must
71 * be SILC_PKCS1_BT_PUB. The encoded data is copied into the `dest_data'
72 * buffer which is size of `dest_data_size'. If the `dest_data' is not
73 * able to hold the encoded block this returns FALSE. Usually the
74 * `dest_data_size' is set to the RSA key length value as it is the
75 * length of one block. The `rng' should be set when `bt' is set to
76 * SILC_PKCS1_BT_PUB. If `rng' is NULL global RNG is used. This
77 * function returns TRUE on success.
80 SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
81 const unsigned char *data,
83 unsigned char *dest_data,
84 SilcUInt32 dest_data_size,
87 /****f* silccrypt/SilcPKCS1API/silc_pkcs1_decode
91 * SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
92 * const unsigned char *data,
93 * SilcUInt32 data_len,
94 * unsigned char *dest_data,
95 * SilcUInt32 dest_data_size,
96 * SilcUInt32 *dest_len);
100 * Decodes the PKCS#1 encoded block according to the block type `bt'.
101 * When verifying signatures the `bt' must be SILC_PKCS1_BT_PRV1 and
102 * when decrypting it must be SILC_PKCS1_BT_PUB. This copies the
103 * decoded data into `dest_data' which is size of `dest_data_size'. If
104 * the deocded block does not fit to `dest_data' this returns FALSE.
105 * Returns the decoded length into `dest_len'.
108 SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
109 const unsigned char *data,
111 unsigned char *dest_data,
112 SilcUInt32 dest_data_size,
113 SilcUInt32 *dest_len);
115 #endif /* SILCPKCS1_H */