Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
d1a927a9
Commit
d1a927a9
authored
Sep 29, 2013
by
MinRK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add zmq_curve_keypair to zmq_utils
parent
30d34888
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
zmq_utils.h
include/zmq_utils.h
+4
-0
zmq_utils.cpp
src/zmq_utils.cpp
+36
-1
No files found.
include/zmq_utils.h
View file @
d1a927a9
...
...
@@ -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 */
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
#ifdef __cplusplus
...
...
src/zmq_utils.cpp
View file @
d1a927a9
...
...
@@ -30,6 +30,10 @@
#else
#include "windows.hpp"
#endif
#ifdef HAVE_LIBSODIUM
# include <sodium.h>
#endif
void
zmq_sleep
(
int
seconds_
)
{
...
...
@@ -125,7 +129,7 @@ char *zmq_z85_encode (char *dest, uint8_t *data, size_t size)
return
dest
;
}
// --------------------------------------------------------------------------
// Decode an encoded string into a binary frame; dest must be at least
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
...
...
@@ -153,3 +157,34 @@ uint8_t *zmq_z85_decode (uint8_t *dest, char *string)
assert
(
byte_nbr
==
strlen
(
string
)
*
4
/
5
);
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment