-
Hi, I am using libsodium via pynacl to create something similar to saltpack. I create an encrypted and authenticated manifest with the self._shared_key = nacl.bindings.crypto_box_beforenm(
public_key.encode(encoder=encoding.RawEncoder),
private_key.encode(encoder=encoding.RawEncoder),
) which uses:
Then the manifest contains random symmetric keys generated using I was wondering if it would be safe to use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
crypto_box_beforenm returns a value that can later be used with crypto_box_afternm. However, that return value is meant to be treated as opaque. Semantically, using it for anything else is unexpected. I must admit, I had to check the source code myself to confirm that it's currently just the 32-byte shared key. Although it's unlikely to change, you shouldn't rely on that detail. For instance, beforenm could eventually skip the hashing step, leaving it to afternm instead. Again, this is unlikely, but possible. For key exchange, it's better to use the dedicated API: That said, using the same key for both |
Beta Was this translation helpful? Give feedback.
crypto_box_beforenm returns a value that can later be used with crypto_box_afternm. However, that return value is meant to be treated as opaque.
Semantically, using it for anything else is unexpected. I must admit, I had to check the source code myself to confirm that it's currently just the 32-byte shared key. Although it's unlikely to change, you shouldn't rely on that detail. For instance, beforenm could eventually skip the hashing step, leaving it to afternm instead. Again, this is unlikely, but possible.
For key exchange, it's better to use the dedicated API:
crypto_kx
. It has the added benefit of producing two separate keys, one for each direction.That said, using the same key for …