# crypt.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: crypt.h,v $
    00003  -------------------
    00004  cvs         : $Id: crypt.h,v 1.21 2005/03/08 00:00:47 aquamaniac Exp $
    00005  begin       : Thu Nov 06 2003
    00006  copyright   : (C) 2003 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 GWENHYWFAR_CRYPT_H
    00030 #define GWENHYWFAR_CRYPT_H
    00031
    00032
    00033 #include <gwenhywfar/error.h>
    00034 #include <gwenhywfar/buffer.h>
    00035 #include <gwenhywfar/db.h>
    00036 #include <gwenhywfar/keyspec.h>
    00037 #include <gwenhywfar/inherit.h>
    00038 #include <gwenhywfar/list2.h>
    00039
    00040 #ifdef __cplusplus
    00041 extern "C" {
    00042 #endif
    00043
    00044 #define GWEN_CRYPT_ERROR_TYPE "Crypt"
    00045 #define GWEN_CRYPT_ERROR_ALREADY_REGISTERED 1
    00046 #define GWEN_CRYPT_ERROR_NOT_REGISTERED     2
    00047 #define GWEN_CRYPT_ERROR_BAD_SIZE           3
    00048 #define GWEN_CRYPT_ERROR_BUFFER_FULL        4
    00049 #define GWEN_CRYPT_ERROR_ENCRYPT            5
    00050 #define GWEN_CRYPT_ERROR_DECRYPT            6
    00051 #define GWEN_CRYPT_ERROR_SIGN               7
    00052 #define GWEN_CRYPT_ERROR_VERIFY             8
    00053 #define GWEN_CRYPT_ERROR_UNSUPPORTED        9
    00054 #define GWEN_CRYPT_ERROR_SSL                10
    00055 #define GWEN_CRYPT_ERROR_GENERIC            11
    00056
    00057
    00062 #define GWEN_CRYPT_FLAG_DISABLE_SMALLER_SIGNATURE 0x00000001
    00063
    00064 int GWEN_Crypt_IsAvailable();
    00065
    00066
    00075 GWENHYWFAR_API
    00076   GWEN_ERRORCODE GWEN_CryptImpl_Init();
    00077
    00083 GWENHYWFAR_API
    00084   GWEN_ERRORCODE GWEN_CryptImpl_Fini();
    00088 typedef struct GWEN_CRYPTKEY GWEN_CRYPTKEY;
    00089
    00090 GWEN_INHERIT_FUNCTION_LIB_DEFS(GWEN_CRYPTKEY, GWENHYWFAR_API)
    00091 GWEN_LIST2_FUNCTION_LIB_DEFS(GWEN_CRYPTKEY, GWEN_CryptKey, GWENHYWFAR_API)
    00092 void GWEN_CryptKey_List2_freeAll(GWEN_CRYPTKEY_LIST2 *stl);
    00093
    00094
    00099 typedef GWEN_CRYPTKEY* (*GWEN_CRYPTKEY_DUP_FN)(const GWEN_CRYPTKEY *key);
    00100
    00101 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_ENCRYPT_FN)(const GWEN_CRYPTKEY *key,
    00102                                                    GWEN_BUFFER *src,
    00103                                                    GWEN_BUFFER *dst);
    00104
    00105 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_DECRYPT_FN)(const GWEN_CRYPTKEY *key,
    00106                                                    GWEN_BUFFER *src,
    00107                                                    GWEN_BUFFER *dst);
    00108
    00109 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_SIGN_FN)(const GWEN_CRYPTKEY *key,
    00110                                                 GWEN_BUFFER *src,
    00111                                                 GWEN_BUFFER *dst);
    00112
    00113 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_VERIFY_FN)(const GWEN_CRYPTKEY *key,
    00114                                                   GWEN_BUFFER *src,
    00115                                                   GWEN_BUFFER *dst);
    00116
    00117 typedef unsigned int
    00118     (*GWEN_CRYPTKEY_GETCHUNKSIZE_FN)(const GWEN_CRYPTKEY *key);
    00119
    00120 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_FROMDB_FN)(GWEN_CRYPTKEY *key,
    00121                                                   GWEN_DB_NODE *db);
    00122
    00123 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_TODB_FN)(const GWEN_CRYPTKEY *key,
    00124                                                 GWEN_DB_NODE *db,
    00125                                                 int pub);
    00126
    00127 typedef void (*GWEN_CRYPTKEY_FREEKEYDATA_FN)(GWEN_CRYPTKEY *key);
    00128
    00129 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_GENERATEKEY_FN)(GWEN_CRYPTKEY *key,
    00130                                                        unsigned keylength);
    00131
    00132 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_OPEN_FN)(GWEN_CRYPTKEY *key);
    00133
    00134 typedef GWEN_ERRORCODE (*GWEN_CRYPTKEY_CLOSE_FN)(GWEN_CRYPTKEY *key);
    00142 GWENHYWFAR_API
    00143   GWEN_CRYPTKEY *GWEN_CryptKey_new();
    00144
    00145
    00146 GWENHYWFAR_API
    00147   GWEN_CRYPTKEY *GWEN_CryptKey_Factory(const char *t);
    00148
    00149 GWENHYWFAR_API
    00150   void GWEN_CryptKey_free(GWEN_CRYPTKEY *key);
    00151
    00152 GWENHYWFAR_API
    00153   GWEN_CRYPTKEY *GWEN_CryptKey_dup(const GWEN_CRYPTKEY *key);
    00154
    00155 GWENHYWFAR_API
    00156   int GWEN_CryptKey_IsPublic(const GWEN_CRYPTKEY *key);
    00157 GWENHYWFAR_API
    00158   void GWEN_CryptKey_SetPublic(GWEN_CRYPTKEY *key, int i);
    00159
    00160 GWENHYWFAR_API
    00161   GWEN_ERRORCODE GWEN_CryptKey_Encrypt(const GWEN_CRYPTKEY *key,
    00162                                        GWEN_BUFFER *src,
    00163                                        GWEN_BUFFER *dst);
    00164
    00165 GWENHYWFAR_API
    00166   GWEN_ERRORCODE GWEN_CryptKey_Decrypt(const GWEN_CRYPTKEY *key,
    00167                                        GWEN_BUFFER *src,
    00168                                        GWEN_BUFFER *dst);
    00169
    00170 GWENHYWFAR_API
    00171   GWEN_ERRORCODE GWEN_CryptKey_Sign(const GWEN_CRYPTKEY *key,
    00172                                     GWEN_BUFFER *src,
    00173                                     GWEN_BUFFER *dst);
    00174
    00175 GWENHYWFAR_API
    00176   GWEN_ERRORCODE GWEN_CryptKey_Verify(const GWEN_CRYPTKEY *key,
    00177                                       GWEN_BUFFER *src,
    00178                                       GWEN_BUFFER *dst);
    00179
    00180 GWENHYWFAR_API
    00181   unsigned int GWEN_CryptKey_GetChunkSize(const GWEN_CRYPTKEY *key);
    00182
    00183 GWENHYWFAR_API
    00184   GWEN_CRYPTKEY *GWEN_CryptKey_FromDb(GWEN_DB_NODE *db);
    00185
    00186 GWENHYWFAR_API
    00187   GWEN_ERRORCODE GWEN_CryptKey_ToDb(const GWEN_CRYPTKEY *key,
    00188                                     GWEN_DB_NODE *db,
    00189                                     int pub);
    00190
    00191 GWENHYWFAR_API
    00192 GWEN_TYPE_UINT32 GWEN_CryptKey_GetFlags(const GWEN_CRYPTKEY *key);
    00193 GWENHYWFAR_API
    00194 void GWEN_CryptKey_SetFlags(GWEN_CRYPTKEY *key, GWEN_TYPE_UINT32 fl);
    00195 GWENHYWFAR_API
    00196 void GWEN_CryptKey_AddFlags(GWEN_CRYPTKEY *key, GWEN_TYPE_UINT32 fl);
    00197 GWENHYWFAR_API
    00198 void GWEN_CryptKey_SubFlags(GWEN_CRYPTKEY *key, GWEN_TYPE_UINT32 fl);
    00199
    00200
    00207 GWENHYWFAR_API
    00208   GWEN_ERRORCODE GWEN_CryptKey_SetData(GWEN_CRYPTKEY *key,
    00209                                        const char *buffer,
    00210                                        unsigned int bsize);
    00211
    00216 int GWEN_CryptKey_FromPassword(const char *password,
    00217                                unsigned char *buffer,
    00218                                unsigned int bsize);
    00219
    00231 int GWEN_CryptKey_FromPasswordSSL(const char *password,
    00232                                   unsigned char *buffer,
    00233                                   unsigned int bsize);
    00234
    00241 GWEN_ERRORCODE GWEN_CryptKey_GetData(GWEN_CRYPTKEY *key,
    00242                                      char *buffer,
    00243                                      unsigned int *bsize);
    00244
    00245
    00246 GWENHYWFAR_API
    00247   GWEN_ERRORCODE GWEN_CryptKey_Generate(GWEN_CRYPTKEY *key,
    00248                                         unsigned int keylength);
    00249
    00250 GWENHYWFAR_API
    00251   GWEN_ERRORCODE GWEN_CryptKey_Open(GWEN_CRYPTKEY *key);
    00252
    00253 GWENHYWFAR_API
    00254   GWEN_ERRORCODE GWEN_CryptKey_Close(GWEN_CRYPTKEY *key);
    00255
    00260 GWENHYWFAR_API
    00261   const GWEN_KEYSPEC *GWEN_CryptKey_GetKeySpec(const GWEN_CRYPTKEY *key);
    00262
    00268 GWENHYWFAR_API
    00269 int GWEN_CryptKey_GetStatus(const GWEN_CRYPTKEY *key);
    00270 GWENHYWFAR_API
    00271 void GWEN_CryptKey_SetStatus(GWEN_CRYPTKEY *key, int i);
    00272
    00273
    00274 GWENHYWFAR_API
    00275   const char *GWEN_CryptKey_GetKeyType(const GWEN_CRYPTKEY *key);
    00276 GWENHYWFAR_API
    00277   void GWEN_CryptKey_SetKeyType(GWEN_CRYPTKEY *key,
    00278                                 const char *s);
    00279
    00280 GWENHYWFAR_API
    00281   const char *GWEN_CryptKey_GetKeyName(const GWEN_CRYPTKEY *key);
    00282 GWENHYWFAR_API
    00283   void GWEN_CryptKey_SetKeyName(GWEN_CRYPTKEY *key,
    00284                                 const char *s);
    00285
    00286 GWENHYWFAR_API
    00287   const char *GWEN_CryptKey_GetOwner(const GWEN_CRYPTKEY *key);
    00288 GWENHYWFAR_API
    00289   void GWEN_CryptKey_SetOwner(GWEN_CRYPTKEY *key,
    00290                               const char *s);
    00291 GWENHYWFAR_API
    00292   unsigned int GWEN_CryptKey_GetNumber(const GWEN_CRYPTKEY *key);
    00293 GWENHYWFAR_API
    00294   void GWEN_CryptKey_SetNumber(GWEN_CRYPTKEY *key,
    00295                                unsigned int i);
    00296 GWENHYWFAR_API
    00297   unsigned int GWEN_CryptKey_GetVersion(const GWEN_CRYPTKEY *key);
    00298 GWENHYWFAR_API
    00299   void GWEN_CryptKey_SetVersion(GWEN_CRYPTKEY *key,
    00300                                 unsigned int i);
    00301
    00302 #if (defined(GWEN_EXTEND_CRYPTKEY) || defined(DOXYGEN))
    00303
    00310 GWENHYWFAR_API
    00311   void *GWEN_CryptKey_GetKeyData(const GWEN_CRYPTKEY *key);
    00312
    00320 GWENHYWFAR_API
    00321   void GWEN_CryptKey_SetKeyData(GWEN_CRYPTKEY *key,
    00322                                 void *kd);
    00323 #endif
    00324
    00325 GWENHYWFAR_API
    00326   int GWEN_CryptKey_GetOpenCount(const GWEN_CRYPTKEY *key);
    00327
    00328 #if (defined(GWEN_EXTEND_CRYPTKEY) || defined(DOXYGEN))
    00329 GWENHYWFAR_API
    00330   void GWEN_CryptKey_IncrementOpenCount(GWEN_CRYPTKEY *key);
    00331 GWENHYWFAR_API
    00332   void GWEN_CryptKey_DecrementOpenCount(GWEN_CRYPTKEY *key);
    00333 #endif
    00334
    00339 #if (defined(GWEN_EXTEND_CRYPTKEY) || defined(DOXYGEN))
    00340 GWENHYWFAR_API
    00341   void GWEN_CryptKey_SetEncryptFn(GWEN_CRYPTKEY *key,
    00342                                   GWEN_CRYPTKEY_ENCRYPT_FN encryptFn);
    00343 GWENHYWFAR_API
    00344   void GWEN_CryptKey_SetDecryptFn(GWEN_CRYPTKEY *key,
    00345                                   GWEN_CRYPTKEY_DECRYPT_FN decryptFn);
    00346 GWENHYWFAR_API
    00347   void GWEN_CryptKey_SetSignFn(GWEN_CRYPTKEY *key,
    00348                                GWEN_CRYPTKEY_SIGN_FN signFn);
    00349 GWENHYWFAR_API
    00350   void GWEN_CryptKey_SetVerifyFn(GWEN_CRYPTKEY *key,
    00351                                  GWEN_CRYPTKEY_VERIFY_FN verifyFn);
    00352 GWENHYWFAR_API
    00353   void GWEN_CryptKey_SetGetChunkSizeFn(GWEN_CRYPTKEY *key,
    00354                                        GWEN_CRYPTKEY_GETCHUNKSIZE_FN getChunkSizeFn);
    00355 GWENHYWFAR_API
    00356   void GWEN_CryptKey_SetFromDbFn(GWEN_CRYPTKEY *key,
    00357                                  GWEN_CRYPTKEY_FROMDB_FN fromDbFn);
    00358 GWENHYWFAR_API
    00359   void GWEN_CryptKey_SetToDbFn(GWEN_CRYPTKEY *key,
    00360                                GWEN_CRYPTKEY_TODB_FN toDbFn);
    00361 GWENHYWFAR_API
    00362   void GWEN_CryptKey_SetGenerateKeyFn(GWEN_CRYPTKEY *key,
    00363                                       GWEN_CRYPTKEY_GENERATEKEY_FN generateKeyFn);
    00364 GWENHYWFAR_API
    00365   void GWEN_CryptKey_SetFreeKeyDataFn(GWEN_CRYPTKEY *key,
    00366                                       GWEN_CRYPTKEY_FREEKEYDATA_FN freeKeyDataFn);
    00367
    00368 GWENHYWFAR_API
    00369   void GWEN_CryptKey_SetOpenFn(GWEN_CRYPTKEY *key,
    00370                                GWEN_CRYPTKEY_OPEN_FN openKeyFn);
    00371 GWENHYWFAR_API
    00372   void GWEN_CryptKey_SetCloseFn(GWEN_CRYPTKEY *key,
    00373                                 GWEN_CRYPTKEY_CLOSE_FN closeKeyFn);
    00374 GWENHYWFAR_API
    00375   void GWEN_CryptKey_SetDupFn(GWEN_CRYPTKEY *key,
    00376                               GWEN_CRYPTKEY_DUP_FN dupFn);
    00377 #endif
    00378
    00384   /* _______________________________________________________________________
    00385    * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    00386    *                           Crypt provider (plugin)
    00387    * YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
    00388    */
    00389
    00390 typedef struct GWEN_CRYPTKEY_PROVIDER GWEN_CRYPTKEY_PROVIDER;
    00391
    00392 typedef GWEN_CRYPTKEY*
    00393     (*GWEN_CRYPTPROVIDER_NEWKEY_FN)(GWEN_CRYPTKEY_PROVIDER *pr);
    00394
    00395 GWENHYWFAR_API
    00396   GWEN_CRYPTKEY_PROVIDER *GWEN_CryptProvider_new();
    00397 GWENHYWFAR_API
    00398   void GWEN_CryptProvider_free(GWEN_CRYPTKEY_PROVIDER *pr);
    00399
    00400 GWENHYWFAR_API
    00401   void GWEN_CryptProvider_SetNewKeyFn(GWEN_CRYPTKEY_PROVIDER *pr,
    00402                                       GWEN_CRYPTPROVIDER_NEWKEY_FN newKeyFn);
    00403 GWENHYWFAR_API
    00404   void GWEN_CryptProvider_SetName(GWEN_CRYPTKEY_PROVIDER *pr,
    00405                                   const char *name);
    00406
    00410 GWENHYWFAR_API
    00411   GWEN_ERRORCODE GWEN_Crypt_RegisterProvider(GWEN_CRYPTKEY_PROVIDER *pr);
    00412 GWENHYWFAR_API
    00413   GWEN_ERRORCODE GWEN_Crypt_UnregisterProvider(GWEN_CRYPTKEY_PROVIDER *pr);
    00414
    00415 GWENHYWFAR_API
    00416   void GWEN_Crypt_UnregisterAllProviders();
    00417
    00418
    00419 #ifdef __cplusplus
    00420 }
    00421 #endif
    00422
    00423
    00424
    00425 #endif