Xuyi Wang / wolfcrypt

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cryptodev.h Source File

cryptodev.h

00001 /* cryptodev.h
00002  *
00003  * Copyright (C) 2006-2018 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef _WOLF_CRYPTO_DEV_H_
00022 #define _WOLF_CRYPTO_DEV_H_
00023 
00024 #include <wolfcrypt/types.h>
00025 
00026 #ifdef __cplusplus
00027     extern "C" {
00028 #endif
00029 
00030 #ifdef WOLF_CRYPTO_DEV
00031 
00032 #ifndef NO_RSA
00033     #include <wolfcrypt/rsa.h>
00034 #endif
00035 #ifdef HAVE_ECC
00036     #include <wolfcrypt/ecc.h>
00037 #endif
00038 
00039 /* Crypto Information Structure for callbacks */
00040 typedef struct wc_CryptoInfo {
00041     int algo_type; /* enum wc_AlgoType */
00042     struct {
00043         int type; /* enum wc_PkType */
00044         union {
00045         #ifndef NO_RSA
00046             struct {
00047                 const byte* in;
00048                 word32 inLen;
00049                 byte* out;
00050                 word32* outLen;
00051                 int type;
00052                 RsaKey* key;
00053                 WC_RNG* rng;
00054             } rsa;
00055         #endif
00056         #ifdef HAVE_ECC
00057             struct {
00058                 ecc_key* private_key;
00059                 ecc_key* public_key;
00060                 byte* out;
00061                 word32* outlen;
00062             } ecdh;
00063             struct {
00064                 const byte* in;
00065                 word32 inlen;
00066                 byte* out;
00067                 word32 *outlen;
00068                 WC_RNG* rng;
00069                 ecc_key* key;
00070             } eccsign;
00071             struct {
00072                 const byte* sig;
00073                 word32 siglen;
00074                 const byte* hash;
00075                 word32 hashlen;
00076                 int* res;
00077                 ecc_key* key;
00078             } eccverify;
00079         #endif
00080         };
00081     } pk;
00082 } wc_CryptoInfo;
00083 
00084 typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);
00085 
00086 WOLFSSL_LOCAL void wc_CryptoDev_Init(void);
00087 
00088 WOLFSSL_API int  wc_CryptoDev_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
00089 WOLFSSL_API void wc_CryptoDev_UnRegisterDevice(int devId);
00090 
00091 
00092 #ifndef NO_RSA
00093 WOLFSSL_LOCAL int wc_CryptoDev_Rsa(const byte* in, word32 inLen, byte* out,
00094     word32* outLen, int type, RsaKey* key, WC_RNG* rng);
00095 #endif /* !NO_RSA */
00096 
00097 #ifdef HAVE_ECC
00098 WOLFSSL_LOCAL int wc_CryptoDev_Ecdh(ecc_key* private_key, ecc_key* public_key,
00099     byte* out, word32* outlen);
00100 
00101 WOLFSSL_LOCAL int wc_CryptoDev_EccSign(const byte* in, word32 inlen, byte* out,
00102     word32 *outlen, WC_RNG* rng, ecc_key* key);
00103 
00104 WOLFSSL_LOCAL int wc_CryptoDev_EccVerify(const byte* sig, word32 siglen,
00105     const byte* hash, word32 hashlen, int* res, ecc_key* key);
00106 #endif /* HAVE_ECC */
00107 
00108 #endif /* WOLF_CRYPTO_DEV */
00109 
00110 #ifdef __cplusplus
00111     } /* extern "C" */
00112 #endif
00113 
00114 #endif /* _WOLF_CRYPTO_DEV_H_ */
00115