Compilation environment fixes to make make install work correctly.
[crypto.git] / lib / silccrypt / silcpkcs1.h
1 /*
2
3   silcpkcs1.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 - 2008 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/PKCS#1 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  * This is a low level interface that usually is not needed or used directly.
31  *
32  ***/
33
34 #ifndef SILCPKCS1_H
35 #define SILCPKCS1_H
36
37 /****d* silccrypt/SilcPkcs1BlockType
38  *
39  * NAME
40  *
41  *    typedef enum { ... } SilcPkcs1BlockType
42  *
43  * DESCRIPTION
44  *
45  *    Defines the PKCS#1 block types that define how the blcok is encoded
46  *    for different RSA operations.
47  *
48  * SOURCE
49  */
50 typedef enum {
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 */
54 } SilcPkcs1BlockType;
55 /***/
56
57 /****f* silccrypt/silc_pkcs1_encode
58  *
59  * SYNOPSIS
60  *
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,
66  *                               SilcRng rng);
67  *
68  * DESCRIPTION
69  *
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.
80  *
81  ***/
82 SilcBool silc_pkcs1_encode(SilcPkcs1BlockType bt,
83                            const unsigned char *data,
84                            SilcUInt32 data_len,
85                            unsigned char *dest_data,
86                            SilcUInt32 dest_data_size,
87                            SilcRng rng);
88
89 /****f* silccrypt/silc_pkcs1_decode
90  *
91  * SYNOPSIS
92  *
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);
99  *
100  * DESCRIPTION
101  *
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'.
108  *
109  ***/
110 SilcBool silc_pkcs1_decode(SilcPkcs1BlockType bt,
111                            const unsigned char *data,
112                            SilcUInt32 data_len,
113                            unsigned char *dest_data,
114                            SilcUInt32 dest_data_size,
115                            SilcUInt32 *dest_len);
116
117 #endif /* SILCPKCS1_H */