Dear SSLites,
     Please take a look at my code. It is meant for calculating square
of a big number. To test the things I started by providing integers on
command line and tried to obtain the values back in integer. But could
not get success. Can you figure out my mistake?

#include<openssl/bn.h>
#include<string.h>
#include<math.h>

int main(int argc, char **argv) {
  int i = atoi(argv[1]);       //collect integer
  BIGNUM *I = BN_new();
  BIGNUM *II = BN_new();
  BN_CTX *CTX = BN_CTX_new();

  BN_CTX_init(CTX);
  tmp_str = (unsigned char *)malloc(20000);

  sprintf(tmp_str, "%d", i);     // itoa();
  BN_bin2bn(tmp_str, (int)strlen(tmp_str), I);    // int to BN
  if(!BN_sqr(II, I, CTX)) printf("ERROR while doing BN_sqr\n"); // BN square
  BN_bn2bin(II, tmp_str); // BN to int
  printf("i SQUARE = %s\n", tmp_str); // am getting garbage
  
  BN_CTX_free(CTX);
  BN_free(I);
  BN_free(II);
  free(tmp_str);
  return 1;
}




-- 
Best Regards,
Vishwas.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to