Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.2 KiB

  1. //========= Copyright � 2005, Valve Inc., All rights reserved. ==========
  2. //
  3. // Purpose: Cryptographic hash agility helper definitions
  4. //
  5. //=============================================================================
  6. #ifndef PASSWORDHASH_H
  7. #define PASSWORDHASH_H
  8. #if defined( _WIN32 )
  9. #pragma once
  10. #endif
  11. #include "checksum_sha1.h"
  12. typedef unsigned char BigPasswordHash_t[32];
  13. typedef unsigned char PBKDF2Hash_t[32];
  14. //
  15. // A union of all the possible password hash types.
  16. // When adding to this, if the maximum size of the
  17. // structure has changed then the Account table and
  18. // the AccountSecurityHistory table need to be manually
  19. // revised using something like the following SQL:
  20. //
  21. // ALTER TABLE Account ALTER COLUMN PasswordHash binary(32)
  22. // ALTER TABLE AccountSecurityHistory ALTER COLUMN PasswordHashOld binary(32)
  23. // ALTER TABLE AccountSecurityHistory ALTER COLUMN PasswordHashNew binary(32)
  24. //
  25. // Replace 32 with the new size of PasswordHash_t.
  26. //
  27. // If the width of those columns does not match sizeof(PasswordHash_t), many
  28. // database operations will fail.
  29. //
  30. // Note that while this query was correct at the time this code was checked in,
  31. // it may not be sufficient at the time you actually change the size of the
  32. // type, so look around.
  33. //
  34. typedef union
  35. {
  36. SHADigest_t sha;
  37. BigPasswordHash_t bigpassword;
  38. PBKDF2Hash_t pbkdf2;
  39. } PasswordHash_t;
  40. //
  41. // Enum of all available password hash algorithms. These should
  42. // be consecutive and ordinals should never be reused.
  43. //
  44. // k_EHashSHA1: A salted SHA-1 hash, width 20 bytes.
  45. // k_EHashBigPassword: For testing purposes, a salted SHA-1 hash extended to 32 bytes, with 6 bytes of 0x1 on either side.
  46. // k_EHashPBKDF2_1000: A PKCS#5 v2.0 Password-Based Key Derivation Function hash (PBKDF2-HMAC-SHA256) with 1,000 iterations.
  47. // The digest width is 32 bytes.
  48. // k_EHashPBKDF2_5000: A PKCS#5 v2.0 Password-Based Key Derivation Function hash (PBKDF2-HMAC-SHA256) with 5,000 iterations.
  49. // k_EHashPBKDF2_10000: A PKCS#5 v2.0 Password-Based Key Derivation Function hash (PBKDF2-HMAC-SHA256) with 10,000 iterations.
  50. // k_EHashSHA1WrappedWithPBKDF2_10000: A SHA-1 hash which is then further hashed with PBKDF2 at 10,000 rounds. Used for
  51. // strengthening old hashes in the database that haven't been logged in in a long time.
  52. //
  53. // Make sure to update k_EHashMax when adding new hash types. Also add the length into the k_HashLengths array below.
  54. enum EPasswordHashAlg
  55. {
  56. k_EHashSHA1 = 0,
  57. k_EHashBigPassword = 1,
  58. k_EHashPBKDF2_1000 = 2,
  59. k_EHashPBKDF2_5000 = 3,
  60. k_EHashPBKDF2_10000 = 4,
  61. k_EHashSHA1WrappedWithPBKDF2_10000 = 5,
  62. k_EHashMax = 5,
  63. };
  64. //
  65. // Hash sizes for the various available hash algorithms,
  66. // indexed by EPasswordHashAlg.
  67. const uint k_HashLengths[] = {
  68. sizeof(SHADigest_t),
  69. sizeof(BigPasswordHash_t),
  70. sizeof(PBKDF2Hash_t),
  71. sizeof(PBKDF2Hash_t),
  72. sizeof(PBKDF2Hash_t),
  73. sizeof(PBKDF2Hash_t),
  74. };
  75. #if defined(C_ASSERT)
  76. //
  77. // If you're hitting this assert at compile time, it means that you've added a new
  78. // hash type and properly updated k_EHashMax, but you forgot to add the length
  79. // of the new hash type into k_HashLengths. So do that.
  80. //
  81. C_ASSERT( ( ( sizeof(k_HashLengths) / sizeof(uint) ) == k_EHashMax + 1 ) );
  82. #endif
  83. #endif // PASSWORDHASH_H