From 9af3fae2d53a34003af405b68923061c01584bc6 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Mon, 18 Jun 2007 22:02:02 +0000 Subject: reworked zero-padding machinery and added one more instance of zero-padding --- (limited to 'lib/util.cc') diff --git a/lib/util.cc b/lib/util.cc index d9abca7..94f6f53 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -86,9 +86,13 @@ namespace opkele { } string bignum_to_base64(const BIGNUM *bn) { - vector bin(BN_num_bytes(bn)); - int l = BN_bn2bin(bn,&(bin.front())); - return encode_base64(&(bin.front()),l); + vector bin(BN_num_bytes(bn)+1); + unsigned char *binptr = &(bin.front())+1; + int l = BN_bn2bin(bn,binptr); + if(l && (*binptr)&0x80){ + (*(--binptr)) = 0; ++l; + } + return encode_base64(binptr,l); } /* -- cgit v0.9.0.2