ct_keyinfo.c

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

Generated on Mon Jan 25 12:56:01 2010 for gwenhywfar by  doxygen 1.5.6