File
Blob: src/workerd/api/crypto/scrypt.c++
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | #include "impl.h" |
| 6 | #include "kdf.h" |
| 7 | |
| 8 | #include <ncrypto.h> |
| 9 | |
| 10 | namespace workerd::api { |
| 11 | |
| 12 | kj::Maybe<jsg::JsArrayBuffer> scrypt(jsg::Lock& js, |
| 13 | size_t length, |
| 14 | uint32_t N, |
| 15 | uint32_t r, |
| 16 | uint32_t p, |
| 17 | uint32_t maxmem, |
| 18 | kj::ArrayPtr<const kj::byte> pass, |
| 19 | kj::ArrayPtr<const kj::byte> salt) { |
| 20 | ncrypto::ClearErrorOnReturn clearErrorOnReturn; |
| 21 | auto buf = jsg::JsArrayBuffer::create(js, length); |
| 22 | auto ncBuf = ToNcryptoBuffer(buf.asArrayPtr()); |
| 23 | if (ncrypto::scryptInto(ToNcryptoBuffer(pass.asChars()), ToNcryptoBuffer(salt), N, r, p, maxmem, |
| 24 | length, &ncBuf)) { |
| 25 | return kj::mv(buf); |
| 26 | } |
| 27 | return kj::none; |
| 28 | } |
| 29 | |
| 30 | } // namespace workerd::api |