Skip to content

Commit 34df3cd

Browse files
committed
sodium ext: skip scrypt if it is not available
scrypt was removed from minimal libsodium builds in version 1.0.13
1 parent 650f68c commit 34df3cd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ext/sodium/libsodium.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@ const zend_function_entry sodium_functions[] = {
225225
PHP_FE(sodium_crypto_pwhash_str, AI_PasswordAndOpsLimitAndMemLimit)
226226
PHP_FE(sodium_crypto_pwhash_str_verify, AI_HashAndPassword)
227227
#endif
228+
#ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES
228229
PHP_FE(sodium_crypto_pwhash_scryptsalsa208sha256, AI_LengthAndPasswordAndSaltAndOpsLimitAndMemLimit)
229230
PHP_FE(sodium_crypto_pwhash_scryptsalsa208sha256_str, AI_PasswordAndOpsLimitAndMemLimit)
230231
PHP_FE(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify, AI_HashAndPassword)
232+
#endif
231233
PHP_FE(sodium_crypto_scalarmult, AI_TwoStrings)
232234
PHP_FE(sodium_crypto_secretbox, AI_StringAndNonceAndKey)
233235
PHP_FE(sodium_crypto_secretbox_open, AI_StringAndNonceAndKey)
@@ -472,11 +474,9 @@ PHP_MINIT_FUNCTION(sodium)
472474
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE",
473475
crypto_pwhash_memlimit_sensitive(), CONST_CS | CONST_PERSISTENT);
474476
#endif
477+
#ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES
475478
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES",
476479
crypto_pwhash_scryptsalsa208sha256_SALTBYTES, CONST_CS | CONST_PERSISTENT);
477-
#ifndef crypto_pwhash_scryptsalsa208sha256_STRPREFIX
478-
# define crypto_pwhash_scryptsalsa208sha256_STRPREFIX "$7$"
479-
#endif
480480
REGISTER_STRING_CONSTANT("SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRPREFIX",
481481
crypto_pwhash_scryptsalsa208sha256_STRPREFIX, CONST_CS | CONST_PERSISTENT);
482482
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE",
@@ -487,6 +487,7 @@ PHP_MINIT_FUNCTION(sodium)
487487
crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive(), CONST_CS | CONST_PERSISTENT);
488488
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_SENSITIVE",
489489
crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive(), CONST_CS | CONST_PERSISTENT);
490+
#endif
490491
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_SCALARMULT_BYTES",
491492
crypto_scalarmult_BYTES, CONST_CS | CONST_PERSISTENT);
492493
REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_SCALARMULT_SCALARBYTES",
@@ -1654,6 +1655,7 @@ PHP_FUNCTION(sodium_crypto_stream_xor)
16541655
RETURN_STR(ciphertext);
16551656
}
16561657

1658+
#ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES
16571659
PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
16581660
{
16591661
zend_string *hash;
@@ -1776,6 +1778,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify)
17761778
}
17771779
RETURN_FALSE;
17781780
}
1781+
#endif
17791782

17801783
#ifdef crypto_pwhash_SALTBYTES
17811784
PHP_FUNCTION(sodium_crypto_pwhash)

ext/sodium/tests/pwhash_scrypt.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
--TEST--
2-
Check for libsodium utils
2+
Check for libsodium scrypt
33
--SKIPIF--
4-
<?php if (!extension_loaded("sodium")) print "skip"; ?>
4+
<?php if (!extension_loaded("sodium")) print "skip";
5+
if (!defined('SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES')) print "skip libsodium without scrypt"; ?>
56
--FILE--
67
<?php
78
$passwd = 'test';

0 commit comments

Comments
 (0)