2 * @file rsa_public_key.h
4 * @brief Interface of rsa_public_key_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
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>.
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
26 #ifndef RSA_PUBLIC_KEY_H_
27 #define RSA_PUBLIC_KEY_H_
29 typedef struct rsa_public_key_t rsa_public_key_t
;
34 #include <crypto/hashers/hasher.h>
37 * @brief RSA public key with associated functions.
39 * Currently only supports signature verification using
40 * the EMSA encoding (see PKCS1)
43 * - rsa_public_key_create_from_chunk()
44 * - rsa_public_key_create_from_file()
45 * - rsa_private_key_t.get_public_key()
47 * @see rsa_private_key_t
49 * @todo Implement getkey() and savekey()
53 struct rsa_public_key_t
{
56 * @brief Verify a EMSA-PKCS1 encodined signature.
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.
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
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
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
);
78 * @brief Get the modulus of the key.
80 * @param this calling object
81 * @return modulus (n) of the key
83 mpz_t
*(*get_modulus
) (const rsa_public_key_t
*this);
86 * @brief Get the size of the modulus in bytes.
88 * @param this calling object
89 * @return size of the modulus (n) in bytes
91 size_t (*get_keysize
) (const rsa_public_key_t
*this);
94 * @brief Get the DER encoded publicKeyInfo object.
96 * @param this calling object
97 * @return DER encoded publicKeyInfo object
99 chunk_t (*get_publicKeyInfo
) (const rsa_public_key_t
*this);
102 * @brief Get the keyid formed as the SHA-1 hash of a publicKeyInfo object.
104 * @param this calling object
105 * @return keyid in the form of a SHA-1 hash
107 chunk_t (*get_keyid
) (const rsa_public_key_t
*this);
110 * @brief Clone the public key.
112 * @param this public key to clone
113 * @return clone of this
115 rsa_public_key_t
*(*clone
) (const rsa_public_key_t
*this);
118 * @brief Destroys the public key.
120 * @param this public key to destroy
122 void (*destroy
) (rsa_public_key_t
*this);
126 * @brief Load an RSA public key from a chunk.
128 * Load a key from a chunk, encoded in the more frequently
129 * used publicKeyInfo object (ASN1 DER encoded).
131 * @param chunk chunk containing the DER encoded key
132 * @return loaded rsa_public_key_t, or NULL
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
149 rsa_public_key_t
*rsa_public_key_create_from_file(char *filename
);
151 #endif /*RSA_PUBLIC_KEY_H_*/