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
193d0bb6
Commit
193d0bb6
authored
Sep 15, 2013
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Z85 methods to be static and not pollute library
parent
65ef76bb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
8 deletions
+80
-8
z85_codec.hpp
src/z85_codec.hpp
+2
-2
test_security_curve.cpp
tests/test_security_curve.cpp
+39
-2
curve_keygen.c
tools/curve_keygen.c
+37
-2
z85_codec.h
tools/z85_codec.h
+2
-2
No files found.
src/z85_codec.hpp
View file @
193d0bb6
...
...
@@ -51,7 +51,7 @@ static uint8_t decoder [96] = {
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
// dest. Size must be a multiple of 4.
char
*
static
char
*
Z85_encode
(
char
*
dest
,
uint8_t
*
data
,
size_t
size
)
{
assert
(
size
%
4
==
0
);
...
...
@@ -82,7 +82,7 @@ Z85_encode (char *dest, uint8_t *data, size_t size)
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
// must be a multiple of 5.
uint8_t
*
static
uint8_t
*
Z85_decode
(
uint8_t
*
dest
,
char
*
string
)
{
assert
(
strlen
(
string
)
%
5
==
0
);
...
...
tests/test_security_curve.cpp
View file @
193d0bb6
...
...
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include "testutil.hpp"
#include "../include/zmq_utils.h"
#include "../src/z85_codec.hpp"
#include "platform.hpp"
// Test keys from the zmq_curve man page
...
...
@@ -30,6 +29,44 @@ static char client_secret [] = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs";
static
char
server_public
[]
=
"rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7"
;
static
char
server_secret
[]
=
"JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6"
;
// --------------------------------------------------------------------------
// Encode a binary frame as a string; destination string MUST be at least
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
// dest. Size must be a multiple of 4.
// Maps base 256 to base 85
static
char
encoder
[
85
+
1
]
=
{
"0123456789"
"abcdefghij"
"klmnopqrst"
"uvwxyzABCD"
"EFGHIJKLMN"
"OPQRSTUVWX"
"YZ.-:+=^!/"
"*?&<>()[]{"
"}@%$#"
};
static
char
*
Z85_encode
(
char
*
dest
,
uint8_t
*
data
,
size_t
size
)
{
assert
(
size
%
4
==
0
);
unsigned
int
char_nbr
=
0
;
unsigned
int
byte_nbr
=
0
;
uint32_t
value
=
0
;
while
(
byte_nbr
<
size
)
{
// Accumulate value in base 256 (binary)
value
=
value
*
256
+
data
[
byte_nbr
++
];
if
(
byte_nbr
%
4
==
0
)
{
// Output value in base 85
unsigned
int
divisor
=
85
*
85
*
85
*
85
;
while
(
divisor
)
{
dest
[
char_nbr
++
]
=
encoder
[
value
/
divisor
%
85
];
divisor
/=
85
;
}
value
=
0
;
}
}
assert
(
char_nbr
==
size
*
5
/
4
);
dest
[
char_nbr
]
=
0
;
return
dest
;
}
static
void
zap_handler
(
void
*
ctx
)
{
// Create and bind ZAP socket
...
...
@@ -71,7 +108,7 @@ static void zap_handler (void *ctx)
}
else
{
s_sendmore
(
zap
,
"400"
);
s_sendmore
(
zap
,
"Invalid
username or password
"
);
s_sendmore
(
zap
,
"Invalid
client public key
"
);
s_sendmore
(
zap
,
""
);
s_send
(
zap
,
""
);
}
...
...
tools/curve_keygen.c
View file @
193d0bb6
...
...
@@ -28,12 +28,47 @@
#include <stdlib.h>
#include <assert.h>
#include "../src/platform.hpp"
#ifdef HAVE_LIBSODIUM
# include <sodium.h>
# include "z85_codec.h"
#endif
// Maps base 256 to base 85
static
char
encoder
[
85
+
1
]
=
{
"0123456789"
"abcdefghij"
"klmnopqrst"
"uvwxyzABCD"
"EFGHIJKLMN"
"OPQRSTUVWX"
"YZ.-:+=^!/"
"*?&<>()[]{"
"}@%$#"
};
// --------------------------------------------------------------------------
// Encode a binary frame as a string; destination string MUST be at least
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
// dest. Size must be a multiple of 4.
static
char
*
Z85_encode
(
char
*
dest
,
uint8_t
*
data
,
size_t
size
)
{
assert
(
size
%
4
==
0
);
uint
char_nbr
=
0
;
uint
byte_nbr
=
0
;
uint32_t
value
=
0
;
while
(
byte_nbr
<
size
)
{
// Accumulate value in base 256 (binary)
value
=
value
*
256
+
data
[
byte_nbr
++
];
if
(
byte_nbr
%
4
==
0
)
{
// Output value in base 85
uint
divisor
=
85
*
85
*
85
*
85
;
while
(
divisor
)
{
dest
[
char_nbr
++
]
=
encoder
[
value
/
divisor
%
85
];
divisor
/=
85
;
}
value
=
0
;
}
}
assert
(
char_nbr
==
size
*
5
/
4
);
dest
[
char_nbr
]
=
0
;
return
dest
;
}
int
main
(
void
)
{
#ifdef HAVE_LIBSODIUM
...
...
tools/z85_codec.h
View file @
193d0bb6
...
...
@@ -53,7 +53,7 @@ static uint8_t decoder [96] = {
// size * 5 / 4 bytes long plus 1 byte for the null terminator. Returns
// dest. Size must be a multiple of 4.
char
*
static
char
*
Z85_encode
(
char
*
dest
,
uint8_t
*
data
,
size_t
size
)
{
assert
(
size
%
4
==
0
);
...
...
@@ -84,7 +84,7 @@ Z85_encode (char *dest, uint8_t *data, size_t size)
// strlen (string) * 4 / 5 bytes long. Returns dest. strlen (string)
// must be a multiple of 5.
uint8_t
*
static
uint8_t
*
Z85_decode
(
uint8_t
*
dest
,
char
*
string
)
{
assert
(
strlen
(
string
)
%
5
==
0
);
...
...
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