Added SILC Thread Queue API
[silc.git] / lib / silccrypt / silcpkcs1.h
1 /*
2
3   silcpkcs1.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 - 2005 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 /****h* silccrypt/SILC PKCS1 Interface
21  *
22  * DESCRIPTION
23  *
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
28  * decryption.
29  *
30  ***/
31
32 #ifndef SILCPKCS1_H
33 #define SILCPKCS1_H
34
35 /****d* silccrypt/SilcPKCS1API/SilcPkcs1BlockType
36  *
37  * NAME
38  *
39  *    typedef enum { ... } SilcPkcs1BlockType
40  *
41  * DESCRIPTION
42  *
43  *    Defines the PKCS#1 block types that define how the blcok is encoded
44  *    for different RSA operations.
45  *
46  * SOURCE
47  */
48 typedef enum {
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 */
52 } SilcPkcs1BlockType;
53 /***/
54
55 /****f* silccrypt/SilcPKCS1API/silc_pkcs1_encode
56  *
57  * SYNOPSIS
58  *
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,
64  *                               SilcRng rng);
65  *
66  * DESCRIPTION
67  *
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.
78  *
79  ***/
80 SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
81                            const unsigned char *data,
82                            SilcUInt32 data_len,
83                            unsigned char *dest_data,
84                            SilcUInt32 dest_data_size,
85                            SilcRng rng);
86
87 /****f* silccrypt/SilcPKCS1API/silc_pkcs1_decode
88  *
89  * SYNOPSIS
90  *
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);
97  *
98  * DESCRIPTION
99  *
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'.
106  *
107  ***/
108 SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
109                            const unsigned char *data,
110                            SilcUInt32 data_len,
111                            unsigned char *dest_data,
112                            SilcUInt32 dest_data_size,
113                            SilcUInt32 *dest_len);
114
115 #endif /* SILCPKCS1_H */