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