Skip to content

Commit

Permalink
feat: add crypto_kdf_CONTEXTBYTES
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Dec 13, 2022
1 parent 6eb47a6 commit 53eca47
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
crypto_box_open_easy,
crypto_box_PUBLICKEYBYTES,
crypto_box_SECRETKEYBYTES,
crypto_kdf_CONTEXTBYTES,
crypto_kdf_derive_from_key,
crypto_kdf_KEYBYTES,
crypto_kdf_keygen,
Expand Down
1 change: 1 addition & 0 deletions cpp/react-native-libsodium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void installLibsodium(jsi::Runtime &jsiRuntime)
jsiRuntime.global().setProperty(jsiRuntime, "jsi_crypto_kdf_KEYBYTES", (int)crypto_kdf_KEYBYTES);
jsiRuntime.global().setProperty(jsiRuntime, "jsi_crypto_pwhash_BYTES_MAX", (int)crypto_pwhash_BYTES_MAX);
jsiRuntime.global().setProperty(jsiRuntime, "jsi_crypto_pwhash_BYTES_MIN", (int)crypto_pwhash_BYTES_MIN);
jsiRuntime.global().setProperty(jsiRuntime, "jsi_crypto_kdf_CONTEXTBYTES", (int)crypto_kdf_CONTEXTBYTES);

auto jsi_from_base64_to_arraybuffer = jsi::Function::createFromHostFunction(
jsiRuntime,
Expand Down
6 changes: 6 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import sodium, {
crypto_box_open_easy,
crypto_box_PUBLICKEYBYTES,
crypto_box_SECRETKEYBYTES,
crypto_kdf_CONTEXTBYTES,
crypto_kdf_derive_from_key,
crypto_kdf_KEYBYTES,
crypto_kdf_keygen,
Expand Down Expand Up @@ -69,8 +70,13 @@ function LibsodiumTests() {
crypto_kdf_KEYBYTES,
crypto_pwhash_BYTES_MIN,
crypto_pwhash_BYTES_MAX,
crypto_kdf_CONTEXTBYTES,
});

if (crypto_kdf_CONTEXTBYTES !== 8) {
throw new Error('crypto_kdf_CONTEXTBYTES not properly exported');
}

const randombytes_buf_1 = randombytes_buf(1);
const randombytes_buf_3 = randombytes_buf(3);
const randombytes_buf_9 = randombytes_buf(9);
Expand Down
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare global {
var jsi_crypto_kdf_KEYBYTES: number;
var jsi_crypto_pwhash_BYTES_MIN: number;
var jsi_crypto_pwhash_BYTES_MAX: number;
var jsi_crypto_kdf_CONTEXTBYTES: number;

function jsi_from_base64_to_arraybuffer(
input: string,
Expand Down Expand Up @@ -176,6 +177,7 @@ export const crypto_aead_xchacha20poly1305_ietf_NPUBBYTES =
export const crypto_kdf_KEYBYTES = global.jsi_crypto_kdf_KEYBYTES;
export const crypto_pwhash_BYTES_MIN = global.jsi_crypto_pwhash_BYTES_MIN;
export const crypto_pwhash_BYTES_MAX = global.jsi_crypto_pwhash_BYTES_MAX;
export const crypto_kdf_CONTEXTBYTES = global.jsi_crypto_kdf_CONTEXTBYTES;

export const from_base64 = (
input: string,
Expand Down Expand Up @@ -668,6 +670,7 @@ export default {
crypto_box_PUBLICKEYBYTES,
crypto_box_SECRETKEYBYTES,
crypto_kdf_derive_from_key,
crypto_kdf_CONTEXTBYTES,
crypto_kdf_KEYBYTES,
crypto_kdf_keygen,
crypto_pwhash,
Expand Down

0 comments on commit 53eca47

Please sign in to comment.