5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2003 - 2008 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/PKCS#1 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
30 * This is a low level interface that usually is not needed or used directly.
37 /****d* silccrypt/SilcPkcs1BlockType
41 * typedef enum { ... } SilcPkcs1BlockType
45 * Defines the PKCS#1 block types that define how the blcok is encoded
46 * for different RSA operations.
51 SILC_PKCS1_BT_PRV0 = 0x00, /* Private key BT 0 */
52 SILC_PKCS1_BT_PRV1 = 0x01, /* Private key BT 1 (use this always) */
53 SILC_PKCS1_BT_PUB = 0x02, /* Public key BT */
57 /****f* silccrypt/silc_pkcs1_encode
61 * SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
62 * const unsigned char *data,
63 * SilcUInt32 data_len,
64 * unsigned char *dest_data,
65 * SilcUInt32 dest_data_size,
70 * Encodes PKCS#1 data block from the `data' according to the block type
71 * indicated by `bt'. When encoding signatures the `bt' must be
72 * SILC_PKCS1_BT_PRV1 and when encoding encryption blocks the `bt' must
73 * be SILC_PKCS1_BT_PUB. The encoded data is copied into the `dest_data'
74 * buffer which is size of `dest_data_size'. If the `dest_data' is not
75 * able to hold the encoded block this returns FALSE. Usually the
76 * `dest_data_size' is set to the RSA key length value as it is the
77 * length of one block. The `rng' should be set when `bt' is set to
78 * SILC_PKCS1_BT_PUB. If `rng' is NULL global RNG is used. This
79 * function returns TRUE on success.
82 SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
83 const unsigned char *data,
85 unsigned char *dest_data,
86 SilcUInt32 dest_data_size,
89 /****f* silccrypt/silc_pkcs1_decode
93 * SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
94 * const unsigned char *data,
95 * SilcUInt32 data_len,
96 * unsigned char *dest_data,
97 * SilcUInt32 dest_data_size,
98 * SilcUInt32 *dest_len);
102 * Decodes the PKCS#1 encoded block according to the block type `bt'.
103 * When verifying signatures the `bt' must be SILC_PKCS1_BT_PRV1 and
104 * when decrypting it must be SILC_PKCS1_BT_PUB. This copies the
105 * decoded data into `dest_data' which is size of `dest_data_size'. If
106 * the deocded block does not fit to `dest_data' this returns FALSE.
107 * Returns the decoded length into `dest_len'.
110 SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
111 const unsigned char *data,
113 unsigned char *dest_data,
114 SilcUInt32 dest_data_size,
115 SilcUInt32 *dest_len);
117 #endif /* SILCPKCS1_H */