Problem: no function to derive curve public key from secret key.

This commit is contained in:
evoskuil
2016-05-18 23:51:18 -07:00
parent 34164ec6f5
commit 460bc7525b
3 changed files with 42 additions and 2 deletions

View File

@@ -197,7 +197,7 @@ int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key)
uint8_t secret_key [32];
int rc = crypto_box_keypair (public_key, secret_key);
// Is there a sensible errno to set here?
// Is there a sensible errno to set here (no, it cannot fail)?
if (rc)
return rc;
@@ -212,6 +212,41 @@ int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key)
#endif
}
// --------------------------------------------------------------------------
// Derive the public key from a private key using tweetnacl or libsodium.
// Derived key will be 40 byte z85-encoded string.
// Returns 0 on success, -1 on failure, setting errno.
// Sets errno = ENOTSUP in the absence of a CURVE library.
int zmq_curve_public (char *z85_public_key, const char *z85_secret_key)
{
#if defined (ZMQ_HAVE_CURVE)
# if crypto_box_PUBLICKEYBYTES != 32 \
|| crypto_box_SECRETKEYBYTES != 32
# error "CURVE encryption library not built correctly"
# endif
uint8_t public_key[32];
uint8_t secret_key[32];
if (zmq_z85_decode (secret_key, z85_secret_key) == NULL)
return -1;
int rc = crypto_scalarmult_base (public_key, secret_key);
// Is there a sensible errno to set here (no, it cannot fail)?
if (rc)
return rc;
zmq_z85_encode (z85_public_key, public_key, 32);
return 0;
#else
(void) z85_public_key, (void) z85_secret_key;
errno = ENOTSUP;
return -1;
#endif
}
// --------------------------------------------------------------------------
// Initialize a new atomic counter, which is set to zero