Hello Mounir, So converting char* hex = "0000" to a BN using BN_hex2bn then converting the resulting bn to it's byte representation using BN_bn2bin is not the same as allocating a zero buffer? i.e
char* hex = "0000"; BN_hex2bn(&bignum, hex); buffer = (char*)malloc(2); BN_bn2bin(bignum, buffer); wont' do the same thing as buffer = (char*) malloc(2); memset(buffer, 0, 2); ? Thannks for your help! On 3/22/07, Mounir IDRASSI <[EMAIL PROTECTED]> wrote:
Hi Gabriel, This is no bug. In your code, you should check the return value of BN_bn2bin and you will notice that it returns zero. This means that nothing has been written to your "bytes" buffer. So, your code is just printing garbage. In your example, you are dealing with the zero value, and in openSSL, BN_num_bytes returns 0 in this case (it's deduced from BN_num_bits). Cheers, Mounir IDRASSI IDRIX http://www.idrix.fr Gabriel Maganis wrote: > Hello, > I am new to openssl and I have tried to use the bignumber library > like below, > > ------------------ > unsigned char* hex = "000000000000000000000000000000"; > BIGNUM* bn; > unsigned char* bytes; > int i; > bn = BN_new(); > > BN_hex2bn(&bn, hex); > > bytes = (unsigned char*) malloc(16); > BN_bn2bin(bn, bytes); > > for(i=0; i<16; i++) > printf("%02x", bytes[i]); > ----------------- > > I believe I have found a bug because the above should print 32 '0' > characters but it doesn't. I also found that the code above works for > other hexadecimal strings and it's only for the above case that it > fails. > > Thanks. > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > Development Mailing List openssl-dev@openssl.org > Automated List Manager [EMAIL PROTECTED] > > ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager [EMAIL PROTECTED]
______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager [EMAIL PROTECTED]