-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphp_jh.c
More file actions
83 lines (69 loc) · 1.48 KB
/
php_jh.c
File metadata and controls
83 lines (69 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "ext/standard/basic_functions.h"
#include "jh.c"
#include "php_jh.h"
#define JH_DEFAULT_BIT_LENGTH 512
zend_function_entry jh_functions[] = {
PHP_FE(jh_hash, NULL)
{NULL, NULL, NULL}
};
zend_module_entry jh_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"jh",
jh_functions,
PHP_MINIT(jh),
PHP_MSHUTDOWN(jh),
NULL,
NULL,
PHP_MINFO(jh),
#if ZEND_MODULE_API_NO >= 20010901
"0.1",
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_JH
ZEND_GET_MODULE(jh)
#endif
PHP_MINIT_FUNCTION(jh)
{
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(jh)
{
return SUCCESS;
}
PHP_MINFO_FUNCTION(jh)
{
php_info_print_table_start();
php_info_print_table_header(2, "jh hash support", "enabled");
php_info_print_table_end();
}
PHP_FUNCTION(jh_hash)
{
char hash[64];
char *buffer = NULL;
int buffer_size;
long hash_bit_length = JH_DEFAULT_BIT_LENGTH;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
&buffer, &buffer_size, &hash_bit_length) == FAILURE)
{
RETURN_FALSE;
}
HashReturn result;
if ((result = Hash((size_t) hash_bit_length, buffer, buffer_size, hash)) != HASH_SUCCESS)
{
if (result == BAD_HASHLEN)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad bit-length");
}
RETURN_FALSE;
}
RETURN_STRINGL(hash, ceil(hash_bit_length / 8), 1);
}