- comments added
[strongswan.git] / Source / charon / transforms / rsa / rsa_public_key.h
1 /**
2 * @file rsa_public_key.h
3 *
4 * @brief Interface rsa_public_key_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef RSA_PUBLIC_KEY_H_
24 #define RSA_PUBLIC_KEY_H_
25
26 #include <gmp.h>
27
28 #include <types.h>
29 #include <definitions.h>
30
31
32 typedef struct rsa_public_key_t rsa_public_key_t;
33
34 /**
35 * @brief RSA public key with associated functions.
36 *
37 * Currently only supports signature verification using
38 * the EMSA encoding (see PKCS1)
39 *
40 * @b Constructors:
41 * - rsa_public_key_create()
42 *
43 * @see rsa_private_key_t
44 *
45 * @ingroup rsa
46 */
47 struct rsa_public_key_t {
48
49 /**
50 * @bief Verify a EMSA-PKCS1 encodined signature.
51 *
52 * Processes the supplied signature with the RSAVP1 function,
53 * selects the hash algorithm form the resultign ASN1-OID and
54 * verifies the hash against the supplied data.
55 *
56 * @param this rsa_private_key to use
57 * @param data data to sign
58 * @param signature signature to verify
59 * @return
60 * - SUCCESS, if signature ok
61 * - INVALID_STATE, if key not set
62 * - NOT_SUPPORTED, if hash algorithm not supported
63 * - INVALID_ARG, if signature is not a signature
64 * - FAILED if signature invalid or unable to verify
65 */
66 status_t (*verify_emsa_pkcs1_signature) (rsa_public_key_t *this, chunk_t data, chunk_t signature);
67
68 /**
69 * @brief Set the key.
70 *
71 * Currently uses a proprietary format which is only inteded
72 * for testing. This should be replaced with a proper
73 * ASN1 encoded key format, when charon gets the ASN1
74 * capabilities.
75 *
76 * @param this calling object
77 * @param key key (in a propriarity format)
78 * @return currently SUCCESS in any case
79 */
80 status_t (*set_key) (rsa_public_key_t *this, chunk_t key);
81
82 /**
83 * @brief Gets the key.
84 *
85 * Currently uses a proprietary format which is only inteded
86 * for testing. This should be replaced with a proper
87 * ASN1 encoded key format, when charon gets the ASN1
88 * capabilities.
89 *
90 * @param this calling object
91 * @param key key (in a propriarity format)
92 * @return
93 * - SUCCESS
94 * - INVALID_STATE, if key not set
95 */
96 status_t (*get_key) (rsa_public_key_t *this, chunk_t *key);
97
98 /**
99 * @brief Loads a key from a file.
100 *
101 * Not implemented!
102 *
103 * @param this calling object
104 * @param file file from which key should be read
105 * @return NOT_SUPPORTED
106 */
107 status_t (*load_key) (rsa_public_key_t *this, char *file);
108
109 /**
110 * @brief Saves a key to a file.
111 *
112 * Not implemented!
113 *
114 * @param this calling object
115 * @param file file to which the key should be written.
116 * @return NOT_SUPPORTED
117 */
118 status_t (*save_key) (rsa_public_key_t *this, char *file);
119
120 /**
121 * @brief Destroys the public key.
122 *
123 * @param this public key to destroy
124 */
125 void (*destroy) (rsa_public_key_t *this);
126 };
127
128 /**
129 * @brief Create a public key without any key inside.
130 *
131 * @return created rsa_public_key_t.
132 *
133 * @ingroup rsa
134 */
135 rsa_public_key_t *rsa_public_key_create();
136
137 #endif /*RSA_PUBLIC_KEY_H_*/