Skip to content
Permalink
Browse files

Replace copied scrypt implementation with call to libsodium

Summary:
libsodium actually uses the same implementation; using libsodium means we don't
need to maintain a copy ourselves.

Keep the `pickparams` implementation though, as that's not exposed in libsodium.

We should deprecate this extension, and strongly encourage directly using `ext_sodium` instead from Hack code; stored hashes from `ext_scrypt` can be verified like this:

```
$enc = scrypt_enc('foo', random_bytes(SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES));
	​
​list($_, $algo, $n, $r, $p, $salt, $out) = explode('$', $enc);
​invariant($algo === 's', 'did not get an scrypt result');
​$salt = base64_decode($salt);
​$out = base64_decode($out);
​
​$opslimit = (1 << $n) * $r * $p * 4;
​$memlimit = (1 << $n) * $r * 128;
​$sodium = sodium_crypto_pwhash_scryptsalsa208sha256(strlen($out), 'foo', $salt, $opslimit, $memlimit);
​\var_dump($sodium === $out);
```

This also makes the scrypt extension depend on libsodium; this is fine, libsodium's going to be a hard dependency for HHVM  anyway when the proxygen pin is next updated.

Reviewed By: alexeyt

Differential Revision: D15702142

fbshipit-source-id: 2dcad7c6cb273d4ce4b3479ffa445841fa2d1107
  • Loading branch information...
fredemmott authored and hhvm-bot committed Jun 11, 2019
1 parent 97ef580 commit cc331e4349e91706a673e2a09f1f2ea5bbb33815
@@ -1,14 +1,13 @@
HHVM_DEFINE_EXTENSION("scrypt"
HHVM_DEFINE_EXTENSION("scrypt" IMPLICIT
SOURCES
ext_scrypt.cpp
crypto/crypto_scrypt-sse.cpp
crypto/crypto_scrypt-nosse.cpp
crypto/sha256.cpp
crypto/crypto_scrypt.cpp
crypto/params.cpp
HEADERS
crypto/crypto_scrypt.h
crypto/params.h
crypto/sha256.h
SYSTEMLIB
ext_scrypt.php
DEPENDS
"libsodium 1.0.9"
)

This file was deleted.

0 comments on commit cc331e4

Please sign in to comment.
You can’t perform that action at this time.