]> git.ipfire.org Git - people/ms/strongswan.git/blame - Source/charon/transforms/rsa/rsa_private_key.h
- starter work on asn1 with der de/encoder
[people/ms/strongswan.git] / Source / charon / transforms / rsa / rsa_private_key.h
CommitLineData
8ff8c33d
MW
1/**
2 * @file rsa_private_key.h
3 *
b66cb987 4 * @brief Interface of rsa_private_key_t.
8ff8c33d
MW
5 *
6 */
7
8/*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23#ifndef RSA_PRIVATE_KEY_H_
24#define RSA_PRIVATE_KEY_H_
25
26#include <types.h>
27#include <definitions.h>
8ff8c33d
MW
28#include <transforms/rsa/rsa_public_key.h>
29#include <transforms/hashers/hasher.h>
30
31
32typedef struct rsa_private_key_t rsa_private_key_t;
33
34/**
35 * @brief RSA private key with associated functions.
36 *
37 * Currently only supports signing using EMSA encoding.
38 *
89e0f219
MW
39 * @b Constructors:
40 * - rsa_private_key_create()
41 *
42 * @see rsa_public_key_t
43 *
4b41a0d4
JH
44 * @todo Implement proper key set/get load/save methods using ASN1.
45 *
89e0f219 46 * @ingroup rsa
8ff8c33d
MW
47 */
48struct rsa_private_key_t {
49
89e0f219 50 /**
19f78a6f 51 * @brief Build a signature over a chunk using EMSA-PKCS1 encoding.
89e0f219 52 *
b66cb987 53 * This signature creates a hash using the specified hash algorithm, concatenates
89e0f219
MW
54 * it with an ASN1-OID of the hash algorithm and runs the RSASP1 function
55 * on it.
56 *
4b41a0d4 57 * @param this calling object
89e0f219
MW
58 * @param hash_algorithm hash algorithm to use for hashing
59 * @param data data to sign
60 * @param[out] signature allocated signature
61 * @return
62 * - SUCCESS
63 * - INVALID_STATE, if key not set
64 * - NOT_SUPPORTED, if hash algorithm not supported
65 */
8ff8c33d
MW
66 status_t (*build_emsa_pkcs1_signature) (rsa_private_key_t *this, hash_algorithm_t hash_algorithm, chunk_t data, chunk_t *signature);
67
89e0f219
MW
68 /**
69 * @brief Set the key.
70 *
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
74 * capabilities.
75 *
76 * @param this calling object
77 * @param key key (in a propriarity format)
78 * @return currently SUCCESS in any case
79 */
8ff8c33d
MW
80 status_t (*set_key) (rsa_private_key_t *this, chunk_t key);
81
89e0f219
MW
82 /**
83 * @brief Gets the key.
84 *
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
88 * capabilities.
89 *
90 * @param this calling object
91 * @param key key (in a propriarity format)
92 * @return
93 * - SUCCESS
94 * - INVALID_STATE, if key not set
95 */
8ff8c33d
MW
96 status_t (*get_key) (rsa_private_key_t *this, chunk_t *key);
97
89e0f219
MW
98 /**
99 * @brief Loads a key from a file.
100 *
101 * Not implemented!
102 *
103 * @param this calling object
104 * @param file file from which key should be read
105 * @return NOT_SUPPORTED
106 */
8ff8c33d
MW
107 status_t (*load_key) (rsa_private_key_t *this, char *file);
108
89e0f219
MW
109 /**
110 * @brief Saves a key to a file.
111 *
112 * Not implemented!
113 *
114 * @param this calling object
115 * @param file file to which the key should be written.
116 * @return NOT_SUPPORTED
117 */
8ff8c33d
MW
118 status_t (*save_key) (rsa_private_key_t *this, char *file);
119
89e0f219
MW
120 /**
121 * @brief Generate a new key.
122 *
123 * Generates a new private_key with specified key size
124 *
125 * @param this calling object
126 * @param key_size size of the key in bits
127 * @return
128 * - SUCCESS
129 * - INVALID_ARG if key_size invalid
130 */
8ff8c33d
MW
131 status_t (*generate_key) (rsa_private_key_t *this, size_t key_size);
132
89e0f219
MW
133 /**
134 * @brief Create a rsa_public_key_t with the public
135 * parts of the key.
136 *
137 * @param this calling object
138 * @return public_key
139 */
8ff8c33d 140 rsa_public_key_t *(*get_public_key) (rsa_private_key_t *this);
89e0f219
MW
141
142 /**
143 * @brief Destroys the private key.
144 *
145 * @param this private key to destroy
146 */
8ff8c33d
MW
147 void (*destroy) (rsa_private_key_t *this);
148};
149
150/**
89e0f219
MW
151 * @brief Create a new rsa_private_key without
152 * any key inside.
153 *
154 * @return created rsa_private_key_t.
8ff8c33d 155 *
89e0f219 156 * @ingroup rsa
8ff8c33d
MW
157 */
158rsa_private_key_t *rsa_private_key_create();
159
160#endif /*RSA_PRIVATE_KEY_H_*/