summaryrefslogtreecommitdiffstats
path: root/xpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'xpass.c')
-rw-r--r--xpass.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/xpass.c b/xpass.c
index bab404a..cb16131 100644
--- a/xpass.c
+++ b/xpass.c
@@ -26,6 +26,8 @@
#include "php_xpass.h"
#include <crypt.h>
+#include "xpass_arginfo.h"
+
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(xpass)
{
@@ -149,8 +151,60 @@ static const php_password_algo xpass_algo_yescrypt = {
NULL,
};
+/* {{{ Generates a salt for algo */
+PHP_FUNCTION(crypt_gensalt)
+{
+ char salt[CRYPT_GENSALT_OUTPUT_SIZE + 1];
+ char *prefix = NULL;
+ size_t prefix_len = 0;
+ zend_long count = 0;
+
+ ZEND_PARSE_PARAMETERS_START(0, 2)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STRING(prefix, prefix_len)
+ Z_PARAM_LONG(count)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (crypt_gensalt_rn(prefix, (unsigned long)count, NULL, 0, salt, CRYPT_GENSALT_OUTPUT_SIZE)) {
+ RETURN_STRING(salt);
+ }
+ RETURN_NULL();
+}
+/* }}} */
+
+/* {{{ Get preferred hasing method prefix */
+PHP_FUNCTION(crypt_preferred_method)
+{
+ const char *prefix;
+
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ prefix = crypt_preferred_method();
+ if (prefix) {
+ RETURN_STRING(prefix);
+ }
+ RETURN_NULL();
+}
+/* }}} */
+
+/* {{{ Determine whether the user's passphrase should be re-hashed using the currently preferred hashing method */
+PHP_FUNCTION(crypt_checksalt)
+{
+ char *prefix;
+ size_t prefix_len;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STRING(prefix, prefix_len)
+ ZEND_PARSE_PARAMETERS_END();
+
+ RETURN_LONG(crypt_checksalt(prefix));
+}
+/* }}} */
+
PHP_MINIT_FUNCTION(xpass) /* {{{ */ {
+ register_xpass_symbols(module_number);
+
#ifdef HAVE_CRYPT_SHA512
if (FAILURE == php_password_algo_register("6", &xpass_algo_sha512)) {
return FAILURE;
@@ -172,7 +226,7 @@ PHP_MINIT_FUNCTION(xpass) /* {{{ */ {
zend_module_entry xpass_module_entry = {
STANDARD_MODULE_HEADER,
"xpass", /* Extension name */
- NULL, /* zend_function_entry */
+ ext_functions, /* zend_function_entry */
PHP_MINIT(xpass), /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(xpass), /* PHP_RINIT - Request initialization */