|
1 /* |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Methods that allows to sign and verify data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* A wrapper for evp.h in openssl */ |
|
20 |
|
21 #ifndef __SYMBIANCRYPTO_EVP_WRAPPER_H__ |
|
22 #define __SYMBIANCRYPTO_EVP_WRAPPER_H__ |
|
23 |
|
24 #ifdef __cplusplus |
|
25 extern "C" { |
|
26 #endif /* __cplusplus */ |
|
27 #include "xmlsecc_config.h" |
|
28 #include "xmlsecc_bio.h" |
|
29 |
|
30 |
|
31 /************************************ |
|
32 * |
|
33 * RSA Sign functions |
|
34 * |
|
35 ************************************/ |
|
36 |
|
37 /* data type compatibility for OpenSSL*/ |
|
38 |
|
39 #define HASKEY 1 |
|
40 #define NOKEY 0 |
|
41 |
|
42 /** |
|
43 * Key algorithms. |
|
44 * EVP_PKEY_UNKNOWN unknown algorithm |
|
45 * EVP_PKEY_RSA RSA algorithm |
|
46 * EVP_PKEY_DSA DSA algorithm |
|
47 */ |
|
48 enum sc_key_algos |
|
49 { |
|
50 EVP_PKEY_UNKNOWN=0, |
|
51 EVP_PKEY_RSA, |
|
52 EVP_PKEY_DSA |
|
53 }; |
|
54 |
|
55 struct ScKeyStore; |
|
56 typedef struct ScKeyStore ScKeyStore, *ScKeyStorePtr; |
|
57 typedef unsigned char* RSA; |
|
58 |
|
59 typedef struct ScPkey |
|
60 { |
|
61 int type; |
|
62 int load; // HASKEY - 1, NOKEY - 0 |
|
63 unsigned int bitsize; // Bit size of the key |
|
64 int duplicate; // Indicate whether this is a duplicate copy |
|
65 char *name; |
|
66 ScKeyStorePtr keyStore; |
|
67 } EVP_PKEY; |
|
68 |
|
69 |
|
70 /** |
|
71 * Create a new key store structure |
|
72 * |
|
73 * @param keytype type of the key |
|
74 * @param keyname name of the key |
|
75 * @return EVP_PKEY structure |
|
76 */ |
|
77 EVP_PKEY *sc_pkey_new(int keytype, char *keyname); |
|
78 |
|
79 /** |
|
80 * Symbian key store Initialization |
|
81 * |
|
82 * @return 0 if correct initialization |
|
83 * @return error code in the other hand |
|
84 */ |
|
85 int sc_pkey_init(); |
|
86 |
|
87 /** |
|
88 * Load an RSA key |
|
89 * |
|
90 * @param pkey EVP_PKEY structure |
|
91 * @return 0 if key is loaded |
|
92 * @return -1 if key is not loaded |
|
93 * @return error code in the other hand |
|
94 */ |
|
95 int sc_pkey_load(EVP_PKEY *pkey); |
|
96 |
|
97 /** |
|
98 * Generate an RSA key |
|
99 * |
|
100 * @param pkey EVP_KEY structure |
|
101 * @param sizeBits size of the key |
|
102 * @return 0 if key is loaded |
|
103 * @return -1 if key is not loaded |
|
104 * @return error code in the other hand |
|
105 */ |
|
106 int sc_pkey_generate(EVP_PKEY *pkey, unsigned int sizeBits); |
|
107 |
|
108 /** |
|
109 * Free the EVP_PKEY structure |
|
110 */ |
|
111 void sc_pkey_free(EVP_PKEY *pkey); |
|
112 |
|
113 /** |
|
114 * Duplicate an EVP key |
|
115 * |
|
116 * @param pkey EVP_KEY structure |
|
117 * @return EVP_PKEY duplicated structure |
|
118 */ |
|
119 EVP_PKEY *sc_pkey_duplicate(EVP_PKEY *aPKey); |
|
120 |
|
121 /** |
|
122 * Symbian key store shutdown process |
|
123 */ |
|
124 void sc_pkey_shutdown(); |
|
125 |
|
126 /** |
|
127 * Get the pkey size |
|
128 * |
|
129 * @param pkey EVP_KEY structure |
|
130 * @return size of the key |
|
131 */ |
|
132 unsigned int sc_pkey_size(EVP_PKEY *aPKey); |
|
133 |
|
134 /** |
|
135 * Read the private key from ASN.1 DER encoded PKCS#8 format |
|
136 * |
|
137 * @param aBio BIO structure |
|
138 * @param aPwdCallback callback |
|
139 * @param aPwdCallbackCtx callback context |
|
140 * @return EVP_PKEY structure |
|
141 */ |
|
142 EVP_PKEY* d2i_PKCS8PrivateKey_bio(BIO *aBio, void *aPwdCallback, void *aPwdCallbackCtx); |
|
143 |
|
144 /** |
|
145 * Read the private key from Unified Key Store |
|
146 * |
|
147 * @param keyname name of the key |
|
148 * @return EVP_PKEY structure |
|
149 */ |
|
150 EVP_PKEY* d2i_PKCS8PrivateKey(char *keyname); |
|
151 |
|
152 /** |
|
153 * Read the public key from ASN.1 DER encoded format |
|
154 * |
|
155 * @param aBio BIO structure |
|
156 * @return EVP_PKEY structure |
|
157 */ |
|
158 EVP_PKEY* d2i_PUBKEY_bio(BIO *aBio); |
|
159 |
|
160 #ifndef XMLSEC_NO_X509 |
|
161 |
|
162 /************************************ |
|
163 * |
|
164 * X.509 related functions |
|
165 * |
|
166 ************************************/ |
|
167 |
|
168 typedef struct ScX509St |
|
169 { |
|
170 char* der; // Certificate in ASN.1 DER format |
|
171 unsigned int derlen; |
|
172 |
|
173 } X509; |
|
174 |
|
175 /** |
|
176 * Set the public key info |
|
177 * |
|
178 * @param pkey EVP_KEY structure |
|
179 * @param aCert X509 structure |
|
180 * @return 0 if operation correct |
|
181 * @return error code if operation fail |
|
182 */ |
|
183 int sc_pkey_setPublic(EVP_PKEY* aPKey, X509 *aCert); |
|
184 |
|
185 #endif // XMLSEC_NO_X509 |
|
186 |
|
187 #ifdef __cplusplus |
|
188 } |
|
189 #endif /* __cplusplus */ |
|
190 |
|
191 #endif /* __SYMBIANCRYPTO_EVP_WRAPPER_H__ */ |
|
192 |
|
193 #define __SYMBIANCRYPTO_EVP_WRAPPER_H__ |