Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 592 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert a big number given as a string to an OpenSSL BIGNUM

#1
I am trying to convert a string `p_str` representing a big integer to a `BIGNUM` `p` using the OpenSSL library.

#include <stdio.h>
#include <openssl/bn.h>

int main ()
{
/* I shortened the integer */
unsigned char *p_str = "82019154470699086128524248488673846867876336512717";

BIGNUM *p = BN_bin2bn(p_str, sizeof(p_str), NULL);

BN_print_fp(stdout, p);
puts("");

BN_free(p);
return 0;
}

Compiled it with:

gcc -Wall -Wextra -g -o convert convert.c -lcrypto

But, when I execute it, I get the following result:

3832303139313534
Reply

#2
> unsigned char *p_str = "82019154470699086128524248488673846867876336512717";
>
> BIGNUM *p = BN_bin2bn(p_str, sizeof(p_str), NULL);

Use `int BN_dec2bn(BIGNUM **a, const char *str)` instead.

You would use `BN_bin2bn` when you have an array of `bytes` (and not a NULL terminated ASCII string).

The man pages are located at [`BN_bin2bn(3)`](

[To see links please register here]

).

The correct code would look like this:

#include <stdio.h>
#include <openssl/bn.h>

int main ()
{
static const
char p_str[] = "82019154470699086128524248488673846867876336512717";

BIGNUM *p = BN_new();
BN_dec2bn(&p, p_str);

char * number_str = BN_bn2hex(p);
printf("%s\n", number_str);

OPENSSL_free(number_str);
BN_free(p);

return 0;
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through