2 * @file rsa_public_key.h
4 * @brief Interface of rsa_public_key_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #ifndef RSA_PUBLIC_KEY_H_
24 #define RSA_PUBLIC_KEY_H_
29 #include <definitions.h>
32 typedef struct rsa_public_key_t rsa_public_key_t
;
35 * @brief RSA public key with associated functions.
37 * Currently only supports signature verification using
38 * the EMSA encoding (see PKCS1)
41 * - rsa_public_key_create_from_chunk()
42 * - rsa_public_key_create_from_file()
43 * - rsa_private_key_t.get_public_key()
45 * @see rsa_private_key_t
47 * @todo Implement getkey() and savekey()
51 struct rsa_public_key_t
{
54 * @brief Verify a EMSA-PKCS1 encodined signature.
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.
60 * @param this rsa_public_key to use
61 * @param data data to sign
62 * @param signature signature to verify
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
70 status_t (*verify_emsa_pkcs1_signature
) (rsa_public_key_t
*this, chunk_t data
, chunk_t signature
);
73 * @brief Gets the key.
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
80 * @param this calling object
81 * @param key key (in a propriarity format)
84 * - INVALID_STATE, if key not set
86 status_t (*get_key
) (rsa_public_key_t
*this, chunk_t
*key
);
89 * @brief Saves a key to a file.
93 * @param this calling object
94 * @param file file to which the key should be written.
95 * @return NOT_SUPPORTED
97 status_t (*save_key
) (rsa_public_key_t
*this, char *file
);
100 * @brief Get the modulus of the key.
102 * @param this calling object
103 * @return modulus (n) of the key
105 mpz_t
*(*get_modulus
) (rsa_public_key_t
*this);
108 * @brief Clone the public key.
110 * @param this public key to clone
111 * @return clone of this
113 rsa_public_key_t
*(*clone
) (rsa_public_key_t
*this);
116 * @brief Destroys the public key.
118 * @param this public key to destroy
120 void (*destroy
) (rsa_public_key_t
*this);
124 * @brief Load an RSA public key from a chunk.
126 * Load a key from a chunk, encoded in the more frequently
127 * used PublicKeyInfo struct (ASN1 DER encoded).
129 * @param chunk chunk containing the DER encoded key
130 * @return loaded rsa_public_key_t, or NULL
132 * @todo Check OID in PublicKeyInfo
136 rsa_public_key_t
*rsa_public_key_create_from_chunk(chunk_t chunk
);
139 * @brief Load an RSA public key from a file.
141 * Load a key from a file, which is either in binary
142 * format (DER), or in PEM format.
144 * @param filename filename which holds the key
145 * @return loaded rsa_public_key_t, or NULL
147 * @todo Implement PEM file loading
151 rsa_public_key_t
*rsa_public_key_create_from_file(char *filename
);
153 #endif /*RSA_PUBLIC_KEY_H_*/