Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ scrypt-*.tgz
#

.deps
*.dep
*.lo
*.la
.libs
Expand All @@ -23,6 +24,7 @@ libtool
configure*
install-sh
ltmain.sh
ltmain.sh.backup
Makefile*
missing
mkinstalldirs
Expand Down
10 changes: 4 additions & 6 deletions crypto/crypto_scrypt-nosse.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,22 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
uint8_t * XY;
uint32_t i;

TSRMLS_FETCH();

/* Sanity-check parameters. */
#if SIZE_MAX > UINT32_MAX
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters: $keyLength too big");
php_error_docref(NULL, E_WARNING, "Invalid Parameters: $keyLength too big");
errno = EFBIG;
goto err0;
}
#endif
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
errno = EFBIG;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters; $r * $p is >= 2^30");
php_error_docref(NULL, E_WARNING, "Invalid Parameters; $r * $p is >= 2^30");
goto err0;
}
if (((N & (N - 1)) != 0) || (N == 0)) {
errno = EINVAL;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters; $N is not a power of two greater than 1");
php_error_docref(NULL, E_WARNING, "Invalid Parameters; $N is not a power of two greater than 1");
goto err0;
}
if ((r > SIZE_MAX / 128 / p) ||
Expand All @@ -257,7 +255,7 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
#endif
(N > SIZE_MAX / 128 / r)) {
errno = ENOMEM;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters");
php_error_docref(NULL, E_WARNING, "Invalid Parameters");
goto err0;
}

Expand Down
10 changes: 4 additions & 6 deletions crypto/crypto_scrypt-sse.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,30 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
uint32_t * XY;
uint32_t i;

TSRMLS_FETCH();

/* Sanity-check parameters. */
#if SIZE_MAX > UINT32_MAX
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters: $keyLength too big");
php_error_docref(NULL, E_WARNING, "Invalid Parameters: $keyLength too big");
errno = EFBIG;
goto err0;
}
#endif
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
errno = EFBIG;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters; $r * $p is >= 2^30");
php_error_docref(NULL, E_WARNING, "Invalid Parameters; $r * $p is >= 2^30");
goto err0;
}
if (((N & (N - 1)) != 0) || (N == 0)) {
errno = EINVAL;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters; $N is not a power of two greater than 1");
php_error_docref(NULL, E_WARNING, "Invalid Parameters; $N is not a power of two greater than 1");
goto err0;
}
if ((r > SIZE_MAX / 128 / p) ||
#if SIZE_MAX / 256 <= UINT32_MAX
(r > (SIZE_MAX - 64) / 256) ||
#endif
(N > SIZE_MAX / 128 / r)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Parameters");
php_error_docref(NULL, E_WARNING, "Invalid Parameters");
errno = ENOMEM;
goto err0;
}
Expand Down
8 changes: 3 additions & 5 deletions php_scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ PHP_FUNCTION(scrypt)
uint64_t cryptN;
uint32_t cryptR;
uint32_t cryptP;
int castError;

/* Output variables */
char *hex;
Expand All @@ -126,7 +125,7 @@ PHP_FUNCTION(scrypt)
/* Get the parameters for this call */
raw_output = 0;
if (zend_parse_parameters_throw(
ZEND_NUM_ARGS() TSRMLS_CC, "ssllll|b",
ZEND_NUM_ARGS(), "ssllll|b",
&password, &password_len, &salt, &salt_len,
&phpN, &phpR, &phpP, &keyLength, &raw_output
) == FAILURE)
Expand All @@ -136,7 +135,6 @@ PHP_FUNCTION(scrypt)

/* Checks on the parameters */

castError = 0;
cryptN = clampAndCast64(3, "N", phpN, 1);
if (EG(exception)) {
RETURN_THROWS();
Expand Down Expand Up @@ -231,7 +229,7 @@ PHP_FUNCTION(scrypt_pickparams)

/* Get the parameters for this call */
if (zend_parse_parameters_throw(
ZEND_NUM_ARGS() TSRMLS_CC, "ldd",
ZEND_NUM_ARGS(), "ldd",
&maxmem, &memfrac, &maxtime
) == FAILURE)
{
Expand Down Expand Up @@ -268,7 +266,7 @@ PHP_FUNCTION(scrypt_pickparams)
rc = pickparams((size_t) maxmem, memfrac, maxtime, &cryptN, &cryptR, &cryptP);

if (rc != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not determine scrypt parameters.");
php_error_docref(NULL, E_WARNING, "Could not determine scrypt parameters.");
RETURN_FALSE;
}

Expand Down
5 changes: 0 additions & 5 deletions php_scrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@
extern zend_module_entry scrypt_module_entry;
#define phpext_scrypt_ptr &scrypt_module_entry

#ifndef TSRMLS_CC
#define TSRMLS_CC
#define TSRMLS_FETCH()
#endif

#endif
2 changes: 0 additions & 2 deletions php_scrypt_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
uint64_t clampAndCast64(uint32_t argNum, const char *argName, long value, long min)
{
TSRMLS_FETCH();
if (value <= min)
{
#if PHP_VERSION_ID >= 80000
Expand Down Expand Up @@ -63,7 +62,6 @@ uint64_t clampAndCast64(uint32_t argNum, const char *argName, long value, long m
*/
uint32_t clampAndCast32(uint32_t argNum, const char *argName, long value, long min)
{
TSRMLS_FETCH();
if (value <= min)
{
#if PHP_VERSION_ID >= 80000
Expand Down