Citation from the letter of Ludovic FLAMENT
<[EMAIL PROTECTED]>:

> Angel Martinez Gonzalez wrote:
>
> >Hello:
> >
> >I wrote a BIGNUM into a file using the function:
> >
> >        int BN_print_fp(FILE *fp, const BIGNUM *a);
> >
> >But, How I can read this bignum from this file?. I don?t
> know a openssl
> >function to read a bignum from a file.
> >
> >
>     Hello, you can read Bignum from file with this
> method,
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <openssl/bn.h>
>
> int main()
> {
>         BIGNUM  *b;
>         FILE    *f;
>         char    buff[128]; /* must depend of Bignum size
> */
>
>         b = BN_new();
>         if (b == NULL)
>            return 0;
>
>         BN_add_word(b, 123456789);
>
>         f = fopen("bignum", "w");
>         if (f == NULL)
>                 return 0;
>
>         BN_print_fp(f, b);
>
>         BN_free(b);
>         fclose(f);
>
>         /* start reading */
>         f = fopen("bignum", "r");
>         if (f == NULL)
>                 return 0;
>
>         if (fread(buff, sizeof(char), sizeof(buff), f) <=
> 0)
>        {
>              fclose(f);
>              return 0;
>        }
>        fclose(f);
>
>         if (!BN_hex2bn(&b, buff))
>                 return 0;
>
>         printf("BN read from file : ");
>         BN_print_fp(stdout, b);
>         printf("\n");
>
>         BN_add_word(b, 1);
>
>         printf("BN read from file + 1 : ");
>         BN_print_fp(stdout, b);
>         printf("\n");
>
>         BN_free(b);
>         return 1;
> }
>
> --
> Ludovic FLAMENT
>
______________________________________________________________________
> OpenSSL Project
> http://www.openssl.org
> User Support Mailing List
> openssl-users@openssl.org
> Automated List Manager
> [EMAIL PROTECTED]
>




Just a minor remark about the sample source:

you should not BN_free(b) before BN_hex2bn(&b, buff)


-----------------------------

Гладен ли си?
Поръчай on-line
от AmAm.bg

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to