mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 07:56:09 +00:00
add zmq_curve_keypair to zmq_utils
This commit is contained in:
parent
30d34888e0
commit
d1a927a92e
@ -88,6 +88,10 @@ ZMQ_EXPORT char *zmq_z85_encode (char *dest, uint8_t *data, size_t size);
|
|||||||
/* Decode data with Z85 encoding. Returns decoded data */
|
/* Decode data with Z85 encoding. Returns decoded data */
|
||||||
ZMQ_EXPORT uint8_t *zmq_z85_decode (uint8_t *dest, char *string);
|
ZMQ_EXPORT uint8_t *zmq_z85_decode (uint8_t *dest, char *string);
|
||||||
|
|
||||||
|
/* Generate z85-encoded public and private keypair with libsodium. */
|
||||||
|
/* Returns 0 on success. */
|
||||||
|
ZMQ_EXPORT int zmq_curve_keypair (char* z85_public_key, char *z85_secret_key);
|
||||||
|
|
||||||
#undef ZMQ_EXPORT
|
#undef ZMQ_EXPORT
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
#else
|
#else
|
||||||
#include "windows.hpp"
|
#include "windows.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_LIBSODIUM
|
||||||
|
# include <sodium.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void zmq_sleep (int seconds_)
|
void zmq_sleep (int seconds_)
|
||||||
{
|
{
|
||||||
@ -153,3 +157,34 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
|
|||||||
assert (byte_nbr == strlen (string) * 4 / 5);
|
assert (byte_nbr == strlen (string) * 4 / 5);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// Generate a public/private keypair with libsodium.
|
||||||
|
// Generated keys will be 40 byte z85-encoded strings.
|
||||||
|
// Returns 0 on success, -1 on failure, setting errno.
|
||||||
|
// Sets errno = ENOTSUP in the absence of libsodium.
|
||||||
|
|
||||||
|
int zmq_curve_keypair (char* z85_public_key, char *z85_secret_key)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_LIBSODIUM
|
||||||
|
# if crypto_box_PUBLICKEYBYTES != 32 \
|
||||||
|
|| crypto_box_SECRETKEYBYTES != 32
|
||||||
|
# error "libsodium not built correctly"
|
||||||
|
# endif
|
||||||
|
|
||||||
|
uint8_t public_key [32];
|
||||||
|
uint8_t secret_key [32];
|
||||||
|
|
||||||
|
int rc = crypto_box_keypair (public_key, secret_key);
|
||||||
|
// is there a sensible errno to set here?
|
||||||
|
if (rc) return rc;
|
||||||
|
|
||||||
|
zmq_z85_encode (z85_public_key, public_key, 32);
|
||||||
|
zmq_z85_encode (z85_secret_key, secret_key, 32);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#else // requires libsodium
|
||||||
|
errno = ENOTSUP;
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user