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

crypto_box(_open) confusion #38

Closed
25A0 opened this issue May 26, 2016 · 3 comments
Closed

crypto_box(_open) confusion #38

25A0 opened this issue May 26, 2016 · 3 comments

Comments

@25A0
Copy link

25A0 commented May 26, 2016

I'm trying to use crypto_box and crypto_box_open to let party A encrypt and sign data for party B.
From my understanding, the following code should work:

def test_cross_box():
    pkA, skA = pysodium.crypto_sign_keypair()
    pkB, skB = pysodium.crypto_sign_keypair()
    nonce = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
    msg = "foo"
    c = pysodium.crypto_box(msg, nonce, pkB, skA)
    d = pysodium.crypto_box_open(c, nonce, pkA, skB)
    assert msg == d

However, the above code raises a ValueError in
/usr/local/lib/python2.7/site-packages/pysodium/__init__.py:256: in crypto_box_open __check(sodium.crypto_box_open(msg, padded, ctypes.c_ulonglong(len(padded)), nonce, pk, sk))

The unit test only seems to check for cases where the public and secret key are the same when calling crypto_box and crypto_box_open, and indeed the following code works:

def test_self_box():
    pkA, skA = pysodium.crypto_sign_keypair()
    nonce = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
    msg = "foo"
    c = pysodium.crypto_box(msg, nonce, pkA, skA)
    d = pysodium.crypto_box_open(c, nonce, pkA, skA)
    assert msg == d

Am I missing something about how crypto_box should be used, or is this a bug?

Using python 2.7, pysodium 0.6.8, libsodium 1.0.9

@stef
Copy link
Owner

stef commented May 26, 2016

would you try out crypto_box_keypair instead of crypto_sign_keypair, and check if it works like this?

@stef
Copy link
Owner

stef commented May 26, 2016

i'm not sure you should reuse the keys for encryption and signing. so you need two keys and also use crypto_sign_keypair not only crypto_box_keypair.

@25A0
Copy link
Author

25A0 commented May 26, 2016

Thanks a lot! :)
Using crypto_box_keypair works flawlessly.
I admittedly didn't pay attention to the type of keypair I generated. Sorry for the noise

@25A0 25A0 closed this as completed May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants