[botan-devel] Binary encoding of GOST private value

Jack Lloyd lloyd at randombit.net
Sat Aug 16 10:15:02 EDT 2014

On Sat, Aug 16, 2014 at 12:49:07PM +0200, Rickard Bellgrim wrote:
> Is it possible that you get a buffer length shorter than 32 bytes when you
> binary encode the BigInt value of the GOST private value because of the
> little endian storage?
> The buffer is allocated based on x.bytes().
> If you always want a buffer with 32 bytes, should you pad it manually?

BigInt::encode_1363 will encode to a vector and pad up to the desired
size, then you can flip the bytes.

The library just uses the ECDSA/ECDH format for GOST keys since there
doesn't seem to be a standard encoding for GOST private keys (at least
that I have seen). That just encodes x as an ASN.1 INTEGER type
instead of the little-endian octet string bigint format that GOST
uses, so would not be affected by an x that had low zero bytes.


More information about the botan-devel mailing list