author | Michael Krelin <hacker@klever.net> | 2007-06-18 22:02:02 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-06-18 22:02:02 (UTC) |
commit | 9af3fae2d53a34003af405b68923061c01584bc6 (patch) (side-by-side diff) | |
tree | dd63e5bc3515c47ab074c564c51879b7c9652ab2 /lib/util.cc | |
parent | 3b404dd029a2aba05efc2edadcc7f67c59746cf7 (diff) | |
download | libopkele-9af3fae2d53a34003af405b68923061c01584bc6.zip libopkele-9af3fae2d53a34003af405b68923061c01584bc6.tar.gz libopkele-9af3fae2d53a34003af405b68923061c01584bc6.tar.bz2 |
reworked zero-padding machinery and added one more instance of zero-padding
-rw-r--r-- | lib/util.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/util.cc b/lib/util.cc index d9abca7..94f6f53 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -85,11 +85,15 @@ namespace opkele { return rv; } string bignum_to_base64(const BIGNUM *bn) { - vector<unsigned char> bin(BN_num_bytes(bn)); - int l = BN_bn2bin(bn,&(bin.front())); - return encode_base64(&(bin.front()),l); + vector<unsigned char> 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); } /* * w3c times |