gwenhywfar  5.10.1
paddalgo.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Wed Mar 16 2005
3  copyright : (C) 2005 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 
15 #define DISABLE_DEBUGLOG
16 
17 
18 #include "paddalgo_p.h"
19 #include <gwenhywfar/misc.h>
20 #include <gwenhywfar/debug.h>
21 
22 
23 
24 GWEN_LIST2_FUNCTIONS(GWEN_CRYPT_PADDALGO, GWEN_Crypt_PaddAlgo)
25 
26 
27 
29 {
30  assert(s);
31  if (strcasecmp(s, "none")==0)
32  return GWEN_Crypt_PaddAlgoId_None;
33  else if (strcasecmp(s, "iso9796_1")==0)
34  return GWEN_Crypt_PaddAlgoId_Iso9796_1;
35  else if (strcasecmp(s, "iso9796_1a4")==0)
36  return GWEN_Crypt_PaddAlgoId_Iso9796_1A4;
37  else if (strcasecmp(s, "iso9796_2")==0)
38  return GWEN_Crypt_PaddAlgoId_Iso9796_2;
39  else if (strcasecmp(s, "pkcs1_1")==0)
40  return GWEN_Crypt_PaddAlgoId_Pkcs1_1;
41  else if (strcasecmp(s, "pkcs1_2")==0)
42  return GWEN_Crypt_PaddAlgoId_Pkcs1_2;
43  else if (strcasecmp(s, "leftzero")==0)
44  return GWEN_Crypt_PaddAlgoId_LeftZero;
45  else if (strcasecmp(s, "rightzero")==0)
46  return GWEN_Crypt_PaddAlgoId_RightZero;
47  else if (strcasecmp(s, "ansix9_23")==0)
48  return GWEN_Crypt_PaddAlgoId_AnsiX9_23;
49  else if (strcasecmp(s, "pkcs1_pss_sha256")==0)
50  return GWEN_Crypt_PaddAlgoId_Pkcs1_Pss_Sha256;
51  else if (strcasecmp(s, "any")==0)
52  return GWEN_Crypt_PaddAlgoId_Any;
53  return GWEN_Crypt_PaddAlgoId_Unknown;
54 }
55 
56 
57 
59 {
60  switch (a) {
61  case GWEN_Crypt_PaddAlgoId_None:
62  return "none";
63  case GWEN_Crypt_PaddAlgoId_Iso9796_1:
64  return "iso9796_1";
65  case GWEN_Crypt_PaddAlgoId_Iso9796_1A4:
66  return "iso9796_1a4";
67  case GWEN_Crypt_PaddAlgoId_Iso9796_2:
68  return "iso9796_2";
69  case GWEN_Crypt_PaddAlgoId_Pkcs1_1:
70  return "pkcs1_1";
71  case GWEN_Crypt_PaddAlgoId_Pkcs1_2:
72  return "pkcs1_2";
73  case GWEN_Crypt_PaddAlgoId_LeftZero:
74  return "leftzero";
75  case GWEN_Crypt_PaddAlgoId_RightZero:
76  return "rightzero";
77  case GWEN_Crypt_PaddAlgoId_AnsiX9_23:
78  return "ansix9_23";
79  case GWEN_Crypt_PaddAlgoId_Pkcs1_Pss_Sha256:
80  return "pkcs1_pss_sha256";
81  case GWEN_Crypt_PaddAlgoId_Any:
82  return "any";
83  default:
84  return "unknown";
85  }
86 }
87 
88 
89 
91 {
93 
95  a->refCount=1;
96 
97  a->id=id;
98 
99  return a;
100 }
101 
102 
103 
105 {
106  assert(a);
107  assert(a->refCount);
108  a->refCount++;
109 }
110 
111 
112 
114 {
115  const char *s;
116 
117  assert(db);
118  s=GWEN_DB_GetCharValue(db, "id", 0, NULL);
119  if (s) {
122 
124  if (id==GWEN_Crypt_PaddAlgoId_Unknown) {
125  DBG_INFO(GWEN_LOGDOMAIN, "Unknown paddalgo id [%s]", s);
126  return NULL;
127  }
129  assert(a);
130 
131  a->paddSize=GWEN_DB_GetIntValue(db, "paddSize", 0, 0);
132 
133  return a;
134  }
135  else {
136  DBG_INFO(GWEN_LOGDOMAIN, "Missing paddalgo id");
137  return NULL;
138  }
139 }
140 
141 
142 
144 {
145  assert(a);
146  assert(a->refCount);
147 
149  "id",
152  "paddSize", a->paddSize);
153  return 0;
154 }
155 
156 
157 
159 {
161 
162  assert(na);
163  a=GWEN_Crypt_PaddAlgo_new(na->id);
164  a->paddSize=na->paddSize;
165  return a;
166 }
167 
168 
169 
171 {
172  if (a) {
173  assert(a->refCount);
174  if (a->refCount==1) {
175  a->refCount--;
176  GWEN_FREE_OBJECT(a);
177  }
178  else {
179  a->refCount--;
180  }
181  }
182 }
183 
184 
185 
187 {
188  assert(a);
189  assert(a->refCount);
190  return a->id;
191 }
192 
193 
194 
196 {
197  assert(a);
198  assert(a->refCount);
199  return a->paddSize;
200 }
201 
202 
203 
205 {
206  assert(a);
207  assert(a->refCount);
208  a->paddSize=s;
209 }
210 
211 
212 
213 
int GWEN_Crypt_PaddAlgo_GetPaddSize(const GWEN_CRYPT_PADDALGO *a)
Definition: paddalgo.c:195
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
#define GWEN_LIST2_FUNCTIONS(t, pr)
Definition: list2.h:99
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
GWEN_CRYPT_PADDALGO * GWEN_Crypt_PaddAlgo_new(GWEN_CRYPT_PADDALGOID id)
Definition: paddalgo.c:90
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
GWEN_CRYPT_PADDALGO * GWEN_Crypt_PaddAlgo_fromDb(GWEN_DB_NODE *db)
Definition: paddalgo.c:113
struct GWEN_CRYPT_PADDALGO GWEN_CRYPT_PADDALGO
Definition: paddalgo.h:21
#define GWEN_LOGDOMAIN
Definition: logger.h:35
void GWEN_Crypt_PaddAlgo_free(GWEN_CRYPT_PADDALGO *a)
Definition: paddalgo.c:170
void GWEN_Crypt_PaddAlgo_SetPaddSize(GWEN_CRYPT_PADDALGO *a, int s)
Definition: paddalgo.c:204
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
const char * GWEN_Crypt_PaddAlgoId_toString(GWEN_CRYPT_PADDALGOID a)
Definition: paddalgo.c:58
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
GWEN_CRYPT_PADDALGOID GWEN_Crypt_PaddAlgo_GetId(const GWEN_CRYPT_PADDALGO *a)
Definition: paddalgo.c:186
GWEN_CRYPT_PADDALGOID GWEN_Crypt_PaddAlgoId_fromString(const char *s)
Definition: paddalgo.c:28
int GWEN_Crypt_PaddAlgo_toDb(const GWEN_CRYPT_PADDALGO *a, GWEN_DB_NODE *db)
Definition: paddalgo.c:143
GWEN_CRYPT_PADDALGOID
Definition: paddalgo.h:60
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:997
GWEN_CRYPT_PADDALGO * GWEN_Crypt_PaddAlgo_dup(const GWEN_CRYPT_PADDALGO *na)
Definition: paddalgo.c:158
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1202
void GWEN_Crypt_PaddAlgo_Attach(GWEN_CRYPT_PADDALGO *a)
Definition: paddalgo.c:104