/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Sascha Schumann | | Nikos Mavroyanopoulos (HMAC, KEYGEN) | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #if HAVE_LIBMHASH #include "fcntl.h" #include "php_mhash.h" #include "mhash.h" #include "php_ini.h" #include "php_globals.h" #include "ext/standard/info.h" function_entry mhash_functions[] = { PHP_FE(mhash_get_block_size, NULL) PHP_FE(mhash_get_hash_name, NULL) PHP_FE(mhash_keygen_s2k, NULL) PHP_FE(mhash_count, NULL) PHP_FE(mhash, NULL) {NULL, NULL, NULL} }; zend_module_entry mhash_module_entry = { STANDARD_MODULE_HEADER, "mhash", mhash_functions, PHP_MINIT(mhash), NULL, NULL, NULL, PHP_MINFO(mhash), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES, }; #ifdef COMPILE_DL_MHASH ZEND_GET_MODULE(mhash) #endif /* SALTED S2K uses a fixed salt */ #define SALT_SIZE 8 static PHP_MINIT_FUNCTION(mhash) { int i, n, l; char *name; char buf[128]; n = mhash_count() + 1; for (i=0; i mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)); } memcpy(salt, in_salt, salt_len); if (salt_len < SALT_SIZE) { memset(salt + salt_len, 0, SALT_SIZE - salt_len); } salt_len = SALT_SIZE; keystruct.hash_algorithm[0] = hash; keystruct.hash_algorithm[1] = hash; keystruct.count = 0; keystruct.salt = salt; keystruct.salt_size = salt_len; ret = emalloc(bytes + 1); if (mhash_keygen_ext(KEYGEN_S2K_SALTED, keystruct, ret, bytes, password, password_len) >= 0) { ret[bytes] = '\0'; RETVAL_STRINGL(ret, bytes, 0); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash key generation failed"); efree(ret); RETURN_FALSE; } } /* }}} */ #endif /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */