Skip to content

Instantly share code, notes, and snippets.

@46bit
Created November 17, 2014 22:47
Show Gist options
  • Select an option

  • Save 46bit/a226addf737fd80994af to your computer and use it in GitHub Desktop.

Select an option

Save 46bit/a226addf737fd80994af to your computer and use it in GitHub Desktop.
An extract from OpenSSL crypto/bn/bn_lib.c. BN_bn2bin is used to extract binary data from bignums. I think?
int BN_bn2bin(const BIGNUM *a, unsigned char *to)
{
int n,i;
BN_ULONG l;
bn_check_top(a);
n=i=BN_num_bytes(a);
while (i--)
{
l=a->d[i/BN_BYTES];
*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
}
return(n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment