sha1.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * sha1.h
  3. *
  4. * Description:
  5. * This is the header file for code which implements the Secure
  6. * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
  7. * April 17, 1995.
  8. *
  9. * Many of the variable names in this code, especially the
  10. * single character names, were used because those were the names
  11. * used in the publication.
  12. *
  13. * Please read the file sha1.cc for more information.
  14. *
  15. * Authorship:
  16. * This file is adapted from RFC 4634, by D. Eastlake et al.
  17. * Copyright (C) The Internet Society (2006).
  18. *
  19. * Permission is granted for all uses, commercial and non-commercial,
  20. * of the sample code found in Section 8. Royalty free license to
  21. * use, copy, modify and distribute the software found in Section 8 is
  22. * granted, provided that this document is identified in all material
  23. * mentioning or referencing this software, and provided that
  24. * redistributed derivative works do not contain misleading author or
  25. * version information.
  26. *
  27. * The authors make no representations concerning either the
  28. * merchantability of this software or the suitability of this
  29. * software for any particular purpose. It is provided "as is"
  30. * without express or implied warranty of any kind.
  31. */
  32. #ifndef SHA1_H
  33. #define SHA1_H
  34. #include <stdint.h>
  35. namespace isc {
  36. namespace util {
  37. namespace hash {
  38. /*
  39. * If you do not have the ISO standard stdint.h header file, then you
  40. * must typdef the following:
  41. * name meaning
  42. * uint32_t unsigned 32 bit integer
  43. * uint8_t unsigned 8 bit integer (i.e., unsigned char)
  44. * int_least16_t integer of >= 16 bits
  45. *
  46. */
  47. enum {
  48. SHA_SUCCESS = 0,
  49. SHA_NULL, /* Null pointer parameter */
  50. SHA_STATEERROR /* called Input after Result */
  51. };
  52. enum {
  53. SHA1_HASHSIZE = 20,
  54. SHA1_HASHBITS = 20,
  55. SHA1_BLOCKSIZE = 64
  56. };
  57. /*
  58. * This structure will hold context information for the SHA-1
  59. * hashing operation
  60. */
  61. typedef struct SHA1Context
  62. {
  63. uint32_t Intermediate_Hash[SHA1_HASHSIZE/4]; /* Message Digest */
  64. uint32_t Length_Low; /* Message length in bits */
  65. uint32_t Length_High; /* Message length in bits */
  66. int_least16_t Message_Block_Index; /* Index into message block array */
  67. uint8_t Message_Block[64]; /* 512-bit message blocks */
  68. int Computed; /* Is the digest computed? */
  69. int Corrupted; /* Is the message digest corrupted? */
  70. } SHA1Context;
  71. /*
  72. * Function Prototypes
  73. */
  74. extern int SHA1Reset(SHA1Context *);
  75. extern int SHA1Input(SHA1Context *, const uint8_t *bytes,
  76. unsigned int bytecount);
  77. extern int SHA1FinalBits(SHA1Context *, const uint8_t bits,
  78. unsigned int bitcount);
  79. extern int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1_HASHSIZE]);
  80. } // namespace hash
  81. } // namespace util
  82. } // namespace isc
  83. #endif