[zeromq-dev] RFC 32 - Z85
Pieter Hintjens
ph at imatix.com
Mon Jul 1 11:38:07 CEST 2013
I'll explain the reasons for creating Z85.
The first time I needed to use Curve keys, it broke. This was in CZMQ
where we generate the socket options test cases. Here's what I wanted
to put into my model:
<option name = "curve_publickey" type = "blob" mode = "rw"
test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID" />
<option name = "curve_secretkey" type = "blob" mode = "rw"
test = "PUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs" />
<option name = "curve_serverkey" type = "blob" mode = "rw"
test = "SUB"
ifdef = "HAVE_LIBSODIUM"
test_value = "rq:rM>}U?@Lns47E1%kR.o at n%FcmmsL/@{H8]yf7" />
Ascii85 generates quotes, so couldn't work. I also noticed that the
code in tests/test_security_curve.cpp was pretty messy. Here's what I
wanted to write there:
// Test keys from the zmq_curve man page
char client_public [] = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID";
char client_secret [] = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs";
char server_public [] = "rq:rM>}U?@Lns47E1%kR.o at n%FcmmsL/@{H8]yf7";
char server_secret [] = "JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6";
Now Base64 looks like the most plausible answer but (a) it's not a
single standard, and (b) it is surprisingly, not ideal for keys since
it uses 3-byte blocks. With a little thought and a pre-calculated
table, a Base256 to Base85 codec turned out to be very simple. See
https://github.com/zeromq/rfc/blob/master/src/spec_32.c.
Since Base85 works off 4-byte chunks, it is rather simpler, and that's
the main reason I chose it over Base64. The added compression is nice
but not essential. I wanted a minimalist algorithm that could be clean
in any language.
Also there's no real cost to using Z85 since we don't need
interoperability with any other system here, and it's not exposed to
application developers.
If anyone feels strongly that MIME encoding would be better, of course
you can send patches.
-Pieter
More information about the zeromq-dev
mailing list