implemented sha2_hasher which supports SHA-256, SHA-384 and SHA-512
[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 #include <types.h>
28 #include <definitions.h>
29
30 typedef enum integrity_algorithm_t integrity_algorithm_t;
31
32 /**
33 * @brief Integrity algorithm, as in IKEv2 RFC 3.3.2.
34 *
35 * Currently only the following algorithms are implemented and therefore supported:
36 * - AUTH_HMAC_MD5_96
37 * - AUTH_HMAC_SHA1_96
38 *
39 * @ingroup signers
40 */
41 enum integrity_algorithm_t {
42 AUTH_UNDEFINED = 1024,
43 /** Implemented via hmac_signer_t */
44 AUTH_HMAC_MD5_96 = 1,
45 /** Implemented via hmac_signer_t */
46 AUTH_HMAC_SHA1_96 = 2,
47 AUTH_DES_MAC = 3,
48 AUTH_KPDK_MD5 = 4,
49 AUTH_AES_XCBC_96 = 5
50 };
51
52 /**
53 * String mappings for integrity_algorithm_t.
54 */
55 extern mapping_t integrity_algorithm_m[];
56
57
58 typedef struct signer_t signer_t;
59
60 /**
61 * @brief Generig interface for a symmetric signature algorithm.
62 *
63 * @b Constructors:
64 * - signer_create()
65 * - hmac_signer_create()
66 *
67 * @todo Implement more integrity algorithms
68 *
69 * @ingroup signers
70 */
71 struct signer_t {
72 /**
73 * @brief Generate a signature.
74 *
75 * @param this calling object
76 * @param data a chunk containing the data to sign
77 * @param[out] buffer pointer where the signature will be written
78 */
79 void (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
80
81 /**
82 * @brief Generate a signature and allocate space for it.
83 *
84 * @param this calling object
85 * @param data a chunk containing the data to sign
86 * @param[out] chunk chunk which will hold the allocated signature
87 */
88 void (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
89
90 /**
91 * @brief Verify a signature.
92 *
93 * @param this calling object
94 * @param data a chunk containing the data to verify
95 * @param signature a chunk containing the signature
96 * @return TRUE, if signature is valid, FALSE otherwise
97 */
98 bool (*verify_signature) (signer_t *this, chunk_t data, chunk_t signature);
99
100 /**
101 * @brief Get the block size of this signature algorithm.
102 *
103 * @param this calling object
104 * @return block size in bytes
105 */
106 size_t (*get_block_size) (signer_t *this);
107
108 /**
109 * @brief Get the key size of the signature algorithm.
110 *
111 * @param this calling object
112 * @return key size in bytes
113 */
114 size_t (*get_key_size) (signer_t *this);
115
116 /**
117 * @brief Set the key for this object.
118 *
119 * @param this calling object
120 * @param key key to set
121 */
122 void (*set_key) (signer_t *this, chunk_t key);
123
124 /**
125 * @brief Destroys a signer_t object.
126 *
127 * @param this calling object
128 */
129 void (*destroy) (signer_t *this);
130 };
131
132 /**
133 * @brief Creates a new signer_t object.
134 *
135 * @param integrity_algorithm Algorithm to use for signing and verifying.
136 * @return
137 * - signer_t object
138 * - NULL if signer not supported
139 *
140 * @ingroup signers
141 */
142 signer_t *signer_create(integrity_algorithm_t integrity_algorithm);
143
144 #endif /*SIGNER_H_*/