| 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-ossl.h |
| 29 |
|
| 30 |
Header file for OpenSSL implemented |
| 31 |
*****************************************************************************/ |
| 32 |
|
| 33 |
#ifndef _SOFTHSM_V2_SOFTHSM2_UTIL_OSSL_H |
| 34 |
#define _SOFTHSM_V2_SOFTHSM2_UTIL_OSSL_H |
| 35 |
|
| 36 |
#include <openssl/rsa.h> |
| 37 |
#include <openssl/dsa.h> |
| 38 |
#ifdef WITH_ECC |
| 39 |
#include <openssl/ec.h> |
| 40 |
#endif |
| 41 |
#ifdef WITH_EDDSA |
| 42 |
#include <openssl/evp.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
typedef struct rsa_key_material_t { |
| 46 |
CK_ULONG sizeE; |
| 47 |
CK_ULONG sizeN; |
| 48 |
CK_ULONG sizeD; |
| 49 |
CK_ULONG sizeP; |
| 50 |
CK_ULONG sizeQ; |
| 51 |
CK_ULONG sizeDMP1; |
| 52 |
CK_ULONG sizeDMQ1; |
| 53 |
CK_ULONG sizeIQMP; |
| 54 |
CK_VOID_PTR bigE; |
| 55 |
CK_VOID_PTR bigN; |
| 56 |
CK_VOID_PTR bigD; |
| 57 |
CK_VOID_PTR bigP; |
| 58 |
CK_VOID_PTR bigQ; |
| 59 |
CK_VOID_PTR bigDMP1; |
| 60 |
CK_VOID_PTR bigDMQ1; |
| 61 |
CK_VOID_PTR bigIQMP; |
| 62 |
rsa_key_material_t() { |
| 63 |
sizeE = 0; |
| 64 |
sizeN = 0; |
| 65 |
sizeD = 0; |
| 66 |
sizeP = 0; |
| 67 |
sizeQ = 0; |
| 68 |
sizeDMP1 = 0; |
| 69 |
sizeDMQ1 = 0; |
| 70 |
sizeIQMP = 0; |
| 71 |
bigE = NULL_PTR; |
| 72 |
bigN = NULL_PTR; |
| 73 |
bigD = NULL_PTR; |
| 74 |
bigP = NULL_PTR; |
| 75 |
bigQ = NULL_PTR; |
| 76 |
bigDMP1 = NULL_PTR; |
| 77 |
bigDMQ1 = NULL_PTR; |
| 78 |
bigIQMP = NULL_PTR; |
| 79 |
} |
| 80 |
} rsa_key_material_t; |
| 81 |
|
| 82 |
typedef struct dsa_key_material_t { |
| 83 |
CK_ULONG sizeP; |
| 84 |
CK_ULONG sizeQ; |
| 85 |
CK_ULONG sizeG; |
| 86 |
CK_ULONG sizeX; |
| 87 |
CK_ULONG sizeY; |
| 88 |
CK_VOID_PTR bigP; |
| 89 |
CK_VOID_PTR bigQ; |
| 90 |
CK_VOID_PTR bigG; |
| 91 |
CK_VOID_PTR bigX; |
| 92 |
CK_VOID_PTR bigY; |
| 93 |
dsa_key_material_t() { |
| 94 |
sizeP = 0; |
| 95 |
sizeQ = 0; |
| 96 |
sizeG = 0; |
| 97 |
sizeX = 0; |
| 98 |
sizeY = 0; |
| 99 |
bigP = NULL_PTR; |
| 100 |
bigQ = NULL_PTR; |
| 101 |
bigG = NULL_PTR; |
| 102 |
bigX = NULL_PTR; |
| 103 |
bigY = NULL_PTR; |
| 104 |
} |
| 105 |
} dsa_key_material_t; |
| 106 |
|
| 107 |
#ifdef WITH_ECC |
| 108 |
typedef struct ecdsa_key_material_t { |
| 109 |
CK_ULONG sizeParams; |
| 110 |
CK_ULONG sizeD; |
| 111 |
CK_ULONG sizeQ; |
| 112 |
CK_VOID_PTR derParams; |
| 113 |
CK_VOID_PTR bigD; |
| 114 |
CK_VOID_PTR derQ; |
| 115 |
ecdsa_key_material_t() { |
| 116 |
sizeParams = 0; |
| 117 |
sizeD = 0; |
| 118 |
sizeQ = 0; |
| 119 |
derParams = NULL_PTR; |
| 120 |
bigD = NULL_PTR; |
| 121 |
derQ = NULL_PTR; |
| 122 |
} |
| 123 |
} ecdsa_key_material_t; |
| 124 |
#endif |
| 125 |
|
| 126 |
#ifdef WITH_EDDSA |
| 127 |
typedef struct eddsa_key_material_t { |
| 128 |
CK_ULONG sizeOID; |
| 129 |
CK_ULONG sizeK; |
| 130 |
CK_ULONG sizeA; |
| 131 |
CK_VOID_PTR derOID; |
| 132 |
CK_VOID_PTR bigK; |
| 133 |
CK_VOID_PTR bigA; |
| 134 |
eddsa_key_material_t() { |
| 135 |
sizeOID = 0; |
| 136 |
sizeK = 0; |
| 137 |
sizeA = 0; |
| 138 |
derOID = NULL_PTR; |
| 139 |
bigK = NULL_PTR; |
| 140 |
bigA = NULL_PTR; |
| 141 |
} |
| 142 |
} eddsa_key_material_t; |
| 143 |
#endif |
| 144 |
|
| 145 |
EVP_PKEY* crypto_read_file(char* filePath, char* filePIN); |
| 146 |
|
| 147 |
// RSA |
| 148 |
int crypto_save_rsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, RSA* rsa); |
| 149 |
rsa_key_material_t* crypto_malloc_rsa(RSA* rsa); |
| 150 |
void crypto_free_rsa(rsa_key_material_t* keyMat); |
| 151 |
|
| 152 |
// DSA |
| 153 |
int crypto_save_dsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, DSA* dsa); |
| 154 |
dsa_key_material_t* crypto_malloc_dsa(DSA* dsa); |
| 155 |
void crypto_free_dsa(dsa_key_material_t* keyMat); |
| 156 |
|
| 157 |
#ifdef WITH_ECC |
| 158 |
// ECDSA |
| 159 |
int crypto_save_ecdsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, EC_KEY* ecdsa); |
| 160 |
ecdsa_key_material_t* crypto_malloc_ecdsa(EC_KEY* ecdsa); |
| 161 |
void crypto_free_ecdsa(ecdsa_key_material_t* keyMat); |
| 162 |
#endif |
| 163 |
|
| 164 |
#ifdef WITH_EDDSA |
| 165 |
// EDDSA |
| 166 |
int crypto_save_eddsa(CK_SESSION_HANDLE hSession, char* label, char* objID, size_t objIDLen, int noPublicKey, EVP_PKEY* eddsa); |
| 167 |
eddsa_key_material_t* crypto_malloc_eddsa(EVP_PKEY* eddsa); |
| 168 |
void crypto_free_eddsa(eddsa_key_material_t* keyMat); |
| 169 |
#endif |
| 170 |
|
| 171 |
#endif // !_SOFTHSM_V2_SOFTHSM2_UTIL_OSSL_H |