added get_publicKeyInfo() method
[strongswan.git] / src / libstrongswan / 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-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 * RCSID $Id$
24 */
25
26 #ifndef RSA_PUBLIC_KEY_H_
27 #define RSA_PUBLIC_KEY_H_
28
29 typedef struct rsa_public_key_t rsa_public_key_t;
30
31 #include <gmp.h>
32
33 #include <library.h>
34 #include <crypto/hashers/hasher.h>
35
36 /**
37 * @brief RSA public key with associated functions.
38 *
39 * Currently only supports signature verification using
40 * the EMSA encoding (see PKCS1)
41 *
42 * @b Constructors:
43 * - rsa_public_key_create_from_chunk()
44 * - rsa_public_key_create_from_file()
45 * - rsa_private_key_t.get_public_key()
46 *
47 * @see rsa_private_key_t
48 *
49 * @todo Implement getkey() and savekey()
50 *
51 * @ingroup rsa
52 */
53 struct rsa_public_key_t {
54
55 /**
56 * @brief Verify a EMSA-PKCS1 encodined signature.
57 *
58 * Processes the supplied signature with the RSAVP1 function,
59 * selects the hash algorithm form the resultign ASN1-OID and
60 * verifies the hash against the supplied data.
61 *
62 * @param this rsa_public_key to use
63 * @param data data to sign
64 # @param algorithm hash algorithm the signature is based on
65 * @param signature signature to verify
66 * @return
67 * - SUCCESS, if signature ok
68 * - INVALID_STATE, if key not set
69 * - NOT_SUPPORTED, if hash algorithm not supported
70 * - INVALID_ARG, if signature is not a signature
71 * - FAILED if signature invalid or unable to verify
72 */
73 status_t (*verify_emsa_pkcs1_signature) (const rsa_public_key_t *this,
74 hash_algorithm_t algorithm,
75 chunk_t data, chunk_t signature);
76
77 /**
78 * @brief Get the modulus of the key.
79 *
80 * @param this calling object
81 * @return modulus (n) of the key
82 */
83 mpz_t *(*get_modulus) (const rsa_public_key_t *this);
84
85 /**
86 * @brief Get the size of the modulus in bytes.
87 *
88 * @param this calling object
89 * @return size of the modulus (n) in bytes
90 */
91 size_t (*get_keysize) (const rsa_public_key_t *this);
92
93 /**
94 * @brief Get the DER encoded publicKeyInfo object.
95 *
96 * @param this calling object
97 * @return DER encoded publicKeyInfo object
98 */
99 chunk_t (*get_publicKeyInfo) (const rsa_public_key_t *this);
100
101 /**
102 * @brief Get the keyid formed as the SHA-1 hash of a publicKeyInfo object.
103 *
104 * @param this calling object
105 * @return keyid in the form of a SHA-1 hash
106 */
107 chunk_t (*get_keyid) (const rsa_public_key_t *this);
108
109 /**
110 * @brief Clone the public key.
111 *
112 * @param this public key to clone
113 * @return clone of this
114 */
115 rsa_public_key_t *(*clone) (const rsa_public_key_t *this);
116
117 /**
118 * @brief Destroys the public key.
119 *
120 * @param this public key to destroy
121 */
122 void (*destroy) (rsa_public_key_t *this);
123 };
124
125 /**
126 * @brief Load an RSA public key from a chunk.
127 *
128 * Load a key from a chunk, encoded in the more frequently
129 * used publicKeyInfo object (ASN1 DER encoded).
130 *
131 * @param chunk chunk containing the DER encoded key
132 * @return loaded rsa_public_key_t, or NULL
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 * @ingroup rsa
148 */
149 rsa_public_key_t *rsa_public_key_create_from_file(char *filename);
150
151 #endif /*RSA_PUBLIC_KEY_H_*/