jedisct1 / libsodium.js

libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Other
968 stars 138 forks source link

New 1.0.19 functions only partially supported #335

Closed bschick closed 3 weeks ago

bschick commented 5 months ago

While working on this issue: https://github.com/jedisct1/libsodium.js/issues/334 I hit errors trying to call the following 1.0.19 functions from plain old javascript:

crypto_aeadaegis128l crypto_aeadaegis256 crypto_kdfhkdf*

After some grepping and simple tests, it looks like:

  1. The crypto_aead_aegis* functions are defined in normal npm libsodium-wrappers but not in the normal npm libsodium package. Therefore the following throws a TypeError in nodejs 21
    
    const sodium = require('libsodium-wrappers');

sodium.ready.then( () => { let k1 = sodium.crypto_aead_aegis256_keygen(); console.log(k1); })

TypeError: sodium.crypto_aead_aegis256_keygen is not a function at /home/bschick/shared/lstest/index.js:



2. The crypto_aead_aegis* functions are present in both  libsodium-wrappers-sumo and libsodium-sumo and work as expected in a simple test. Since the crypto_aead_aegis* functions are "standard track" in libsodium 1.0.19, however, I expected them to be in both normal and sumo packages. 

3. crypto_kdf_hkdf_* don't seem to be present in either normal or sumo packages

I'll send a patch if I have time to dig into the libsodium.js build, but hoping a fix is quicker for someone already familiar. 
jedisct1 commented 5 months ago

Can you try the current code? The aegis functions are now in standard packages. Additionally, new emscripten versions removed support for a command-line flag we were using, which may have prevented some updates.

bschick commented 5 months ago

Cloning the libsodium.js repo and using code from /dist/modules I did get aegis functions to work in a nodejs project with the non-sumo files.

The crypto_kdf_hkdf functions I tested still do not work, for example:

TypeError: sodium.crypto_kdf_hkdf_sha256_extract is not a function
    at /home/bschick/shared/lstest/index.js:30:19

In a browser project using angular and typescript, I have not gotten the aegis functions to work yet using the cloned repo, but I may be doing something wrong since I have not built the npm packages and installed them properly (I just replaced the project's node_module files with those from libsodium.js repo's /dist/modules, and cleared caches). The error is:

TypeError: libsodium_wrappers__WEBPACK_IMPORTED_MODULE_1___default(...).crypto_aead_aegis256_encrypt is not a function
bschick commented 5 months ago

@jedisct1 anything else you'd like me to try?

jedisct1 commented 5 months ago

Looks like Javascript wrappers for these functions don't exist, so they have to be written 🤷

bschick commented 5 months ago

I figured out the local problem with crypto_aead_aegis functions not working in a browser project. So we can limit this report to just the missing crypto_kdf_hkdf wrappers. If I get time and the full build working, I'll work on that