2 * @file rsa_public_key.h
4 * @brief Interface 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()
43 * @see rsa_private_key_t
47 struct rsa_public_key_t
{
50 * @bief Verify a EMSA-PKCS1 encodined signature.
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.
56 * @param this rsa_private_key to use
57 * @param data data to sign
58 * @param signature signature to verify
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
66 status_t (*verify_emsa_pkcs1_signature
) (rsa_public_key_t
*this, chunk_t data
, chunk_t signature
);
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
76 * @param this calling object
77 * @param key key (in a propriarity format)
78 * @return currently SUCCESS in any case
80 status_t (*set_key
) (rsa_public_key_t
*this, chunk_t key
);
83 * @brief Gets the key.
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
90 * @param this calling object
91 * @param key key (in a propriarity format)
94 * - INVALID_STATE, if key not set
96 status_t (*get_key
) (rsa_public_key_t
*this, chunk_t
*key
);
99 * @brief Loads a key from a file.
103 * @param this calling object
104 * @param file file from which key should be read
105 * @return NOT_SUPPORTED
107 status_t (*load_key
) (rsa_public_key_t
*this, char *file
);
110 * @brief Saves a key to a file.
114 * @param this calling object
115 * @param file file to which the key should be written.
116 * @return NOT_SUPPORTED
118 status_t (*save_key
) (rsa_public_key_t
*this, char *file
);
121 * @brief Destroys the public key.
123 * @param this public key to destroy
125 void (*destroy
) (rsa_public_key_t
*this);
129 * @brief Create a public key without any key inside.
131 * @return created rsa_public_key_t.
135 rsa_public_key_t
*rsa_public_key_create();
137 #endif /*RSA_PUBLIC_KEY_H_*/