entropy.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "wizard/studio.h"
00044 #include "wizard/bzip.h"
00045 #include "wizard/entropy.h"
00046 #include "wizard/exception.h"
00047 #include "wizard/exception-private.h"
00048 #include "wizard/memory_.h"
00049 #include "wizard/zip.h"
00050
00051
00052
00053
00054 struct _EntropyInfo
00055 {
00056 EntropyType
00057 entropy;
00058
00059 void
00060 *handle;
00061
00062 time_t
00063 timestamp;
00064
00065 size_t
00066 signature;
00067 };
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 WizardExport EntropyInfo *AcquireEntropyInfo(const EntropyType entropy,
00095 const size_t level)
00096 {
00097 EntropyInfo
00098 *entropy_info;
00099
00100 entropy_info=(EntropyInfo *) AcquireAlignedMemory(1,sizeof(*entropy_info));
00101 if (entropy_info == (EntropyInfo *) NULL)
00102 ThrowWizardFatalError(EntropyDomain,MemoryError);
00103 (void) ResetWizardMemory(entropy_info,0,sizeof(*entropy_info));
00104 entropy_info->entropy=entropy;
00105 switch (entropy_info->entropy)
00106 {
00107 case BZIPEntropy:
00108 {
00109 entropy_info->handle=(EntropyInfo *) AcquireBZIPInfo(level);
00110 break;
00111 }
00112 case ZIPEntropy:
00113 {
00114 entropy_info->handle=(EntropyInfo *) AcquireZIPInfo(level);
00115 break;
00116 }
00117 default:
00118 ThrowWizardFatalError(EntropyDomain,EnumerateError);
00119 }
00120 entropy_info->timestamp=time((time_t *) NULL);
00121 entropy_info->signature=WizardSignature;
00122 return(entropy_info);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 WizardExport EntropyInfo *DestroyEntropyInfo(EntropyInfo *entropy_info)
00149 {
00150 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00151 WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL);
00152 WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature);
00153 if (entropy_info->handle != (EntropyInfo *) NULL)
00154 switch (entropy_info->entropy)
00155 {
00156 case BZIPEntropy:
00157 {
00158 entropy_info->handle=(void *) DestroyBZIPInfo((BZIPInfo *)
00159 entropy_info->handle);
00160 break;
00161 }
00162 case ZIPEntropy:
00163 {
00164 entropy_info->handle=(void *) DestroyZIPInfo((ZIPInfo *)
00165 entropy_info->handle);
00166 break;
00167 }
00168 default:
00169 break;
00170 }
00171 entropy_info->signature=(~WizardSignature);
00172 entropy_info=(EntropyInfo *) RelinquishWizardMemory(entropy_info);
00173 return(entropy_info);
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 WizardExport const StringInfo *GetEntropyChaos(const EntropyInfo *entropy_info)
00199 {
00200 const StringInfo
00201 *chaos;
00202
00203
00204
00205
00206 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00207 WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL);
00208 WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature);
00209 switch (entropy_info->entropy)
00210 {
00211 case BZIPEntropy:
00212 {
00213 BZIPInfo
00214 *bzip_info;
00215
00216 bzip_info=(BZIPInfo *) entropy_info->handle;
00217 chaos=GetBZIPChaos(bzip_info);
00218 break;
00219 }
00220 case ZIPEntropy:
00221 {
00222 ZIPInfo
00223 *zip_info;
00224
00225 zip_info=(ZIPInfo *) entropy_info->handle;
00226 chaos=GetZIPChaos(zip_info);
00227 break;
00228 }
00229 default:
00230 ThrowWizardFatalError(EntropyDomain,EnumerateError);
00231 }
00232 return(chaos);
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 WizardExport WizardBooleanType IncreaseEntropy(EntropyInfo *entropy_info,
00263 const StringInfo *message,ExceptionInfo *exception)
00264 {
00265 WizardBooleanType
00266 status;
00267
00268
00269
00270
00271 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00272 WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL);
00273 WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature);
00274 WizardAssert(EntropyDomain,message != (const StringInfo *) NULL);
00275 status=WizardFalse;
00276 switch (entropy_info->entropy)
00277 {
00278 case BZIPEntropy:
00279 {
00280 BZIPInfo
00281 *bzip_info;
00282
00283 bzip_info=(BZIPInfo *) entropy_info->handle;
00284 status=IncreaseBZIP(bzip_info,message,exception);
00285 break;
00286 }
00287 case ZIPEntropy:
00288 {
00289 ZIPInfo
00290 *zip_info;
00291
00292 zip_info=(ZIPInfo *) entropy_info->handle;
00293 status=IncreaseZIP(zip_info,message,exception);
00294 break;
00295 }
00296 default:
00297 ThrowWizardFatalError(EntropyDomain,EnumerateError);
00298 }
00299 return(status);
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 WizardExport WizardBooleanType RestoreEntropy(EntropyInfo *entropy_info,
00333 const size_t length,const StringInfo *message,ExceptionInfo *exception)
00334 {
00335 WizardBooleanType
00336 status;
00337
00338
00339
00340
00341 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00342 WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL);
00343 WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature);
00344 WizardAssert(EntropyDomain,message != (const StringInfo *) NULL);
00345 status=WizardFalse;
00346 switch (entropy_info->entropy)
00347 {
00348 case BZIPEntropy:
00349 {
00350 BZIPInfo
00351 *bzip_info;
00352
00353 bzip_info=(BZIPInfo *) entropy_info->handle;
00354 status=RestoreBZIP(bzip_info,length,message,exception);
00355 break;
00356 }
00357 case ZIPEntropy:
00358 {
00359 ZIPInfo
00360 *zip_info;
00361
00362 zip_info=(ZIPInfo *) entropy_info->handle;
00363 status=RestoreZIP(zip_info,length,message,exception);
00364 break;
00365 }
00366 default:
00367 ThrowWizardFatalError(EntropyDomain,EnumerateError);
00368 }
00369 return(status);
00370 }