| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #include "wizard/studio.h" |
|---|
| 44 | #include "wizard/bzip.h" |
|---|
| 45 | #include "wizard/entropy.h" |
|---|
| 46 | #include "wizard/exception.h" |
|---|
| 47 | #include "wizard/exception-private.h" |
|---|
| 48 | #include "wizard/memory_.h" |
|---|
| 49 | #include "wizard/zip.h" |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | struct _EntropyInfo |
|---|
| 55 | { |
|---|
| 56 | EntropyType |
|---|
| 57 | entropy; |
|---|
| 58 | |
|---|
| 59 | void |
|---|
| 60 | *handle; |
|---|
| 61 | |
|---|
| 62 | time_t |
|---|
| 63 | timestamp; |
|---|
| 64 | |
|---|
| 65 | unsigned long |
|---|
| 66 | signature; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | WizardExport EntropyInfo *AcquireEntropyInfo(const EntropyType entropy, |
|---|
| 95 | const unsigned long level) |
|---|
| 96 | { |
|---|
| 97 | EntropyInfo |
|---|
| 98 | *entropy_info; |
|---|
| 99 | |
|---|
| 100 | entropy_info=(EntropyInfo *) AcquireWizardMemory(sizeof(*entropy_info)); |
|---|
| 101 | if (entropy_info == (EntropyInfo *) NULL) |
|---|
| 102 | ThrowWizardFatalError(EntropyDomain,MemoryError); |
|---|
| 103 | (void) ResetWizardMemory(entropy_info,0,sizeof(*entropy_info)); |
|---|
| 104 | entropy_info->entropy=entropy; |
|---|
| 105 | switch (entropy_info->entropy) |
|---|
| 106 | { |
|---|
| 107 | case BZIPEntropy: |
|---|
| 108 | { |
|---|
| 109 | entropy_info->handle=(EntropyInfo *) AcquireBZIPInfo(level); |
|---|
| 110 | break; |
|---|
| 111 | } |
|---|
| 112 | case ZIPEntropy: |
|---|
| 113 | { |
|---|
| 114 | entropy_info->handle=(EntropyInfo *) AcquireZIPInfo(level); |
|---|
| 115 | break; |
|---|
| 116 | } |
|---|
| 117 | default: |
|---|
| 118 | ThrowWizardFatalError(EntropyDomain,EnumerateError); |
|---|
| 119 | } |
|---|
| 120 | entropy_info->timestamp=time((time_t *) NULL); |
|---|
| 121 | entropy_info->signature=WizardSignature; |
|---|
| 122 | return(entropy_info); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | WizardExport EntropyInfo *DestroyEntropyInfo(EntropyInfo *entropy_info) |
|---|
| 149 | { |
|---|
| 150 | (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); |
|---|
| 151 | WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL); |
|---|
| 152 | WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature); |
|---|
| 153 | if (entropy_info->handle != (EntropyInfo *) NULL) |
|---|
| 154 | switch (entropy_info->entropy) |
|---|
| 155 | { |
|---|
| 156 | case BZIPEntropy: |
|---|
| 157 | { |
|---|
| 158 | entropy_info->handle=(void *) DestroyBZIPInfo((BZIPInfo *) |
|---|
| 159 | entropy_info->handle); |
|---|
| 160 | break; |
|---|
| 161 | } |
|---|
| 162 | case ZIPEntropy: |
|---|
| 163 | { |
|---|
| 164 | entropy_info->handle=(void *) DestroyZIPInfo((ZIPInfo *) |
|---|
| 165 | entropy_info->handle); |
|---|
| 166 | break; |
|---|
| 167 | } |
|---|
| 168 | default: |
|---|
| 169 | break; |
|---|
| 170 | } |
|---|
| 171 | entropy_info->signature=(~WizardSignature); |
|---|
| 172 | entropy_info=(EntropyInfo *) RelinquishWizardMemory(entropy_info); |
|---|
| 173 | return(entropy_info); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | WizardExport const StringInfo *GetEntropyChaos(const EntropyInfo *entropy_info) |
|---|
| 199 | { |
|---|
| 200 | const StringInfo |
|---|
| 201 | *chaos; |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); |
|---|
| 207 | WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL); |
|---|
| 208 | WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature); |
|---|
| 209 | switch (entropy_info->entropy) |
|---|
| 210 | { |
|---|
| 211 | case BZIPEntropy: |
|---|
| 212 | { |
|---|
| 213 | BZIPInfo |
|---|
| 214 | *bzip_info; |
|---|
| 215 | |
|---|
| 216 | bzip_info=(BZIPInfo *) entropy_info->handle; |
|---|
| 217 | chaos=GetBZIPChaos(bzip_info); |
|---|
| 218 | break; |
|---|
| 219 | } |
|---|
| 220 | case ZIPEntropy: |
|---|
| 221 | { |
|---|
| 222 | ZIPInfo |
|---|
| 223 | *zip_info; |
|---|
| 224 | |
|---|
| 225 | zip_info=(ZIPInfo *) entropy_info->handle; |
|---|
| 226 | chaos=GetZIPChaos(zip_info); |
|---|
| 227 | break; |
|---|
| 228 | } |
|---|
| 229 | default: |
|---|
| 230 | ThrowWizardFatalError(EntropyDomain,EnumerateError); |
|---|
| 231 | } |
|---|
| 232 | return(chaos); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | WizardExport WizardBooleanType IncreaseEntropy(EntropyInfo *entropy_info, |
|---|
| 263 | const StringInfo *message,ExceptionInfo *exception) |
|---|
| 264 | { |
|---|
| 265 | WizardBooleanType |
|---|
| 266 | status; |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); |
|---|
| 272 | WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL); |
|---|
| 273 | WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature); |
|---|
| 274 | WizardAssert(EntropyDomain,message != (const StringInfo *) NULL); |
|---|
| 275 | status=WizardFalse; |
|---|
| 276 | switch (entropy_info->entropy) |
|---|
| 277 | { |
|---|
| 278 | case BZIPEntropy: |
|---|
| 279 | { |
|---|
| 280 | BZIPInfo |
|---|
| 281 | *bzip_info; |
|---|
| 282 | |
|---|
| 283 | bzip_info=(BZIPInfo *) entropy_info->handle; |
|---|
| 284 | status=IncreaseBZIP(bzip_info,message,exception); |
|---|
| 285 | break; |
|---|
| 286 | } |
|---|
| 287 | case ZIPEntropy: |
|---|
| 288 | { |
|---|
| 289 | ZIPInfo |
|---|
| 290 | *zip_info; |
|---|
| 291 | |
|---|
| 292 | zip_info=(ZIPInfo *) entropy_info->handle; |
|---|
| 293 | status=IncreaseZIP(zip_info,message,exception); |
|---|
| 294 | break; |
|---|
| 295 | } |
|---|
| 296 | default: |
|---|
| 297 | ThrowWizardFatalError(EntropyDomain,EnumerateError); |
|---|
| 298 | } |
|---|
| 299 | return(status); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | WizardExport WizardBooleanType RestoreEntropy(EntropyInfo *entropy_info, |
|---|
| 333 | const size_t length,const StringInfo *message,ExceptionInfo *exception) |
|---|
| 334 | { |
|---|
| 335 | WizardBooleanType |
|---|
| 336 | status; |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); |
|---|
| 342 | WizardAssert(EntropyDomain,entropy_info != (EntropyInfo *) NULL); |
|---|
| 343 | WizardAssert(EntropyDomain,entropy_info->signature == WizardSignature); |
|---|
| 344 | WizardAssert(EntropyDomain,message != (const StringInfo *) NULL); |
|---|
| 345 | status=WizardFalse; |
|---|
| 346 | switch (entropy_info->entropy) |
|---|
| 347 | { |
|---|
| 348 | case BZIPEntropy: |
|---|
| 349 | { |
|---|
| 350 | BZIPInfo |
|---|
| 351 | *bzip_info; |
|---|
| 352 | |
|---|
| 353 | bzip_info=(BZIPInfo *) entropy_info->handle; |
|---|
| 354 | status=RestoreBZIP(bzip_info,length,message,exception); |
|---|
| 355 | break; |
|---|
| 356 | } |
|---|
| 357 | case ZIPEntropy: |
|---|
| 358 | { |
|---|
| 359 | ZIPInfo |
|---|
| 360 | *zip_info; |
|---|
| 361 | |
|---|
| 362 | zip_info=(ZIPInfo *) entropy_info->handle; |
|---|
| 363 | status=RestoreZIP(zip_info,length,message,exception); |
|---|
| 364 | break; |
|---|
| 365 | } |
|---|
| 366 | default: |
|---|
| 367 | ThrowWizardFatalError(EntropyDomain,EnumerateError); |
|---|
| 368 | } |
|---|
| 369 | return(status); |
|---|
| 370 | } |
|---|