Skip to content

Using the same key for the Secret Box and Secret Stream #1461

Answered by jedisct1
wodny asked this question in Q&A
Discussion options

You must be logged in to vote

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 …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@wodny
Comment options

@jedisct1
Comment options

Answer selected by wodny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants