hash.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                         H   H   AAA   SSSSS  H   H                          %
00006 %                         H   H  A   A  SS     H   H                          %
00007 %                         HHHHH  AAAAA   SSS   HHHHH                          %
00008 %                         H   H  A   A     SS  H   H                          %
00009 %                         H   H  A   A  SSSSS  H   H                          %
00010 %                                                                             %
00011 %                                                                             %
00012 %                Wizard's Toolkit Secure Hash Algorithm Methods               %
00013 %                                                                             %
00014 %                             Software Design                                 %
00015 %                               John Cristy                                   %
00016 %                               March  2003                                   %
00017 %                                                                             %
00018 %                                                                             %
00019 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
00020 %  dedicated to making software imaging solutions freely available.           %
00021 %                                                                             %
00022 %  You may not use this file except in compliance with the License.  You may  %
00023 %  obtain a copy of the License at                                            %
00024 %                                                                             %
00025 %    http://www.wizards-toolkit.org/script/license.php                        %
00026 %                                                                             %
00027 %  Unless required by applicable law or agreed to in writing, software        %
00028 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00029 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00030 %  See the License for the specific language governing permissions and        %
00031 %  limitations under the License.                                             %
00032 %                                                                             %
00033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00034 %
00035 % See http://csrc.nist.gov/cryptval/shs.htm.
00036 %
00037 */
00038 
00039 /*
00040   Include declarations.
00041 */
00042 #include "wizard/studio.h"
00043 #include "wizard/crc64.h"
00044 #include "wizard/exception.h"
00045 #include "wizard/exception-private.h"
00046 #include "wizard/hash.h"
00047 #include "wizard/memory_.h"
00048 #include "wizard/md5.h"
00049 #include "wizard/sha1.h"
00050 #include "wizard/sha224.h"
00051 #include "wizard/sha256.h"
00052 #include "wizard/sha384.h"
00053 #include "wizard/sha512.h"
00054 
00055 /*
00056   Typedef declarations.
00057 */
00058 struct _HashInfo
00059 {   
00060   HashType
00061     hash;
00062 
00063   StringInfo
00064     *digest;
00065 
00066   void
00067     *handle;
00068 
00069   time_t
00070     timestamp;
00071 
00072   size_t
00073     signature;
00074 };
00075 
00076 /*
00077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00078 %                                                                             %
00079 %                                                                             %
00080 %                                                                             %
00081 %   A c q u i r e H a s h I n f o                                             %
00082 %                                                                             %
00083 %                                                                             %
00084 %                                                                             %
00085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00086 %
00087 %  AcquireHashInfo() allocates the HashInfo structure.
00088 %
00089 %  The format of the AcquireHashInfo method is:
00090 %
00091 %      HashInfo *AcquireHashInfo(const HashType hash)
00092 %
00093 %  A description of each parameter follows:
00094 %
00095 %    o hash: The hash type.
00096 %
00097 */
00098 WizardExport HashInfo *AcquireHashInfo(const HashType hash)
00099 {
00100   HashInfo
00101     *hash_info;
00102 
00103   size_t
00104     digestsize;
00105 
00106   hash_info=(HashInfo *) AcquireAlignedMemory(1,sizeof(*hash_info));
00107   if (hash_info == (HashInfo *) NULL)
00108     ThrowWizardFatalError(HashDomain,MemoryError);
00109   (void) ResetWizardMemory(hash_info,0,sizeof(*hash_info));
00110   hash_info->hash=hash;
00111   switch (hash_info->hash)
00112   {
00113     case CRC64Hash:
00114     {
00115       CRC64Info
00116         *crc_info;
00117 
00118       crc_info=AcquireCRC64Info();
00119       hash_info->handle=(HashInfo *) crc_info;
00120       digestsize=GetCRC64Digestsize(crc_info);
00121       break;
00122     }
00123     case MD5Hash:
00124     {
00125       MD5Info
00126         *md5_info;
00127 
00128       md5_info=AcquireMD5Info();
00129       hash_info->handle=(HashInfo *) md5_info;
00130       digestsize=GetMD5Digestsize(md5_info);
00131       break;
00132     }
00133     case SHA1Hash:
00134     {
00135       SHA1Info
00136         *sha_info;
00137 
00138       sha_info=AcquireSHA1Info();
00139       hash_info->handle=(HashInfo *) sha_info;
00140       digestsize=GetSHA1Digestsize(sha_info);
00141       break;
00142     }
00143     case SHA224Hash:
00144     {
00145       SHA224Info
00146         *sha_info;
00147 
00148       sha_info=AcquireSHA224Info();
00149       hash_info->handle=(HashInfo *) sha_info;
00150       digestsize=GetSHA224Digestsize(sha_info);
00151       break;
00152     }
00153     case SHA256Hash:
00154     {
00155       SHA256Info
00156         *sha_info;
00157 
00158       sha_info=AcquireSHA256Info();
00159       hash_info->handle=(HashInfo *) sha_info;
00160       digestsize=GetSHA256Digestsize(sha_info);
00161       break;
00162     }
00163     case SHA384Hash:
00164     {
00165       SHA384Info
00166         *sha_info;
00167 
00168       sha_info=AcquireSHA384Info();
00169       hash_info->handle=(HashInfo *) sha_info;
00170       digestsize=GetSHA384Digestsize(sha_info);
00171       break;
00172     }
00173     case SHA512Hash:
00174     {
00175       SHA512Info
00176         *sha_info;
00177 
00178       sha_info=AcquireSHA512Info();
00179       hash_info->handle=(HashInfo *) sha_info;
00180       digestsize=GetSHA512Digestsize(sha_info);
00181       break;
00182     }
00183     default:
00184       ThrowWizardFatalError(HashDomain,EnumerateError);
00185   }
00186   hash_info->digest=AcquireStringInfo((size_t) digestsize);
00187   ResetStringInfo(hash_info->digest);
00188   hash_info->timestamp=time((time_t *) NULL);
00189   hash_info->signature=WizardSignature;
00190   return(hash_info);
00191 }
00192 
00193 /*
00194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00195 %                                                                             %
00196 %                                                                             %
00197 %                                                                             %
00198 %   D e s t r o y H a s h I n f o                                             %
00199 %                                                                             %
00200 %                                                                             %
00201 %                                                                             %
00202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00203 %
00204 %  DestroyHashInfo() zeros memory associated with the HashInfo structure.
00205 %
00206 %  The format of the DestroyHashInfo method is:
00207 %
00208 %      HashInfo *DestroyHashInfo(HashInfo *hash_info)
00209 %
00210 %  A description of each parameter follows:
00211 %
00212 %    o hash_info: The hash info.
00213 %
00214 */
00215 WizardExport HashInfo *DestroyHashInfo(HashInfo *hash_info)
00216 {
00217   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00218   assert(hash_info != (HashInfo *) NULL);
00219   assert(hash_info->signature == WizardSignature);
00220   if (hash_info->handle != (HashInfo *) NULL)
00221     switch (hash_info->hash)
00222     {
00223       case CRC64Hash:
00224       {
00225         hash_info->handle=(void *) DestroyCRC64Info((CRC64Info *)
00226           hash_info->handle);
00227         break;
00228       }
00229       case MD5Hash:
00230       {
00231         hash_info->handle=(void *) DestroyMD5Info((MD5Info *)
00232           hash_info->handle);
00233         break;
00234       }
00235       case SHA1Hash:
00236       {
00237         hash_info->handle=(void *) DestroySHA1Info((SHA1Info *)
00238           hash_info->handle);
00239         break;
00240       }
00241       case SHA224Hash:
00242       {
00243         hash_info->handle=(void *) DestroySHA224Info((SHA224Info *)
00244           hash_info->handle);
00245         break;
00246       }
00247       case SHA256Hash:
00248       {
00249         hash_info->handle=(void *) DestroySHA256Info((SHA256Info *)
00250           hash_info->handle);
00251         break;
00252       }
00253       case SHA384Hash:
00254       {
00255         hash_info->handle=(void *) DestroySHA384Info((SHA384Info *)
00256           hash_info->handle);
00257         break;
00258       }
00259       case SHA512Hash:
00260       {
00261         hash_info->handle=(void *) DestroySHA512Info((SHA512Info *)
00262           hash_info->handle);
00263         break;
00264       }
00265       default:
00266         ThrowWizardFatalError(HashDomain,EnumerateError);
00267     }
00268   if (hash_info->digest != (StringInfo *) NULL)
00269     hash_info->digest=DestroyStringInfo(hash_info->digest);
00270   hash_info->signature=(~WizardSignature);
00271   hash_info=(HashInfo *) RelinquishWizardMemory(hash_info);
00272   return(hash_info);
00273 }
00274 
00275 /*
00276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00277 %                                                                             %
00278 %                                                                             %
00279 %                                                                             %
00280 %   F i n a l i z e H a s h                                                   %
00281 %                                                                             %
00282 %                                                                             %
00283 %                                                                             %
00284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00285 %
00286 %  FinalizeHash() finalizes the Hash message accumulator computation.
00287 %
00288 %  The format of the FinalizeHash method is:
00289 %
00290 %      FinalizeHash(HashInfo *hash_info)
00291 %
00292 %  A description of each parameter follows:
00293 %
00294 %    o hash_info: The address of a structure of type HashInfo.
00295 %
00296 */
00297 WizardExport void FinalizeHash(HashInfo *hash_info)
00298 {
00299   /*
00300     Add padding and return the message accumulator.
00301   */
00302   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00303   assert(hash_info != (HashInfo *) NULL);
00304   assert(hash_info->signature == WizardSignature);
00305   switch (hash_info->hash)
00306   {
00307     case CRC64Hash:
00308     {
00309       CRC64Info
00310         *crc_info;
00311 
00312       crc_info=(CRC64Info *) hash_info->handle;
00313       FinalizeCRC64(crc_info);
00314       SetStringInfo(hash_info->digest,GetCRC64Digest(crc_info));
00315       break;
00316     }
00317     case MD5Hash:
00318     {
00319       MD5Info
00320         *md5_info;
00321 
00322       md5_info=(MD5Info *) hash_info->handle;
00323       FinalizeMD5(md5_info);
00324       SetStringInfo(hash_info->digest,GetMD5Digest(md5_info));
00325       break;
00326     }
00327     case SHA1Hash:
00328     {
00329       SHA1Info
00330         *sha_info;
00331 
00332       sha_info=(SHA1Info *) hash_info->handle;
00333       FinalizeSHA1(sha_info);
00334       SetStringInfo(hash_info->digest,GetSHA1Digest(sha_info));
00335       break;
00336     }
00337     case SHA224Hash:
00338     {
00339       SHA224Info
00340         *sha_info;
00341 
00342       sha_info=(SHA224Info *) hash_info->handle;
00343       FinalizeSHA224(sha_info);
00344       SetStringInfo(hash_info->digest,GetSHA224Digest(sha_info));
00345       break;
00346     }
00347     case SHA256Hash:
00348     {
00349       SHA256Info
00350         *sha_info;
00351 
00352       sha_info=(SHA256Info *) hash_info->handle;
00353       FinalizeSHA256(sha_info);
00354       SetStringInfo(hash_info->digest,GetSHA256Digest(sha_info));
00355       break;
00356     }
00357     case SHA384Hash:
00358     {
00359       SHA384Info
00360         *sha_info;
00361 
00362       sha_info=(SHA384Info *) hash_info->handle;
00363       FinalizeSHA384(sha_info);
00364       SetStringInfo(hash_info->digest,GetSHA384Digest(sha_info));
00365       break;
00366     }
00367     case SHA512Hash:
00368     {
00369       SHA512Info
00370         *sha_info;
00371 
00372       sha_info=(SHA512Info *) hash_info->handle;
00373       FinalizeSHA512(sha_info);
00374       SetStringInfo(hash_info->digest,GetSHA512Digest(sha_info));
00375       break;
00376     }
00377     default:
00378       ThrowWizardFatalError(HashDomain,EnumerateError);
00379   }
00380 }
00381 
00382 /*
00383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00384 %                                                                             %
00385 %                                                                             %
00386 %                                                                             %
00387 %   G e t H a s h B l o c k s i z e                                           %
00388 %                                                                             %
00389 %                                                                             %
00390 %                                                                             %
00391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00392 %
00393 %  GetHashBlocksize() returns the Hash blocksize.
00394 %
00395 %  The format of the GetHashBlocksize method is:
00396 %
00397 %      size_t *GetHashBlocksize(const HashInfo *hash_info)
00398 %
00399 %  A description of each parameter follows:
00400 %
00401 %    o hash_info: The hash info.
00402 %
00403 */
00404 WizardExport size_t GetHashBlocksize(const HashInfo *hash_info)
00405 {
00406   size_t
00407     blocksize;
00408 
00409   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00410   WizardAssert(CipherDomain,hash_info != (HashInfo *) NULL);
00411   WizardAssert(CipherDomain,hash_info->signature == WizardSignature);
00412   switch (hash_info->hash)
00413   {
00414     case CRC64Hash:
00415     {
00416       CRC64Info
00417         *crc_info;
00418 
00419       crc_info=(CRC64Info *) hash_info->handle;
00420       blocksize=GetCRC64Blocksize(crc_info);
00421       break;
00422     }
00423     case MD5Hash:
00424     {
00425       MD5Info
00426         *md5_info;
00427 
00428       md5_info=(MD5Info *) hash_info->handle;
00429       blocksize=GetMD5Blocksize(md5_info);
00430       break;
00431     }
00432     case SHA1Hash:
00433     {
00434       SHA1Info
00435         *sha_info;
00436 
00437       sha_info=(SHA1Info *) hash_info->handle;
00438       blocksize=GetSHA1Blocksize(sha_info);
00439       break;
00440     }
00441     case SHA224Hash:
00442     {
00443       SHA224Info
00444         *sha_info;
00445 
00446       sha_info=(SHA224Info *) hash_info->handle;
00447       blocksize=GetSHA224Blocksize(sha_info);
00448       break;
00449     }
00450     case SHA256Hash:
00451     {
00452       SHA256Info
00453         *sha_info;
00454 
00455       sha_info=(SHA256Info *) hash_info->handle;
00456       blocksize=GetSHA256Blocksize(sha_info);
00457       break;
00458     }
00459     case SHA384Hash:
00460     {
00461       SHA384Info
00462         *sha_info;
00463 
00464       sha_info=(SHA384Info *) hash_info->handle;
00465       blocksize=GetSHA384Blocksize(sha_info);
00466       break;
00467     }
00468     case SHA512Hash:
00469     {
00470       SHA512Info
00471         *sha_info;
00472 
00473       sha_info=(SHA512Info *) hash_info->handle;
00474       blocksize=GetSHA512Blocksize(sha_info);
00475       break;
00476     }
00477     default:
00478       ThrowWizardFatalError(HashDomain,EnumerateError);
00479   }
00480   return(blocksize);
00481 }
00482 
00483 /*
00484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00485 %                                                                             %
00486 %                                                                             %
00487 %                                                                             %
00488 %   G e t H a s h D i g e s t                                                 %
00489 %                                                                             %
00490 %                                                                             %
00491 %                                                                             %
00492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00493 %
00494 %  GetHashDigest() returns the Hash digest.
00495 %
00496 %  The format of the GetHashDigest method is:
00497 %
00498 %      const StringInfo *GetHashDigest(const HashInfo *hash_info)
00499 %
00500 %  A description of each parameter follows:
00501 %
00502 %    o hash_info: The hash info.
00503 %
00504 */
00505 WizardExport const StringInfo *GetHashDigest(const HashInfo *hash_info)
00506 {
00507   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00508   WizardAssert(HashDomain,hash_info != (HashInfo *) NULL);
00509   WizardAssert(HashDomain,hash_info->signature == WizardSignature);
00510   return(hash_info->digest);
00511 }
00512 
00513 /*
00514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00515 %                                                                             %
00516 %                                                                             %
00517 %                                                                             %
00518 %   G e t H a s h D i g e s t s i z e                                         %
00519 %                                                                             %
00520 %                                                                             %
00521 %                                                                             %
00522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00523 %
00524 %  GetHashDigestsize() returns the Hash digest size.
00525 %
00526 %  The format of the GetHashDigestsize method is:
00527 %
00528 %      unsigned int *GetHashDigestsize(const HashInfo *hash_info)
00529 %
00530 %  A description of each parameter follows:
00531 %
00532 %    o hash_info: The hash info.
00533 %
00534 */
00535 WizardExport size_t GetHashDigestsize(const HashInfo *hash_info)
00536 {
00537   size_t
00538     digestsize;
00539 
00540   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00541   WizardAssert(CipherDomain,hash_info != (HashInfo *) NULL);
00542   WizardAssert(CipherDomain,hash_info->signature == WizardSignature);
00543   switch (hash_info->hash)
00544   {
00545     case CRC64Hash:
00546     {
00547       CRC64Info
00548         *crc_info;
00549 
00550       crc_info=(CRC64Info *) hash_info->handle;
00551       digestsize=GetCRC64Digestsize(crc_info);
00552       break;
00553     }
00554     case MD5Hash:
00555     {
00556       MD5Info
00557         *md5_info;
00558 
00559       md5_info=(MD5Info *) hash_info->handle;
00560       digestsize=GetMD5Digestsize(md5_info);
00561       break;
00562     }
00563     case SHA1Hash:
00564     {
00565       SHA1Info
00566         *sha_info;
00567 
00568       sha_info=(SHA1Info *) hash_info->handle;
00569       digestsize=GetSHA1Digestsize(sha_info);
00570       break;
00571     }
00572     case SHA224Hash:
00573     {
00574       SHA224Info
00575         *sha_info;
00576 
00577       sha_info=(SHA224Info *) hash_info->handle;
00578       digestsize=GetSHA224Digestsize(sha_info);
00579       break;
00580     }
00581     case SHA256Hash:
00582     {
00583       SHA256Info
00584         *sha_info;
00585 
00586       sha_info=(SHA256Info *) hash_info->handle;
00587       digestsize=GetSHA256Digestsize(sha_info);
00588       break;
00589     }
00590     case SHA384Hash:
00591     {
00592       SHA384Info
00593         *sha_info;
00594 
00595       sha_info=(SHA384Info *) hash_info->handle;
00596       digestsize=GetSHA384Digestsize(sha_info);
00597       break;
00598     }
00599     case SHA512Hash:
00600     {
00601       SHA512Info
00602         *sha_info;
00603 
00604       sha_info=(SHA512Info *) hash_info->handle;
00605       digestsize=GetSHA512Digestsize(sha_info);
00606       break;
00607     }
00608     default:
00609       ThrowWizardFatalError(HashDomain,EnumerateError);
00610   }
00611   return(digestsize);
00612 }
00613 
00614 /*
00615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00616 %                                                                             %
00617 %                                                                             %
00618 %                                                                             %
00619 %   G e t H a s h H e x D i g e s t                                           %
00620 %                                                                             %
00621 %                                                                             %
00622 %                                                                             %
00623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00624 %
00625 %  GetHashHexDigest() returns the hash digest as a hex string.
00626 %
00627 %  The format of the GetHashHexDigest method is:
00628 %
00629 %      char *GetHashHexDigest(const HashInfo *hash_info)
00630 %
00631 %  A description of each parameter follows:
00632 %
00633 %    o hash_info: The hash info.
00634 %
00635 */
00636 WizardExport char *GetHashHexDigest(const HashInfo *hash_info)
00637 {
00638   char
00639     *digest;
00640 
00641   register const unsigned char
00642     *p;
00643 
00644   register ssize_t
00645     i;
00646 
00647   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00648   WizardAssert(HashDomain,hash_info != (HashInfo *) NULL);
00649   WizardAssert(HashDomain,hash_info->signature == WizardSignature);
00650   digest=(char *) AcquireQuantumMemory(2UL*GetHashDigestsize(hash_info)+1UL,
00651     sizeof(*digest));
00652   if (digest == (char *) NULL)
00653     ThrowWizardFatalError(HashDomain,MemoryError);
00654   p=GetStringInfoDatum(hash_info->digest);
00655   for (i=0; i < (ssize_t) GetHashDigestsize(hash_info); i++)
00656     (void) FormatWizardString(digest+2*i,MaxTextExtent,"%02x",*p++);
00657   digest[2*i]='\0';
00658   return(digest);
00659 }
00660 
00661 /*
00662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00663 %                                                                             %
00664 %                                                                             %
00665 %                                                                             %
00666 %   I n i t i a l i z e H a s h                                               %
00667 %                                                                             %
00668 %                                                                             %
00669 %                                                                             %
00670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00671 %
00672 %  IntializeHash() intializes the Hash accumulator.
00673 %
00674 %  The format of the IntializeHash method is:
00675 %
00676 %      void IntializeHash(HashInfo *hash_info)
00677 %
00678 %  A description of each parameter follows:
00679 %
00680 %    o hash_info: The hash info.
00681 %
00682 */
00683 WizardExport void InitializeHash(HashInfo *hash_info)
00684 {
00685   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00686   assert(hash_info != (HashInfo *) NULL);
00687   assert(hash_info->signature == WizardSignature);
00688   switch (hash_info->hash)
00689   {
00690     case CRC64Hash:
00691     {
00692       InitializeCRC64((CRC64Info *) hash_info->handle);
00693       break;
00694     }
00695     case MD5Hash:
00696     {
00697       InitializeMD5((MD5Info *) hash_info->handle);
00698       break;
00699     }
00700     case SHA1Hash:
00701     {
00702       InitializeSHA1((SHA1Info *) hash_info->handle);
00703       break;
00704     }
00705     case SHA224Hash:
00706     {
00707       InitializeSHA224((SHA224Info *) hash_info->handle);
00708       break;
00709     }
00710     case SHA256Hash:
00711     {
00712       InitializeSHA256((SHA256Info *) hash_info->handle);
00713       break;
00714     }
00715     case SHA384Hash:
00716     {
00717       InitializeSHA384((SHA384Info *) hash_info->handle);
00718       break;
00719     }
00720     case SHA512Hash:
00721     {
00722       InitializeSHA512((SHA512Info *) hash_info->handle);
00723       break;
00724     }
00725     default:
00726       ThrowWizardFatalError(HashDomain,EnumerateError);
00727   }
00728 }
00729 
00730 /*
00731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00732 %                                                                             %
00733 %                                                                             %
00734 %                                                                             %
00735 %   U p d a t e H a s h                                                       %
00736 %                                                                             %
00737 %                                                                             %
00738 %                                                                             %
00739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00740 %
00741 %  UpdateHash() updates the Hash message accumulator.
00742 %
00743 %  The format of the UpdateHash method is:
00744 %
00745 %      UpdateHash(HashInfo *hash_info,const StringInfo *message)
00746 %
00747 %  A description of each parameter follows:
00748 %
00749 %    o hash_info: The address of a structure of type HashInfo.
00750 %
00751 %    o message: The message.
00752 %
00753 */
00754 WizardExport void UpdateHash(HashInfo *hash_info,const StringInfo *message)
00755 {
00756   /*
00757     Update the Hash accumulator.
00758   */
00759   (void) LogWizardEvent(TraceEvent,GetWizardModule(),"...");
00760   assert(hash_info != (HashInfo *) NULL);
00761   assert(hash_info->signature == WizardSignature);
00762   switch (hash_info->hash)
00763   {
00764     case CRC64Hash:
00765     {
00766       UpdateCRC64((CRC64Info *) hash_info->handle,message);
00767       break;
00768     }
00769     case MD5Hash:
00770     {
00771       UpdateMD5((MD5Info *) hash_info->handle,message);
00772       break;
00773     }
00774     case SHA1Hash:
00775     {
00776       UpdateSHA1((SHA1Info *) hash_info->handle,message);
00777       break;
00778     }
00779     case SHA224Hash:
00780     {
00781       UpdateSHA224((SHA224Info *) hash_info->handle,message);
00782       break;
00783     }
00784     case SHA256Hash:
00785     {
00786       UpdateSHA256((SHA256Info *) hash_info->handle,message);
00787       break;
00788     }
00789     case SHA384Hash:
00790     {
00791       UpdateSHA384((SHA384Info *) hash_info->handle,message);
00792       break;
00793     }
00794     case SHA512Hash:
00795     {
00796       UpdateSHA512((SHA512Info *) hash_info->handle,message);
00797       break;
00798     }
00799     default:
00800       ThrowWizardFatalError(HashDomain,EnumerateError);
00801   }
00802 }
Generated by  doxygen 1.6.2-20100208