From e033df715613f87b58e7e493fd0e12513ce507fe Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Thu, 31 Jul 2014 16:41:20 +0200 Subject: [PATCH] changed z85 padding (incompatible to previous pcp versions!): now we padd with zeroes as usual but append 4 bytes to the raw input, the last one indicates the pad count. It's always present, even if no padding occurred (the pad blob will then read 0000). This fixes the issue of earlier versions where trailing zeroes in the original input (between block boundaries) have been removed. Since we now add the pad counter, we know how many zeroes to remove. If the original chunk already ended with zeroes they will left untouched. Re-created all test keys/data to match the change. Also, the pcp_z85_encode() function now haves another flag doblock. If set to 1, the function does the 72 chars per line block creation itself, otherwise it just returns the z85 string without any newlines added. Required by pcpstream class. --- TODO | 4 ++ bindings/cpp/key.cpp | 4 +- include/pcp/z85.h | 15 +++---- libpcp/ed.c | 4 +- libpcp/pcpstream.c | 24 ++++------- libpcp/z85.c | 97 +++++++++++++++++++++++++++++--------------- src/keymgmt.c | 6 +-- src/keyprint.c | 2 +- src/z85util.c | 2 +- tests/bart.pub | 14 +++---- tests/decodertest.c | 12 +++--- tests/key-alicia-pub | 14 +++---- tests/key-alicia-sec | 12 +++--- tests/key-bobby-pub | 14 +++---- tests/key-bobby-sec | 12 +++--- tests/keys.cfg | 8 ++-- tests/pipetest.c | 26 +++++------- tests/static.h | 46 ++++++++++----------- tests/unittests.cfg | 26 ++++-------- tests/unknown1 | 14 +++---- tests/unknown2 | 12 +++--- tests/unknown4 | 2 +- 22 files changed, 192 insertions(+), 178 deletions(-) diff --git a/TODO b/TODO index 84d1885..5551322 100644 --- a/TODO +++ b/TODO @@ -41,3 +41,7 @@ py % nacl.crypto_hash_sha256(pointer(hash), pointer(key), 32) py % hash.raw ';\xa3\xf5\xf4;\x92`&\x83\xc1\x9a\xeeb\xa2\x03B\xb0\x84\... py % + +after new z85 padding scheme: write z85 blocksize to output +as well? if a reader doesn't know the blocksize it won't be +able to decode it properly. Or no issue? Not sure yet... diff --git a/bindings/cpp/key.cpp b/bindings/cpp/key.cpp index e7d51e2..27bddce 100644 --- a/bindings/cpp/key.cpp +++ b/bindings/cpp/key.cpp @@ -119,7 +119,7 @@ string Key::export_secret(const string &passphrase) { throw pcp::exception(PTX); size_t zlen; - char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen); + char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1); string out = string(EXP_SK_HEADER) + "\r\n" + string(z85) + "\r\n" + string(EXP_SK_FOOTER) + "\r\n"; @@ -135,7 +135,7 @@ string Key::export_public() { throw pcp::exception(PTX); size_t zlen; - char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen); + char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1); string out = string(EXP_PK_HEADER) + "\r\n" + string(z85) + "\r\n" + string(EXP_PK_FOOTER) + "\r\n"; diff --git a/include/pcp/z85.h b/include/pcp/z85.h index 5ee0b10..385e72c 100644 --- a/include/pcp/z85.h +++ b/include/pcp/z85.h @@ -53,9 +53,9 @@ we pad the input with zeroes and remove them after decoding. the original pointer into it and adds a number of zeros so that the result has a size divisable by 4. - \param[in] src Unpadded data. - \param[in] srclen Size of unpadded data. - \param[in] dstlen Returned size of padded data (pointer to int). + \param[in] src Unpadded data. + \param[in] srclen Size of unpadded data. + \param[out] dstlen Returned size of padded data (pointer to int). \return Returns a pointer to the padded data. */ @@ -95,13 +95,14 @@ byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen); It allocates the memory for the returned char pointer. The caller is responsible the free() it. - \param[in] raw Pointer to raw data. - \param[in] srclen Size of the data. - \param[in] dstlen Returned size of encoded data (pointer to int). + \param[in] raw Pointer to raw data. + \param[in] srclen Size of the data. + \param[out] dstlen Returned size of encoded data (pointer to int). + \param[in] doblock If set to 1, turn the encoded data into a 72 chars wide block. \return Returns a string (char array) containing the Z85 encoded data. */ -char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen); +char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen, int doblock); /** Read a Z85 encoded file. diff --git a/libpcp/ed.c b/libpcp/ed.c index 673f75c..e3d2863 100644 --- a/libpcp/ed.c +++ b/libpcp/ed.c @@ -107,7 +107,7 @@ size_t pcp_ed_sign_buffered(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_ if(z85) { ps_print(out, "\r\n%s\r\nVersion: PCP v%d.%d.%d \r\n\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); size_t zlen; - char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); + char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen, 1); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); } else { @@ -328,7 +328,7 @@ size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s) { ps_print(out, "%s\r\nVersion: PCP v%d.%d.%d\r\n", PCP_SIG_START, PCP_VERSION_MAJOR, PCP_VERSION_MINOR, PCP_VERSION_PATCH); size_t zlen; - char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen); + char *z85encoded = pcp_z85_encode((byte*)signature, mlen, &zlen, 1); ps_print(out, "%s\r\n%s\r\n", z85encoded, PCP_SIG_END); free(st); diff --git a/libpcp/pcpstream.c b/libpcp/pcpstream.c index eabe476..c7e0eab 100644 --- a/libpcp/pcpstream.c +++ b/libpcp/pcpstream.c @@ -60,7 +60,11 @@ Pcpstream *ps_new_outbuffer() { void ps_setdetermine(Pcpstream *stream, size_t blocksize) { assert(blocksize % 4 == 0); stream->determine = 1; - stream->blocksize = blocksize + (5 - (blocksize % 5)); + /* expand blocksize by the remainder of %5 plus another 5 bytes + for the pad blob */ + //stream->blocksize = blocksize + (5 - (blocksize % 5)) + 5; + stream->blocksize = blocksize + (blocksize / 4) + 5; + //fprintf(stderr, "blocksize: %ld\n", stream->blocksize); if(stream->cache == NULL) { stream->cache = buffer_new(32, "Pcpstreamcachedetermine"); stream->next = buffer_new(32, "Pcpstreamcachenextdetermin"); @@ -435,8 +439,9 @@ size_t ps_read_decode(Pcpstream *stream) { size_t binlen, outlen; byte *bin = pcp_z85_decode(ptx, buffer_get_str(z), &binlen); //fprintf(stderr, "ps_read_decode decoding z: %ld, got: %ld\n", buffer_size(z), binlen); - // _dump("bin", bin, binlen); + //_dump("bin", bin, binlen); //fatals_ifany(); + if(bin == NULL) { /* it's not z85 encoded, so threat it as binary */ if(stream->firstread) { @@ -550,20 +555,8 @@ size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes) { void ps_write_encode(Pcpstream *stream, Buffer *dst) { size_t zlen, i, pos; - /* do z85 0 padding, manually */ - if(buffer_size(stream->cache) % 4 != 0) { - size_t outlen = buffer_size(stream->cache); - while (outlen % 4 != 0) { - buffer_add8(stream->cache, 0); - outlen = buffer_size(stream->cache); - } - } - /* z85 encode */ - zlen = (buffer_size(stream->cache) * 5 / 4) + 1; - char *z85 = ucmalloc(zlen); - - zmq_z85_encode(z85, buffer_get(stream->cache), buffer_size(stream->cache)); + char *z85 = pcp_z85_encode(buffer_get(stream->cache), buffer_size(stream->cache), &zlen, 0); /* add newlines */ pos = stream->linewr; @@ -578,7 +571,6 @@ void ps_write_encode(Pcpstream *stream, Buffer *dst) { buffer_add8(dst, z85[i]); } - /* remember where to start next */ stream->linewr = pos; } diff --git a/libpcp/z85.c b/libpcp/z85.c index 8e0e464..1df1bce 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -184,8 +184,9 @@ size_t pcp_unpadfour(byte *src, size_t srclen) { byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen) { byte *bin = NULL; - size_t binlen, outlen; + size_t binlen, outlen, padlen; size_t srclen; + byte padblob[4]; srclen = strlen(z85block); @@ -203,61 +204,93 @@ byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen) { return NULL; } - outlen = pcp_unpadfour(bin, binlen); + /* extract pad blob */ + memcpy(padblob, &bin[binlen-4], 4); + padlen = padblob[3]; + if(padlen > 3) { + free(bin); + fatal(ptx, "zmq_z85_decode() failed, invalid pad counter (got %ld, expected 0-3)\n", padlen); + return NULL; + } + + /* + fprintf(stderr, "srclen: %ld, binlen: %ld, padlen: %ld\n", srclen, binlen, padlen); + _dump(" z", (byte *)z85block, srclen); + _dump("padblob", padblob, 4); + */ + + outlen = binlen - 4 - padlen; //pcp_unpadfour(bin, binlen, padlen); *dstlen = outlen; return bin; } -char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen) { +char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen, int doblock) { int pos = 0; byte *padded; - size_t outlen, blocklen, zlen; + size_t outlen, blocklen, zlen, padlen; + char *padblob = NULL; + char *z85 = NULL; + char *z85block = NULL; if(srclen %4 == 0) { /* no padding required */ padded = raw; outlen = srclen; + padlen = 0; } else { /* make z85 happy (size % 4) */ padded = pcp_padfour(raw, srclen, &outlen); + padlen = outlen - srclen; } /* encode to z85 */ zlen = (outlen * 5 / 4) + 1; - char *z85 = ucmalloc(zlen); + z85 = ucmalloc(zlen + 5); /* plus space for pad blob */ z85 = zmq_z85_encode(z85, padded, outlen); - - /* make it a 72 chars wide block */ - blocklen = (zlen + ((zlen / 72) * 2)) + 1; - char *z85block = ucmalloc(blocklen); - - char *z = &z85[0]; - char *B = &z85block[0]; - - while(*z != '\0') { - if(pos >= 71) { - *B++ = '\r'; - *B++ = '\n'; - pos = 1; - } - else { - pos++; - } - *B++ = *z++; - } - *B = '\0'; - - *dstlen = blocklen; - free(z85); - if(srclen %4 != 0) free(padded); - return z85block; + /* prepare pad blob */ + padblob = ucmalloc(6); + snprintf(padblob, 6, "0000%ld", padlen); + + /* append pad blob to encoded output */ + memcpy(&z85[zlen-1], padblob, 5); + free(padblob); + zlen += 5; + + if(doblock) { + /* make it a 72 chars wide block */ + blocklen = (zlen + ((zlen / 72) * 2)) + 1; + + z85block = ucmalloc(blocklen); + char *z = &z85[0]; + char *B = &z85block[0]; + + while(*z != '\0') { + if(pos >= 71) { + *B++ = '\r'; + *B++ = '\n'; + pos = 1; + } + else { + pos++; + } + *B++ = *z++; + } + *B = '\0'; + *dstlen = blocklen; + free(z85); + return z85block; + } + else { + *dstlen = zlen; + return z85; + } } @@ -295,9 +328,9 @@ char *pcp_readz85string(PCPCTX *ptx, unsigned char *input, size_t bufsize) { fatal(ptx, "Input file is empty!\n"); return NULL; } - + _dump("read", input, bufsize); if(_buffer_is_binary(input, bufsize) > 0) { - fatal(ptx, "input is not z85 encoded and contains pure binary data\n"); + fatal(ptx, "input is not z85 encoded and contains pure binary data at %ld\n", _buffer_is_binary(input, bufsize) ); return NULL; } diff --git a/src/keymgmt.c b/src/keymgmt.c index f248ae1..8d48927 100644 --- a/src/keymgmt.c +++ b/src/keymgmt.c @@ -271,7 +271,7 @@ void pcp_exportsecret(char *keyid, int useid, char *outfile, int armor, char *pa if(exported_sk != NULL) { if(armor == 1) { size_t zlen; - char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen); + char *z85 = pcp_z85_encode(buffer_get(exported_sk), buffer_size(exported_sk), &zlen, 1); fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_SK_HEADER, z85, EXP_SK_FOOTER); free(z85); } @@ -369,7 +369,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int if(exported_pk != NULL) { if(armor == 1) { size_t zlen; - char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen); + char *z85 = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1); fprintf(out, "%s\r\n%s\r\n%s\r\n", EXP_PK_HEADER, z85, EXP_PK_FOOTER); free(z85); } @@ -391,7 +391,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int if(exported_pk != NULL) { /* PBP format requires armoring always */ size_t zlen; - char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen); + char *z85pbp = pcp_z85_encode(buffer_get(exported_pk), buffer_size(exported_pk), &zlen, 1); fprintf(out, "%s", z85pbp); free(z85pbp); buffer_free(exported_pk); diff --git a/src/keyprint.c b/src/keyprint.c index b34177d..0bb4b26 100644 --- a/src/keyprint.c +++ b/src/keyprint.c @@ -203,7 +203,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) { fprintf(out, " Mail: %s\n", key->mail); fprintf(out, " Key-ID: 0x%s\n", key->id); - fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen)); + fprintf(out, " Public-Key: %s\n", pcp_z85_encode(key->pub, 32, &zlen, 1)); /* 2004-06-14T23:34:30. */ fprintf(out, " Creation Time: %04d-%02d-%02dT%02d:%02d:%02d\n", diff --git a/src/z85util.c b/src/z85util.c index 214c31e..9891925 100644 --- a/src/z85util.c +++ b/src/z85util.c @@ -64,7 +64,7 @@ int pcpz85_encode(char *infile, char *outfile) { } size_t zlen; - char *encoded = pcp_z85_encode(input, inputBufSize, &zlen); + char *encoded = pcp_z85_encode(input, inputBufSize, &zlen, 1); if(encoded != NULL) { fprintf(out, "%s\n%s\n%s\n", PCP_ZFILE_HEADER, encoded, PCP_ZFILE_FOOTER); diff --git a/tests/bart.pub b/tests/bart.pub index 463367a..d02c7de 100644 --- a/tests/bart.pub +++ b/tests/bart.pub @@ -1,9 +1,9 @@ ----- BEGIN ED25519-CURVE29915 PUBLIC KEY ----- -1][S608)M?oD<3BoQn[bA5Y.x9f]x:Sl$G(amCxNK9.45b0031t3nfctQ1tNuPtmJ!({r/O&2P[Ma]).MjeakB/faP7m3/ey.XHv1?:eZv50}CB -(iTB/MG}TKO4u}S(-J6mn2RAhRj6<-3-7Ci60-ig!G-tkF/-eD:(9chVwfOyWVna[k6&C6y -0Mdk@qV/$ +1][S608}PxJV?5A[Wwp%=4UFF0I1o]]>&tIIBzr3%nx$4=*4{8i#6aJtj/@VxJwiF5I9{Zl +kaN)/[j#0H-IW7vAaR2lGb&u{eyD*Wb*pFTDUZ{3NjaZ&+K/2Z*qRV:oCmKZBfa8bo^9)00 +0080SSi208}PxJSo4V2M>5b0033hD>3bR00&(h00010Yl>7*000Gy00SAaB7GxavqD.=Hr6 +t{01xRx1POWzCwZ#jlsB[R0000i6Awmo3t +!sze+HEAMv{o]@Bn8y:fx]fDY)]3tXc]DE30bpcp_errset == 0) { - fatal(ptx, "failed to encoded data to Z85\n"); + fatal(ptx, "failed to encode data to Z85\n"); } goto OUT; } diff --git a/tests/key-alicia-pub b/tests/key-alicia-pub index 3625237..ce669a8 100644 --- a/tests/key-alicia-pub +++ b/tests/key-alicia-pub @@ -1,9 +1,9 @@ ----- BEGIN ED25519-CURVE29915 PUBLIC KEY ----- -1][S608)M?n*eqKkH?l++@(u0.LHh*tkldO3Ihr{AcL}WsD*kTjhV:vP:(GSDY*}tc!*NG* -#^{JV%!mWkveUa-b#Br5[]X)U+1=UkFl)HHU8Hx+h?Y12&mZs}/PGIT{c3xWK81%bo^9)00 -0080SSi208)M?n=O?>2M>5b0031rbYic]}e8iE#EyH5pAv+q3(o0KRay}KED($B1D03v+85y -59qPN[EyDzWqP+rA6Q-eDxXMO?G/{bOUdC(izVt8x*5MjEcaq9>E8p$YS1J9n#>tnD +6Cd$3dT0*1h9h1h-ng@K?slf6y2(32y7y#L8je>zu^KLbhUDv(C?j[ja%7DGeAVKbo^9)00 +0080SSi208}PxJq@}U2M>5b0033hD<{5Q00&(h00010Yl>4/000Gy00SAaB7GxavqLm=j5( +mX01P+z1PO:BCwZ#jl2pmBx<*#w02caE1ond8K&s3O*hED>I+d%S&?OYIOaKl7JgH}0Go#pwA]KB(kaxr% +3.-h$:}>pn8zqF]laLMCoq/jZnyh+Z7f5(kEHwA#lyfj67EznX:PRrNTu0XlpiwUpup![rV +.F^+[nU{v(&m1=00003 ----- END ED25519-CURVE29915 PUBLIC KEY ----- diff --git a/tests/key-alicia-sec b/tests/key-alicia-sec index 4161ee5..3577f24 100644 --- a/tests/key-alicia-sec +++ b/tests/key-alicia-sec @@ -1,8 +1,8 @@ ----- BEGIN ED25519-CURVE29915 PRIVATE KEY ----- -5u%W6TXtCe8k^+2Y]Ov7koRK.YAroCq[EmPF[K?P7CtUefzQ=N.Jxt99?IBqLU(abi3Lgt} -+$&lBkEf>bPS.6XWm&6WVVp(KQgNKyiPobLty-BijM[$4knaVW=R*6cHK/TZq7!DYcq?jH0 -Wp:+clTXG.Cly<^]Y2:fyuT25j6uS{gucVJt[pO4:B*M/a-2PnrkuL]/ylISU(H!4X9@HI6 -^5nhIO}SC)i#rsn8J&g0>3^-$8C5+[{VdJO$wKOUB9&j>h4B=>{PW<<-9T.eyu4muM]sy*9 -g3H)}CAPe5eV8O:.h1FBx&YEw{j98mlAbD:XZBTcNM)aAD=jNM+4HK]..A?rCums*Jl6mDa -Fz7)/3cn$mJuK85&GqKB1yxBT13QamcJ:3Z68wpUNIOVZ8MG^:g&}50A-Mq5z$W57h-6xX4O=EauF73+Y)s#SWP-vfNGqt<18MmZp=dmbD13#96U7U(8?}71F< +e@#bBNiKv<.[B%27N4t%@E05b&Bk9:JBx2n]Zh5?tWwS@Pr0gvYQbID:9bA^[?5*Z9[z1*Y +f+um^M+@Hha[f@>X36r?Heh*uL4AAmFhf9Y)Lx9Ur[*C(t*L59UJV%B1CCZrG=.6A!wse#V ++GsM-r4tTzhayYCnFrs0$s}FsoNI@}ozO[ZkG>*!Kw5JVZ6ZTyIJgXnGXt-I}?OROV-y<7c +f6tR^W}2DHxYjoiJK.p2.D4>nA^H{ruZ?Yj.Zsvti25XJ3Z}IyFN*nBgX!g)-rukw00002 ----- END ED25519-CURVE29915 PRIVATE KEY ----- diff --git a/tests/key-bobby-pub b/tests/key-bobby-pub index 160307b..6879852 100644 --- a/tests/key-bobby-pub +++ b/tests/key-bobby-pub @@ -1,9 +1,9 @@ ----- BEGIN ED25519-CURVE29915 PUBLIC KEY ----- -1][S608)M?ocD^MIYWu4O02j^^^{jxl]&BnaC8?@Nxg1HY5^nBUEKrq&*.x.!!Hfxh*bz81 -i(UN7@yB&ZBQz+BXG]KmpAk4u^y7}wnh?abgr!xFtiJaaOry#}Q2cd(}HmES-Pozbo^9)00 -0080SSi208)M?o8[}(2M>5b0031rWY$%*#E{0F$@^c&])9EKG@Gj:2c3jKx9zgD.] -j)u?@cwCB +1][S608}PxJuH!P!yF7tGbRlwH]L{{yE{N.yU?cE7PfXsOtbOb3wLt)*n5fmZ(u.!{[[m3+ +mR[x6>?1v4e%d5A$jE5:%u0zJP94M[FkdkBc/*EPOaX(mmK{>bC&+qxOxf[UQ6q(bo^9)00 +0080SSi208}PxJSo4V2M>5b0033hD>3bR00&(h00010Yl>4/000Gy00SAaB7GxavqFFeUsw +M)01GXy1POZACwZ#jlt{sxC(N*A6bgAH01iTLx(4l%vQ:QFy&r/(yYBCn0uh3qSXng*N(7P +DZissLHR2T5SD#[/&2m+Iwkc6!S/rgDIgKsrtSDuB.VZA{QD}ShyggUo@0eWE8}(#TDDupu +&J6IU.1EtQjwF=jG4{S6h2epu39BiqS5xoLyxfT4NOi}Gm*Sd@v8@Q=uFGi3dnB5kJj!}1h +87y7{(@#500001 ----- END ED25519-CURVE29915 PUBLIC KEY ----- diff --git a/tests/key-bobby-sec b/tests/key-bobby-sec index e9ed30f..b8ae04c 100644 --- a/tests/key-bobby-sec +++ b/tests/key-bobby-sec @@ -1,8 +1,8 @@ ----- BEGIN ED25519-CURVE29915 PRIVATE KEY ----- -=OJ[EglpH!]AK8Wtm$+L/kTBGSr&YBRl3$rmsD}>O6YmJW-(WevNA7]]J{5ii1.Q.r1[lp) -z5*9uKH&3b*DlG:?T4OHyLp@gSOfDHGCU*&Ph8KYeY#-=zg}d=08p$VPh1%@^RZj8B7LS^/ -wU]vOz%DJKO&kEN)-V1tP=+1/L$HJ/*lf:t[FybaBR62.WG+Fi/E=8Iu}D0%UL?8q3N8lUx -$uktDv.2{hi[oxl#ajyrcaP5:CC0$H:Qo]ti10rO-6{MJ9SLmh$i3RwIlem8[hrB8-b=[[& -q8HAEvfoJG+DETVCC>DZuxKHkP[19DRTkL3.aC}{WhapK4awVY(JgwruXppNjVHdUU2)z!) -cy?oCdI/1SnJx9f+X>8evejVbWfX]X%1k-fBe:Qh1L3^m[KD5 +oIme#QsTbLK!{=GqE{LPyinNkS9@}AuxhKunBEm%aAL7BDnu^iuF-jx?7$0M@!LL+j&Y>wo +sBb)jNY)uR)#?fQMB)37KL5a{9aImj8>e&%2JzR[xAIt^3TCO3xpvrJpc&7X#Q4y!Avzv@4 +oQG)$0/6W.5/]i&lx?gyeV&lg+4^XgXv6UR9bb[ufq!xalrcnaLrlk%y>x5}$>]1.^si6EBL$(h#}gS9Wn{GXUqgO4sAs6W +I*o^RucnR]B((HTV/1-tUW&^qv+8*@IS%nraQ?kK4nsmHsS]&imY.vI@W?JtPlNhaQ:T]jK +9Bn0+wi>EP)wa{Kx&1)@E}9EjgjL^s-)ztQ}os^TO6TsS(E9iw^j+%nDFY&T00000 ----- END ED25519-CURVE29915 PRIVATE KEY ----- diff --git a/tests/keys.cfg b/tests/keys.cfg index 665eba0..c02626b 100644 --- a/tests/keys.cfg +++ b/tests/keys.cfg @@ -1,6 +1,6 @@ -bartid = 0xB389A718C85E3A64 -bartserial = 0x9D75EF8F -idbobby = 0x1B0B4712982982C8 -idalicia = 0x32092E3EDBA01044 +bartid = 0x7A88E19429C196D8 +bartserial = 0x170886C8 +idbobby = 0xAE1098607B00C2B8 +idalicia = 0x437A76EDE40D67EC mailbobby = bobby@local mailalicia = alicia@local diff --git a/tests/pipetest.c b/tests/pipetest.c index 1621793..6bd7cdd 100644 --- a/tests/pipetest.c +++ b/tests/pipetest.c @@ -6,32 +6,26 @@ #include int main(int argc, char **argv) { - if(argc < 4) { - fprintf(stderr, "Usage: pipetest \n"); + if(argc < 3) { + fprintf(stderr, "Usage: pipetest \n"); fprintf(stderr, "d - decode\ne - encode\n"); return 1; } - size_t rblocksize; - size_t zblocksize; + size_t blocksize; char mode; - if((rblocksize = strtol(argv[1], NULL, 0)) == 0) { + if((blocksize = strtol(argv[1], NULL, 0)) == 0) { fprintf(stderr, "Error: invalid read blocksize %s\n", argv[1]); return 1; } - if((zblocksize = strtol(argv[2], NULL, 0)) == 0) { - fprintf(stderr, "Error: invalid z85 blocksize %s\n", argv[2]); - return 1; - } - - if(zblocksize % 4 != 0) { + if(blocksize % 4 != 0) { fprintf(stderr, "Error: z85 blocksize shall be divisible by 4\n"); return 1; } - mode = argv[3][0]; + mode = argv[2][0]; if(mode != 'd' && mode != 'e') { fprintf(stderr, "Error: invalid mode %s\n", argv[3]); @@ -43,14 +37,14 @@ int main(int argc, char **argv) { size_t got; if(mode == 'e') - ps_armor(out, zblocksize); + ps_armor(out, blocksize); else - ps_setdetermine(in, zblocksize); + ps_setdetermine(in, blocksize); - void *buf = ucmalloc(rblocksize); + void *buf = ucmalloc(blocksize); while(!ps_end(in)) { - got = ps_read(in, buf, rblocksize); + got = ps_read(in, buf, blocksize); if(got > 0) ps_write(out, buf, got); } diff --git a/tests/static.h b/tests/static.h index b31f909..ce241ea 100644 --- a/tests/static.h +++ b/tests/static.h @@ -1,33 +1,33 @@ size_t secret_a_len = 32; unsigned char secret_a[32] = { -0x88, 0x7c, 0x08, 0x37, 0xed, 0x3b, 0x72, 0x0f, -0x5c, 0xc1, 0x1c, 0x83, 0xe4, 0x04, 0xbe, 0xca, -0xff, 0x23, 0x7c, 0x32, 0xf3, 0x2b, 0x03, 0x9c, -0x6e, 0x1c, 0xd5, 0xdb, 0x19, 0x3b, 0x3a, 0x5b +0x58, 0x08, 0xc7, 0x3b, 0xfb, 0xc5, 0x85, 0xe2, +0x00, 0xbb, 0x75, 0x31, 0x05, 0xb1, 0xed, 0xb9, +0x8b, 0xc8, 0xf5, 0x05, 0x23, 0xf5, 0xda, 0x8d, +0x46, 0xca, 0xb1, 0x3c, 0xb4, 0xe2, 0xaa, 0x65 }; size_t public_a_len = 32; unsigned char public_a[32] = { -0x7a, 0xa9, 0x18, 0x30, 0xf1, 0xab, 0xca, 0x88, -0x14, 0x7b, 0x72, 0x8a, 0x4f, 0xc0, 0x09, 0x37, -0xa6, 0xd6, 0x74, 0x24, 0xc5, 0x06, 0x5f, 0x5a, -0xf7, 0x15, 0x0c, 0xb7, 0x2c, 0x0c, 0x45, 0x7a +0x5d, 0x55, 0x3b, 0xf1, 0xa9, 0xf9, 0xaa, 0x69, +0x2c, 0x21, 0x9f, 0x90, 0x02, 0xd7, 0xab, 0x3d, +0x6c, 0xce, 0xa3, 0xb3, 0x5a, 0x23, 0xd9, 0x92, +0x9f, 0x0a, 0x6c, 0xee, 0x8c, 0x59, 0x7a, 0x3a }; size_t secret_b_len = 32; unsigned char secret_b[32] = { -0x28, 0x19, 0x3f, 0x07, 0x66, 0xc8, 0x1c, 0x60, -0xf5, 0x56, 0x48, 0xa2, 0x8e, 0x74, 0xd1, 0x0c, -0xe6, 0x9f, 0x16, 0x06, 0x9b, 0x04, 0x6d, 0xe9, -0x0f, 0x7c, 0x2a, 0x36, 0xee, 0xad, 0xb4, 0x59 +0xa8, 0xce, 0x93, 0x86, 0xff, 0xa9, 0x16, 0xdc, +0x88, 0x2a, 0xd3, 0xab, 0x30, 0x25, 0x9c, 0xf0, +0x6e, 0x5e, 0x4e, 0x83, 0x7d, 0x96, 0xa1, 0x08, +0x18, 0x44, 0x30, 0x68, 0x9b, 0xb7, 0xd0, 0x5f }; size_t public_b_len = 32; unsigned char public_b[32] = { -0x62, 0xa7, 0xad, 0xce, 0x41, 0x45, 0x49, 0x5e, -0xc9, 0xb0, 0xe9, 0xc9, 0x45, 0x82, 0x79, 0x9e, -0x47, 0x1b, 0x71, 0x7c, 0xbd, 0x2d, 0xda, 0x8d, -0x8a, 0xb8, 0xc5, 0x5e, 0x14, 0x2d, 0x35, 0x7e +0x71, 0xb3, 0x81, 0xa1, 0x16, 0xfd, 0x37, 0x3d, +0xff, 0xd6, 0xb3, 0xb3, 0xd3, 0x8e, 0xe0, 0xaa, +0xb6, 0xf9, 0x01, 0xf8, 0xe7, 0xfc, 0xc3, 0x6a, +0x7a, 0xfe, 0xab, 0x09, 0x52, 0x22, 0x45, 0x63 }; size_t message_len = 12; @@ -38,16 +38,16 @@ unsigned char message[12] = { size_t nonce_len = 24; unsigned char nonce[24] = { -0xa6, 0x53, 0x14, 0x2a, 0x7c, 0x31, 0x53, 0xc9, -0xcb, 0x44, 0x83, 0x1e, 0xf3, 0x15, 0xa5, 0x81, -0x2b, 0x1f, 0x10, 0xb6, 0x31, 0x68, 0x2c, 0x88 +0xf9, 0x40, 0x18, 0xd2, 0xdc, 0xf6, 0xab, 0x80, +0xfb, 0xe0, 0x77, 0x59, 0x21, 0xaa, 0xd5, 0xa6, +0xd3, 0xe1, 0x8b, 0xc4, 0xbd, 0x22, 0xee, 0xbc }; size_t cipher_len = 28; unsigned char cipher[28] = { -0x7a, 0x4f, 0x59, 0x9b, 0x27, 0x3c, 0x22, 0x6c, -0x5f, 0x25, 0xd0, 0x01, 0x17, 0x61, 0x6e, 0x6c, -0xf0, 0x62, 0x0c, 0x81, 0x6c, 0x58, 0x57, 0x2b, -0x0b, 0x38, 0x48, 0x12 +0x74, 0x81, 0x08, 0x7c, 0xf6, 0x45, 0xd0, 0x99, +0x58, 0x79, 0xbb, 0x84, 0x40, 0x0a, 0x13, 0x8a, +0x73, 0x1a, 0x2b, 0x4f, 0x13, 0x57, 0x15, 0xfb, +0x07, 0x7e, 0x06, 0x88 }; diff --git a/tests/unittests.cfg b/tests/unittests.cfg index a45af83..1ea7677 100644 --- a/tests/unittests.cfg +++ b/tests/unittests.cfg @@ -37,34 +37,24 @@ include keys.cfg - + md5 = `./md5 ../COPYING` - cmd = ./pipetest 8 8 e < ../COPYING | ./pipetest 8 8 d | ./md5 + cmd = ./pipetest 8 e < ../COPYING | ./pipetest 8 d | ./md5 expect = /$md5/ - + md5 = `./md5 ../COPYING` - cmd = ./pipetest 8 16 e < ../COPYING | ./pipetest 8 16 d | ./md5 + cmd = ./pipetest 16 e < ../COPYING | ./pipetest 16 d | ./md5 expect = /$md5/ - + md5 = `./md5 ../COPYING` - cmd = ./pipetest 16 8 e < ../COPYING | ./pipetest 16 8 d | ./md5 + cmd = ./pipetest 32 e < ../COPYING | ./pipetest 32 d | ./md5 expect = /$md5/ - + md5 = `./md5 ../COPYING` - cmd = ./pipetest 64 32 e < ../COPYING | ./pipetest 64 32 d | ./md5 - expect = /$md5/ - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 32 64 e < ../COPYING | ./pipetest 32 64 d | ./md5 - expect = /$md5/ - - - md5 = `./md5 ../COPYING` - cmd = ./pipetest 64 64 e < ../COPYING | ./pipetest 64 64 d | ./md5 + cmd = ./pipetest 64 e < ../COPYING | ./pipetest 64 d | ./md5 expect = /$md5/ diff --git a/tests/unknown1 b/tests/unknown1 index 276d790..8a77487 100644 --- a/tests/unknown1 +++ b/tests/unknown1 @@ -1,9 +1,9 @@ ----- BEGIN ED25519-CURVE29915 PUBLIC KEY ----- -1][S608)M?o^bg=DTHr&HDQ5Mh#oh$WhV!KxwM}<9OG&*Ls26^#bo^9)00 -0080SSi208)M?p5>m]2M>5b0031Y3- -jKBN$o)!WM2@+zcuO?{a.G[ioHP^t4MHXKS=uFuFPAZ^l]VC3byZ{nY*sYGvW:rZ(zRb-E0 -a3X57iYnuonC?k +1][S608}PxJV>G/!8Vhi)6Yjo!DqLQW5^vbPD}hvgBgfIFYGdsF77eJBiMBwyG&+-To2i}B +gL#xzQ2xNoQbS-@TJ#x*^T-MRClOblFE]jR?lEgVR$y7Q[L>z5EUww{J=kA+%IHNbo^9)00 +0080SSi208}PxJ@PdW2M>5b0033hD>chS00&(h00010Yl>7*000Gy00SAaB7GxavqHsVvL! +5+01Y?A1PO^CCwZ#jphaoRvqYPQ000-F00Aohzddc{zFrW0vqYQvy&r/(yYBCn0uh2cID>+ +C0tc$Ga.-{JG^nWb+c)h6dy{}!p(HtZ/X28Vr{%rAl73K1KU-cUF(&!lXL^itwL^l)gNRM1 +B/C<=9Ysfd@hKyQ0$g(f+=%dOD.zeUGy#[j@Kt:srRjFZYG@lX8CE87qJWszsUR@XW-}Z88Mk@!Yh[:Us:o=QUK[. -K:#uxC68?fFU/iRhje]ZxCrrK]6L5G>IoYrmR&tnoMxC12EaeSGDWn[!<^a8&d}xxyNx$6^ -(Q4(@N?CtUYz{w(=aF^VD+Xf.Uz4=WseXMZ.srl}[=u8vUjlpT)VLI/<7K4bdr -&i>3J^&=Q$H]6](BO-u{^tlzdv{/kCRgx}%h?sBHX^s^pDO&OLRZcY@VXSSrb%-#o]RX]1c -3*xxx0@Dn)ND[5BL+fek-uztY{%dsUfxUjr!+u(kes$i]#dzZLOS?Y5Y:Bf-AN?/>+W6%AM -b{AQ4vmV[:tFp#Vi]=I=hFke]lnTS.(I!YG(.ypG{]SRcB144m0kD5]Ne}H)f5)O3 +7z!4XlTnE<{pyNIUPKRe)c/&(C*69HiE.2HEUvk}.{wei49/gs&i?hdkbpwbVT6z[=*a +)f?0y3>Ccx1rtWn>jkD*#fz{so-a]r+KxOyNf0.+![hraO(]D9EC+]i@T=G1WinO?I>n[lo +hqW&W/FvEHflDY73Ww)Q6[3w7oT)woNhZEa^^G1baNKF[?pLg)=-UJ.1hRVf1B]LZon$W{n +Ra[hEp4lT)8?DfO[a^%TPGNJSu5y?mbJvcmQ5?i.)B8qe0:Hy@jxWYbr(![Wrkz.{00000 ----- END ED25519-CURVE29915 PRIVATE KEY ----- diff --git a/tests/unknown4 b/tests/unknown4 index a405474..ba66e7c 100644 --- a/tests/unknown4 +++ b/tests/unknown4 @@ -1 +1 @@ -7HzAIQmHj@B+wh@0m%9a.l+/hvKBi:QqeyL*%NRjALYqs]mk*xEy=D5[1ja< +7PsEP4u#Q3RHx+3j*qzsPG*m5FRmq9YAVXA!>h^si9SJ4%ma3oPM]j+-Z}MU00001