2 * @file rsa_private_key.h
4 * @brief Interface rsa_private_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_PRIVATE_KEY_H_
24 #define RSA_PRIVATE_KEY_H_
27 #include <definitions.h>
29 #include <transforms/rsa/rsa_public_key.h>
30 #include <transforms/hashers/hasher.h>
33 typedef struct rsa_private_key_t rsa_private_key_t
;
36 * @brief RSA private key with associated functions.
38 * Currently only supports signing using EMSA encoding.
40 * @todo Implement proper key set/get load/save
44 * - rsa_private_key_create()
46 * @see rsa_public_key_t
50 struct rsa_private_key_t
{
53 * @bief Build a signature over a chunk using EMSA-PKCS1 encoding.
55 * This signature creates a hash using the specied hash algorithm, concatenates
56 * it with an ASN1-OID of the hash algorithm and runs the RSASP1 function
59 * @param this rsa_private_key to use
60 * @param hash_algorithm hash algorithm to use for hashing
61 * @param data data to sign
62 * @param[out] signature allocated signature
65 * - INVALID_STATE, if key not set
66 * - NOT_SUPPORTED, if hash algorithm not supported
68 status_t (*build_emsa_pkcs1_signature
) (rsa_private_key_t
*this, hash_algorithm_t hash_algorithm
, chunk_t data
, chunk_t
*signature
);
73 * Currently uses a proprietary format which is only inteded
74 * for testing. This should be replaced with a proper
75 * ASN1 encoded key format, when charon gets the ASN1
78 * @param this calling object
79 * @param key key (in a propriarity format)
80 * @return currently SUCCESS in any case
82 status_t (*set_key
) (rsa_private_key_t
*this, chunk_t key
);
85 * @brief Gets the key.
87 * Currently uses a proprietary format which is only inteded
88 * for testing. This should be replaced with a proper
89 * ASN1 encoded key format, when charon gets the ASN1
92 * @param this calling object
93 * @param key key (in a propriarity format)
96 * - INVALID_STATE, if key not set
98 status_t (*get_key
) (rsa_private_key_t
*this, chunk_t
*key
);
101 * @brief Loads a key from a file.
105 * @param this calling object
106 * @param file file from which key should be read
107 * @return NOT_SUPPORTED
109 status_t (*load_key
) (rsa_private_key_t
*this, char *file
);
112 * @brief Saves a key to a file.
116 * @param this calling object
117 * @param file file to which the key should be written.
118 * @return NOT_SUPPORTED
120 status_t (*save_key
) (rsa_private_key_t
*this, char *file
);
123 * @brief Generate a new key.
125 * Generates a new private_key with specified key size
127 * @param this calling object
128 * @param key_size size of the key in bits
131 * - INVALID_ARG if key_size invalid
133 status_t (*generate_key
) (rsa_private_key_t
*this, size_t key_size
);
136 * @brief Create a rsa_public_key_t with the public
139 * @param this calling object
142 rsa_public_key_t
*(*get_public_key
) (rsa_private_key_t
*this);
145 * @brief Destroys the private key.
147 * @param this private key to destroy
149 void (*destroy
) (rsa_private_key_t
*this);
153 * @brief Create a new rsa_private_key without
156 * @return created rsa_private_key_t.
160 rsa_private_key_t
*rsa_private_key_create();
162 #endif /*RSA_PRIVATE_KEY_H_*/