On Wed, 25 Mar 1998, Hamdi Tounsi wrote:
> how to print a BIGNUM as a decimal string ? (BN_bn2ascii outputs hex
> representation)

Ah, how to get people enthused for easter :-), as part of the perl5 support,
I added, this function (and renamed the old ones).  I now have

char *  BN_bn2hex(BIGNUM *a);
char *  BN_bn2dec(BIGNUM *a);
int     BN_hex2bn(BIGNUM **a,char *str);
int     BN_dec2bn(BIGNUM **a,char *str);

Unfortunaly the first 2 require you to 'free' the returned string, and the
last 2 will create a bignum if you don't provide it.
Anyway, they handle negatives correctly.

I have also added
BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
int     BN_bn2mpi(BIGNUM *a, unsigned char *to);

which basically support the mpi bignum format which is used I belive by
the SSH protocol amongst other things...

There is still the old
BIGNUM *BN_bin2bn(unsigned char *s,int len,BIGNUM *ret);
int     BN_bn2bin(BIGNUM *a, unsigned char *to);
which does not handle negatives (unlike mpi).  I would sugest using the mpi or
ASN1 format for binary bignums.

For asn1, things are a little ugly in that I still have a 2 step conversion,
ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, long len);

I have considered making the ASN1_INTEGER type the BIGNUM type, but will
probably not.  Most of the time ASN1_INTEGERs are part of a rather ridged
structure where the numbers are 'blobs'.  The current ASN1_INTEGER treats them
more as blobs....

eric

+-------------------------------------------------------------------------+
| Administrative requests should be sent to [EMAIL PROTECTED] |
| List service provided by Open Software Associates, http://www.osa.com/  |
+-------------------------------------------------------------------------+

Reply via email to