15 #define DISABLE_DEBUGLOG
18 #include "cryptalgo_p.h"
19 #include <gwenhywfar/misc.h>
20 #include <gwenhywfar/debug.h>
30 if (strcasecmp(s,
"none")==0)
31 return GWEN_Crypt_CryptAlgoId_None;
32 else if (strcasecmp(s,
"rsa")==0)
33 return GWEN_Crypt_CryptAlgoId_Rsa;
34 else if (strcasecmp(s,
"dsa")==0)
35 return GWEN_Crypt_CryptAlgoId_Dsa;
36 else if (strcasecmp(s,
"des")==0)
37 return GWEN_Crypt_CryptAlgoId_Des;
38 else if (strcasecmp(s,
"des_3k")==0 ||
39 strcasecmp(s,
"des3k")==0)
40 return GWEN_Crypt_CryptAlgoId_Des3K;
41 else if (strcasecmp(s,
"blowfish")==0)
42 return GWEN_Crypt_CryptAlgoId_BlowFish;
43 else if (strcasecmp(s,
"aes128")==0)
44 return GWEN_Crypt_CryptAlgoId_Aes128;
45 else if (strcasecmp(s,
"any")==0)
46 return GWEN_Crypt_CryptAlgoId_Any;
47 return GWEN_Crypt_CryptAlgoId_Unknown;
54 case GWEN_Crypt_CryptAlgoId_None:
56 case GWEN_Crypt_CryptAlgoId_Rsa:
58 case GWEN_Crypt_CryptAlgoId_Dsa:
60 case GWEN_Crypt_CryptAlgoId_Des:
62 case GWEN_Crypt_CryptAlgoId_Des3K:
64 case GWEN_Crypt_CryptAlgoId_BlowFish:
66 case GWEN_Crypt_CryptAlgoId_Aes128:
68 case GWEN_Crypt_CryptAlgoId_Any:
79 if (strcasecmp(s,
"none")==0)
81 else if (strcasecmp(s,
"ecb")==0)
83 else if (strcasecmp(s,
"cfb")==0)
85 else if (strcasecmp(s,
"cbc")==0)
145 if (
id==GWEN_Crypt_CryptAlgoId_Unknown) {
187 if (a->pInitVector && a->lInitVector)
190 a->pInitVector, a->lInitVector);
208 if (na->pInitVector && na->lInitVector) {
209 a->pInitVector=(uint8_t*) malloc(na->lInitVector);
210 if (a->pInitVector==
NULL) {
215 memmove(a->pInitVector, na->pInitVector, na->lInitVector);
216 a->lInitVector=na->lInitVector;
218 a->chunkSize=na->chunkSize;
219 a->keySizeInBits=na->keySizeInBits;
228 if (a->refCount==1) {
229 if (a->pInitVector) {
230 free(a->pInitVector);
263 return a->pInitVector;
271 return a->lInitVector;
285 nv=(uint8_t*) malloc(lv);
291 if (a->pInitVector && a->lInitVector)
292 free(a->pInitVector);
295 a->lInitVector=(nv!=
NULL)?lv:0;
324 return a->keySizeInBits;
int GWEN_Crypt_CryptAlgo_GetChunkSize(const GWEN_CRYPT_CRYPTALGO *a)
#define GWEN_DB_FLAGS_OVERWRITE_VARS
struct GWEN_DB_NODE GWEN_DB_NODE
GWEN_CRYPT_CRYPTALGOID GWEN_Crypt_CryptAlgoId_fromString(const char *s)
const char * GWEN_Crypt_CryptMode_toString(GWEN_CRYPT_CRYPTMODE m)
#define GWEN_FREE_OBJECT(varname)
void GWEN_Crypt_CryptAlgo_free(GWEN_CRYPT_CRYPTALGO *a)
GWEN_CRYPT_CRYPTALGO * GWEN_Crypt_CryptAlgo_dup(const GWEN_CRYPT_CRYPTALGO *na)
void GWEN_Crypt_CryptAlgo_SetKeySizeInBits(GWEN_CRYPT_CRYPTALGO *a, int s)
void GWEN_Crypt_CryptAlgo_SetChunkSize(GWEN_CRYPT_CRYPTALGO *a, int s)
int GWEN_Crypt_CryptAlgo_SetInitVector(GWEN_CRYPT_CRYPTALGO *a, const uint8_t *pv, uint32_t lv)
int GWEN_DB_SetBinValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const void *val, unsigned int valSize)
#define GWEN_NEW_OBJECT(typ, varname)
int GWEN_Crypt_CryptAlgo_toDb(const GWEN_CRYPT_CRYPTALGO *a, GWEN_DB_NODE *db)
GWEN_CRYPT_CRYPTALGO * GWEN_Crypt_CryptAlgo_fromDb(GWEN_DB_NODE *db)
const char * GWEN_Crypt_CryptAlgoId_toString(GWEN_CRYPT_CRYPTALGOID a)
const void * GWEN_DB_GetBinValue(GWEN_DB_NODE *n, const char *path, int idx, const void *defVal, unsigned int defValSize, unsigned int *returnValueSize)
uint32_t GWEN_Crypt_CryptAlgo_GetInitVectorLen(const GWEN_CRYPT_CRYPTALGO *a)
int GWEN_Crypt_CryptAlgo_GetKeySizeInBits(const GWEN_CRYPT_CRYPTALGO *a)
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
GWEN_CRYPT_CRYPTMODE GWEN_Crypt_CryptMode_fromString(const char *s)
GWEN_LIST2_FUNCTIONS(TYPEMAKER2_TYPE, Typemaker2_Type)
struct GWEN_CRYPT_CRYPTALGO GWEN_CRYPT_CRYPTALGO
void GWEN_Crypt_CryptAlgo_Attach(GWEN_CRYPT_CRYPTALGO *a)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
GWEN_CRYPT_CRYPTALGOID GWEN_Crypt_CryptAlgo_GetId(const GWEN_CRYPT_CRYPTALGO *a)
uint8_t * GWEN_Crypt_CryptAlgo_GetInitVectorPtr(const GWEN_CRYPT_CRYPTALGO *a)
#define DBG_INFO(dbg_logger, format, args...)
GWEN_CRYPT_CRYPTMODE GWEN_Crypt_CryptAlgo_GetMode(const GWEN_CRYPT_CRYPTALGO *a)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
GWEN_CRYPT_CRYPTALGO * GWEN_Crypt_CryptAlgo_new(GWEN_CRYPT_CRYPTALGOID id, GWEN_CRYPT_CRYPTMODE m)
#define GWEN_ERROR_MEMORY_FULL