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

NaCl: add default parameter for optional random generated sk #668

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion naclite.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,12 @@ int crypto_sign_open(byte *m,word64 *mlen,const byte *sm,word64 n,const byte *pk
/// \brief Generate a keypair for signing
/// \param pk public key byte buffer
/// \param sk private key byte buffer
/// \param rnd_sk generate random private key
/// \details crypto_sign_keypair() creates an ed25519 keypair.
/// \returns 0 on success, non-0 otherwise
/// \sa <A HREF="https://nacl.cr.yp.to/sign.html">NaCl crypto_sign documentation</A>
/// \since Crypto++ 6.0
int crypto_sign_keypair(byte *pk, byte *sk);
int crypto_sign_keypair(byte *pk, byte *sk, const bool rnd_sk = true);

/// \brief Produce a keystream using XSalsa20
/// \details crypto_stream() uses crypto_stream_xsalsa20
Expand Down
5 changes: 3 additions & 2 deletions tweetnacl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,14 @@ static void scalarbase(gf p[4],const byte *s)
scalarmult(p,q,s);
}

int crypto_sign_keypair(byte *pk, byte *sk)
int crypto_sign_keypair(byte *pk, byte *sk, const bool rnd_sk)
{
byte d[64];
gf p[4];
int i;

randombytes(sk, 32);
if (rnd_sk)
randombytes(sk, 32);
crypto_hash(d, sk, 32);
d[0] &= 248;
d[31] &= 127;
Expand Down