Debian Codegraph @

src/bin/util/softhsm2-util-botan.h

raw
1 /*
2 * Copyright (c) 2010 .SE (The Internet Infrastructure Foundation)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 softhsm2-util-botan.h
29
30 Header file for Botan implemented
31 *****************************************************************************/
32
33 #ifndef _SOFTHSM_V2_SOFTHSM2_UTIL_BOTAN_H
34 #define _SOFTHSM_V2_SOFTHSM2_UTIL_BOTAN_H
35
36 #include <botan/rsa.h>
37 #include <botan/dsa.h>
38 #ifdef WITH_ECC
39 #include <botan/ecdsa.h>
40 #endif
41 #ifdef WITH_EDDSA
42 #include <botan/curve25519.h>
43 #include <botan/ed25519.h>
44 // #include <botan/curve448.h>
45 // #include <botan/ed448.h>
46 #endif
47
48 typedef struct rsa_key_material_t {
49 CK_ULONG sizeE;
50 CK_ULONG sizeN;
51 CK_ULONG sizeD;
52 CK_ULONG sizeP;
53 CK_ULONG sizeQ;
54 CK_ULONG sizeDMP1;
55 CK_ULONG sizeDMQ1;
56 CK_ULONG sizeIQMP;
57 CK_VOID_PTR bigE;
58 CK_VOID_PTR bigN;
59 CK_VOID_PTR bigD;
60 CK_VOID_PTR bigP;
61 CK_VOID_PTR bigQ;
62 CK_VOID_PTR bigDMP1;
63 CK_VOID_PTR bigDMQ1;
64 CK_VOID_PTR bigIQMP;
65 rsa_key_material_t() {
66 sizeE = 0;
67 sizeN = 0;
68 sizeD = 0;
69 sizeP = 0;
70 sizeQ = 0;
71 sizeDMP1 = 0;
72 sizeDMQ1 = 0;
73 sizeIQMP = 0;
74 bigE = NULL_PTR;
75 bigN = NULL_PTR;
76 bigD = NULL_PTR;
77 bigP = NULL_PTR;
78 bigQ = NULL_PTR;
79 bigDMP1 = NULL_PTR;
80 bigDMQ1 = NULL_PTR;
81 bigIQMP = NULL_PTR;
82 }
83 } rsa_key_material_t;
84
85 typedef struct dsa_key_material_t {
86 CK_ULONG sizeP;
87 CK_ULONG sizeQ;
88 CK_ULONG sizeG;
89 CK_ULONG sizeX;
90 CK_ULONG sizeY;
91 CK_VOID_PTR bigP;
92 CK_VOID_PTR bigQ;
93 CK_VOID_PTR bigG;
94 CK_VOID_PTR bigX;
95 CK_VOID_PTR bigY;
96 dsa_key_material_t() {
97 sizeP = 0;
98 sizeQ = 0;
99 sizeG = 0;
100 sizeX = 0;
101 sizeY = 0;
102 bigP = NULL_PTR;
103 bigQ = NULL_PTR;
104 bigG = NULL_PTR;
105 bigX = NULL_PTR;
106 bigY = NULL_PTR;
107 }
108 } dsa_key_material_t;
109
110 #ifdef WITH_ECC
111 typedef struct ecdsa_key_material_t {
112 CK_ULONG sizeParams;
113 CK_ULONG sizeD;
114 CK_ULONG sizeQ;
115 CK_VOID_PTR derParams;
116 CK_VOID_PTR bigD;
117 CK_VOID_PTR derQ;
118 ecdsa_key_material_t() {
119 sizeParams = 0;
120 sizeD = 0;
121 sizeQ = 0;
122 derParams = NULL_PTR;
123 bigD = NULL_PTR;
124 derQ = NULL_PTR;
125 }
126 } ecdsa_key_material_t;
127 #endif
128
129 #ifdef WITH_EDDSA
130 typedef struct eddsa_key_material_t {
131 CK_ULONG sizeOID;
132 CK_ULONG sizeK;
133 CK_ULONG sizeA;
134 CK_VOID_PTR derOID;
135 CK_VOID_PTR bigK;
136 CK_VOID_PTR bigA;
137 eddsa_key_material_t() {
138 sizeOID = 0;
139 sizeK = 0;
140 sizeA = 0;
141 derOID = NULL_PTR;
142 bigK = NULL_PTR;
143 bigA = NULL_PTR;
144 }
145 } eddsa_key_material_t;
146 #endif
147
148 Botan::Private_Key* crypto_read_file(char* filePath, char* filePIN);
149
150 // RSA
151 int crypto_save_rsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, Botan::RSA_PrivateKey* rsa);
152 rsa_key_material_t* crypto_malloc_rsa(Botan::RSA_PrivateKey* rsa);
153 void crypto_free_rsa(rsa_key_material_t* keyMat);
154
155 // DSA
156 int crypto_save_dsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, Botan::DSA_PrivateKey* dsa);
157 dsa_key_material_t* crypto_malloc_dsa(Botan::DSA_PrivateKey* dsa);
158 void crypto_free_dsa(dsa_key_material_t* keyMat);
159
160 // ECDSA
161 #ifdef WITH_ECC
162 int crypto_save_ecdsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, Botan::ECDSA_PrivateKey* ecdsa);
163 ecdsa_key_material_t* crypto_malloc_ecdsa(Botan::ECDSA_PrivateKey* ecdsa);
164 void crypto_free_ecdsa(ecdsa_key_material_t* keyMat);
165 #endif
166
167 // EDDSA
168 #ifdef WITH_EDDSA
169 int crypto_save_eddsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, Botan::Curve25519_PrivateKey* x25519, Botan::Ed25519_PrivateKey* ed25519);
170 eddsa_key_material_t* crypto_malloc_eddsa(Botan::Curve25519_PrivateKey* x25519, Botan::Ed25519_PrivateKey* ed25519);
171 void crypto_free_eddsa(eddsa_key_material_t* keyMat);
172 #endif
173
174 #endif // !_SOFTHSM_V2_SOFTHSM2_UTIL_BOTAN_H