Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pynacl crypto_core_hsalsa20 #632

Open
DanielRadl opened this issue Sep 15, 2020 · 1 comment
Open

pynacl crypto_core_hsalsa20 #632

DanielRadl opened this issue Sep 15, 2020 · 1 comment

Comments

@DanielRadl
Copy link

I need the crypto_core_hsalsa20 function to greate an secret key for my NUKI.

Both sides calculate DH Key k using function dh1
a. Key
0DE40B998E0E330376F2D2FC4892A6931E25055FD09F054F99E93FECD9BA611E
8. Both sides derive a long term shared secret key s from k using function kdf1
a. Shared key
217FCB0F18CAF284E9BDEA0B94B83B8D10867ED706BFDEDBD2381F4CB3B8F730

4.2 The key derivation function kdf1
static const unsigned char _0[16];
static const unsigned char sigma[16] = "expand 32-byte k";
crypto_core_hsalsa20(k,_0,s,sigma)
Used to derive a long term secret key out of the shared key calculated by dh1

I alredy calculated the DH Key k with the nacl.publik.Box (=dh1) function.

Can someone tell me how to use the kdf1 function with pynacl?
Thanks!

@ljluestc
Copy link

import nacl.utils
from nacl.secret import SecretBox

Your shared key calculated by DH

shared_key = b'\x21\x7F\xCB\x0F\x18\xCA\xF2\x84\xE9\xBD\xEA\x0B\x94\xB8\x3B\x8D\x10\x86\x7E\xD7\x06\xBF\xDE\xDB\xD2\x38\x1F\x4C\xB3\xB8\xF7\x30'

Derivation constant

sigma = b'expand 32-byte k'

Create a SecretBox with the shared key as the key

box = SecretBox(shared_key)

Derive the long-term secret key using crypto_core_hsalsa20

derived_secret_key = box._encrypt_nonce(sigma, nacl.utils.zero(nacl.secret.SecretBox.KEY_SIZE))

print(derived_secret_key)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants