sha1.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /*
  36. * If you do not have the ISO standard stdint.h header file, then you
  37. * must typdef the following:
  38. * name meaning
  39. * uint32_t unsigned 32 bit integer
  40. * uint8_t unsigned 8 bit integer (i.e., unsigned char)
  41. * int_least16_t integer of >= 16 bits
  42. *
  43. */
  44. enum {
  45. SHA_SUCCESS = 0,
  46. SHA_NULL, /* Null pointer parameter */
  47. SHA_STATEERROR /* called Input after Result */
  48. };
  49. enum {
  50. SHA1_HASHSIZE = 20,
  51. SHA1_HASHBITS = 20,
  52. SHA1_BLOCKSIZE = 64
  53. };
  54. /*
  55. * This structure will hold context information for the SHA-1
  56. * hashing operation
  57. */
  58. typedef struct SHA1Context
  59. {
  60. uint32_t Intermediate_Hash[SHA1_HASHSIZE/4]; /* Message Digest */
  61. uint32_t Length_Low; /* Message length in bits */
  62. uint32_t Length_High; /* Message length in bits */
  63. int_least16_t Message_Block_Index; /* Index into message block array */
  64. uint8_t Message_Block[64]; /* 512-bit message blocks */
  65. int Computed; /* Is the digest computed? */
  66. int Corrupted; /* Is the message digest corrupted? */
  67. } SHA1Context;
  68. /*
  69. * Function Prototypes
  70. */
  71. extern int SHA1Reset(SHA1Context *);
  72. extern int SHA1Input(SHA1Context *, const uint8_t *bytes,
  73. unsigned int bytecount);
  74. extern int SHA1FinalBits(SHA1Context *, const uint8_t bits,
  75. unsigned int bitcount);
  76. extern int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1_HASHSIZE]);
  77. #endif