Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

cryp.h

Go to the documentation of this file.
00001 /*************************************************************************** 00002 $RCSfile: cryp.h,v $ 00003 ------------------- 00004 cvs : $Id: cryp.h,v 1.4 2003/04/12 21:03:38 aquamaniac Exp $ 00005 begin : Sat Nov 02 2002 00006 copyright : (C) 2002 by Martin Preuss 00007 email : martin@libchipcard.de 00008 00009 *************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00024 * MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 00029 #ifndef CRYP_H 00030 #define CRYP_H "$Id" 00031 00032 #include <openssl/rsa.h> 00033 #include <openssl/blowfish.h> 00034 #include <openssl/ripemd.h> 00035 #include <chameleon/error.h> 00036 #include <chameleon/ipcmessage.h> 00037 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 00044 #define CRYP_RSA_DEFAULT_KEY_LENGTH 1024 00045 #define CRYP_RSA_MAX_KEY_LENGTH 4096 00046 #define CRYP_RSA_DEFAULT_EXPONENT 65537 00047 #define CRYP_RSA_DEFAULT_EXPONENT_STR "65537" 00048 00049 00050 #define CRYP_ERROR_MEMORY_FULL 1 00051 #define CRYP_ERROR_KEY_GENERATION 2 00052 #define CRYP_ERROR_BUFFER_TOO_SMALL 3 00053 #define CRYP_ERROR_BAD_PADDING 4 00054 #define CRYP_ERROR_ENCRYPTION 5 00055 #define CRYP_ERROR_DECRYPTION 6 00056 #define CRYP_ERROR_BAD_SIZE 7 00057 #define CRYP_ERROR_BAD_SIGNATURE 8 00058 #define CRYP_ERROR_BAD_ALGO 9 00059 #define CRYP_ERROR_BAD_EXPONENT 10 00060 00061 00062 CHIPCARD_API typedef enum { 00063 CryptAlgoNone=0, 00064 CryptAlgoBlowfish, 00065 CryptAlgoRSA 00066 } CryptAlgo; 00067 00068 00072 CHIPCARD_API struct CRYP_RSAKEYSTRUCT { 00073 RSA *key; 00074 }; 00075 00076 00077 CHIPCARD_API typedef struct CRYP_RSAKEYSTRUCT CRYP_RSAKEY; 00078 CHIPCARD_API typedef CRYP_RSAKEY *CRYP_RSAKEYPTR; 00079 00080 00081 CHIPCARD_API ERRORCODE Cryp_ModuleInit(); 00082 CHIPCARD_API ERRORCODE Cryp_ModuleFini(); 00083 00084 CHIPCARD_API CRYP_RSAKEYPTR Cryp_RsaKey_new(); 00085 CHIPCARD_API void Cryp_RsaKey_free(CRYP_RSAKEYPTR k); 00086 00087 CHIPCARD_API ERRORCODE Cryp_RsaKey_Generate(CRYP_RSAKEYPTR k, int keylength, int expo); 00088 CHIPCARD_API ERRORCODE Cryp_RsaKey_ToMessage(CRYP_RSAKEYPTR k, IPCMESSAGE *m, int pub); 00089 CHIPCARD_API ERRORCODE Cryp_RsaKey_FromMessage(CRYP_RSAKEYPTR k, IPCMESSAGE *m); 00090 CHIPCARD_API ERRORCODE Cryp_RsaKey_GetChunkSize(CRYP_RSAKEYPTR k, int *size); 00091 CHIPCARD_API ERRORCODE Cryp_Rsa_CryptPublic(CRYP_RSAKEYPTR k, 00092 const unsigned char *source, 00093 unsigned int size, 00094 unsigned char *target, 00095 unsigned int bsize); 00096 CHIPCARD_API ERRORCODE Cryp_Rsa_CryptPrivate(CRYP_RSAKEYPTR k, 00097 const unsigned char *source, 00098 unsigned int size, 00099 unsigned char *target, 00100 unsigned int bsize); 00101 CHIPCARD_API ERRORCODE Cryp_Rsa_DecryptPublic(CRYP_RSAKEYPTR k, 00102 const unsigned char *source, 00103 unsigned int size, 00104 unsigned char *target, 00105 unsigned int bsize); 00106 CHIPCARD_API ERRORCODE Cryp_Rsa_DecryptPrivate(CRYP_RSAKEYPTR k, 00107 const unsigned char *source, 00108 unsigned int size, 00109 unsigned char *target, 00110 unsigned int bsize); 00111 CHIPCARD_API ERRORCODE Cryp_Rsa_Sign(CRYP_RSAKEYPTR k, 00112 const unsigned char *text, 00113 unsigned int size, 00114 unsigned char *buffer, 00115 unsigned int *bsize); 00116 00117 CHIPCARD_API ERRORCODE Cryp_Rsa_Verify(CRYP_RSAKEYPTR k, 00118 const unsigned char *text, 00119 unsigned int size, 00120 const unsigned char *signature, 00121 unsigned int ssize); 00122 00123 00124 CHIPCARD_API ERRORCODE Cryp_PaddForRSAKey(CRYP_RSAKEYPTR k, 00125 unsigned char *source, 00126 unsigned int *size, 00127 unsigned int bsize); 00128 00129 CHIPCARD_API int Cryp_Rsa_GetChunkSize(CRYP_RSAKEYPTR k); 00130 00131 CHIPCARD_API ERRORCODE Cryp_Unpadd(const unsigned char *source, 00132 unsigned int *size); 00133 00134 CHIPCARD_API ERRORCODE Cryp_RipeMD160(const unsigned char *source, 00135 unsigned int size, 00136 unsigned char *buffer, 00137 unsigned int bsize); 00138 00139 00140 00141 00145 CHIPCARD_API struct CRYP_BFKEYSTRUCT { 00146 BF_KEY key; 00147 int keylen; 00148 char keydata[16]; 00149 }; 00150 00151 00152 CHIPCARD_API typedef struct CRYP_BFKEYSTRUCT CRYP_BFKEY; 00153 00154 00155 CHIPCARD_API CRYP_BFKEY *Cryp_BlowfishKey_new(); 00156 CHIPCARD_API void Cryp_BlowfishKey_free(CRYP_BFKEY *); 00157 00158 CHIPCARD_API ERRORCODE Cryp_BlowfishKey_SetKey(CRYP_BFKEY *key, 00159 const char *data, 00160 int len); 00161 00162 CHIPCARD_API ERRORCODE Cryp_BlowfishKey_GenerateKey(CRYP_BFKEY *key); 00163 00164 CHIPCARD_API ERRORCODE Cryp_BlowfishKey_GetKey(CRYP_BFKEY *key, 00165 char **data, 00166 int *len); 00167 00168 CHIPCARD_API ERRORCODE Cryp_Blowfish_Encrypt(CRYP_BFKEY *key, 00169 const char *indata, 00170 int size, 00171 char *outdata); 00172 00173 CHIPCARD_API ERRORCODE Cryp_Blowfish_Decrypt(CRYP_BFKEY *key, 00174 const char *indata, 00175 int size, 00176 char *outdata); 00177 00178 CHIPCARD_API ERRORCODE Cryp_PaddForBFKey(CRYP_BFKEY *k, 00179 unsigned char *source, 00180 unsigned int *size, 00181 unsigned int bsize); 00182 00183 00184 CHIPCARD_API ERRORCODE Cryp_Encrypt(void *key, 00185 CryptAlgo algo, 00186 const unsigned char *source, 00187 int insize, 00188 unsigned char **outbuffer, 00189 int *outsize); 00190 00191 CHIPCARD_API ERRORCODE Cryp_Decrypt(void *key, 00192 CryptAlgo algo, 00193 const unsigned char *source, 00194 int insize, 00195 unsigned char **outbuffer, 00196 int *outsize); 00197 00201 CHIPCARD_API struct CRYP_RMD160STRUCT { 00202 RIPEMD160_CTX ctx; 00203 }; 00204 CHIPCARD_API typedef struct CRYP_RMD160STRUCT CRYP_RMD160; 00205 00206 00207 CHIPCARD_API CRYP_RMD160 *Cryp_RMD160_new(); 00208 CHIPCARD_API void Cryp_RMD160_free(CRYP_RMD160 *r); 00209 00210 CHIPCARD_API ERRORCODE Cryp_RMD160_Init(CRYP_RMD160 *r); 00211 CHIPCARD_API ERRORCODE Cryp_RMD160_Update(CRYP_RMD160 *r, 00212 const unsigned char *data, 00213 int bsize); 00214 CHIPCARD_API ERRORCODE Cryp_RMD160_Final(CRYP_RMD160 *r, 00215 unsigned char *buffer, 00216 int *bsize); 00217 00218 #ifdef __cplusplus 00219 } 00220 #endif 00221 00222 #endif 00223 00224

Generated on Wed Jul 28 14:56:49 2004 for libchipcard by doxygen 1.3.7