Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using curve25519xsalsa20poly1305/fn.seal from sodiumoxide crate written in Rust language which is a wrapper over libsodium c library and that function calls crypto_box_curve25519xsalsa20poly1305 in libsodium library.

The rust code would look something like this:

let (pub_key, sec_key) = ::sodiumoxide::crypto::box_::gen_keypair();
let nonce = ::sodiumoxide::crypto::box_::gen_nonce();

let data = vec![0; 10]; // plain-text

// Cipher-text
let encrypted = ::sodiumoxide::crypto::box_::seal(&data,

println!("Encrypted: {:?}", encrypted);
assert!(data != encrypted);

How much is it a security concern if i use a related key-pair (Public, Secret Key pair) generated through crypto_box_curve25519xsalsa20poly1305_keypair in calling that function?

Will this be regarded as a potential weakness, given that only I intend to encrypt and decrypt it? I know it is better to use symmetric encryption in this case but just for learning purposes – what is the security risk ?

share|improve this question
Well, ..., the code looks OK. For public key crypto, you have to generate a key-pair, where the one key decrypts and the other one encrypts. – SEJPM Sep 22 '15 at 13:22
ah yes .. but that's not the problem here. It is something to do with the definition. So if you check out the link i posted, it'll say that sender's secret key is used t(till this point all appears normal) along with receiver's public key. What i have done is used sender's public and private keys to encrypt/authenticate. So in your opinion could that be a security leak of some sort, or it does not matter and is pretty strong ? – ustulation Sep 22 '15 at 14:06
It's pretty strong, because noone can read this message except you. I'll add an explaining answer. – SEJPM Sep 22 '15 at 16:36
@ustulation Simply consider that you are now sender and receiver in your description. – mephisto Sep 23 '15 at 8:39
up vote 2 down vote accepted

You are effectively using symmetric encryption.

The crypto_box function uses elliptic curve Diffie–Hellman on Curve25519. With a given input private key and public key it always generates the same symmetric key, which is then used for authenticated encryption. By using the private and public key from the same key pair you are generating the point $a^2G$, which with a random $a$ is just a random point on the curve. This point is then used to derive a symmetric key for authenticated encryption.

Of course, it would be more efficient to just use that derived key (or a random key) in the first place, but as long as you keep the key pair secret, what you are doing is secure.

share|improve this answer

It is no security leak to use the sender's public and private key with that function rather than the receiver's public and the sender's private key.

The reason for this is that you're the only person who can decipher the message afterwards.

To understand this you need to understand how the keys are used.

  • The inputted secret key is used to sign the message being sent, ensuring that you are actually the person / entity sending this message to the intended recipient. Only the intended receiver will be able to check this signature as is embedded in the encrypted message.
  • The inputted public key is used to asymmetrically encrypt the message (and the signature). After the encryption, only the holder of the private key corresponding to the inputted public key will be able to decrypt the message. Usually this is the intended receipient to allow only him to read the message. If you input your own public key here, you make yourself the intended recipient, meaning only you can read the message (which is a bit pointless). If you want to securely store a message, using standard symmetric cryptosystem is the optimal solution as it is alot faster.

According to the comments the process of signing is skipped for NaCl, but the point that nobody will be able to decrypt the message still holds.

share|improve this answer
There's no signature here. The crypto_box function uses Diffie–Hellman on Curve25519 with the private and public key given, derives a symmetric key and uses that for authenticated encryption. – otus Sep 22 '15 at 17:01
thanks .. I am not well versed with the internals of cryptography, i just use the libraries after reading their documentation. So I was just worried about functions yeilding something like this: Tx-SecretKey(Rx-PublicKey(PlainText)) == PlainText for Tx == Rx or similar. But from your answers it's apparently not. Thanks ! – ustulation Sep 23 '15 at 8:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.