merged EAP framework from branch into trunk
[strongswan.git] / src / libstrongswan / crypto / signers / signer.h
1 /**
2 * @file signer.h
3 *
4 * @brief Interface for signer_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef SIGNER_H_
25 #define SIGNER_H_
26
27 typedef enum integrity_algorithm_t integrity_algorithm_t;
28 typedef struct signer_t signer_t;
29
30 #include <library.h>
31
32 /**
33 * @brief Integrity algorithm, as in IKEv2 RFC 3.3.2.
34 *
35 * Algorithms not specified in IKEv2 are allocated in private use space.
36 *
37 * @ingroup signers
38 */
39 enum integrity_algorithm_t {
40 AUTH_UNDEFINED = 1024,
41 /** Implemented via hmac_signer_t */
42 AUTH_HMAC_MD5_96 = 1,
43 /** Implemented via hmac_signer_t */
44 AUTH_HMAC_SHA1_96 = 2,
45 AUTH_DES_MAC = 3,
46 AUTH_KPDK_MD5 = 4,
47 AUTH_AES_XCBC_96 = 5,
48 /** Implemented via hmac_signer_t */
49 AUTH_HMAC_SHA1_128 = 1025,
50 };
51
52 /**
53 * enum names for integrity_algorithm_t.
54 */
55 extern enum_name_t *integrity_algorithm_names;
56
57 /**
58 * @brief Generig interface for a symmetric signature algorithm.
59 *
60 * @b Constructors:
61 * - signer_create()
62 * - hmac_signer_create()
63 *
64 * @todo Implement more integrity algorithms
65 *
66 * @ingroup signers
67 */
68 struct signer_t {
69 /**
70 * @brief Generate a signature.
71 *
72 * @param this calling object
73 * @param data a chunk containing the data to sign
74 * @param[out] buffer pointer where the signature will be written
75 */
76 void (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
77
78 /**
79 * @brief Generate a signature and allocate space for it.
80 *
81 * @param this calling object
82 * @param data a chunk containing the data to sign
83 * @param[out] chunk chunk which will hold the allocated signature
84 */
85 void (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
86
87 /**
88 * @brief Verify a signature.
89 *
90 * @param this calling object
91 * @param data a chunk containing the data to verify
92 * @param signature a chunk containing the signature
93 * @return TRUE, if signature is valid, FALSE otherwise
94 */
95 bool (*verify_signature) (signer_t *this, chunk_t data, chunk_t signature);
96
97 /**
98 * @brief Get the block size of this signature algorithm.
99 *
100 * @param this calling object
101 * @return block size in bytes
102 */
103 size_t (*get_block_size) (signer_t *this);
104
105 /**
106 * @brief Get the key size of the signature algorithm.
107 *
108 * @param this calling object
109 * @return key size in bytes
110 */
111 size_t (*get_key_size) (signer_t *this);
112
113 /**
114 * @brief Set the key for this object.
115 *
116 * @param this calling object
117 * @param key key to set
118 */
119 void (*set_key) (signer_t *this, chunk_t key);
120
121 /**
122 * @brief Destroys a signer_t object.
123 *
124 * @param this calling object
125 */
126 void (*destroy) (signer_t *this);
127 };
128
129 /**
130 * @brief Creates a new signer_t object.
131 *
132 * @param integrity_algorithm Algorithm to use for signing and verifying.
133 * @return
134 * - signer_t object
135 * - NULL if signer not supported
136 *
137 * @ingroup signers
138 */
139 signer_t *signer_create(integrity_algorithm_t integrity_algorithm);
140
141 #endif /*SIGNER_H_*/