Skip to content

Commit

Permalink
rename constant from XPASS_CRYPT_ to CRYPT_PREFIX_
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Sep 13, 2024
1 parent 6ebefa0 commit 4d07d6b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ distributions, using extended crypt library (libxcrypt):
</stability>
<license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license>
<notes>
- add crypt_gensalt(?string $salt = null, int $count = 0): ?string {}
- add crypt_gensalt(?string $prefix = null, int $count = 0): ?string {}
- add crypt_preferred_method(): ?string {}
- add crypt_checksalt(string $salt): int {}
</notes>
Expand Down
2 changes: 1 addition & 1 deletion tests/crypt_checksalt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Test crypt_checksalt
--FILE--
<?php
// salt with old algo is OK or LEGACY
$r = crypt_checksalt(crypt_gensalt(XPASS_CRYPT_STD_DES));
$r = crypt_checksalt(crypt_gensalt(CRYPT_PREFIX_STD_DES));
var_dump($r === CRYPT_SALT_METHOD_LEGACY || $r === CRYPT_SALT_OK);

// salt with default algo is OK
Expand Down
18 changes: 9 additions & 9 deletions tests/crypt_gensalt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Test crypt_gensalt
--FILE--
<?php
var_dump(crypt_gensalt(XPASS_CRYPT_STD_DES));
var_dump(crypt_gensalt(XPASS_CRYPT_EXT_DES));
var_dump(crypt_gensalt(XPASS_CRYPT_MD5));
var_dump(crypt_gensalt(XPASS_CRYPT_BLOWFISH));
var_dump(crypt_gensalt(XPASS_CRYPT_SHA256));
var_dump(crypt_gensalt(XPASS_CRYPT_SHA512));
var_dump(crypt_gensalt(XPASS_CRYPT_SCRYPT));
var_dump(crypt_gensalt(XPASS_CRYPT_GOST_YESCRYPT));
var_dump(crypt_gensalt(XPASS_CRYPT_YESCRYPT));
var_dump(crypt_gensalt(CRYPT_PREFIX_STD_DES));
var_dump(crypt_gensalt(CRYPT_PREFIX_EXT_DES));
var_dump(crypt_gensalt(CRYPT_PREFIX_MD5));
var_dump(crypt_gensalt(CRYPT_PREFIX_BLOWFISH));
var_dump(crypt_gensalt(CRYPT_PREFIX_SHA256));
var_dump(crypt_gensalt(CRYPT_PREFIX_SHA512));
var_dump(crypt_gensalt(CRYPT_PREFIX_SCRYPT));
var_dump(crypt_gensalt(CRYPT_PREFIX_GOST_YESCRYPT));
var_dump(crypt_gensalt(CRYPT_PREFIX_YESCRYPT));

?>
--EXPECTF--
Expand Down
2 changes: 1 addition & 1 deletion tests/password_compat.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $h = password_hash($secret, PASSWORD_BCRYPT);
var_dump($h, password_verify($secret, $h), $h===crypt($secret, $h));

/* generate with crypt, check with both */
$h = crypt($secret, crypt_gensalt(XPASS_CRYPT_BLOWFISH));
$h = crypt($secret, crypt_gensalt(CRYPT_PREFIX_BLOWFISH));
var_dump($h, password_verify($secret, $h), $h===crypt($secret, $h));
?>
--EXPECTF--
Expand Down
8 changes: 4 additions & 4 deletions xpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ PHP_FUNCTION(crypt_preferred_method)
/* {{{ 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;
char *salt;
size_t salt_len;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(prefix, prefix_len)
Z_PARAM_STRING(salt, salt_len)
ZEND_PARSE_PARAMETERS_END();

RETURN_LONG(crypt_checksalt(prefix));
RETURN_LONG(crypt_checksalt(salt));
}
/* }}} */

Expand Down
22 changes: 10 additions & 12 deletions xpass.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@
*/


/* use XPASS prefix to avoid conflicts with standard constants */

/** @var string */
const XPASS_CRYPT_STD_DES = '';
const CRYPT_PREFIX_STD_DES = '';
/** @var string */
const XPASS_CRYPT_EXT_DES = '_';
const CRYPT_PREFIX_EXT_DES = '_';
/** @var string */
const XPASS_CRYPT_MD5 = '$1$';
const CRYPT_PREFIX_MD5 = '$1$';
/** @var string */
const XPASS_CRYPT_BLOWFISH = '$2y$';
const CRYPT_PREFIX_BLOWFISH = '$2y$';
/** @var string */
const XPASS_CRYPT_SHA256 = '$5$';
const CRYPT_PREFIX_SHA256 = '$5$';
/** @var string */
const XPASS_CRYPT_SHA512 = '$6$';
const CRYPT_PREFIX_SHA512 = '$6$';
/** @var string */
const XPASS_CRYPT_SCRYPT = '$7$';
const CRYPT_PREFIX_SCRYPT = '$7$';
/** @var string */
const XPASS_CRYPT_GOST_YESCRYPT = '$gy$';
const CRYPT_PREFIX_GOST_YESCRYPT = '$gy$';
/** @var string */
const XPASS_CRYPT_YESCRYPT = '$y$';
const CRYPT_PREFIX_YESCRYPT = '$y$';

/**
* @var int
Expand Down Expand Up @@ -54,7 +52,7 @@
const CRYPT_SALT_TOO_CHEAP = UNKNOWN;


function crypt_gensalt(?string $salt = null, int $count = 0): ?string {}
function crypt_gensalt(?string $prefix = null, int $count = 0): ?string {}

function crypt_preferred_method(): ?string {}

Expand Down
22 changes: 11 additions & 11 deletions xpass_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 09c1d047a579afe870fadd302bd2e34a5d06c370 */
* Stub hash: 9f75db3279543b07de6b59e720e8521694200a7c */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_crypt_gensalt, 0, 0, IS_STRING, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, salt, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prefix, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()

Expand All @@ -26,15 +26,15 @@ static const zend_function_entry ext_functions[] = {

static void register_xpass_symbols(int module_number)
{
REGISTER_STRING_CONSTANT("XPASS_CRYPT_STD_DES", "", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_EXT_DES", "_", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_MD5", "$1$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_BLOWFISH", "$2y$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_SHA256", "$5$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_SHA512", "$6$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_SCRYPT", "$7$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_GOST_YESCRYPT", "$gy$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("XPASS_CRYPT_YESCRYPT", "$y$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_STD_DES", "", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_EXT_DES", "_", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_MD5", "$1$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_BLOWFISH", "$2y$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_SHA256", "$5$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_SHA512", "$6$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_SCRYPT", "$7$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_GOST_YESCRYPT", "$gy$", CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("CRYPT_PREFIX_YESCRYPT", "$y$", CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CRYPT_SALT_OK", CRYPT_SALT_OK, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CRYPT_SALT_INVALID", CRYPT_SALT_INVALID, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CRYPT_SALT_METHOD_DISABLED", CRYPT_SALT_METHOD_DISABLED, CONST_PERSISTENT);
Expand Down

0 comments on commit 4d07d6b

Please sign in to comment.