gwenhywfar 4.0.3

ct_keyinfo.c

Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Wed Mar 16 2005
00003     copyright   : (C) 2005 by Martin Preuss
00004     email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 #ifdef HAVE_CONFIG_H
00011 # include <config.h>
00012 #endif
00013 
00014 #define DISABLE_DEBUGLOG
00015 
00016 
00017 #include "ct_keyinfo_p.h"
00018 #include <gwenhywfar/misc.h>
00019 #include <gwenhywfar/debug.h>
00020 
00021 
00022 
00023 GWEN_LIST_FUNCTIONS(GWEN_CRYPT_TOKEN_KEYINFO, GWEN_Crypt_Token_KeyInfo)
00024 GWEN_LIST2_FUNCTIONS(GWEN_CRYPT_TOKEN_KEYINFO, GWEN_Crypt_Token_KeyInfo)
00025 
00026 
00027 
00028 
00029 GWEN_CRYPT_TOKEN_KEYINFO *GWEN_Crypt_Token_KeyInfo_new(uint32_t kid,
00030                                                        GWEN_CRYPT_CRYPTALGOID a,
00031                                                        int keySize) {
00032   GWEN_CRYPT_TOKEN_KEYINFO *ki;
00033 
00034   GWEN_NEW_OBJECT(GWEN_CRYPT_TOKEN_KEYINFO, ki)
00035   ki->refCount=1;
00036   GWEN_LIST_INIT(GWEN_CRYPT_TOKEN_KEYINFO, ki)
00037 
00038   ki->keyId=kid;
00039   ki->cryptAlgoId=a;
00040   ki->keySize=keySize;
00041 
00042   return ki;
00043 }
00044 
00045 
00046 
00047 void GWEN_Crypt_Token_KeyInfo_free(GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00048   if (ki) {
00049     assert(ki->refCount);
00050     if (ki->refCount==1) {
00051       free(ki->keyDescr);
00052       if (ki->modulusData)
00053         free(ki->modulusData);
00054       ki->modulusData=NULL;
00055       if (ki->exponentData)
00056         free(ki->exponentData);
00057       ki->exponentData=NULL;
00058 
00059       ki->refCount=0;
00060       GWEN_FREE_OBJECT(ki);
00061     }
00062     else {
00063       ki->refCount--;
00064     }
00065   }
00066 }
00067 
00068 
00069 
00070 GWEN_CRYPT_TOKEN_KEYINFO *GWEN_Crypt_Token_KeyInfo_dup(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00071   GWEN_CRYPT_TOKEN_KEYINFO *nki;
00072 
00073   nki=GWEN_Crypt_Token_KeyInfo_new(ki->keyId,
00074                                    ki->cryptAlgoId,
00075                                    ki->keySize);
00076   nki->flags=ki->flags;
00077 
00078   if (ki->modulusData && ki->modulusLen) {
00079     nki->modulusData=(uint8_t*)malloc(ki->modulusLen);
00080     assert(nki->modulusData);
00081     memmove(nki->modulusData, ki->modulusData, ki->modulusLen);
00082     nki->modulusLen=ki->modulusLen;
00083   }
00084 
00085   if (ki->exponentData && ki->exponentLen) {
00086     nki->exponentData=(uint8_t*)malloc(ki->exponentLen);
00087     assert(nki->exponentData);
00088     memmove(nki->exponentData, ki->exponentData, ki->exponentLen);
00089     nki->exponentLen=ki->exponentLen;
00090   }
00091 
00092   if (ki->keyDescr)
00093     nki->keyDescr=strdup(ki->keyDescr);
00094 
00095   nki->keyNumber=ki->keyNumber;
00096   nki->keyVersion=ki->keyVersion;
00097   nki->signCounter=ki->signCounter;
00098 
00099   return nki;
00100 }
00101 
00102 
00103 
00104 uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyId(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00105   assert(ki);
00106   assert(ki->refCount);
00107   return ki->keyId;
00108 }
00109 
00110 
00111 
00112 GWEN_CRYPT_CRYPTALGOID GWEN_Crypt_Token_KeyInfo_GetCryptAlgoId(const GWEN_CRYPT_TOKEN_KEYINFO *ki){
00113   assert(ki);
00114   assert(ki->refCount);
00115   return ki->cryptAlgoId;
00116 }
00117 
00118 
00119 
00120 int GWEN_Crypt_Token_KeyInfo_GetKeySize(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00121   assert(ki);
00122   assert(ki->refCount);
00123   return ki->keySize;
00124 }
00125 
00126 
00127 
00128 void GWEN_Crypt_Token_KeyInfo_SetKeySize(GWEN_CRYPT_TOKEN_KEYINFO *ki, int i){
00129   assert(ki);
00130   assert(ki->refCount);
00131   ki->keySize=i;
00132 }
00133 
00134 
00135 
00136 uint32_t GWEN_Crypt_Token_KeyInfo_GetFlags(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00137   assert(ki);
00138   assert(ki->refCount);
00139   return ki->flags;
00140 }
00141 
00142 
00143 
00144 void GWEN_Crypt_Token_KeyInfo_SetFlags(GWEN_CRYPT_TOKEN_KEYINFO *ki, uint32_t f) {
00145   assert(ki);
00146   assert(ki->refCount);
00147   ki->flags=f;
00148 }
00149 
00150 
00151 
00152 void GWEN_Crypt_Token_KeyInfo_AddFlags(GWEN_CRYPT_TOKEN_KEYINFO *ki, uint32_t f) {
00153   assert(ki);
00154   assert(ki->refCount);
00155   ki->flags|=f;
00156 }
00157 
00158 
00159 
00160 void GWEN_Crypt_Token_KeyInfo_SubFlags(GWEN_CRYPT_TOKEN_KEYINFO *ki, uint32_t f) {
00161   assert(ki);
00162   assert(ki->refCount);
00163   ki->flags&=~f;
00164 }
00165 
00166 
00167 
00168 const uint8_t *GWEN_Crypt_Token_KeyInfo_GetModulusData(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00169   assert(ki);
00170   assert(ki->refCount);
00171   return ki->modulusData;
00172 }
00173 
00174 
00175 
00176 uint32_t GWEN_Crypt_Token_KeyInfo_GetModulusLen(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00177   assert(ki);
00178   assert(ki->refCount);
00179   return ki->modulusLen;
00180 }
00181 
00182 
00183 
00184 void GWEN_Crypt_Token_KeyInfo_SetModulus(GWEN_CRYPT_TOKEN_KEYINFO *ki,
00185                                          const uint8_t *p,
00186                                          uint32_t len) {
00187   assert(ki);
00188   assert(ki->refCount);
00189 
00190   assert(p);
00191   assert(len);
00192 
00193   if (ki->modulusData)
00194     free(ki->modulusData);
00195   ki->modulusData=(uint8_t*) malloc(len);
00196   assert(ki->modulusData);
00197   memmove(ki->modulusData, p, len);
00198   ki->modulusLen=len;
00199 }
00200 
00201 
00202 
00203 const uint8_t *GWEN_Crypt_Token_KeyInfo_GetExponentData(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00204   assert(ki);
00205   assert(ki->refCount);
00206   return ki->exponentData;
00207 }
00208 
00209 
00210 
00211 uint32_t GWEN_Crypt_Token_KeyInfo_GetExponentLen(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00212   assert(ki);
00213   assert(ki->refCount);
00214   return ki->exponentLen;
00215 }
00216 
00217 
00218 
00219 void GWEN_Crypt_Token_KeyInfo_SetExponent(GWEN_CRYPT_TOKEN_KEYINFO *ki,
00220                                           const uint8_t *p,
00221                                           uint32_t len) {
00222   assert(ki);
00223   assert(ki->refCount);
00224 
00225   assert(p);
00226   assert(len);
00227 
00228   if (ki->exponentData)
00229     free(ki->exponentData);
00230   ki->exponentData=(uint8_t*) malloc(len);
00231   assert(ki->exponentData);
00232   memmove(ki->exponentData, p, len);
00233   ki->exponentLen=len;
00234 }
00235 
00236 
00237 
00238 uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyVersion(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00239   assert(ki);
00240   assert(ki->refCount);
00241 
00242   return ki->keyVersion;
00243 }
00244 
00245 
00246 
00247 void GWEN_Crypt_Token_KeyInfo_SetKeyVersion(GWEN_CRYPT_TOKEN_KEYINFO *ki,
00248                                             uint32_t i) {
00249   assert(ki);
00250   assert(ki->refCount);
00251 
00252   ki->keyVersion=i;
00253 }
00254 
00255 
00256 
00257 uint32_t GWEN_Crypt_Token_KeyInfo_GetKeyNumber(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00258   assert(ki);
00259   assert(ki->refCount);
00260 
00261   return ki->keyNumber;
00262 }
00263 
00264 
00265 
00266 void GWEN_Crypt_Token_KeyInfo_SetKeyNumber(GWEN_CRYPT_TOKEN_KEYINFO *ki,
00267                                             uint32_t i) {
00268   assert(ki);
00269   assert(ki->refCount);
00270 
00271   ki->keyNumber=i;
00272 }
00273 
00274 
00275 
00276 uint32_t GWEN_Crypt_Token_KeyInfo_GetSignCounter(const GWEN_CRYPT_TOKEN_KEYINFO *ki){
00277   assert(ki);
00278   assert(ki->refCount);
00279 
00280   return ki->signCounter;
00281 }
00282 
00283 
00284 
00285 void GWEN_Crypt_Token_KeyInfo_SetSignCounter(GWEN_CRYPT_TOKEN_KEYINFO *ki,
00286                                              uint32_t i) {
00287   assert(ki);
00288   assert(ki->refCount);
00289 
00290   ki->signCounter=i;
00291 }
00292 
00293 
00294 
00295 const char *GWEN_Crypt_Token_KeyInfo_GetKeyDescr(const GWEN_CRYPT_TOKEN_KEYINFO *ki) {
00296   assert(ki);
00297   assert(ki->refCount);
00298 
00299   return ki->keyDescr;
00300 }
00301 
00302 
00303 
00304 void GWEN_Crypt_Token_KeyInfo_SetKeyDescr(GWEN_CRYPT_TOKEN_KEYINFO *ki, const char *s) {
00305   assert(ki);
00306   assert(ki->refCount);
00307 
00308   free(ki->keyDescr);
00309   if (s)
00310     ki->keyDescr=strdup(s);
00311   else
00312     ki->keyDescr=NULL;
00313 }
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327