removing svn keyword $Id$ from all files
[strongswan.git] / src / libstrongswan / credentials / keys / public_key.h
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup public_key public_key
18 * @{ @ingroup keys
19 */
20
21 #ifndef PUBLIC_KEY_H_
22 #define PUBLIC_KEY_H_
23
24 typedef struct public_key_t public_key_t;
25 typedef enum key_type_t key_type_t;
26 typedef enum key_id_type_t key_id_type_t;
27 typedef enum signature_scheme_t signature_scheme_t;
28
29 #include <library.h>
30 #include <utils/identification.h>
31
32 /**
33 * Type of a key pair, the used crypto system
34 */
35 enum key_type_t {
36 /** key type wildcard */
37 KEY_ANY,
38 /** RSA crypto system as in PKCS#1 */
39 KEY_RSA,
40 /** ECDSA as in ANSI X9.62 */
41 KEY_ECDSA,
42 /** DSS, ElGamal, ... */
43 };
44
45 /**
46 * Enum names for key_type_t
47 */
48 extern enum_name_t *key_type_names;
49
50 /**
51 * Signature scheme for signature creation
52 *
53 * EMSA-PKCS1 signatures are from the PKCS#1 standard. They include
54 * the ASN1-OID of the used hash algorithm.
55 */
56 enum signature_scheme_t {
57 /** default scheme of that underlying crypto system */
58 SIGN_DEFAULT,
59 /** EMSA-PKCS1 with MD5 */
60 SIGN_RSA_EMSA_PKCS1_MD5,
61 /** EMSA-PKCS1 signature as in PKCS#1 standard using SHA1 as hash. */
62 SIGN_RSA_EMSA_PKCS1_SHA1,
63 /** EMSA-PKCS1 signature as in PKCS#1 standard using SHA256 as hash. */
64 SIGN_RSA_EMSA_PKCS1_SHA256,
65 /** EMSA-PKCS1 signature as in PKCS#1 standard using SHA384 as hash. */
66 SIGN_RSA_EMSA_PKCS1_SHA384,
67 /** EMSA-PKCS1 signature as in PKCS#1 standard using SHA512 as hash. */
68 SIGN_RSA_EMSA_PKCS1_SHA512,
69 /** ECDSA using SHA-1 as hash. */
70 SIGN_ECDSA_WITH_SHA1,
71 /** ECDSA with SHA-256 on the P-256 curve as in RFC 4754 */
72 SIGN_ECDSA_256,
73 /** ECDSA with SHA-384 on the P-384 curve as in RFC 4754 */
74 SIGN_ECDSA_384,
75 /** ECDSA with SHA-512 on the P-521 curve as in RFC 4754 */
76 SIGN_ECDSA_521,
77 };
78
79 /**
80 * Enum names for signature_scheme_t
81 */
82 extern enum_name_t *signature_scheme_names;
83
84 /**
85 * Abstract interface of a public key.
86 */
87 struct public_key_t {
88
89 /**
90 * Get the key type.
91 *
92 * @return type of the key
93 */
94 key_type_t (*get_type)(public_key_t *this);
95
96 /**
97 * Verifies a signature against a chunk of data.
98 *
99 * @param scheme signature scheme to use for verification, may be default
100 * @param data data to check signature against
101 * @param signature signature to check
102 * @return TRUE if signature matches
103 */
104 bool (*verify)(public_key_t *this, signature_scheme_t scheme,
105 chunk_t data, chunk_t signature);
106
107 /**
108 * Encrypt a chunk of data.
109 *
110 * @param crypto chunk containing plaintext data
111 * @param plain where to allocate encrypted data
112 * @return TRUE if data successfully encrypted
113 */
114 bool (*encrypt)(public_key_t *this, chunk_t crypto, chunk_t *plain);
115
116 /**
117 * Get the strength of the key in bytes.
118 *
119 * @return strength of the key in bytes
120 */
121 size_t (*get_keysize) (public_key_t *this);
122
123 /**
124 * Get a unique key identifier, such as a hash over the key.
125 *
126 * @param type type of the key ID to get
127 * @return unique ID of the key as identification_t, or NULL
128 */
129 identification_t* (*get_id) (public_key_t *this, id_type_t type);
130
131 /**
132 * Get an encoded form of the key.
133 *
134 * @todo Do we need a encoding type specification?
135 *
136 * @return allocated chunk containing encoded key
137 */
138 chunk_t (*get_encoding)(public_key_t *this);
139
140 /**
141 * Increase the refcount of the key.
142 *
143 * @return this with an increased refcount
144 */
145 public_key_t* (*get_ref)(public_key_t *this);
146
147 /**
148 * Destroy a public_key instance.
149 */
150 void (*destroy)(public_key_t *this);
151 };
152
153 #endif /** PUBLIC_KEY_H_ @}*/