]> git.ipfire.org Git - people/ms/strongswan.git/blob - Source/lib/crypto/rsa/rsa_public_key.h
- renamed get_block_size of hasher
[people/ms/strongswan.git] / Source / lib / crypto / rsa / rsa_public_key.h
1 /**
2 * @file rsa_public_key.h
3 *
4 * @brief Interface of 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_from_chunk()
42 * - rsa_public_key_create_from_file()
43 * - rsa_private_key_t.get_public_key()
44 *
45 * @see rsa_private_key_t
46 *
47 * @todo Implement getkey() and savekey()
48 *
49 * @ingroup rsa
50 */
51 struct rsa_public_key_t {
52
53 /**
54 * @brief Verify a EMSA-PKCS1 encodined signature.
55 *
56 * Processes the supplied signature with the RSAVP1 function,
57 * selects the hash algorithm form the resultign ASN1-OID and
58 * verifies the hash against the supplied data.
59 *
60 * @param this rsa_public_key to use
61 * @param data data to sign
62 * @param signature signature to verify
63 * @return
64 * - SUCCESS, if signature ok
65 * - INVALID_STATE, if key not set
66 * - NOT_SUPPORTED, if hash algorithm not supported
67 * - INVALID_ARG, if signature is not a signature
68 * - FAILED if signature invalid or unable to verify
69 */
70 status_t (*verify_emsa_pkcs1_signature) (rsa_public_key_t *this, chunk_t data, chunk_t signature);
71
72 /**
73 * @brief Gets the key.
74 *
75 * Currently uses a proprietary format which is only inteded
76 * for testing. This should be replaced with a proper
77 * ASN1 encoded key format, when charon gets the ASN1
78 * capabilities.
79 *
80 * @param this calling object
81 * @param key key (in a propriarity format)
82 * @return
83 * - SUCCESS
84 * - INVALID_STATE, if key not set
85 */
86 status_t (*get_key) (rsa_public_key_t *this, chunk_t *key);
87
88 /**
89 * @brief Saves a key to a file.
90 *
91 * Not implemented!
92 *
93 * @param this calling object
94 * @param file file to which the key should be written.
95 * @return NOT_SUPPORTED
96 */
97 status_t (*save_key) (rsa_public_key_t *this, char *file);
98
99 /**
100 * @brief Get the modulus of the key.
101 *
102 * @param this calling object
103 * @return modulus (n) of the key
104 */
105 mpz_t *(*get_modulus) (rsa_public_key_t *this);
106
107 /**
108 * @brief Clone the public key.
109 *
110 * @param this public key to clone
111 * @return clone of this
112 */
113 rsa_public_key_t *(*clone) (rsa_public_key_t *this);
114
115 /**
116 * @brief Destroys the public key.
117 *
118 * @param this public key to destroy
119 */
120 void (*destroy) (rsa_public_key_t *this);
121 };
122
123 /**
124 * @brief Load an RSA public key from a chunk.
125 *
126 * Load a key from a chunk, encoded in the more frequently
127 * used PublicKeyInfo struct (ASN1 DER encoded).
128 *
129 * @param chunk chunk containing the DER encoded key
130 * @return loaded rsa_public_key_t, or NULL
131 *
132 * @todo Check OID in PublicKeyInfo
133 *
134 * @ingroup rsa
135 */
136 rsa_public_key_t *rsa_public_key_create_from_chunk(chunk_t chunk);
137
138 /**
139 * @brief Load an RSA public key from a file.
140 *
141 * Load a key from a file, which is either in binary
142 * format (DER), or in PEM format.
143 *
144 * @param filename filename which holds the key
145 * @return loaded rsa_public_key_t, or NULL
146 *
147 * @todo Implement PEM file loading
148 *
149 * @ingroup rsa
150 */
151 rsa_public_key_t *rsa_public_key_create_from_file(char *filename);
152
153 #endif /*RSA_PUBLIC_KEY_H_*/