php_hash.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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. | Author: Sara Golemon <pollita@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef PHP_HASH_H
  20. #define PHP_HASH_H
  21. #include "php.h"
  22. #define PHP_HASH_EXTNAME "hash"
  23. #define PHP_HASH_EXTVER "1.0"
  24. #define PHP_HASH_RESNAME "Hash Context"
  25. #define PHP_HASH_HMAC 0x0001
  26. #define L64 INT64_C
  27. #define php_hash_int32 int32_t
  28. #define php_hash_uint32 uint32_t
  29. #define php_hash_int64 int64_t
  30. #define php_hash_uint64 uint64_t
  31. typedef void (*php_hash_init_func_t)(void *context);
  32. typedef void (*php_hash_update_func_t)(void *context, const unsigned char *buf, unsigned int count);
  33. typedef void (*php_hash_final_func_t)(unsigned char *digest, void *context);
  34. typedef int (*php_hash_copy_func_t)(const void *ops, void *orig_context, void *dest_context);
  35. typedef struct _php_hash_ops {
  36. php_hash_init_func_t hash_init;
  37. php_hash_update_func_t hash_update;
  38. php_hash_final_func_t hash_final;
  39. php_hash_copy_func_t hash_copy;
  40. int digest_size;
  41. int block_size;
  42. int context_size;
  43. } php_hash_ops;
  44. typedef struct _php_hash_data {
  45. const php_hash_ops *ops;
  46. void *context;
  47. long options;
  48. unsigned char *key;
  49. } php_hash_data;
  50. extern const php_hash_ops php_hash_md2_ops;
  51. extern const php_hash_ops php_hash_md4_ops;
  52. extern const php_hash_ops php_hash_md5_ops;
  53. extern const php_hash_ops php_hash_sha1_ops;
  54. extern const php_hash_ops php_hash_sha224_ops;
  55. extern const php_hash_ops php_hash_sha256_ops;
  56. extern const php_hash_ops php_hash_sha384_ops;
  57. extern const php_hash_ops php_hash_sha512_ops;
  58. extern const php_hash_ops php_hash_ripemd128_ops;
  59. extern const php_hash_ops php_hash_ripemd160_ops;
  60. extern const php_hash_ops php_hash_ripemd256_ops;
  61. extern const php_hash_ops php_hash_ripemd320_ops;
  62. extern const php_hash_ops php_hash_whirlpool_ops;
  63. extern const php_hash_ops php_hash_3tiger128_ops;
  64. extern const php_hash_ops php_hash_3tiger160_ops;
  65. extern const php_hash_ops php_hash_3tiger192_ops;
  66. extern const php_hash_ops php_hash_4tiger128_ops;
  67. extern const php_hash_ops php_hash_4tiger160_ops;
  68. extern const php_hash_ops php_hash_4tiger192_ops;
  69. extern const php_hash_ops php_hash_snefru_ops;
  70. extern const php_hash_ops php_hash_gost_ops;
  71. extern const php_hash_ops php_hash_gost_crypto_ops;
  72. extern const php_hash_ops php_hash_adler32_ops;
  73. extern const php_hash_ops php_hash_crc32_ops;
  74. extern const php_hash_ops php_hash_crc32b_ops;
  75. extern const php_hash_ops php_hash_fnv132_ops;
  76. extern const php_hash_ops php_hash_fnv1a32_ops;
  77. extern const php_hash_ops php_hash_fnv164_ops;
  78. extern const php_hash_ops php_hash_fnv1a64_ops;
  79. extern const php_hash_ops php_hash_joaat_ops;
  80. #define PHP_HASH_HAVAL_OPS(p,b) extern const php_hash_ops php_hash_##p##haval##b##_ops;
  81. PHP_HASH_HAVAL_OPS(3,128)
  82. PHP_HASH_HAVAL_OPS(3,160)
  83. PHP_HASH_HAVAL_OPS(3,192)
  84. PHP_HASH_HAVAL_OPS(3,224)
  85. PHP_HASH_HAVAL_OPS(3,256)
  86. PHP_HASH_HAVAL_OPS(4,128)
  87. PHP_HASH_HAVAL_OPS(4,160)
  88. PHP_HASH_HAVAL_OPS(4,192)
  89. PHP_HASH_HAVAL_OPS(4,224)
  90. PHP_HASH_HAVAL_OPS(4,256)
  91. PHP_HASH_HAVAL_OPS(5,128)
  92. PHP_HASH_HAVAL_OPS(5,160)
  93. PHP_HASH_HAVAL_OPS(5,192)
  94. PHP_HASH_HAVAL_OPS(5,224)
  95. PHP_HASH_HAVAL_OPS(5,256)
  96. extern zend_module_entry hash_module_entry;
  97. #define phpext_hash_ptr &hash_module_entry
  98. #ifdef PHP_WIN32
  99. # define PHP_HASH_API __declspec(dllexport)
  100. #elif defined(__GNUC__) && __GNUC__ >= 4
  101. # define PHP_HASH_API __attribute__ ((visibility("default")))
  102. #else
  103. # define PHP_HASH_API
  104. #endif
  105. #ifdef ZTS
  106. #include "TSRM.h"
  107. #endif
  108. PHP_FUNCTION(hash);
  109. PHP_FUNCTION(hash_file);
  110. PHP_FUNCTION(hash_hmac);
  111. PHP_FUNCTION(hash_hmac_file);
  112. PHP_FUNCTION(hash_init);
  113. PHP_FUNCTION(hash_update);
  114. PHP_FUNCTION(hash_update_stream);
  115. PHP_FUNCTION(hash_update_file);
  116. PHP_FUNCTION(hash_final);
  117. PHP_FUNCTION(hash_algos);
  118. PHP_FUNCTION(hash_pbkdf2);
  119. PHP_FUNCTION(hash_equals);
  120. PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len);
  121. PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops);
  122. PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context);
  123. static inline void php_hash_bin2hex(char *out, const unsigned char *in, int in_len)
  124. {
  125. static const char hexits[17] = "0123456789abcdef";
  126. int i;
  127. for(i = 0; i < in_len; i++) {
  128. out[i * 2] = hexits[in[i] >> 4];
  129. out[(i * 2) + 1] = hexits[in[i] & 0x0F];
  130. }
  131. }
  132. #endif /* PHP_HASH_H */
  133. /*
  134. * Local variables:
  135. * tab-width: 4
  136. * c-basic-offset: 4
  137. * End:
  138. * vim600: noet sw=4 ts=4 fdm=marker
  139. * vim<600: noet sw=4 ts=4
  140. */