First, if you pasted your original code into the email, then you have
several typos.

Second, two of the lines generate warnings on compilation about
incompatible pointer types - these are significant.  The lines are:

 

num_byte = BN_dec2bn(dh_struct->p,str_p);

num_byte = BN_dec2bn(dh_struct->g,str_g);   //Note this was a line with
a typo

 

Try it with these lines as follows:

 

num_byte = BN_dec2bn(&(dh_struct->p),str_p);

num_byte = BN_dec2bn(&(dh_struct->g),str_g);

 

When I did (plus fixing the other typo) and printed the results, I got:

 

Num Bytes for p=5

Num Bytes for g=1

Return code from generate key=1

 

Bill

________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Agustin Cozzetti
Sent: December 14, 2007 5:30 AM
To: openssl-users@openssl.org
Subject: Doubt about the use and initialization of DH struct

 

        From: [EMAIL PROTECTED]
        To: openssl-users@openssl.org
        Subject: Doubt about the use and initialization of DH struct
        Date: Fri, 14 Dec 2007 10:23:19 +0000
        
        Hello,
        I have a problem with DH struct in my source code C.
        
        

        Here a small list of my code:

         

        #include <stdio.h>

        #include <stdlib.h>

        #include <openssl/dh.h>

        #include <openssl/engine.h>

        #include <openssl/bn.h>

         

        DH *dh_struct;

         

        int main()

        {

        unsigned char str_p[] = "57503";
        unsigned char str_g[] = "5";

        unsigned char *string;

        int num_byte,size,i;

         

        dh_struct = DH_new();

        dh_struct->p = BN_new();

        dh_struct->g = BN_new();

        dh_struct->priv_key = BN_new();

        dh_struct->pub_key = BN_new();

         

        num_byte = BN_dec2bn(dh_struct->p,str_p);  // Here it seems that
not execute anything about structure "dh_struct->p"....why???

         

        num_byte = BN_dec2bn(dh_struct->p,str_g);

         

        size = BN_num_bytes(dh_struct->p);  // Here,the result is
zero...why???

        string = BN_bn2dec(dh_struct->p);  // TEST,but string is
NULL...why???

         

        i=DH_generate_ket(dh_struct);  // return 0,operation failed.....

        }

         

        I can not understand where I mistake in the code!

        Thank you for your help,

        Hector Agustin Cozzetti

         

 

________________________________

Per questo Natale fai i tuoi auguri con Messenger! Windows Live
Messenger <http://www.augurimessenger.it> 

Reply via email to