hashmgr.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. ---------------------------------------------------------------------------
  3. Copyright (c) 2003, Dominik Reichl <dominik.reichl@t-online.de>, Germany.
  4. All rights reserved.
  5. Distributed under the terms of the GNU General Public License v2.
  6. This software is provided 'as is' with no explicit or implied warranties
  7. in respect of its properties, including, but not limited to, correctness
  8. and/or fitness for purpose.
  9. ---------------------------------------------------------------------------
  10. */
  11. #ifndef ___HASH_MANAGER_H___
  12. #define ___HASH_MANAGER_H___
  13. #include "rhsyscfg.h"
  14. #include "clutil.h"
  15. #include "algo/crc16.h"
  16. #include "algo/crc32.h"
  17. #include "algo/fcs.h"
  18. #include "algo/ghash.h"
  19. #include "algo/gosthash.h"
  20. #include "algo/haval.h"
  21. #include "algo/md2.h"
  22. #include "algo/md4.h"
  23. #include "algo/md5.h"
  24. #include "algo/sizehash.h"
  25. #include "algo/sha1.h"
  26. #include "algo/sha2.h"
  27. #include "algo/tiger.h"
  28. #define HASHID_NULL 0
  29. #define HASHID_SIZE_32 1
  30. #define HASHID_CRC16 2
  31. #define HASHID_CRC16CCITT 3
  32. #define HASHID_CRC32 4
  33. #define HASHID_FCS_16 5
  34. #define HASHID_FCS_32 6
  35. #define HASHID_GHASH_32_3 7
  36. #define HASHID_GHASH_32_5 8
  37. #define HASHID_GOST 9
  38. #define HASHID_HAVAL 10
  39. #define HASHID_MD2 11
  40. #define HASHID_MD4 12
  41. #define HASHID_MD5 13
  42. #define HASHID_SHA1 14
  43. #define HASHID_SHA2_256 15
  44. #define HASHID_SHA2_384 16
  45. #define HASHID_SHA2_512 17
  46. #define HASHID_TIGER 18
  47. #define RH_MAX_ALGORITHMS 19
  48. #define OPT_NULL 0
  49. #define OPT_FULLPATH 1
  50. #define OPT_RECURSIVE 2
  51. #define OPT_MAX_OPTIONS 3
  52. // You may use all 12 characters
  53. #define SZ_EMPTY " "
  54. #define SZ_SIZEHASH_32 "Size-32 "
  55. #define SZ_CRC16 "CRC-16 "
  56. #define SZ_CRC16CCITT "CRC-16-CCITT"
  57. #define SZ_CRC32 "CRC-32 "
  58. #define SZ_FCS_16 "FCS-16 "
  59. #define SZ_FCS_32 "FCS-32 "
  60. #define SZ_GHASH_32_3 "GHash-32-3 "
  61. #define SZ_GHASH_32_5 "GHash-32-5 "
  62. #define SZ_GOST "GOST-Hash "
  63. #define SZ_HAVAL "HAVAL-5-256 "
  64. #define SZ_MD2 "MD2 "
  65. #define SZ_MD4 "MD4 "
  66. #define SZ_MD5 "MD5 "
  67. #define SZ_SHA1 "SHA-1 "
  68. #define SZ_SHA2_256 "SHA-256 "
  69. #define SZ_SHA2_384 "SHA-384 "
  70. #define SZ_SHA2_512 "SHA-512 "
  71. #define SZ_TIGER "Tiger "
  72. #define SZ_HASHPRE " : "
  73. #define SZ_HASHSEP " "
  74. #define SIZE_HASH_BUFFER 16384
  75. #define NUM_DIGBLOCKS_PER_LINE 24
  76. class CHashManager
  77. {
  78. public:
  79. // Constructor and destructor
  80. CHashManager();
  81. virtual ~CHashManager();
  82. void SelectAllAlgorithms(bool bSelect = true);
  83. bool SelectAlgorithm(int nAlgorithm, bool bSelect = true);
  84. bool SetOption(int nOption, bool bState);
  85. int HashPath(char *pszBasePath, char *pszFileSpec);
  86. int HashFile(char *pszFile);
  87. private:
  88. void fmtFixHashOutput(int nCursorPos);
  89. bool m_bAlgorithm[RH_MAX_ALGORITHMS];
  90. bool m_bFullPath;
  91. bool m_bRecursive;
  92. unsigned short m_crc16;
  93. unsigned short m_crc16ccitt;
  94. unsigned long m_crc32;
  95. unsigned short m_fcs16;
  96. unsigned long m_fcs32;
  97. CGHash m_ghash;
  98. GostHashCtx m_gost;
  99. haval_state m_haval;
  100. CMD2 m_md2;
  101. MD4_CTX m_md4;
  102. MD5_CTX m_md5;
  103. sha1_ctx m_sha1;
  104. sha256_ctx m_sha256;
  105. sha384_ctx m_sha384;
  106. sha512_ctx m_sha512;
  107. unsigned long m_uSizeHash32;
  108. tiger_hash_state m_tiger;
  109. };
  110. #endif // ___HASH_MANAGER_H___