php_hash_sha.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | SHA1 Author: Stefan Esser <sesser@php.net> |
  16. | SHA256 Author: Sara Golemon <pollita@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef PHP_HASH_SHA_H
  20. #define PHP_HASH_SHA_H
  21. /* When SHA is removed from Core,
  22. the ext/standard/sha1.c file can be removed
  23. and the ext/standard/sha1.h file can be reduced to:
  24. #define PHP_HASH_SHA1_NOT_IN_CORE
  25. #include "ext/hash/php_hash_sha.h"
  26. Don't forget to remove sha1() and sha1_file() from basic_functions.c
  27. */
  28. #include "ext/standard/sha1.h"
  29. #include "ext/standard/basic_functions.h"
  30. #ifdef PHP_HASH_SHA1_NOT_IN_CORE
  31. /* SHA1 context. */
  32. typedef struct {
  33. uint32_t state[5]; /* state (ABCD) */
  34. uint32_t count[2]; /* number of bits, modulo 2^64 */
  35. unsigned char buffer[64]; /* input buffer */
  36. } PHP_SHA1_CTX;
  37. PHP_HASH_API void PHP_SHA1Init(PHP_SHA1_CTX *);
  38. PHP_HASH_API void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, unsigned int);
  39. PHP_HASH_API void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *);
  40. PHP_FUNCTION(sha1);
  41. PHP_FUNCTION(sha1_file);
  42. #endif /* PHP_HASH_SHA1_NOT_IN_CORE */
  43. /* SHA224 context. */
  44. typedef struct {
  45. uint32_t state[8]; /* state */
  46. uint32_t count[2]; /* number of bits, modulo 2^64 */
  47. unsigned char buffer[64]; /* input buffer */
  48. } PHP_SHA224_CTX;
  49. PHP_HASH_API void PHP_SHA224Init(PHP_SHA224_CTX *);
  50. PHP_HASH_API void PHP_SHA224Update(PHP_SHA224_CTX *, const unsigned char *, unsigned int);
  51. PHP_HASH_API void PHP_SHA224Final(unsigned char[28], PHP_SHA224_CTX *);
  52. /* SHA256 context. */
  53. typedef struct {
  54. uint32_t state[8]; /* state */
  55. uint32_t count[2]; /* number of bits, modulo 2^64 */
  56. unsigned char buffer[64]; /* input buffer */
  57. } PHP_SHA256_CTX;
  58. PHP_HASH_API void PHP_SHA256Init(PHP_SHA256_CTX *);
  59. PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, unsigned int);
  60. PHP_HASH_API void PHP_SHA256Final(unsigned char[32], PHP_SHA256_CTX *);
  61. /* SHA384 context */
  62. typedef struct {
  63. uint64_t state[8]; /* state */
  64. uint64_t count[2]; /* number of bits, modulo 2^128 */
  65. unsigned char buffer[128]; /* input buffer */
  66. } PHP_SHA384_CTX;
  67. PHP_HASH_API void PHP_SHA384Init(PHP_SHA384_CTX *);
  68. PHP_HASH_API void PHP_SHA384Update(PHP_SHA384_CTX *, const unsigned char *, unsigned int);
  69. PHP_HASH_API void PHP_SHA384Final(unsigned char[48], PHP_SHA384_CTX *);
  70. /* SHA512 context */
  71. typedef struct {
  72. uint64_t state[8]; /* state */
  73. uint64_t count[2]; /* number of bits, modulo 2^128 */
  74. unsigned char buffer[128]; /* input buffer */
  75. } PHP_SHA512_CTX;
  76. PHP_HASH_API void PHP_SHA512Init(PHP_SHA512_CTX *);
  77. PHP_HASH_API void PHP_SHA512Update(PHP_SHA512_CTX *, const unsigned char *, unsigned int);
  78. PHP_HASH_API void PHP_SHA512Final(unsigned char[64], PHP_SHA512_CTX *);
  79. PHP_HASH_API void PHP_SHA512_256Init(PHP_SHA512_CTX *);
  80. #define PHP_SHA512_256Update PHP_SHA512Update
  81. PHP_HASH_API void PHP_SHA512_256Final(unsigned char[32], PHP_SHA512_CTX *);
  82. PHP_HASH_API void PHP_SHA512_224Init(PHP_SHA512_CTX *);
  83. #define PHP_SHA512_224Update PHP_SHA512Update
  84. PHP_HASH_API void PHP_SHA512_224Final(unsigned char[28], PHP_SHA512_CTX *);
  85. #endif /* PHP_HASH_SHA_H */