sodium-friends / sodium-native

Low level bindings for libsodium
MIT License
300 stars 64 forks source link

crypto_secretstream_xchacha20poly1305_state_new is missing since v3.0.0 #180

Closed letalumil closed 1 year ago

letalumil commented 1 year ago

Hi there,

I'm currently busy migrating a project from sodium-native v2.4.6 to v4.0.1. It turned out that the crypto_secretstream_xchacha20poly1305_state_new method was removed during the N-API implementation.

However, the method is still described in the docs.

As the project I am working on relies on this method, can I ask if the method was removed on purpose? Is there any way to get it back?

Thanks in advance!

chm-diederichs commented 1 year ago

Hi, thanks for your message, the docs are indeed out of date.

During the N-API migration we decided to use state buffers instead of opaque state instances, since it's closer aligned with the API of the underlying Libsodium method.

You can use the secretstream API like so:

const state = Buffer.alloc(sodium.crypto_secretstream_xchacha20poly1305_STATEBYTES)

sodium.crypto_secretstream_xchacha20poly1305_init_push(state, header, key)
sodium.crypto_secretstream_xchacha20poly1305_push(state, ciphertext, message, ad, tag)
// ... rest of code here

I'll update the docs now, but the rest of the secretstream methods are documented correctly.

Let me know if you have any further issues!

chm-diederichs commented 1 year ago

Note that the API is documented here: https://sodium-friends.github.io/docs/docs/streamencryption#stateful-api