mirror of
https://github.com/openssl/openssl.git
synced 2024-11-24 10:34:12 +08:00
Step 2 of move of engines: copy engines to new directory and rename them
to be prefixed with e_ instead of hw_. They aren't necessarely hardware engines. The files commited here are exact copies of the corresponding hw_ files found in crypto/engine/.
This commit is contained in:
parent
729f0a277e
commit
5572f482e7
8
engines/e.ec
Normal file
8
engines/e.ec
Normal file
@ -0,0 +1,8 @@
|
||||
L AEPHK hw_aep_err.h hw_aep_err.c
|
||||
L ATALLA hw_atalla_err.h hw_atalla_err.c
|
||||
L CSWIFT hw_cswift_err.h hw_cswift_err.c
|
||||
L HWCRHK hw_ncipher_err.h hw_ncipher_err.c
|
||||
L NURON hw_nuron_err.h hw_nuron_err.c
|
||||
L SUREWARE hw_sureware_err.h hw_sureware_err.c
|
||||
L UBSEC hw_ubsec_err.h hw_ubsec_err.c
|
||||
L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c
|
967
engines/e_4758_cca.c
Normal file
967
engines/e_4758_cca.c
Normal file
@ -0,0 +1,967 @@
|
||||
/* Author: Maurice Gittens <maurice@gittens.nl> */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/crypto.h>
|
||||
/* #include <openssl/pem.h> */
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
#ifndef OPENSSL_NO_HW
|
||||
#ifndef OPENSSL_NO_HW_4758_CCA
|
||||
|
||||
#ifdef FLAT_INC
|
||||
#include "hw_4758_cca.h"
|
||||
#else
|
||||
#include "vendor_defns/hw_4758_cca.h"
|
||||
#endif
|
||||
|
||||
#include "hw_4758_cca_err.c"
|
||||
|
||||
static int ibm_4758_cca_destroy(ENGINE *e);
|
||||
static int ibm_4758_cca_init(ENGINE *e);
|
||||
static int ibm_4758_cca_finish(ENGINE *e);
|
||||
static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
|
||||
|
||||
/* rsa functions */
|
||||
/*---------------*/
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static int cca_rsa_pub_enc(int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,int padding);
|
||||
static int cca_rsa_priv_dec(int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,int padding);
|
||||
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
|
||||
unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
|
||||
static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
|
||||
unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
|
||||
|
||||
/* utility functions */
|
||||
/*-----------------------*/
|
||||
static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
|
||||
static int getModulusAndExponent(const unsigned char *token, long *exponentLength,
|
||||
unsigned char *exponent, long *modulusLength,
|
||||
long *modulusFieldLength, unsigned char *modulus);
|
||||
#endif
|
||||
|
||||
/* RAND number functions */
|
||||
/*-----------------------*/
|
||||
static int cca_get_random_bytes(unsigned char*, int );
|
||||
static int cca_random_status(void);
|
||||
|
||||
static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
|
||||
int idx,long argl, void *argp);
|
||||
|
||||
/* Function pointers for CCA verbs */
|
||||
/*---------------------------------*/
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static F_KEYRECORDREAD keyRecordRead;
|
||||
static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate;
|
||||
static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify;
|
||||
static F_PUBLICKEYEXTRACT publicKeyExtract;
|
||||
static F_PKAENCRYPT pkaEncrypt;
|
||||
static F_PKADECRYPT pkaDecrypt;
|
||||
#endif
|
||||
static F_RANDOMNUMBERGENERATE randomNumberGenerate;
|
||||
|
||||
/* static variables */
|
||||
/*------------------*/
|
||||
static const char *CCA4758_LIB_NAME = NULL;
|
||||
static const char *get_CCA4758_LIB_NAME(void)
|
||||
{
|
||||
if(CCA4758_LIB_NAME)
|
||||
return CCA4758_LIB_NAME;
|
||||
return CCA_LIB_NAME;
|
||||
}
|
||||
static void free_CCA4758_LIB_NAME(void)
|
||||
{
|
||||
if(CCA4758_LIB_NAME)
|
||||
OPENSSL_free((void*)CCA4758_LIB_NAME);
|
||||
CCA4758_LIB_NAME = NULL;
|
||||
}
|
||||
static long set_CCA4758_LIB_NAME(const char *name)
|
||||
{
|
||||
free_CCA4758_LIB_NAME();
|
||||
return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0);
|
||||
}
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static const char* n_keyRecordRead = CSNDKRR;
|
||||
static const char* n_digitalSignatureGenerate = CSNDDSG;
|
||||
static const char* n_digitalSignatureVerify = CSNDDSV;
|
||||
static const char* n_publicKeyExtract = CSNDPKX;
|
||||
static const char* n_pkaEncrypt = CSNDPKE;
|
||||
static const char* n_pkaDecrypt = CSNDPKD;
|
||||
#endif
|
||||
static const char* n_randomNumberGenerate = CSNBRNG;
|
||||
|
||||
static int hndidx = -1;
|
||||
static DSO *dso = NULL;
|
||||
|
||||
/* openssl engine initialization structures */
|
||||
/*------------------------------------------*/
|
||||
|
||||
#define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE
|
||||
static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = {
|
||||
{CCA4758_CMD_SO_PATH,
|
||||
"SO_PATH",
|
||||
"Specifies the path to the '4758cca' shared library",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{0, NULL, NULL, 0}
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static RSA_METHOD ibm_4758_cca_rsa =
|
||||
{
|
||||
"IBM 4758 CCA RSA method",
|
||||
cca_rsa_pub_enc,
|
||||
NULL,
|
||||
NULL,
|
||||
cca_rsa_priv_dec,
|
||||
NULL, /*rsa_mod_exp,*/
|
||||
NULL, /*mod_exp_mont,*/
|
||||
NULL, /* init */
|
||||
NULL, /* finish */
|
||||
RSA_FLAG_SIGN_VER, /* flags */
|
||||
NULL, /* app_data */
|
||||
cca_rsa_sign, /* rsa_sign */
|
||||
cca_rsa_verify /* rsa_verify */
|
||||
};
|
||||
#endif
|
||||
|
||||
static RAND_METHOD ibm_4758_cca_rand =
|
||||
{
|
||||
/* "IBM 4758 RAND method", */
|
||||
NULL, /* seed */
|
||||
cca_get_random_bytes, /* get random bytes from the card */
|
||||
NULL, /* cleanup */
|
||||
NULL, /* add */
|
||||
cca_get_random_bytes, /* pseudo rand */
|
||||
cca_random_status, /* status */
|
||||
};
|
||||
|
||||
static const char *engine_4758_cca_id = "4758cca";
|
||||
static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
|
||||
|
||||
/* engine implementation */
|
||||
/*-----------------------*/
|
||||
static int bind_helper(ENGINE *e)
|
||||
{
|
||||
if(!ENGINE_set_id(e, engine_4758_cca_id) ||
|
||||
!ENGINE_set_name(e, engine_4758_cca_name) ||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
!ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
|
||||
#endif
|
||||
!ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
|
||||
!ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
|
||||
!ENGINE_set_init_function(e, ibm_4758_cca_init) ||
|
||||
!ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
|
||||
!ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
|
||||
!ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
|
||||
!ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
|
||||
!ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
|
||||
return 0;
|
||||
/* Ensure the error handling is set up */
|
||||
ERR_load_CCA4758_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ENGINE *engine_4758_cca(void)
|
||||
{
|
||||
ENGINE *ret = ENGINE_new();
|
||||
if(!ret)
|
||||
return NULL;
|
||||
if(!bind_helper(ret))
|
||||
{
|
||||
ENGINE_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ENGINE_load_4758cca(void)
|
||||
{
|
||||
ENGINE *e_4758 = engine_4758_cca();
|
||||
if (!e_4758) return;
|
||||
ENGINE_add(e_4758);
|
||||
ENGINE_free(e_4758);
|
||||
ERR_clear_error();
|
||||
}
|
||||
|
||||
static int ibm_4758_cca_destroy(ENGINE *e)
|
||||
{
|
||||
ERR_unload_CCA4758_strings();
|
||||
free_CCA4758_LIB_NAME();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ibm_4758_cca_init(ENGINE *e)
|
||||
{
|
||||
if(dso)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED);
|
||||
goto err;
|
||||
}
|
||||
|
||||
dso = DSO_load(NULL, get_CCA4758_LIB_NAME(), NULL, 0);
|
||||
if(!dso)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
if(!(keyRecordRead = (F_KEYRECORDREAD)
|
||||
DSO_bind_func(dso, n_keyRecordRead)) ||
|
||||
!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
|
||||
DSO_bind_func(dso, n_randomNumberGenerate)) ||
|
||||
!(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)
|
||||
DSO_bind_func(dso, n_digitalSignatureGenerate)) ||
|
||||
!(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)
|
||||
DSO_bind_func(dso, n_digitalSignatureVerify)) ||
|
||||
!(publicKeyExtract = (F_PUBLICKEYEXTRACT)
|
||||
DSO_bind_func(dso, n_publicKeyExtract)) ||
|
||||
!(pkaEncrypt = (F_PKAENCRYPT)
|
||||
DSO_bind_func(dso, n_pkaEncrypt)) ||
|
||||
!(pkaDecrypt = (F_PKADECRYPT)
|
||||
DSO_bind_func(dso, n_pkaDecrypt)))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
#else
|
||||
if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
|
||||
DSO_bind_func(dso, n_randomNumberGenerate)))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
|
||||
hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
|
||||
NULL, NULL, cca_ex_free);
|
||||
|
||||
return 1;
|
||||
err:
|
||||
if(dso)
|
||||
DSO_free(dso);
|
||||
dso = NULL;
|
||||
|
||||
keyRecordRead = (F_KEYRECORDREAD)0;
|
||||
randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
|
||||
digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
|
||||
digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
|
||||
publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
|
||||
pkaEncrypt = (F_PKAENCRYPT)0;
|
||||
pkaDecrypt = (F_PKADECRYPT)0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ibm_4758_cca_finish(ENGINE *e)
|
||||
{
|
||||
free_CCA4758_LIB_NAME();
|
||||
if(!dso)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
|
||||
CCA4758_R_NOT_LOADED);
|
||||
return 0;
|
||||
}
|
||||
if(!DSO_free(dso))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
|
||||
CCA4758_R_UNIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
dso = NULL;
|
||||
keyRecordRead = (F_KEYRECORDREAD)0;
|
||||
randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
|
||||
digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
|
||||
digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
|
||||
publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
|
||||
pkaEncrypt = (F_PKAENCRYPT)0;
|
||||
pkaDecrypt = (F_PKADECRYPT)0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
|
||||
{
|
||||
int initialised = ((dso == NULL) ? 0 : 1);
|
||||
switch(cmd)
|
||||
{
|
||||
case CCA4758_CMD_SO_PATH:
|
||||
if(p == NULL)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
|
||||
ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
if(initialised)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
|
||||
CCA4758_R_ALREADY_LOADED);
|
||||
return 0;
|
||||
}
|
||||
return set_CCA4758_LIB_NAME((const char *)p);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
|
||||
CCA4758_R_COMMAND_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
|
||||
#define MAX_CCA_PKA_TOKEN_SIZE 2500
|
||||
|
||||
static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
|
||||
UI_METHOD *ui_method, void *callback_data)
|
||||
{
|
||||
RSA *rtmp = NULL;
|
||||
EVP_PKEY *res = NULL;
|
||||
unsigned char* keyToken = NULL;
|
||||
unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
|
||||
long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
|
||||
long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long exitDataLength = 0;
|
||||
long ruleArrayLength = 0;
|
||||
unsigned char exitData[8];
|
||||
unsigned char ruleArray[8];
|
||||
unsigned char keyLabel[64];
|
||||
long keyLabelLength = strlen(key_id);
|
||||
unsigned char modulus[256];
|
||||
long modulusFieldLength = sizeof(modulus);
|
||||
long modulusLength = 0;
|
||||
unsigned char exponent[256];
|
||||
long exponentLength = sizeof(exponent);
|
||||
|
||||
if (keyLabelLength > sizeof(keyLabel))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(keyLabel,' ', sizeof(keyLabel));
|
||||
memcpy(keyLabel, key_id, keyLabelLength);
|
||||
|
||||
keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
|
||||
if (!keyToken)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
|
||||
exitData, &ruleArrayLength, ruleArray, keyLabel,
|
||||
&keyTokenLength, keyToken+sizeof(long));
|
||||
|
||||
if (returnCode)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
|
||||
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
|
||||
keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
|
||||
|
||||
if (returnCode)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!getModulusAndExponent(pubKeyToken, &exponentLength,
|
||||
exponent, &modulusLength, &modulusFieldLength,
|
||||
modulus))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
(*(long*)keyToken) = keyTokenLength;
|
||||
rtmp = RSA_new_method(e);
|
||||
RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
|
||||
|
||||
rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
|
||||
rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
|
||||
rtmp->flags |= RSA_FLAG_EXT_PKEY;
|
||||
|
||||
res = EVP_PKEY_new();
|
||||
EVP_PKEY_assign_RSA(res, rtmp);
|
||||
|
||||
return res;
|
||||
err:
|
||||
if (keyToken)
|
||||
OPENSSL_free(keyToken);
|
||||
if (res)
|
||||
EVP_PKEY_free(res);
|
||||
if (rtmp)
|
||||
RSA_free(rtmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
|
||||
UI_METHOD *ui_method, void *callback_data)
|
||||
{
|
||||
RSA *rtmp = NULL;
|
||||
EVP_PKEY *res = NULL;
|
||||
unsigned char* keyToken = NULL;
|
||||
long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long exitDataLength = 0;
|
||||
long ruleArrayLength = 0;
|
||||
unsigned char exitData[8];
|
||||
unsigned char ruleArray[8];
|
||||
unsigned char keyLabel[64];
|
||||
long keyLabelLength = strlen(key_id);
|
||||
unsigned char modulus[512];
|
||||
long modulusFieldLength = sizeof(modulus);
|
||||
long modulusLength = 0;
|
||||
unsigned char exponent[512];
|
||||
long exponentLength = sizeof(exponent);
|
||||
|
||||
if (keyLabelLength > sizeof(keyLabel))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(keyLabel,' ', sizeof(keyLabel));
|
||||
memcpy(keyLabel, key_id, keyLabelLength);
|
||||
|
||||
keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
|
||||
if (!keyToken)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
|
||||
&ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
|
||||
keyToken+sizeof(long));
|
||||
|
||||
if (returnCode)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
|
||||
exponent, &modulusLength, &modulusFieldLength, modulus))
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
|
||||
CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
(*(long*)keyToken) = keyTokenLength;
|
||||
rtmp = RSA_new_method(e);
|
||||
RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
|
||||
rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
|
||||
rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
|
||||
rtmp->flags |= RSA_FLAG_EXT_PKEY;
|
||||
res = EVP_PKEY_new();
|
||||
EVP_PKEY_assign_RSA(res, rtmp);
|
||||
|
||||
return res;
|
||||
err:
|
||||
if (keyToken)
|
||||
OPENSSL_free(keyToken);
|
||||
if (res)
|
||||
EVP_PKEY_free(res);
|
||||
if (rtmp)
|
||||
RSA_free(rtmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cca_rsa_pub_enc(int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,int padding)
|
||||
{
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long lflen = flen;
|
||||
long exitDataLength = 0;
|
||||
unsigned char exitData[8];
|
||||
long ruleArrayLength = 1;
|
||||
unsigned char ruleArray[8] = "PKCS-1.2";
|
||||
long dataStructureLength = 0;
|
||||
unsigned char dataStructure[8];
|
||||
long outputLength = RSA_size(rsa);
|
||||
long keyTokenLength;
|
||||
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
|
||||
|
||||
keyTokenLength = *(long*)keyToken;
|
||||
keyToken+=sizeof(long);
|
||||
|
||||
pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
|
||||
&ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
|
||||
&dataStructureLength, dataStructure, &keyTokenLength,
|
||||
keyToken, &outputLength, to);
|
||||
|
||||
if (returnCode || reasonCode)
|
||||
return -(returnCode << 16 | reasonCode);
|
||||
return outputLength;
|
||||
}
|
||||
|
||||
static int cca_rsa_priv_dec(int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,int padding)
|
||||
{
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long lflen = flen;
|
||||
long exitDataLength = 0;
|
||||
unsigned char exitData[8];
|
||||
long ruleArrayLength = 1;
|
||||
unsigned char ruleArray[8] = "PKCS-1.2";
|
||||
long dataStructureLength = 0;
|
||||
unsigned char dataStructure[8];
|
||||
long outputLength = RSA_size(rsa);
|
||||
long keyTokenLength;
|
||||
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
|
||||
|
||||
keyTokenLength = *(long*)keyToken;
|
||||
keyToken+=sizeof(long);
|
||||
|
||||
pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
|
||||
&ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
|
||||
&dataStructureLength, dataStructure, &keyTokenLength,
|
||||
keyToken, &outputLength, to);
|
||||
|
||||
return (returnCode | reasonCode) ? 0 : 1;
|
||||
}
|
||||
|
||||
#define SSL_SIG_LEN 36
|
||||
|
||||
static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
|
||||
unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
|
||||
{
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long lsiglen = siglen;
|
||||
long exitDataLength = 0;
|
||||
unsigned char exitData[8];
|
||||
long ruleArrayLength = 1;
|
||||
unsigned char ruleArray[8] = "PKCS-1.1";
|
||||
long keyTokenLength;
|
||||
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
|
||||
long length = SSL_SIG_LEN;
|
||||
long keyLength ;
|
||||
unsigned char *hashBuffer = NULL;
|
||||
X509_SIG sig;
|
||||
ASN1_TYPE parameter;
|
||||
X509_ALGOR algorithm;
|
||||
ASN1_OCTET_STRING digest;
|
||||
|
||||
keyTokenLength = *(long*)keyToken;
|
||||
keyToken+=sizeof(long);
|
||||
|
||||
if (type == NID_md5 || type == NID_sha1)
|
||||
{
|
||||
sig.algor = &algorithm;
|
||||
algorithm.algorithm = OBJ_nid2obj(type);
|
||||
|
||||
if (!algorithm.algorithm)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!algorithm.algorithm->length)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
parameter.type = V_ASN1_NULL;
|
||||
parameter.value.ptr = NULL;
|
||||
algorithm.parameter = ¶meter;
|
||||
|
||||
sig.digest = &digest;
|
||||
sig.digest->data = (unsigned char*)m;
|
||||
sig.digest->length = m_len;
|
||||
|
||||
length = i2d_X509_SIG(&sig, NULL);
|
||||
}
|
||||
|
||||
keyLength = RSA_size(rsa);
|
||||
|
||||
if (length - RSA_PKCS1_PADDING > keyLength)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NID_md5_sha1 :
|
||||
if (m_len != SSL_SIG_LEN)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
hashBuffer = (unsigned char *)m;
|
||||
length = m_len;
|
||||
break;
|
||||
case NID_md5 :
|
||||
{
|
||||
unsigned char *ptr;
|
||||
ptr = hashBuffer = OPENSSL_malloc(
|
||||
(unsigned int)keyLength+1);
|
||||
if (!hashBuffer)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2d_X509_SIG(&sig, &ptr);
|
||||
}
|
||||
break;
|
||||
case NID_sha1 :
|
||||
{
|
||||
unsigned char *ptr;
|
||||
ptr = hashBuffer = OPENSSL_malloc(
|
||||
(unsigned int)keyLength+1);
|
||||
if (!hashBuffer)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
i2d_X509_SIG(&sig, &ptr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
|
||||
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
|
||||
keyToken, &length, hashBuffer, &lsiglen, sigbuf);
|
||||
|
||||
if (type == NID_sha1 || type == NID_md5)
|
||||
{
|
||||
memset(hashBuffer, 0, keyLength+1);
|
||||
OPENSSL_free(hashBuffer);
|
||||
}
|
||||
|
||||
return ((returnCode || reasonCode) ? 0 : 1);
|
||||
}
|
||||
|
||||
#define SSL_SIG_LEN 36
|
||||
|
||||
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
|
||||
unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
|
||||
{
|
||||
long returnCode;
|
||||
long reasonCode;
|
||||
long exitDataLength = 0;
|
||||
unsigned char exitData[8];
|
||||
long ruleArrayLength = 1;
|
||||
unsigned char ruleArray[8] = "PKCS-1.1";
|
||||
long outputLength=256;
|
||||
long outputBitLength;
|
||||
long keyTokenLength;
|
||||
unsigned char *hashBuffer = NULL;
|
||||
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
|
||||
long length = SSL_SIG_LEN;
|
||||
long keyLength ;
|
||||
X509_SIG sig;
|
||||
ASN1_TYPE parameter;
|
||||
X509_ALGOR algorithm;
|
||||
ASN1_OCTET_STRING digest;
|
||||
|
||||
keyTokenLength = *(long*)keyToken;
|
||||
keyToken+=sizeof(long);
|
||||
|
||||
if (type == NID_md5 || type == NID_sha1)
|
||||
{
|
||||
sig.algor = &algorithm;
|
||||
algorithm.algorithm = OBJ_nid2obj(type);
|
||||
|
||||
if (!algorithm.algorithm)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
|
||||
CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!algorithm.algorithm->length)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
|
||||
CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
parameter.type = V_ASN1_NULL;
|
||||
parameter.value.ptr = NULL;
|
||||
algorithm.parameter = ¶meter;
|
||||
|
||||
sig.digest = &digest;
|
||||
sig.digest->data = (unsigned char*)m;
|
||||
sig.digest->length = m_len;
|
||||
|
||||
length = i2d_X509_SIG(&sig, NULL);
|
||||
}
|
||||
|
||||
keyLength = RSA_size(rsa);
|
||||
|
||||
if (length - RSA_PKCS1_PADDING > keyLength)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NID_md5_sha1 :
|
||||
if (m_len != SSL_SIG_LEN)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
|
||||
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
hashBuffer = (unsigned char*)m;
|
||||
length = m_len;
|
||||
break;
|
||||
case NID_md5 :
|
||||
{
|
||||
unsigned char *ptr;
|
||||
ptr = hashBuffer = OPENSSL_malloc(
|
||||
(unsigned int)keyLength+1);
|
||||
if (!hashBuffer)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
i2d_X509_SIG(&sig, &ptr);
|
||||
}
|
||||
break;
|
||||
case NID_sha1 :
|
||||
{
|
||||
unsigned char *ptr;
|
||||
ptr = hashBuffer = OPENSSL_malloc(
|
||||
(unsigned int)keyLength+1);
|
||||
if (!hashBuffer)
|
||||
{
|
||||
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
i2d_X509_SIG(&sig, &ptr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
|
||||
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
|
||||
keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
|
||||
sigret);
|
||||
|
||||
if (type == NID_sha1 || type == NID_md5)
|
||||
{
|
||||
memset(hashBuffer, 0, keyLength+1);
|
||||
OPENSSL_free(hashBuffer);
|
||||
}
|
||||
|
||||
*siglen = outputLength;
|
||||
|
||||
return ((returnCode || reasonCode) ? 0 : 1);
|
||||
}
|
||||
|
||||
static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
|
||||
unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
|
||||
unsigned char *modulus)
|
||||
{
|
||||
unsigned long len;
|
||||
|
||||
if (*token++ != (char)0x1E) /* internal PKA token? */
|
||||
return 0;
|
||||
|
||||
if (*token++) /* token version must be zero */
|
||||
return 0;
|
||||
|
||||
len = *token++;
|
||||
len = len << 8;
|
||||
len |= (unsigned char)*token++;
|
||||
|
||||
token += 4; /* skip reserved bytes */
|
||||
|
||||
if (*token++ == (char)0x04)
|
||||
{
|
||||
if (*token++) /* token version must be zero */
|
||||
return 0;
|
||||
|
||||
len = *token++;
|
||||
len = len << 8;
|
||||
len |= (unsigned char)*token++;
|
||||
|
||||
token+=2; /* skip reserved section */
|
||||
|
||||
len = *token++;
|
||||
len = len << 8;
|
||||
len |= (unsigned char)*token++;
|
||||
|
||||
*exponentLength = len;
|
||||
|
||||
len = *token++;
|
||||
len = len << 8;
|
||||
len |= (unsigned char)*token++;
|
||||
|
||||
*modulusLength = len;
|
||||
|
||||
len = *token++;
|
||||
len = len << 8;
|
||||
len |= (unsigned char)*token++;
|
||||
|
||||
*modulusFieldLength = len;
|
||||
|
||||
memcpy(exponent, token, *exponentLength);
|
||||
token+= *exponentLength;
|
||||
|
||||
memcpy(modulus, token, *modulusFieldLength);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_RSA */
|
||||
|
||||
static int cca_random_status(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cca_get_random_bytes(unsigned char* buf, int num)
|
||||
{
|
||||
long ret_code;
|
||||
long reason_code;
|
||||
long exit_data_length;
|
||||
unsigned char exit_data[4];
|
||||
unsigned char form[] = "RANDOM ";
|
||||
unsigned char rand_buf[8];
|
||||
|
||||
while(num >= sizeof(rand_buf))
|
||||
{
|
||||
randomNumberGenerate(&ret_code, &reason_code, &exit_data_length,
|
||||
exit_data, form, rand_buf);
|
||||
if (ret_code)
|
||||
return 0;
|
||||
num -= sizeof(rand_buf);
|
||||
memcpy(buf, rand_buf, sizeof(rand_buf));
|
||||
buf += sizeof(rand_buf);
|
||||
}
|
||||
|
||||
if (num)
|
||||
{
|
||||
randomNumberGenerate(&ret_code, &reason_code, NULL, NULL,
|
||||
form, rand_buf);
|
||||
if (ret_code)
|
||||
return 0;
|
||||
memcpy(buf, rand_buf, num);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
|
||||
long argl, void *argp)
|
||||
{
|
||||
if (item)
|
||||
OPENSSL_free(item);
|
||||
}
|
||||
|
||||
/* Goo to handle building as a dynamic engine */
|
||||
#ifdef ENGINE_DYNAMIC_SUPPORT
|
||||
static int bind_fn(ENGINE *e, const char *id)
|
||||
{
|
||||
if(id && (strcmp(id, engine_4758_cca_id) != 0))
|
||||
return 0;
|
||||
if(!bind_helper(e))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
|
||||
#endif /* ENGINE_DYNAMIC_SUPPORT */
|
||||
|
||||
#endif /* !OPENSSL_NO_HW_4758_CCA */
|
||||
#endif /* !OPENSSL_NO_HW */
|
149
engines/e_4758_cca_err.c
Normal file
149
engines/e_4758_cca_err.c
Normal file
@ -0,0 +1,149 @@
|
||||
/* hw_4758_cca_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_4758_cca_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA CCA4758_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"},
|
||||
{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA CCA4758_str_reasons[]=
|
||||
{
|
||||
{CCA4758_R_ALREADY_LOADED ,"already loaded"},
|
||||
{CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"},
|
||||
{CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"},
|
||||
{CCA4758_R_DSO_FAILURE ,"dso failure"},
|
||||
{CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
|
||||
{CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
|
||||
{CCA4758_R_NOT_LOADED ,"not loaded"},
|
||||
{CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
|
||||
{CCA4758_R_UNIT_FAILURE ,"unit failure"},
|
||||
{CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CCA4758_LIB_NAME
|
||||
static ERR_STRING_DATA CCA4758_lib_name[]=
|
||||
{
|
||||
{0 ,CCA4758_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int CCA4758_lib_error_code=0;
|
||||
static int CCA4758_error_init=1;
|
||||
|
||||
static void ERR_load_CCA4758_strings(void)
|
||||
{
|
||||
if (CCA4758_lib_error_code == 0)
|
||||
CCA4758_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (CCA4758_error_init)
|
||||
{
|
||||
CCA4758_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_functs);
|
||||
ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef CCA4758_LIB_NAME
|
||||
CCA4758_lib_name->error = ERR_PACK(CCA4758_lib_error_code,0,0);
|
||||
ERR_load_strings(0,CCA4758_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_CCA4758_strings(void)
|
||||
{
|
||||
if (CCA4758_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_functs);
|
||||
ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef CCA4758_LIB_NAME
|
||||
ERR_unload_strings(0,CCA4758_lib_name);
|
||||
#endif
|
||||
CCA4758_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_CCA4758_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (CCA4758_lib_error_code == 0)
|
||||
CCA4758_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line);
|
||||
}
|
93
engines/e_4758_cca_err.h
Normal file
93
engines/e_4758_cca_err.h
Normal file
@ -0,0 +1,93 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CCA4758_ERR_H
|
||||
#define HEADER_CCA4758_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_CCA4758_strings(void);
|
||||
static void ERR_unload_CCA4758_strings(void);
|
||||
static void ERR_CCA4758_error(int function, int reason, char *file, int line);
|
||||
#define CCA4758err(f,r) ERR_CCA4758_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the CCA4758 functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define CCA4758_F_IBM_4758_CCA_CTRL 100
|
||||
#define CCA4758_F_IBM_4758_CCA_FINISH 101
|
||||
#define CCA4758_F_IBM_4758_CCA_INIT 102
|
||||
#define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103
|
||||
#define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104
|
||||
#define CCA4758_F_IBM_4758_CCA_SIGN 105
|
||||
#define CCA4758_F_IBM_4758_CCA_VERIFY 106
|
||||
|
||||
/* Reason codes. */
|
||||
#define CCA4758_R_ALREADY_LOADED 100
|
||||
#define CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD 101
|
||||
#define CCA4758_R_COMMAND_NOT_IMPLEMENTED 102
|
||||
#define CCA4758_R_DSO_FAILURE 103
|
||||
#define CCA4758_R_FAILED_LOADING_PRIVATE_KEY 104
|
||||
#define CCA4758_R_FAILED_LOADING_PUBLIC_KEY 105
|
||||
#define CCA4758_R_NOT_LOADED 106
|
||||
#define CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
|
||||
#define CCA4758_R_UNIT_FAILURE 108
|
||||
#define CCA4758_R_UNKNOWN_ALGORITHM_TYPE 109
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
1119
engines/e_aep.c
Normal file
1119
engines/e_aep.c
Normal file
File diff suppressed because it is too large
Load Diff
157
engines/e_aep_err.c
Normal file
157
engines/e_aep_err.c
Normal file
@ -0,0 +1,157 @@
|
||||
/* hw_aep_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_aep_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA AEPHK_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"},
|
||||
{ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA AEPHK_str_reasons[]=
|
||||
{
|
||||
{AEPHK_R_ALREADY_LOADED ,"already loaded"},
|
||||
{AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"},
|
||||
{AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"},
|
||||
{AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{AEPHK_R_FINALIZE_FAILED ,"finalize failed"},
|
||||
{AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"},
|
||||
{AEPHK_R_GET_RANDOM_FAILED ,"get random failed"},
|
||||
{AEPHK_R_INIT_FAILURE ,"init failure"},
|
||||
{AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"},
|
||||
{AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"},
|
||||
{AEPHK_R_NOT_LOADED ,"not loaded"},
|
||||
{AEPHK_R_OK ,"ok"},
|
||||
{AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"},
|
||||
{AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"},
|
||||
{AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
|
||||
{AEPHK_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef AEPHK_LIB_NAME
|
||||
static ERR_STRING_DATA AEPHK_lib_name[]=
|
||||
{
|
||||
{0 ,AEPHK_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int AEPHK_lib_error_code=0;
|
||||
static int AEPHK_error_init=1;
|
||||
|
||||
static void ERR_load_AEPHK_strings(void)
|
||||
{
|
||||
if (AEPHK_lib_error_code == 0)
|
||||
AEPHK_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (AEPHK_error_init)
|
||||
{
|
||||
AEPHK_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs);
|
||||
ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef AEPHK_LIB_NAME
|
||||
AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0);
|
||||
ERR_load_strings(0,AEPHK_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_AEPHK_strings(void)
|
||||
{
|
||||
if (AEPHK_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs);
|
||||
ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef AEPHK_LIB_NAME
|
||||
ERR_unload_strings(0,AEPHK_lib_name);
|
||||
#endif
|
||||
AEPHK_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_AEPHK_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (AEPHK_lib_error_code == 0)
|
||||
AEPHK_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line);
|
||||
}
|
101
engines/e_aep_err.h
Normal file
101
engines/e_aep_err.h
Normal file
@ -0,0 +1,101 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AEPHK_ERR_H
|
||||
#define HEADER_AEPHK_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_AEPHK_strings(void);
|
||||
static void ERR_unload_AEPHK_strings(void);
|
||||
static void ERR_AEPHK_error(int function, int reason, char *file, int line);
|
||||
#define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the AEPHK functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define AEPHK_F_AEP_CTRL 100
|
||||
#define AEPHK_F_AEP_FINISH 101
|
||||
#define AEPHK_F_AEP_GET_CONNECTION 102
|
||||
#define AEPHK_F_AEP_INIT 103
|
||||
#define AEPHK_F_AEP_MOD_EXP 104
|
||||
#define AEPHK_F_AEP_MOD_EXP_CRT 105
|
||||
#define AEPHK_F_AEP_RAND 106
|
||||
#define AEPHK_F_AEP_RSA_MOD_EXP 107
|
||||
|
||||
/* Reason codes. */
|
||||
#define AEPHK_R_ALREADY_LOADED 100
|
||||
#define AEPHK_R_CLOSE_HANDLES_FAILED 101
|
||||
#define AEPHK_R_CONNECTIONS_IN_USE 102
|
||||
#define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
|
||||
#define AEPHK_R_FINALIZE_FAILED 104
|
||||
#define AEPHK_R_GET_HANDLE_FAILED 105
|
||||
#define AEPHK_R_GET_RANDOM_FAILED 106
|
||||
#define AEPHK_R_INIT_FAILURE 107
|
||||
#define AEPHK_R_MISSING_KEY_COMPONENTS 108
|
||||
#define AEPHK_R_MOD_EXP_CRT_FAILED 109
|
||||
#define AEPHK_R_MOD_EXP_FAILED 110
|
||||
#define AEPHK_R_NOT_LOADED 111
|
||||
#define AEPHK_R_OK 112
|
||||
#define AEPHK_R_RETURN_CONNECTION_FAILED 113
|
||||
#define AEPHK_R_SETBNCALLBACK_FAILURE 114
|
||||
#define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116
|
||||
#define AEPHK_R_UNIT_FAILURE 115
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
592
engines/e_atalla.c
Normal file
592
engines/e_atalla.c
Normal file
@ -0,0 +1,592 @@
|
||||
/* crypto/engine/hw_atalla.c */
|
||||
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
#ifndef OPENSSL_NO_HW
|
||||
#ifndef OPENSSL_NO_HW_ATALLA
|
||||
|
||||
#ifdef FLAT_INC
|
||||
#include "atalla.h"
|
||||
#else
|
||||
#include "vendor_defns/atalla.h"
|
||||
#endif
|
||||
|
||||
#define ATALLA_LIB_NAME "atalla engine"
|
||||
#include "hw_atalla_err.c"
|
||||
|
||||
static int atalla_destroy(ENGINE *e);
|
||||
static int atalla_init(ENGINE *e);
|
||||
static int atalla_finish(ENGINE *e);
|
||||
static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
|
||||
|
||||
/* BIGNUM stuff */
|
||||
static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx);
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* RSA stuff */
|
||||
static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
|
||||
#endif
|
||||
/* This function is aliased to mod_exp (with the mont stuff dropped). */
|
||||
static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* DSA stuff */
|
||||
static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
|
||||
BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
|
||||
BN_CTX *ctx, BN_MONT_CTX *in_mont);
|
||||
static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
|
||||
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx);
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* DH stuff */
|
||||
/* This function is alised to mod_exp (with the DH and mont dropped). */
|
||||
static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
#endif
|
||||
|
||||
/* The definitions for control commands specific to this engine */
|
||||
#define ATALLA_CMD_SO_PATH ENGINE_CMD_BASE
|
||||
static const ENGINE_CMD_DEFN atalla_cmd_defns[] = {
|
||||
{ATALLA_CMD_SO_PATH,
|
||||
"SO_PATH",
|
||||
"Specifies the path to the 'atasi' shared library",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{0, NULL, NULL, 0}
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* Our internal RSA_METHOD that we provide pointers to */
|
||||
static RSA_METHOD atalla_rsa =
|
||||
{
|
||||
"Atalla RSA method",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
atalla_rsa_mod_exp,
|
||||
atalla_mod_exp_mont,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* Our internal DSA_METHOD that we provide pointers to */
|
||||
static DSA_METHOD atalla_dsa =
|
||||
{
|
||||
"Atalla DSA method",
|
||||
NULL, /* dsa_do_sign */
|
||||
NULL, /* dsa_sign_setup */
|
||||
NULL, /* dsa_do_verify */
|
||||
atalla_dsa_mod_exp, /* dsa_mod_exp */
|
||||
atalla_mod_exp_dsa, /* bn_mod_exp */
|
||||
NULL, /* init */
|
||||
NULL, /* finish */
|
||||
0, /* flags */
|
||||
NULL /* app_data */
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* Our internal DH_METHOD that we provide pointers to */
|
||||
static DH_METHOD atalla_dh =
|
||||
{
|
||||
"Atalla DH method",
|
||||
NULL,
|
||||
NULL,
|
||||
atalla_mod_exp_dh,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Constants used when creating the ENGINE */
|
||||
static const char *engine_atalla_id = "atalla";
|
||||
static const char *engine_atalla_name = "Atalla hardware engine support";
|
||||
|
||||
/* This internal function is used by ENGINE_atalla() and possibly by the
|
||||
* "dynamic" ENGINE support too */
|
||||
static int bind_helper(ENGINE *e)
|
||||
{
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
const RSA_METHOD *meth1;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
const DSA_METHOD *meth2;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
const DH_METHOD *meth3;
|
||||
#endif
|
||||
if(!ENGINE_set_id(e, engine_atalla_id) ||
|
||||
!ENGINE_set_name(e, engine_atalla_name) ||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
!ENGINE_set_RSA(e, &atalla_rsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
!ENGINE_set_DSA(e, &atalla_dsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
!ENGINE_set_DH(e, &atalla_dh) ||
|
||||
#endif
|
||||
!ENGINE_set_destroy_function(e, atalla_destroy) ||
|
||||
!ENGINE_set_init_function(e, atalla_init) ||
|
||||
!ENGINE_set_finish_function(e, atalla_finish) ||
|
||||
!ENGINE_set_ctrl_function(e, atalla_ctrl) ||
|
||||
!ENGINE_set_cmd_defns(e, atalla_cmd_defns))
|
||||
return 0;
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* We know that the "PKCS1_SSLeay()" functions hook properly
|
||||
* to the atalla-specific mod_exp and mod_exp_crt so we use
|
||||
* those functions. NB: We don't use ENGINE_openssl() or
|
||||
* anything "more generic" because something like the RSAref
|
||||
* code may not hook properly, and if you own one of these
|
||||
* cards then you have the right to do RSA operations on it
|
||||
* anyway! */
|
||||
meth1 = RSA_PKCS1_SSLeay();
|
||||
atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
|
||||
atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
|
||||
atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
|
||||
atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
|
||||
* bits. */
|
||||
meth2 = DSA_OpenSSL();
|
||||
atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
|
||||
atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
|
||||
atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* Much the same for Diffie-Hellman */
|
||||
meth3 = DH_OpenSSL();
|
||||
atalla_dh.generate_key = meth3->generate_key;
|
||||
atalla_dh.compute_key = meth3->compute_key;
|
||||
#endif
|
||||
|
||||
/* Ensure the atalla error handling is set up */
|
||||
ERR_load_ATALLA_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ENGINE *engine_atalla(void)
|
||||
{
|
||||
ENGINE *ret = ENGINE_new();
|
||||
if(!ret)
|
||||
return NULL;
|
||||
if(!bind_helper(ret))
|
||||
{
|
||||
ENGINE_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ENGINE_load_atalla(void)
|
||||
{
|
||||
/* Copied from eng_[openssl|dyn].c */
|
||||
ENGINE *toadd = engine_atalla();
|
||||
if(!toadd) return;
|
||||
ENGINE_add(toadd);
|
||||
ENGINE_free(toadd);
|
||||
ERR_clear_error();
|
||||
}
|
||||
|
||||
/* This is a process-global DSO handle used for loading and unloading
|
||||
* the Atalla library. NB: This is only set (or unset) during an
|
||||
* init() or finish() call (reference counts permitting) and they're
|
||||
* operating with global locks, so this should be thread-safe
|
||||
* implicitly. */
|
||||
static DSO *atalla_dso = NULL;
|
||||
|
||||
/* These are the function pointers that are (un)set when the library has
|
||||
* successfully (un)loaded. */
|
||||
static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
|
||||
static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
|
||||
static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
|
||||
|
||||
/* These are the static string constants for the DSO file name and the function
|
||||
* symbol names to bind to. Regrettably, the DSO name on *nix appears to be
|
||||
* "atasi.so" rather than something more consistent like "libatasi.so". At the
|
||||
* time of writing, I'm not sure what the file name on win32 is but clearly
|
||||
* native name translation is not possible (eg libatasi.so on *nix, and
|
||||
* atasi.dll on win32). For the purposes of testing, I have created a symbollic
|
||||
* link called "libatasi.so" so that we can use native name-translation - a
|
||||
* better solution will be needed. */
|
||||
static const char *ATALLA_LIBNAME = NULL;
|
||||
static const char *get_ATALLA_LIBNAME(void)
|
||||
{
|
||||
if(ATALLA_LIBNAME)
|
||||
return ATALLA_LIBNAME;
|
||||
return "atasi";
|
||||
}
|
||||
static void free_ATALLA_LIBNAME(void)
|
||||
{
|
||||
if(ATALLA_LIBNAME)
|
||||
OPENSSL_free((void*)ATALLA_LIBNAME);
|
||||
ATALLA_LIBNAME = NULL;
|
||||
}
|
||||
static long set_ATALLA_LIBNAME(const char *name)
|
||||
{
|
||||
free_ATALLA_LIBNAME();
|
||||
return (((ATALLA_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
|
||||
}
|
||||
static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
|
||||
static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
|
||||
static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
|
||||
|
||||
/* Destructor (complements the "ENGINE_atalla()" constructor) */
|
||||
static int atalla_destroy(ENGINE *e)
|
||||
{
|
||||
free_ATALLA_LIBNAME();
|
||||
/* Unload the atalla error strings so any error state including our
|
||||
* functs or reasons won't lead to a segfault (they simply get displayed
|
||||
* without corresponding string data because none will be found). */
|
||||
ERR_unload_ATALLA_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (de)initialisation functions. */
|
||||
static int atalla_init(ENGINE *e)
|
||||
{
|
||||
tfnASI_GetHardwareConfig *p1;
|
||||
tfnASI_RSAPrivateKeyOpFn *p2;
|
||||
tfnASI_GetPerformanceStatistics *p3;
|
||||
/* Not sure of the origin of this magic value, but Ben's code had it
|
||||
* and it seemed to have been working for a few people. :-) */
|
||||
unsigned int config_buf[1024];
|
||||
|
||||
if(atalla_dso != NULL)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_ALREADY_LOADED);
|
||||
goto err;
|
||||
}
|
||||
/* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
|
||||
* changed unfortunately because the Atalla drivers don't have
|
||||
* standard library names that can be platform-translated well. */
|
||||
/* TODO: Work out how to actually map to the names the Atalla
|
||||
* drivers really use - for now a symbollic link needs to be
|
||||
* created on the host system from libatasi.so to atasi.so on
|
||||
* unix variants. */
|
||||
atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
|
||||
if(atalla_dso == NULL)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
|
||||
atalla_dso, ATALLA_F1)) ||
|
||||
!(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
|
||||
atalla_dso, ATALLA_F2)) ||
|
||||
!(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
|
||||
atalla_dso, ATALLA_F3)))
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
/* Copy the pointers */
|
||||
p_Atalla_GetHardwareConfig = p1;
|
||||
p_Atalla_RSAPrivateKeyOpFn = p2;
|
||||
p_Atalla_GetPerformanceStatistics = p3;
|
||||
/* Perform a basic test to see if there's actually any unit
|
||||
* running. */
|
||||
if(p1(0L, config_buf) != 0)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
/* Everything's fine. */
|
||||
return 1;
|
||||
err:
|
||||
if(atalla_dso)
|
||||
DSO_free(atalla_dso);
|
||||
p_Atalla_GetHardwareConfig = NULL;
|
||||
p_Atalla_RSAPrivateKeyOpFn = NULL;
|
||||
p_Atalla_GetPerformanceStatistics = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atalla_finish(ENGINE *e)
|
||||
{
|
||||
free_ATALLA_LIBNAME();
|
||||
if(atalla_dso == NULL)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED);
|
||||
return 0;
|
||||
}
|
||||
if(!DSO_free(atalla_dso))
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_UNIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
atalla_dso = NULL;
|
||||
p_Atalla_GetHardwareConfig = NULL;
|
||||
p_Atalla_RSAPrivateKeyOpFn = NULL;
|
||||
p_Atalla_GetPerformanceStatistics = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
|
||||
{
|
||||
int initialised = ((atalla_dso == NULL) ? 0 : 1);
|
||||
switch(cmd)
|
||||
{
|
||||
case ATALLA_CMD_SO_PATH:
|
||||
if(p == NULL)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_CTRL,ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
if(initialised)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_ALREADY_LOADED);
|
||||
return 0;
|
||||
}
|
||||
return set_ATALLA_LIBNAME((const char *)p);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx)
|
||||
{
|
||||
/* I need somewhere to store temporary serialised values for
|
||||
* use with the Atalla API calls. A neat cheat - I'll use
|
||||
* BIGNUMs from the BN_CTX but access their arrays directly as
|
||||
* byte arrays <grin>. This way I don't have to clean anything
|
||||
* up. */
|
||||
BIGNUM *modulus;
|
||||
BIGNUM *exponent;
|
||||
BIGNUM *argument;
|
||||
BIGNUM *result;
|
||||
RSAPrivateKey keydata;
|
||||
int to_return, numbytes;
|
||||
|
||||
modulus = exponent = argument = result = NULL;
|
||||
to_return = 0; /* expect failure */
|
||||
|
||||
if(!atalla_dso)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the params */
|
||||
BN_CTX_start(ctx);
|
||||
modulus = BN_CTX_get(ctx);
|
||||
exponent = BN_CTX_get(ctx);
|
||||
argument = BN_CTX_get(ctx);
|
||||
result = BN_CTX_get(ctx);
|
||||
if (!result)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_CTX_FULL);
|
||||
goto err;
|
||||
}
|
||||
if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) ||
|
||||
!bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top))
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_EXPAND_FAIL);
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the key-data */
|
||||
memset(&keydata, 0,sizeof keydata);
|
||||
numbytes = BN_num_bytes(m);
|
||||
memset(exponent->d, 0, numbytes);
|
||||
memset(modulus->d, 0, numbytes);
|
||||
BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p));
|
||||
BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m));
|
||||
keydata.privateExponent.data = (unsigned char *)exponent->d;
|
||||
keydata.privateExponent.len = numbytes;
|
||||
keydata.modulus.data = (unsigned char *)modulus->d;
|
||||
keydata.modulus.len = numbytes;
|
||||
/* Prepare the argument */
|
||||
memset(argument->d, 0, numbytes);
|
||||
memset(result->d, 0, numbytes);
|
||||
BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a));
|
||||
/* Perform the operation */
|
||||
if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d,
|
||||
(unsigned char *)argument->d,
|
||||
keydata.modulus.len) != 0)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_REQUEST_FAILED);
|
||||
goto err;
|
||||
}
|
||||
/* Convert the response */
|
||||
BN_bin2bn((unsigned char *)result->d, numbytes, r);
|
||||
to_return = 1;
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
|
||||
{
|
||||
BN_CTX *ctx = NULL;
|
||||
int to_return = 0;
|
||||
|
||||
if(!atalla_dso)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
if((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
if(!rsa->d || !rsa->n)
|
||||
{
|
||||
ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS);
|
||||
goto err;
|
||||
}
|
||||
to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx);
|
||||
err:
|
||||
if(ctx)
|
||||
BN_CTX_free(ctx);
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* This code was liberated and adapted from the commented-out code in
|
||||
* dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
|
||||
* (it doesn't have a CRT form for RSA), this function means that an
|
||||
* Atalla system running with a DSA server certificate can handshake
|
||||
* around 5 or 6 times faster/more than an equivalent system running with
|
||||
* RSA. Just check out the "signs" statistics from the RSA and DSA parts
|
||||
* of "openssl speed -engine atalla dsa1024 rsa1024". */
|
||||
static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
|
||||
BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
|
||||
BN_CTX *ctx, BN_MONT_CTX *in_mont)
|
||||
{
|
||||
BIGNUM t;
|
||||
int to_return = 0;
|
||||
|
||||
BN_init(&t);
|
||||
/* let rr = a1 ^ p1 mod m */
|
||||
if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
|
||||
/* let t = a2 ^ p2 mod m */
|
||||
if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
|
||||
/* let rr = rr * t mod m */
|
||||
if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
|
||||
to_return = 1;
|
||||
end:
|
||||
BN_free(&t);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
|
||||
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return atalla_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is aliased to mod_exp (with the mont stuff dropped). */
|
||||
static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return atalla_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* This function is aliased to mod_exp (with the dh and mont dropped). */
|
||||
static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return atalla_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This stuff is needed if this ENGINE is being compiled into a self-contained
|
||||
* shared-library. */
|
||||
#ifdef ENGINE_DYNAMIC_SUPPORT
|
||||
static int bind_fn(ENGINE *e, const char *id)
|
||||
{
|
||||
if(id && (strcmp(id, engine_atalla_id) != 0))
|
||||
return 0;
|
||||
if(!bind_helper(e))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
|
||||
#endif /* ENGINE_DYNAMIC_SUPPORT */
|
||||
|
||||
#endif /* !OPENSSL_NO_HW_ATALLA */
|
||||
#endif /* !OPENSSL_NO_HW */
|
145
engines/e_atalla_err.c
Normal file
145
engines/e_atalla_err.c
Normal file
@ -0,0 +1,145 @@
|
||||
/* hw_atalla_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_atalla_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA ATALLA_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"},
|
||||
{ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"},
|
||||
{ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"},
|
||||
{ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"},
|
||||
{ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ATALLA_str_reasons[]=
|
||||
{
|
||||
{ATALLA_R_ALREADY_LOADED ,"already loaded"},
|
||||
{ATALLA_R_BN_CTX_FULL ,"bn ctx full"},
|
||||
{ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"},
|
||||
{ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{ATALLA_R_NOT_LOADED ,"not loaded"},
|
||||
{ATALLA_R_REQUEST_FAILED ,"request failed"},
|
||||
{ATALLA_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ATALLA_LIB_NAME
|
||||
static ERR_STRING_DATA ATALLA_lib_name[]=
|
||||
{
|
||||
{0 ,ATALLA_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int ATALLA_lib_error_code=0;
|
||||
static int ATALLA_error_init=1;
|
||||
|
||||
static void ERR_load_ATALLA_strings(void)
|
||||
{
|
||||
if (ATALLA_lib_error_code == 0)
|
||||
ATALLA_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (ATALLA_error_init)
|
||||
{
|
||||
ATALLA_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs);
|
||||
ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef ATALLA_LIB_NAME
|
||||
ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0);
|
||||
ERR_load_strings(0,ATALLA_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_ATALLA_strings(void)
|
||||
{
|
||||
if (ATALLA_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs);
|
||||
ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef ATALLA_LIB_NAME
|
||||
ERR_unload_strings(0,ATALLA_lib_name);
|
||||
#endif
|
||||
ATALLA_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_ATALLA_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (ATALLA_lib_error_code == 0)
|
||||
ATALLA_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line);
|
||||
}
|
89
engines/e_atalla_err.h
Normal file
89
engines/e_atalla_err.h
Normal file
@ -0,0 +1,89 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ATALLA_ERR_H
|
||||
#define HEADER_ATALLA_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_ATALLA_strings(void);
|
||||
static void ERR_unload_ATALLA_strings(void);
|
||||
static void ERR_ATALLA_error(int function, int reason, char *file, int line);
|
||||
#define ATALLAerr(f,r) ERR_ATALLA_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the ATALLA functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define ATALLA_F_ATALLA_CTRL 100
|
||||
#define ATALLA_F_ATALLA_FINISH 101
|
||||
#define ATALLA_F_ATALLA_INIT 102
|
||||
#define ATALLA_F_ATALLA_MOD_EXP 103
|
||||
#define ATALLA_F_ATALLA_RSA_MOD_EXP 104
|
||||
|
||||
/* Reason codes. */
|
||||
#define ATALLA_R_ALREADY_LOADED 100
|
||||
#define ATALLA_R_BN_CTX_FULL 101
|
||||
#define ATALLA_R_BN_EXPAND_FAIL 102
|
||||
#define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
|
||||
#define ATALLA_R_MISSING_KEY_COMPONENTS 104
|
||||
#define ATALLA_R_NOT_LOADED 105
|
||||
#define ATALLA_R_REQUEST_FAILED 106
|
||||
#define ATALLA_R_UNIT_FAILURE 107
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
995
engines/e_cswift.c
Normal file
995
engines/e_cswift.c
Normal file
@ -0,0 +1,995 @@
|
||||
/* crypto/engine/hw_cswift.c */
|
||||
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
#ifndef OPENSSL_NO_HW
|
||||
#ifndef OPENSSL_NO_HW_CSWIFT
|
||||
|
||||
/* Attribution notice: Rainbow have generously allowed me to reproduce
|
||||
* the necessary definitions here from their API. This means the support
|
||||
* can build independently of whether application builders have the
|
||||
* API or hardware. This will allow developers to easily produce software
|
||||
* that has latent hardware support for any users that have accelerators
|
||||
* installed, without the developers themselves needing anything extra.
|
||||
*
|
||||
* I have only clipped the parts from the CryptoSwift header files that
|
||||
* are (or seem) relevant to the CryptoSwift support code. This is
|
||||
* simply to keep the file sizes reasonable.
|
||||
* [Geoff]
|
||||
*/
|
||||
#ifdef FLAT_INC
|
||||
#include "cswift.h"
|
||||
#else
|
||||
#include "vendor_defns/cswift.h"
|
||||
#endif
|
||||
|
||||
#define CSWIFT_LIB_NAME "cswift engine"
|
||||
#include "hw_cswift_err.c"
|
||||
|
||||
static int cswift_destroy(ENGINE *e);
|
||||
static int cswift_init(ENGINE *e);
|
||||
static int cswift_finish(ENGINE *e);
|
||||
static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
|
||||
|
||||
/* BIGNUM stuff */
|
||||
static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx);
|
||||
static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
|
||||
const BIGNUM *iqmp, BN_CTX *ctx);
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* RSA stuff */
|
||||
static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
|
||||
#endif
|
||||
/* This function is aliased to mod_exp (with the mont stuff dropped). */
|
||||
static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* DSA stuff */
|
||||
static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa);
|
||||
static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
|
||||
DSA_SIG *sig, DSA *dsa);
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* DH stuff */
|
||||
/* This function is alised to mod_exp (with the DH and mont dropped). */
|
||||
static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
#endif
|
||||
|
||||
/* RAND stuff */
|
||||
static int cswift_rand_bytes(unsigned char *buf, int num);
|
||||
static int cswift_rand_status(void);
|
||||
|
||||
/* The definitions for control commands specific to this engine */
|
||||
#define CSWIFT_CMD_SO_PATH ENGINE_CMD_BASE
|
||||
static const ENGINE_CMD_DEFN cswift_cmd_defns[] = {
|
||||
{CSWIFT_CMD_SO_PATH,
|
||||
"SO_PATH",
|
||||
"Specifies the path to the 'cswift' shared library",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{0, NULL, NULL, 0}
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* Our internal RSA_METHOD that we provide pointers to */
|
||||
static RSA_METHOD cswift_rsa =
|
||||
{
|
||||
"CryptoSwift RSA method",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
cswift_rsa_mod_exp,
|
||||
cswift_mod_exp_mont,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* Our internal DSA_METHOD that we provide pointers to */
|
||||
static DSA_METHOD cswift_dsa =
|
||||
{
|
||||
"CryptoSwift DSA method",
|
||||
cswift_dsa_sign,
|
||||
NULL, /* dsa_sign_setup */
|
||||
cswift_dsa_verify,
|
||||
NULL, /* dsa_mod_exp */
|
||||
NULL, /* bn_mod_exp */
|
||||
NULL, /* init */
|
||||
NULL, /* finish */
|
||||
0, /* flags */
|
||||
NULL /* app_data */
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* Our internal DH_METHOD that we provide pointers to */
|
||||
static DH_METHOD cswift_dh =
|
||||
{
|
||||
"CryptoSwift DH method",
|
||||
NULL,
|
||||
NULL,
|
||||
cswift_mod_exp_dh,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
static RAND_METHOD cswift_random =
|
||||
{
|
||||
/* "CryptoSwift RAND method", */
|
||||
NULL,
|
||||
cswift_rand_bytes,
|
||||
NULL,
|
||||
NULL,
|
||||
cswift_rand_bytes,
|
||||
cswift_rand_status,
|
||||
};
|
||||
|
||||
|
||||
/* Constants used when creating the ENGINE */
|
||||
static const char *engine_cswift_id = "cswift";
|
||||
static const char *engine_cswift_name = "CryptoSwift hardware engine support";
|
||||
|
||||
/* This internal function is used by ENGINE_cswift() and possibly by the
|
||||
* "dynamic" ENGINE support too */
|
||||
static int bind_helper(ENGINE *e)
|
||||
{
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
const RSA_METHOD *meth1;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
const DH_METHOD *meth2;
|
||||
#endif
|
||||
if(!ENGINE_set_id(e, engine_cswift_id) ||
|
||||
!ENGINE_set_name(e, engine_cswift_name) ||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
!ENGINE_set_RSA(e, &cswift_rsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
!ENGINE_set_DSA(e, &cswift_dsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
!ENGINE_set_DH(e, &cswift_dh) ||
|
||||
#endif
|
||||
!ENGINE_set_RAND(e, &cswift_random) ||
|
||||
!ENGINE_set_destroy_function(e, cswift_destroy) ||
|
||||
!ENGINE_set_init_function(e, cswift_init) ||
|
||||
!ENGINE_set_finish_function(e, cswift_finish) ||
|
||||
!ENGINE_set_ctrl_function(e, cswift_ctrl) ||
|
||||
!ENGINE_set_cmd_defns(e, cswift_cmd_defns))
|
||||
return 0;
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* We know that the "PKCS1_SSLeay()" functions hook properly
|
||||
* to the cswift-specific mod_exp and mod_exp_crt so we use
|
||||
* those functions. NB: We don't use ENGINE_openssl() or
|
||||
* anything "more generic" because something like the RSAref
|
||||
* code may not hook properly, and if you own one of these
|
||||
* cards then you have the right to do RSA operations on it
|
||||
* anyway! */
|
||||
meth1 = RSA_PKCS1_SSLeay();
|
||||
cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
|
||||
cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
|
||||
cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
|
||||
cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* Much the same for Diffie-Hellman */
|
||||
meth2 = DH_OpenSSL();
|
||||
cswift_dh.generate_key = meth2->generate_key;
|
||||
cswift_dh.compute_key = meth2->compute_key;
|
||||
#endif
|
||||
|
||||
/* Ensure the cswift error handling is set up */
|
||||
ERR_load_CSWIFT_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ENGINE *engine_cswift(void)
|
||||
{
|
||||
ENGINE *ret = ENGINE_new();
|
||||
if(!ret)
|
||||
return NULL;
|
||||
if(!bind_helper(ret))
|
||||
{
|
||||
ENGINE_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ENGINE_load_cswift(void)
|
||||
{
|
||||
/* Copied from eng_[openssl|dyn].c */
|
||||
ENGINE *toadd = engine_cswift();
|
||||
if(!toadd) return;
|
||||
ENGINE_add(toadd);
|
||||
ENGINE_free(toadd);
|
||||
ERR_clear_error();
|
||||
}
|
||||
|
||||
/* This is a process-global DSO handle used for loading and unloading
|
||||
* the CryptoSwift library. NB: This is only set (or unset) during an
|
||||
* init() or finish() call (reference counts permitting) and they're
|
||||
* operating with global locks, so this should be thread-safe
|
||||
* implicitly. */
|
||||
static DSO *cswift_dso = NULL;
|
||||
|
||||
/* These are the function pointers that are (un)set when the library has
|
||||
* successfully (un)loaded. */
|
||||
t_swAcquireAccContext *p_CSwift_AcquireAccContext = NULL;
|
||||
t_swAttachKeyParam *p_CSwift_AttachKeyParam = NULL;
|
||||
t_swSimpleRequest *p_CSwift_SimpleRequest = NULL;
|
||||
t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL;
|
||||
|
||||
/* Used in the DSO operations. */
|
||||
static const char *CSWIFT_LIBNAME = NULL;
|
||||
static const char *get_CSWIFT_LIBNAME(void)
|
||||
{
|
||||
if(CSWIFT_LIBNAME)
|
||||
return CSWIFT_LIBNAME;
|
||||
return "swift";
|
||||
}
|
||||
static void free_CSWIFT_LIBNAME(void)
|
||||
{
|
||||
if(CSWIFT_LIBNAME)
|
||||
OPENSSL_free((void*)CSWIFT_LIBNAME);
|
||||
CSWIFT_LIBNAME = NULL;
|
||||
}
|
||||
static long set_CSWIFT_LIBNAME(const char *name)
|
||||
{
|
||||
free_CSWIFT_LIBNAME();
|
||||
return (((CSWIFT_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
|
||||
}
|
||||
static const char *CSWIFT_F1 = "swAcquireAccContext";
|
||||
static const char *CSWIFT_F2 = "swAttachKeyParam";
|
||||
static const char *CSWIFT_F3 = "swSimpleRequest";
|
||||
static const char *CSWIFT_F4 = "swReleaseAccContext";
|
||||
|
||||
|
||||
/* CryptoSwift library functions and mechanics - these are used by the
|
||||
* higher-level functions further down. NB: As and where there's no
|
||||
* error checking, take a look lower down where these functions are
|
||||
* called, the checking and error handling is probably down there. */
|
||||
|
||||
/* utility function to obtain a context */
|
||||
static int get_context(SW_CONTEXT_HANDLE *hac)
|
||||
{
|
||||
SW_STATUS status;
|
||||
|
||||
status = p_CSwift_AcquireAccContext(hac);
|
||||
if(status != SW_OK)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* similarly to release one. */
|
||||
static void release_context(SW_CONTEXT_HANDLE hac)
|
||||
{
|
||||
p_CSwift_ReleaseAccContext(hac);
|
||||
}
|
||||
|
||||
/* Destructor (complements the "ENGINE_cswift()" constructor) */
|
||||
static int cswift_destroy(ENGINE *e)
|
||||
{
|
||||
free_CSWIFT_LIBNAME();
|
||||
ERR_unload_CSWIFT_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (de)initialisation functions. */
|
||||
static int cswift_init(ENGINE *e)
|
||||
{
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
t_swAcquireAccContext *p1;
|
||||
t_swAttachKeyParam *p2;
|
||||
t_swSimpleRequest *p3;
|
||||
t_swReleaseAccContext *p4;
|
||||
|
||||
if(cswift_dso != NULL)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_ALREADY_LOADED);
|
||||
goto err;
|
||||
}
|
||||
/* Attempt to load libswift.so/swift.dll/whatever. */
|
||||
cswift_dso = DSO_load(NULL, get_CSWIFT_LIBNAME(), NULL, 0);
|
||||
if(cswift_dso == NULL)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
if(!(p1 = (t_swAcquireAccContext *)
|
||||
DSO_bind_func(cswift_dso, CSWIFT_F1)) ||
|
||||
!(p2 = (t_swAttachKeyParam *)
|
||||
DSO_bind_func(cswift_dso, CSWIFT_F2)) ||
|
||||
!(p3 = (t_swSimpleRequest *)
|
||||
DSO_bind_func(cswift_dso, CSWIFT_F3)) ||
|
||||
!(p4 = (t_swReleaseAccContext *)
|
||||
DSO_bind_func(cswift_dso, CSWIFT_F4)))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED);
|
||||
goto err;
|
||||
}
|
||||
/* Copy the pointers */
|
||||
p_CSwift_AcquireAccContext = p1;
|
||||
p_CSwift_AttachKeyParam = p2;
|
||||
p_CSwift_SimpleRequest = p3;
|
||||
p_CSwift_ReleaseAccContext = p4;
|
||||
/* Try and get a context - if not, we may have a DSO but no
|
||||
* accelerator! */
|
||||
if(!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
release_context(hac);
|
||||
/* Everything's fine. */
|
||||
return 1;
|
||||
err:
|
||||
if(cswift_dso)
|
||||
DSO_free(cswift_dso);
|
||||
p_CSwift_AcquireAccContext = NULL;
|
||||
p_CSwift_AttachKeyParam = NULL;
|
||||
p_CSwift_SimpleRequest = NULL;
|
||||
p_CSwift_ReleaseAccContext = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cswift_finish(ENGINE *e)
|
||||
{
|
||||
free_CSWIFT_LIBNAME();
|
||||
if(cswift_dso == NULL)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED);
|
||||
return 0;
|
||||
}
|
||||
if(!DSO_free(cswift_dso))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_UNIT_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
cswift_dso = NULL;
|
||||
p_CSwift_AcquireAccContext = NULL;
|
||||
p_CSwift_AttachKeyParam = NULL;
|
||||
p_CSwift_SimpleRequest = NULL;
|
||||
p_CSwift_ReleaseAccContext = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
|
||||
{
|
||||
int initialised = ((cswift_dso == NULL) ? 0 : 1);
|
||||
switch(cmd)
|
||||
{
|
||||
case CSWIFT_CMD_SO_PATH:
|
||||
if(p == NULL)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
if(initialised)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED);
|
||||
return 0;
|
||||
}
|
||||
return set_CSWIFT_LIBNAME((const char *)p);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Un petit mod_exp */
|
||||
static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx)
|
||||
{
|
||||
/* I need somewhere to store temporary serialised values for
|
||||
* use with the CryptoSwift API calls. A neat cheat - I'll use
|
||||
* BIGNUMs from the BN_CTX but access their arrays directly as
|
||||
* byte arrays <grin>. This way I don't have to clean anything
|
||||
* up. */
|
||||
BIGNUM *modulus;
|
||||
BIGNUM *exponent;
|
||||
BIGNUM *argument;
|
||||
BIGNUM *result;
|
||||
SW_STATUS sw_status;
|
||||
SW_LARGENUMBER arg, res;
|
||||
SW_PARAM sw_param;
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
int to_return, acquired;
|
||||
|
||||
modulus = exponent = argument = result = NULL;
|
||||
to_return = 0; /* expect failure */
|
||||
acquired = 0;
|
||||
|
||||
if(!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
acquired = 1;
|
||||
/* Prepare the params */
|
||||
BN_CTX_start(ctx);
|
||||
modulus = BN_CTX_get(ctx);
|
||||
exponent = BN_CTX_get(ctx);
|
||||
argument = BN_CTX_get(ctx);
|
||||
result = BN_CTX_get(ctx);
|
||||
if(!result)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_CTX_FULL);
|
||||
goto err;
|
||||
}
|
||||
if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, p->top) ||
|
||||
!bn_wexpand(argument, a->top) || !bn_wexpand(result, m->top))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_EXPAND_FAIL);
|
||||
goto err;
|
||||
}
|
||||
sw_param.type = SW_ALG_EXP;
|
||||
sw_param.up.exp.modulus.nbytes = BN_bn2bin(m,
|
||||
(unsigned char *)modulus->d);
|
||||
sw_param.up.exp.modulus.value = (unsigned char *)modulus->d;
|
||||
sw_param.up.exp.exponent.nbytes = BN_bn2bin(p,
|
||||
(unsigned char *)exponent->d);
|
||||
sw_param.up.exp.exponent.value = (unsigned char *)exponent->d;
|
||||
/* Attach the key params */
|
||||
sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
|
||||
switch(sw_status)
|
||||
{
|
||||
case SW_OK:
|
||||
break;
|
||||
case SW_ERR_INPUT_SIZE:
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BAD_KEY_SIZE);
|
||||
goto err;
|
||||
default:
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the argument and response */
|
||||
arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
|
||||
arg.value = (unsigned char *)argument->d;
|
||||
res.nbytes = BN_num_bytes(m);
|
||||
memset(result->d, 0, res.nbytes);
|
||||
res.value = (unsigned char *)result->d;
|
||||
/* Perform the operation */
|
||||
if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1,
|
||||
&res, 1)) != SW_OK)
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
goto err;
|
||||
}
|
||||
/* Convert the response */
|
||||
BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
|
||||
to_return = 1;
|
||||
err:
|
||||
if(acquired)
|
||||
release_context(hac);
|
||||
BN_CTX_end(ctx);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
/* Un petit mod_exp chinois */
|
||||
static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *q, const BIGNUM *dmp1,
|
||||
const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
|
||||
{
|
||||
SW_STATUS sw_status;
|
||||
SW_LARGENUMBER arg, res;
|
||||
SW_PARAM sw_param;
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
BIGNUM *rsa_p = NULL;
|
||||
BIGNUM *rsa_q = NULL;
|
||||
BIGNUM *rsa_dmp1 = NULL;
|
||||
BIGNUM *rsa_dmq1 = NULL;
|
||||
BIGNUM *rsa_iqmp = NULL;
|
||||
BIGNUM *argument = NULL;
|
||||
BIGNUM *result = NULL;
|
||||
int to_return = 0; /* expect failure */
|
||||
int acquired = 0;
|
||||
|
||||
if(!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
acquired = 1;
|
||||
/* Prepare the params */
|
||||
BN_CTX_start(ctx);
|
||||
rsa_p = BN_CTX_get(ctx);
|
||||
rsa_q = BN_CTX_get(ctx);
|
||||
rsa_dmp1 = BN_CTX_get(ctx);
|
||||
rsa_dmq1 = BN_CTX_get(ctx);
|
||||
rsa_iqmp = BN_CTX_get(ctx);
|
||||
argument = BN_CTX_get(ctx);
|
||||
result = BN_CTX_get(ctx);
|
||||
if(!result)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL);
|
||||
goto err;
|
||||
}
|
||||
if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) ||
|
||||
!bn_wexpand(rsa_dmp1, dmp1->top) ||
|
||||
!bn_wexpand(rsa_dmq1, dmq1->top) ||
|
||||
!bn_wexpand(rsa_iqmp, iqmp->top) ||
|
||||
!bn_wexpand(argument, a->top) ||
|
||||
!bn_wexpand(result, p->top + q->top))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
|
||||
goto err;
|
||||
}
|
||||
sw_param.type = SW_ALG_CRT;
|
||||
sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d);
|
||||
sw_param.up.crt.p.value = (unsigned char *)rsa_p->d;
|
||||
sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d);
|
||||
sw_param.up.crt.q.value = (unsigned char *)rsa_q->d;
|
||||
sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1,
|
||||
(unsigned char *)rsa_dmp1->d);
|
||||
sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d;
|
||||
sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1,
|
||||
(unsigned char *)rsa_dmq1->d);
|
||||
sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d;
|
||||
sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp,
|
||||
(unsigned char *)rsa_iqmp->d);
|
||||
sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d;
|
||||
/* Attach the key params */
|
||||
sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
|
||||
switch(sw_status)
|
||||
{
|
||||
case SW_OK:
|
||||
break;
|
||||
case SW_ERR_INPUT_SIZE:
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BAD_KEY_SIZE);
|
||||
goto err;
|
||||
default:
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the argument and response */
|
||||
arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
|
||||
arg.value = (unsigned char *)argument->d;
|
||||
res.nbytes = 2 * BN_num_bytes(p);
|
||||
memset(result->d, 0, res.nbytes);
|
||||
res.value = (unsigned char *)result->d;
|
||||
/* Perform the operation */
|
||||
if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1,
|
||||
&res, 1)) != SW_OK)
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
goto err;
|
||||
}
|
||||
/* Convert the response */
|
||||
BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
|
||||
to_return = 1;
|
||||
err:
|
||||
if(acquired)
|
||||
release_context(hac);
|
||||
BN_CTX_end(ctx);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
int to_return = 0;
|
||||
|
||||
if((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS);
|
||||
goto err;
|
||||
}
|
||||
to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
|
||||
rsa->dmq1, rsa->iqmp, ctx);
|
||||
err:
|
||||
if(ctx)
|
||||
BN_CTX_free(ctx);
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is aliased to mod_exp (with the mont stuff dropped). */
|
||||
static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return cswift_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa)
|
||||
{
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
SW_PARAM sw_param;
|
||||
SW_STATUS sw_status;
|
||||
SW_LARGENUMBER arg, res;
|
||||
unsigned char *ptr;
|
||||
BN_CTX *ctx;
|
||||
BIGNUM *dsa_p = NULL;
|
||||
BIGNUM *dsa_q = NULL;
|
||||
BIGNUM *dsa_g = NULL;
|
||||
BIGNUM *dsa_key = NULL;
|
||||
BIGNUM *result = NULL;
|
||||
DSA_SIG *to_return = NULL;
|
||||
int acquired = 0;
|
||||
|
||||
if((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
if(!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
acquired = 1;
|
||||
/* Prepare the params */
|
||||
BN_CTX_start(ctx);
|
||||
dsa_p = BN_CTX_get(ctx);
|
||||
dsa_q = BN_CTX_get(ctx);
|
||||
dsa_g = BN_CTX_get(ctx);
|
||||
dsa_key = BN_CTX_get(ctx);
|
||||
result = BN_CTX_get(ctx);
|
||||
if(!result)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_CTX_FULL);
|
||||
goto err;
|
||||
}
|
||||
if(!bn_wexpand(dsa_p, dsa->p->top) ||
|
||||
!bn_wexpand(dsa_q, dsa->q->top) ||
|
||||
!bn_wexpand(dsa_g, dsa->g->top) ||
|
||||
!bn_wexpand(dsa_key, dsa->priv_key->top) ||
|
||||
!bn_wexpand(result, dsa->p->top))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_EXPAND_FAIL);
|
||||
goto err;
|
||||
}
|
||||
sw_param.type = SW_ALG_DSA;
|
||||
sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
|
||||
(unsigned char *)dsa_p->d);
|
||||
sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
|
||||
sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
|
||||
(unsigned char *)dsa_q->d);
|
||||
sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
|
||||
sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
|
||||
(unsigned char *)dsa_g->d);
|
||||
sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
|
||||
sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->priv_key,
|
||||
(unsigned char *)dsa_key->d);
|
||||
sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
|
||||
/* Attach the key params */
|
||||
sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
|
||||
switch(sw_status)
|
||||
{
|
||||
case SW_OK:
|
||||
break;
|
||||
case SW_ERR_INPUT_SIZE:
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BAD_KEY_SIZE);
|
||||
goto err;
|
||||
default:
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the argument and response */
|
||||
arg.nbytes = dlen;
|
||||
arg.value = (unsigned char *)dgst;
|
||||
res.nbytes = BN_num_bytes(dsa->p);
|
||||
memset(result->d, 0, res.nbytes);
|
||||
res.value = (unsigned char *)result->d;
|
||||
/* Perform the operation */
|
||||
sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_SIGN, &arg, 1,
|
||||
&res, 1);
|
||||
if(sw_status != SW_OK)
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
goto err;
|
||||
}
|
||||
/* Convert the response */
|
||||
ptr = (unsigned char *)result->d;
|
||||
if((to_return = DSA_SIG_new()) == NULL)
|
||||
goto err;
|
||||
to_return->r = BN_bin2bn((unsigned char *)result->d, 20, NULL);
|
||||
to_return->s = BN_bin2bn((unsigned char *)result->d + 20, 20, NULL);
|
||||
|
||||
err:
|
||||
if(acquired)
|
||||
release_context(hac);
|
||||
if(ctx)
|
||||
{
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
||||
static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
|
||||
DSA_SIG *sig, DSA *dsa)
|
||||
{
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
SW_PARAM sw_param;
|
||||
SW_STATUS sw_status;
|
||||
SW_LARGENUMBER arg[2], res;
|
||||
unsigned long sig_result;
|
||||
BN_CTX *ctx;
|
||||
BIGNUM *dsa_p = NULL;
|
||||
BIGNUM *dsa_q = NULL;
|
||||
BIGNUM *dsa_g = NULL;
|
||||
BIGNUM *dsa_key = NULL;
|
||||
BIGNUM *argument = NULL;
|
||||
int to_return = -1;
|
||||
int acquired = 0;
|
||||
|
||||
if((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
if(!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
acquired = 1;
|
||||
/* Prepare the params */
|
||||
BN_CTX_start(ctx);
|
||||
dsa_p = BN_CTX_get(ctx);
|
||||
dsa_q = BN_CTX_get(ctx);
|
||||
dsa_g = BN_CTX_get(ctx);
|
||||
dsa_key = BN_CTX_get(ctx);
|
||||
argument = BN_CTX_get(ctx);
|
||||
if(!argument)
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_CTX_FULL);
|
||||
goto err;
|
||||
}
|
||||
if(!bn_wexpand(dsa_p, dsa->p->top) ||
|
||||
!bn_wexpand(dsa_q, dsa->q->top) ||
|
||||
!bn_wexpand(dsa_g, dsa->g->top) ||
|
||||
!bn_wexpand(dsa_key, dsa->pub_key->top) ||
|
||||
!bn_wexpand(argument, 40))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_EXPAND_FAIL);
|
||||
goto err;
|
||||
}
|
||||
sw_param.type = SW_ALG_DSA;
|
||||
sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
|
||||
(unsigned char *)dsa_p->d);
|
||||
sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
|
||||
sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
|
||||
(unsigned char *)dsa_q->d);
|
||||
sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
|
||||
sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
|
||||
(unsigned char *)dsa_g->d);
|
||||
sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
|
||||
sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key,
|
||||
(unsigned char *)dsa_key->d);
|
||||
sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
|
||||
/* Attach the key params */
|
||||
sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
|
||||
switch(sw_status)
|
||||
{
|
||||
case SW_OK:
|
||||
break;
|
||||
case SW_ERR_INPUT_SIZE:
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BAD_KEY_SIZE);
|
||||
goto err;
|
||||
default:
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
/* Prepare the argument and response */
|
||||
arg[0].nbytes = dgst_len;
|
||||
arg[0].value = (unsigned char *)dgst;
|
||||
arg[1].nbytes = 40;
|
||||
arg[1].value = (unsigned char *)argument->d;
|
||||
memset(arg[1].value, 0, 40);
|
||||
BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
|
||||
BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
|
||||
res.nbytes = 4; /* unsigned long */
|
||||
res.value = (unsigned char *)(&sig_result);
|
||||
/* Perform the operation */
|
||||
sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2,
|
||||
&res, 1);
|
||||
if(sw_status != SW_OK)
|
||||
{
|
||||
char tmpbuf[DECIMAL_SIZE(sw_status)+1];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", sw_status);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
|
||||
goto err;
|
||||
}
|
||||
/* Convert the response */
|
||||
to_return = ((sig_result == 0) ? 0 : 1);
|
||||
|
||||
err:
|
||||
if(acquired)
|
||||
release_context(hac);
|
||||
if(ctx)
|
||||
{
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* This function is aliased to mod_exp (with the dh and mont dropped). */
|
||||
static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return cswift_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Random bytes are good */
|
||||
static int cswift_rand_bytes(unsigned char *buf, int num)
|
||||
{
|
||||
SW_CONTEXT_HANDLE hac;
|
||||
SW_STATUS swrc;
|
||||
SW_LARGENUMBER largenum;
|
||||
size_t nbytes = 0;
|
||||
int acquired = 0;
|
||||
int to_return = 0; /* assume failure */
|
||||
|
||||
if (!get_context(&hac))
|
||||
{
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_UNIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
acquired = 1;
|
||||
|
||||
while (nbytes < (size_t)num)
|
||||
{
|
||||
/* tell CryptoSwift how many bytes we want and where we want it.
|
||||
* Note: - CryptoSwift cannot do more than 4096 bytes at a time.
|
||||
* - CryptoSwift can only do multiple of 32-bits. */
|
||||
largenum.value = (SW_BYTE *) buf + nbytes;
|
||||
if (4096 > num - nbytes)
|
||||
largenum.nbytes = num - nbytes;
|
||||
else
|
||||
largenum.nbytes = 4096;
|
||||
|
||||
swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
|
||||
if (swrc != SW_OK)
|
||||
{
|
||||
char tmpbuf[20];
|
||||
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED);
|
||||
sprintf(tmpbuf, "%ld", swrc);
|
||||
ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
|
||||
goto err;
|
||||
}
|
||||
|
||||
nbytes += largenum.nbytes;
|
||||
}
|
||||
to_return = 1; /* success */
|
||||
|
||||
err:
|
||||
if (acquired)
|
||||
release_context(hac);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
static int cswift_rand_status(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* This stuff is needed if this ENGINE is being compiled into a self-contained
|
||||
* shared-library. */
|
||||
#ifdef ENGINE_DYNAMIC_SUPPORT
|
||||
static int bind_fn(ENGINE *e, const char *id)
|
||||
{
|
||||
if(id && (strcmp(id, engine_cswift_id) != 0))
|
||||
return 0;
|
||||
if(!bind_helper(e))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
|
||||
#endif /* ENGINE_DYNAMIC_SUPPORT */
|
||||
|
||||
#endif /* !OPENSSL_NO_HW_CSWIFT */
|
||||
#endif /* !OPENSSL_NO_HW */
|
149
engines/e_cswift_err.c
Normal file
149
engines/e_cswift_err.c
Normal file
@ -0,0 +1,149 @@
|
||||
/* hw_cswift_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_cswift_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA CSWIFT_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"},
|
||||
{ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA CSWIFT_str_reasons[]=
|
||||
{
|
||||
{CSWIFT_R_ALREADY_LOADED ,"already loaded"},
|
||||
{CSWIFT_R_BAD_KEY_SIZE ,"bad key size"},
|
||||
{CSWIFT_R_BN_CTX_FULL ,"bn ctx full"},
|
||||
{CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"},
|
||||
{CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{CSWIFT_R_NOT_LOADED ,"not loaded"},
|
||||
{CSWIFT_R_REQUEST_FAILED ,"request failed"},
|
||||
{CSWIFT_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CSWIFT_LIB_NAME
|
||||
static ERR_STRING_DATA CSWIFT_lib_name[]=
|
||||
{
|
||||
{0 ,CSWIFT_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int CSWIFT_lib_error_code=0;
|
||||
static int CSWIFT_error_init=1;
|
||||
|
||||
static void ERR_load_CSWIFT_strings(void)
|
||||
{
|
||||
if (CSWIFT_lib_error_code == 0)
|
||||
CSWIFT_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (CSWIFT_error_init)
|
||||
{
|
||||
CSWIFT_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
|
||||
ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef CSWIFT_LIB_NAME
|
||||
CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0);
|
||||
ERR_load_strings(0,CSWIFT_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_CSWIFT_strings(void)
|
||||
{
|
||||
if (CSWIFT_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
|
||||
ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef CSWIFT_LIB_NAME
|
||||
ERR_unload_strings(0,CSWIFT_lib_name);
|
||||
#endif
|
||||
CSWIFT_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_CSWIFT_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (CSWIFT_lib_error_code == 0)
|
||||
CSWIFT_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line);
|
||||
}
|
93
engines/e_cswift_err.h
Normal file
93
engines/e_cswift_err.h
Normal file
@ -0,0 +1,93 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CSWIFT_ERR_H
|
||||
#define HEADER_CSWIFT_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_CSWIFT_strings(void);
|
||||
static void ERR_unload_CSWIFT_strings(void);
|
||||
static void ERR_CSWIFT_error(int function, int reason, char *file, int line);
|
||||
#define CSWIFTerr(f,r) ERR_CSWIFT_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the CSWIFT functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define CSWIFT_F_CSWIFT_CTRL 100
|
||||
#define CSWIFT_F_CSWIFT_DSA_SIGN 101
|
||||
#define CSWIFT_F_CSWIFT_DSA_VERIFY 102
|
||||
#define CSWIFT_F_CSWIFT_FINISH 103
|
||||
#define CSWIFT_F_CSWIFT_INIT 104
|
||||
#define CSWIFT_F_CSWIFT_MOD_EXP 105
|
||||
#define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106
|
||||
#define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107
|
||||
|
||||
/* Reason codes. */
|
||||
#define CSWIFT_R_ALREADY_LOADED 100
|
||||
#define CSWIFT_R_BAD_KEY_SIZE 101
|
||||
#define CSWIFT_R_BN_CTX_FULL 102
|
||||
#define CSWIFT_R_BN_EXPAND_FAIL 103
|
||||
#define CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED 104
|
||||
#define CSWIFT_R_MISSING_KEY_COMPONENTS 105
|
||||
#define CSWIFT_R_NOT_LOADED 106
|
||||
#define CSWIFT_R_REQUEST_FAILED 107
|
||||
#define CSWIFT_R_UNIT_FAILURE 108
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
1342
engines/e_ncipher.c
Normal file
1342
engines/e_ncipher.c
Normal file
File diff suppressed because it is too large
Load Diff
156
engines/e_ncipher_err.c
Normal file
156
engines/e_ncipher_err.c
Normal file
@ -0,0 +1,156 @@
|
||||
/* hw_ncipher_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_ncipher_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA HWCRHK_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"},
|
||||
{ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA HWCRHK_str_reasons[]=
|
||||
{
|
||||
{HWCRHK_R_ALREADY_LOADED ,"already loaded"},
|
||||
{HWCRHK_R_BIO_WAS_FREED ,"bio was freed"},
|
||||
{HWCRHK_R_CHIL_ERROR ,"chil error"},
|
||||
{HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{HWCRHK_R_DSO_FAILURE ,"dso failure"},
|
||||
{HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{HWCRHK_R_NOT_INITIALISED ,"not initialised"},
|
||||
{HWCRHK_R_NOT_LOADED ,"not loaded"},
|
||||
{HWCRHK_R_NO_CALLBACK ,"no callback"},
|
||||
{HWCRHK_R_NO_KEY ,"no key"},
|
||||
{HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"},
|
||||
{HWCRHK_R_REQUEST_FAILED ,"request failed"},
|
||||
{HWCRHK_R_REQUEST_FALLBACK ,"request fallback"},
|
||||
{HWCRHK_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HWCRHK_LIB_NAME
|
||||
static ERR_STRING_DATA HWCRHK_lib_name[]=
|
||||
{
|
||||
{0 ,HWCRHK_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int HWCRHK_lib_error_code=0;
|
||||
static int HWCRHK_error_init=1;
|
||||
|
||||
static void ERR_load_HWCRHK_strings(void)
|
||||
{
|
||||
if (HWCRHK_lib_error_code == 0)
|
||||
HWCRHK_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (HWCRHK_error_init)
|
||||
{
|
||||
HWCRHK_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
|
||||
ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef HWCRHK_LIB_NAME
|
||||
HWCRHK_lib_name->error = ERR_PACK(HWCRHK_lib_error_code,0,0);
|
||||
ERR_load_strings(0,HWCRHK_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_HWCRHK_strings(void)
|
||||
{
|
||||
if (HWCRHK_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
|
||||
ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef HWCRHK_LIB_NAME
|
||||
ERR_unload_strings(0,HWCRHK_lib_name);
|
||||
#endif
|
||||
HWCRHK_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_HWCRHK_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (HWCRHK_lib_error_code == 0)
|
||||
HWCRHK_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(HWCRHK_lib_error_code,function,reason,file,line);
|
||||
}
|
100
engines/e_ncipher_err.h
Normal file
100
engines/e_ncipher_err.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_HWCRHK_ERR_H
|
||||
#define HEADER_HWCRHK_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_HWCRHK_strings(void);
|
||||
static void ERR_unload_HWCRHK_strings(void);
|
||||
static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
|
||||
#define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the HWCRHK functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define HWCRHK_F_HWCRHK_CTRL 100
|
||||
#define HWCRHK_F_HWCRHK_FINISH 101
|
||||
#define HWCRHK_F_HWCRHK_GET_PASS 102
|
||||
#define HWCRHK_F_HWCRHK_INIT 103
|
||||
#define HWCRHK_F_HWCRHK_INSERT_CARD 104
|
||||
#define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105
|
||||
#define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106
|
||||
#define HWCRHK_F_HWCRHK_MOD_EXP 107
|
||||
#define HWCRHK_F_HWCRHK_RAND_BYTES 108
|
||||
#define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109
|
||||
|
||||
/* Reason codes. */
|
||||
#define HWCRHK_R_ALREADY_LOADED 100
|
||||
#define HWCRHK_R_BIO_WAS_FREED 101
|
||||
#define HWCRHK_R_CHIL_ERROR 102
|
||||
#define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
|
||||
#define HWCRHK_R_DSO_FAILURE 104
|
||||
#define HWCRHK_R_MISSING_KEY_COMPONENTS 105
|
||||
#define HWCRHK_R_NOT_INITIALISED 106
|
||||
#define HWCRHK_R_NOT_LOADED 107
|
||||
#define HWCRHK_R_NO_CALLBACK 108
|
||||
#define HWCRHK_R_NO_KEY 109
|
||||
#define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110
|
||||
#define HWCRHK_R_REQUEST_FAILED 111
|
||||
#define HWCRHK_R_REQUEST_FALLBACK 112
|
||||
#define HWCRHK_R_UNIT_FAILURE 113
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
416
engines/e_nuron.c
Normal file
416
engines/e_nuron.c
Normal file
@ -0,0 +1,416 @@
|
||||
/* crypto/engine/hw_nuron.c */
|
||||
/* Written by Ben Laurie for the OpenSSL Project, leaning heavily on Geoff
|
||||
* Thorpe's Atalla implementation.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_HW
|
||||
#ifndef OPENSSL_NO_HW_NURON
|
||||
|
||||
#define NURON_LIB_NAME "nuron engine"
|
||||
#include "hw_nuron_err.c"
|
||||
|
||||
static const char *NURON_LIBNAME = NULL;
|
||||
static const char *get_NURON_LIBNAME(void)
|
||||
{
|
||||
if(NURON_LIBNAME)
|
||||
return NURON_LIBNAME;
|
||||
return "nuronssl";
|
||||
}
|
||||
static void free_NURON_LIBNAME(void)
|
||||
{
|
||||
if(NURON_LIBNAME)
|
||||
OPENSSL_free((void*)NURON_LIBNAME);
|
||||
NURON_LIBNAME = NULL;
|
||||
}
|
||||
static long set_NURON_LIBNAME(const char *name)
|
||||
{
|
||||
free_NURON_LIBNAME();
|
||||
return (((NURON_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
|
||||
}
|
||||
static const char *NURON_F1 = "nuron_mod_exp";
|
||||
|
||||
/* The definitions for control commands specific to this engine */
|
||||
#define NURON_CMD_SO_PATH ENGINE_CMD_BASE
|
||||
static const ENGINE_CMD_DEFN nuron_cmd_defns[] = {
|
||||
{NURON_CMD_SO_PATH,
|
||||
"SO_PATH",
|
||||
"Specifies the path to the 'nuronssl' shared library",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{0, NULL, NULL, 0}
|
||||
};
|
||||
|
||||
typedef int tfnModExp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,const BIGNUM *m);
|
||||
static tfnModExp *pfnModExp = NULL;
|
||||
|
||||
static DSO *pvDSOHandle = NULL;
|
||||
|
||||
static int nuron_destroy(ENGINE *e)
|
||||
{
|
||||
free_NURON_LIBNAME();
|
||||
ERR_unload_NURON_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nuron_init(ENGINE *e)
|
||||
{
|
||||
if(pvDSOHandle != NULL)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_INIT,NURON_R_ALREADY_LOADED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pvDSOHandle = DSO_load(NULL, get_NURON_LIBNAME(), NULL,
|
||||
DSO_FLAG_NAME_TRANSLATION_EXT_ONLY);
|
||||
if(!pvDSOHandle)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_NOT_FOUND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pfnModExp = (tfnModExp *)DSO_bind_func(pvDSOHandle, NURON_F1);
|
||||
if(!pfnModExp)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_FUNCTION_NOT_FOUND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nuron_finish(ENGINE *e)
|
||||
{
|
||||
free_NURON_LIBNAME();
|
||||
if(pvDSOHandle == NULL)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
|
||||
return 0;
|
||||
}
|
||||
if(!DSO_free(pvDSOHandle))
|
||||
{
|
||||
NURONerr(NURON_F_NURON_FINISH,NURON_R_DSO_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
pvDSOHandle=NULL;
|
||||
pfnModExp=NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
|
||||
{
|
||||
int initialised = ((pvDSOHandle == NULL) ? 0 : 1);
|
||||
switch(cmd)
|
||||
{
|
||||
case NURON_CMD_SO_PATH:
|
||||
if(p == NULL)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_CTRL,ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
if(initialised)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED);
|
||||
return 0;
|
||||
}
|
||||
return set_NURON_LIBNAME((const char *)p);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
NURONerr(NURON_F_NURON_CTRL,NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,
|
||||
const BIGNUM *m,BN_CTX *ctx)
|
||||
{
|
||||
if(!pvDSOHandle)
|
||||
{
|
||||
NURONerr(NURON_F_NURON_MOD_EXP,NURON_R_NOT_LOADED);
|
||||
return 0;
|
||||
}
|
||||
return pfnModExp(r,a,p,m);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
|
||||
{
|
||||
return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* This code was liberated and adapted from the commented-out code in
|
||||
* dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
|
||||
* (it doesn't have a CRT form for RSA), this function means that an
|
||||
* Atalla system running with a DSA server certificate can handshake
|
||||
* around 5 or 6 times faster/more than an equivalent system running with
|
||||
* RSA. Just check out the "signs" statistics from the RSA and DSA parts
|
||||
* of "openssl speed -engine atalla dsa1024 rsa1024". */
|
||||
static int nuron_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
|
||||
BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
|
||||
BN_CTX *ctx, BN_MONT_CTX *in_mont)
|
||||
{
|
||||
BIGNUM t;
|
||||
int to_return = 0;
|
||||
|
||||
BN_init(&t);
|
||||
/* let rr = a1 ^ p1 mod m */
|
||||
if (!nuron_mod_exp(rr,a1,p1,m,ctx))
|
||||
goto end;
|
||||
/* let t = a2 ^ p2 mod m */
|
||||
if (!nuron_mod_exp(&t,a2,p2,m,ctx))
|
||||
goto end;
|
||||
/* let rr = rr * t mod m */
|
||||
if (!BN_mod_mul(rr,rr,&t,m,ctx))
|
||||
goto end;
|
||||
to_return = 1;
|
||||
end:
|
||||
BN_free(&t);
|
||||
return to_return;
|
||||
}
|
||||
|
||||
|
||||
static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
|
||||
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return nuron_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is aliased to mod_exp (with the mont stuff dropped). */
|
||||
static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return nuron_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* This function is aliased to mod_exp (with the dh and mont dropped). */
|
||||
static int nuron_mod_exp_dh(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return nuron_mod_exp(r, a, p, m, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
static RSA_METHOD nuron_rsa =
|
||||
{
|
||||
"Nuron RSA method",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
nuron_rsa_mod_exp,
|
||||
nuron_mod_exp_mont,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
static DSA_METHOD nuron_dsa =
|
||||
{
|
||||
"Nuron DSA method",
|
||||
NULL, /* dsa_do_sign */
|
||||
NULL, /* dsa_sign_setup */
|
||||
NULL, /* dsa_do_verify */
|
||||
nuron_dsa_mod_exp, /* dsa_mod_exp */
|
||||
nuron_mod_exp_dsa, /* bn_mod_exp */
|
||||
NULL, /* init */
|
||||
NULL, /* finish */
|
||||
0, /* flags */
|
||||
NULL /* app_data */
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
static DH_METHOD nuron_dh =
|
||||
{
|
||||
"Nuron DH method",
|
||||
NULL,
|
||||
NULL,
|
||||
nuron_mod_exp_dh,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Constants used when creating the ENGINE */
|
||||
static const char *engine_nuron_id = "nuron";
|
||||
static const char *engine_nuron_name = "Nuron hardware engine support";
|
||||
|
||||
/* This internal function is used by ENGINE_nuron() and possibly by the
|
||||
* "dynamic" ENGINE support too */
|
||||
static int bind_helper(ENGINE *e)
|
||||
{
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
const RSA_METHOD *meth1;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
const DSA_METHOD *meth2;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
const DH_METHOD *meth3;
|
||||
#endif
|
||||
if(!ENGINE_set_id(e, engine_nuron_id) ||
|
||||
!ENGINE_set_name(e, engine_nuron_name) ||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
!ENGINE_set_RSA(e, &nuron_rsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
!ENGINE_set_DSA(e, &nuron_dsa) ||
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
!ENGINE_set_DH(e, &nuron_dh) ||
|
||||
#endif
|
||||
!ENGINE_set_destroy_function(e, nuron_destroy) ||
|
||||
!ENGINE_set_init_function(e, nuron_init) ||
|
||||
!ENGINE_set_finish_function(e, nuron_finish) ||
|
||||
!ENGINE_set_ctrl_function(e, nuron_ctrl) ||
|
||||
!ENGINE_set_cmd_defns(e, nuron_cmd_defns))
|
||||
return 0;
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* We know that the "PKCS1_SSLeay()" functions hook properly
|
||||
* to the nuron-specific mod_exp and mod_exp_crt so we use
|
||||
* those functions. NB: We don't use ENGINE_openssl() or
|
||||
* anything "more generic" because something like the RSAref
|
||||
* code may not hook properly, and if you own one of these
|
||||
* cards then you have the right to do RSA operations on it
|
||||
* anyway! */
|
||||
meth1=RSA_PKCS1_SSLeay();
|
||||
nuron_rsa.rsa_pub_enc=meth1->rsa_pub_enc;
|
||||
nuron_rsa.rsa_pub_dec=meth1->rsa_pub_dec;
|
||||
nuron_rsa.rsa_priv_enc=meth1->rsa_priv_enc;
|
||||
nuron_rsa.rsa_priv_dec=meth1->rsa_priv_dec;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
|
||||
* bits. */
|
||||
meth2=DSA_OpenSSL();
|
||||
nuron_dsa.dsa_do_sign=meth2->dsa_do_sign;
|
||||
nuron_dsa.dsa_sign_setup=meth2->dsa_sign_setup;
|
||||
nuron_dsa.dsa_do_verify=meth2->dsa_do_verify;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* Much the same for Diffie-Hellman */
|
||||
meth3=DH_OpenSSL();
|
||||
nuron_dh.generate_key=meth3->generate_key;
|
||||
nuron_dh.compute_key=meth3->compute_key;
|
||||
#endif
|
||||
|
||||
/* Ensure the nuron error handling is set up */
|
||||
ERR_load_NURON_strings();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ENGINE *engine_nuron(void)
|
||||
{
|
||||
ENGINE *ret = ENGINE_new();
|
||||
if(!ret)
|
||||
return NULL;
|
||||
if(!bind_helper(ret))
|
||||
{
|
||||
ENGINE_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ENGINE_load_nuron(void)
|
||||
{
|
||||
/* Copied from eng_[openssl|dyn].c */
|
||||
ENGINE *toadd = engine_nuron();
|
||||
if(!toadd) return;
|
||||
ENGINE_add(toadd);
|
||||
ENGINE_free(toadd);
|
||||
ERR_clear_error();
|
||||
}
|
||||
|
||||
/* This stuff is needed if this ENGINE is being compiled into a self-contained
|
||||
* shared-library. */
|
||||
#ifdef ENGINE_DYNAMIC_SUPPORT
|
||||
static int bind_fn(ENGINE *e, const char *id)
|
||||
{
|
||||
if(id && (strcmp(id, engine_nuron_id) != 0))
|
||||
return 0;
|
||||
if(!bind_helper(e))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
|
||||
#endif /* ENGINE_DYNAMIC_SUPPORT */
|
||||
|
||||
#endif /* !OPENSSL_NO_HW_NURON */
|
||||
#endif /* !OPENSSL_NO_HW */
|
142
engines/e_nuron_err.c
Normal file
142
engines/e_nuron_err.c
Normal file
@ -0,0 +1,142 @@
|
||||
/* hw_nuron_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_nuron_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA NURON_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"},
|
||||
{ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"},
|
||||
{ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"},
|
||||
{ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA NURON_str_reasons[]=
|
||||
{
|
||||
{NURON_R_ALREADY_LOADED ,"already loaded"},
|
||||
{NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{NURON_R_DSO_FAILURE ,"dso failure"},
|
||||
{NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"},
|
||||
{NURON_R_DSO_NOT_FOUND ,"dso not found"},
|
||||
{NURON_R_NOT_LOADED ,"not loaded"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NURON_LIB_NAME
|
||||
static ERR_STRING_DATA NURON_lib_name[]=
|
||||
{
|
||||
{0 ,NURON_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int NURON_lib_error_code=0;
|
||||
static int NURON_error_init=1;
|
||||
|
||||
static void ERR_load_NURON_strings(void)
|
||||
{
|
||||
if (NURON_lib_error_code == 0)
|
||||
NURON_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (NURON_error_init)
|
||||
{
|
||||
NURON_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(NURON_lib_error_code,NURON_str_functs);
|
||||
ERR_load_strings(NURON_lib_error_code,NURON_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef NURON_LIB_NAME
|
||||
NURON_lib_name->error = ERR_PACK(NURON_lib_error_code,0,0);
|
||||
ERR_load_strings(0,NURON_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_NURON_strings(void)
|
||||
{
|
||||
if (NURON_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(NURON_lib_error_code,NURON_str_functs);
|
||||
ERR_unload_strings(NURON_lib_error_code,NURON_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef NURON_LIB_NAME
|
||||
ERR_unload_strings(0,NURON_lib_name);
|
||||
#endif
|
||||
NURON_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_NURON_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (NURON_lib_error_code == 0)
|
||||
NURON_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(NURON_lib_error_code,function,reason,file,line);
|
||||
}
|
86
engines/e_nuron_err.h
Normal file
86
engines/e_nuron_err.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_NURON_ERR_H
|
||||
#define HEADER_NURON_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_NURON_strings(void);
|
||||
static void ERR_unload_NURON_strings(void);
|
||||
static void ERR_NURON_error(int function, int reason, char *file, int line);
|
||||
#define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the NURON functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define NURON_F_NURON_CTRL 100
|
||||
#define NURON_F_NURON_FINISH 101
|
||||
#define NURON_F_NURON_INIT 102
|
||||
#define NURON_F_NURON_MOD_EXP 103
|
||||
|
||||
/* Reason codes. */
|
||||
#define NURON_R_ALREADY_LOADED 100
|
||||
#define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101
|
||||
#define NURON_R_DSO_FAILURE 102
|
||||
#define NURON_R_DSO_FUNCTION_NOT_FOUND 103
|
||||
#define NURON_R_DSO_NOT_FOUND 104
|
||||
#define NURON_R_NOT_LOADED 105
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
1040
engines/e_sureware.c
Normal file
1040
engines/e_sureware.c
Normal file
File diff suppressed because it is too large
Load Diff
150
engines/e_sureware_err.c
Normal file
150
engines/e_sureware_err.c
Normal file
@ -0,0 +1,150 @@
|
||||
/* hw_sureware_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_sureware_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA SUREWARE_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"},
|
||||
{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA SUREWARE_str_reasons[]=
|
||||
{
|
||||
{SUREWARE_R_BIO_WAS_FREED ,"bio was freed"},
|
||||
{SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{SUREWARE_R_REQUEST_FAILED ,"request failed"},
|
||||
{SUREWARE_R_REQUEST_FALLBACK ,"request fallback"},
|
||||
{SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
|
||||
{SUREWARE_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SUREWARE_LIB_NAME
|
||||
static ERR_STRING_DATA SUREWARE_lib_name[]=
|
||||
{
|
||||
{0 ,SUREWARE_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int SUREWARE_lib_error_code=0;
|
||||
static int SUREWARE_error_init=1;
|
||||
|
||||
static void ERR_load_SUREWARE_strings(void)
|
||||
{
|
||||
if (SUREWARE_lib_error_code == 0)
|
||||
SUREWARE_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (SUREWARE_error_init)
|
||||
{
|
||||
SUREWARE_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
|
||||
ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef SUREWARE_LIB_NAME
|
||||
SUREWARE_lib_name->error = ERR_PACK(SUREWARE_lib_error_code,0,0);
|
||||
ERR_load_strings(0,SUREWARE_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_SUREWARE_strings(void)
|
||||
{
|
||||
if (SUREWARE_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
|
||||
ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef SUREWARE_LIB_NAME
|
||||
ERR_unload_strings(0,SUREWARE_lib_name);
|
||||
#endif
|
||||
SUREWARE_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_SUREWARE_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (SUREWARE_lib_error_code == 0)
|
||||
SUREWARE_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line);
|
||||
}
|
94
engines/e_sureware_err.h
Normal file
94
engines/e_sureware_err.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_SUREWARE_ERR_H
|
||||
#define HEADER_SUREWARE_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_SUREWARE_strings(void);
|
||||
static void ERR_unload_SUREWARE_strings(void);
|
||||
static void ERR_SUREWARE_error(int function, int reason, char *file, int line);
|
||||
#define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the SUREWARE functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define SUREWARE_F_SUREWAREHK_CTRL 100
|
||||
#define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101
|
||||
#define SUREWARE_F_SUREWAREHK_EX_FREE 102
|
||||
#define SUREWARE_F_SUREWAREHK_FINISH 103
|
||||
#define SUREWARE_F_SUREWAREHK_INIT 104
|
||||
#define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105
|
||||
#define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106
|
||||
#define SUREWARE_F_SUREWAREHK_MOD_EXP 107
|
||||
#define SUREWARE_F_SUREWAREHK_RAND_BYTES 108
|
||||
#define SUREWARE_F_SUREWAREHK_RAND_SEED 109
|
||||
#define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110
|
||||
#define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111
|
||||
|
||||
/* Reason codes. */
|
||||
#define SUREWARE_R_BIO_WAS_FREED 100
|
||||
#define SUREWARE_R_MISSING_KEY_COMPONENTS 105
|
||||
#define SUREWARE_R_REQUEST_FAILED 101
|
||||
#define SUREWARE_R_REQUEST_FALLBACK 102
|
||||
#define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103
|
||||
#define SUREWARE_R_UNIT_FAILURE 104
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
1059
engines/e_ubsec.c
Normal file
1059
engines/e_ubsec.c
Normal file
File diff suppressed because it is too large
Load Diff
151
engines/e_ubsec_err.c
Normal file
151
engines/e_ubsec_err.c
Normal file
@ -0,0 +1,151 @@
|
||||
/* hw_ubsec_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "hw_ubsec_err.h"
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
static ERR_STRING_DATA UBSEC_str_functs[]=
|
||||
{
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"},
|
||||
{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA UBSEC_str_reasons[]=
|
||||
{
|
||||
{UBSEC_R_ALREADY_LOADED ,"already loaded"},
|
||||
{UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"},
|
||||
{UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{UBSEC_R_DSO_FAILURE ,"dso failure"},
|
||||
{UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{UBSEC_R_NOT_LOADED ,"not loaded"},
|
||||
{UBSEC_R_REQUEST_FAILED ,"request failed"},
|
||||
{UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
|
||||
{UBSEC_R_UNIT_FAILURE ,"unit failure"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef UBSEC_LIB_NAME
|
||||
static ERR_STRING_DATA UBSEC_lib_name[]=
|
||||
{
|
||||
{0 ,UBSEC_LIB_NAME},
|
||||
{0,NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static int UBSEC_lib_error_code=0;
|
||||
static int UBSEC_error_init=1;
|
||||
|
||||
static void ERR_load_UBSEC_strings(void)
|
||||
{
|
||||
if (UBSEC_lib_error_code == 0)
|
||||
UBSEC_lib_error_code=ERR_get_next_error_library();
|
||||
|
||||
if (UBSEC_error_init)
|
||||
{
|
||||
UBSEC_error_init=0;
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_functs);
|
||||
ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef UBSEC_LIB_NAME
|
||||
UBSEC_lib_name->error = ERR_PACK(UBSEC_lib_error_code,0,0);
|
||||
ERR_load_strings(0,UBSEC_lib_name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_unload_UBSEC_strings(void)
|
||||
{
|
||||
if (UBSEC_error_init == 0)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_functs);
|
||||
ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
|
||||
#endif
|
||||
|
||||
#ifdef UBSEC_LIB_NAME
|
||||
ERR_unload_strings(0,UBSEC_lib_name);
|
||||
#endif
|
||||
UBSEC_error_init=1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ERR_UBSEC_error(int function, int reason, char *file, int line)
|
||||
{
|
||||
if (UBSEC_lib_error_code == 0)
|
||||
UBSEC_lib_error_code=ERR_get_next_error_library();
|
||||
ERR_PUT_error(UBSEC_lib_error_code,function,reason,file,line);
|
||||
}
|
95
engines/e_ubsec_err.h
Normal file
95
engines/e_ubsec_err.h
Normal file
@ -0,0 +1,95 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_UBSEC_ERR_H
|
||||
#define HEADER_UBSEC_ERR_H
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
static void ERR_load_UBSEC_strings(void);
|
||||
static void ERR_unload_UBSEC_strings(void);
|
||||
static void ERR_UBSEC_error(int function, int reason, char *file, int line);
|
||||
#define UBSECerr(f,r) ERR_UBSEC_error((f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Error codes for the UBSEC functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define UBSEC_F_UBSEC_CTRL 100
|
||||
#define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101
|
||||
#define UBSEC_F_UBSEC_DSA_SIGN 102
|
||||
#define UBSEC_F_UBSEC_DSA_VERIFY 103
|
||||
#define UBSEC_F_UBSEC_FINISH 104
|
||||
#define UBSEC_F_UBSEC_INIT 105
|
||||
#define UBSEC_F_UBSEC_MOD_EXP 106
|
||||
#define UBSEC_F_UBSEC_RNG_BYTES 107
|
||||
#define UBSEC_F_UBSEC_RSA_MOD_EXP 108
|
||||
#define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109
|
||||
|
||||
/* Reason codes. */
|
||||
#define UBSEC_R_ALREADY_LOADED 100
|
||||
#define UBSEC_R_BN_EXPAND_FAIL 101
|
||||
#define UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED 102
|
||||
#define UBSEC_R_DSO_FAILURE 103
|
||||
#define UBSEC_R_MISSING_KEY_COMPONENTS 104
|
||||
#define UBSEC_R_NOT_LOADED 105
|
||||
#define UBSEC_R_REQUEST_FAILED 106
|
||||
#define UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
|
||||
#define UBSEC_R_UNIT_FAILURE 108
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user