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