struct problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

struct problem

Nagy Zoltán Márk
Dear all

I would like to create a data structure in C.
Below you can see what I have created, but it doesn't work correctly.
My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?

#define ORANGE 0xffa500

struct ciphers_name
{
   unsigned char *name;
   unsigned char *description;
   const EVP_CIPHER *cipher;
   unsigned int color;
};


struct ciphers_name ciphers[] =
{
   { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
};

Thank you in advance,
King regards,
 mark
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Steve.Pauly

The unsigned char *name and *description are pointers, not storage arrays. For this to work, you would need:

struct ciphers_name
{
  unsigned char name[NAME_LEN];
  unsigned char description[DESC_LEN];
  const EVP_CIPHER *cipher;
  unsigned int color;
};


Steven Pauly
Pitney Bowes GMS
[hidden email]



"Nagy Zoltán Márk" <[hidden email]>
Sent by: [hidden email]

03/29/2006 10:16 AM

Please respond to
[hidden email]

To
[hidden email]
cc
Subject
struct problem





Dear all

I would like to create a data structure in C.
Below you can see what I have created, but it doesn't work correctly.
My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?

#define ORANGE 0xffa500

struct ciphers_name
{
  unsigned char *name;
  unsigned char *description;
  const EVP_CIPHER *cipher;
  unsigned int color;
};


struct ciphers_name ciphers[] =
{
  { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
};

Thank you in advance,
King regards,
mark
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Nagy Zoltán Márk
no no no...
name and description working correctly.
struct ciphers_name ciphers[] =
{
   { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
};

EVP_aes_128_cbc() not working correctly, but i dont known why?


mark


The unsigned char *name and *description are pointers, not storage arrays. For this to work, you would need:

struct ciphers_name
{
  unsigned char name[NAME_LEN];
  unsigned char description[DESC_LEN];

  const EVP_CIPHER *cipher;
  unsigned int color;
};


Steven Pauly
Pitney Bowes GMS
[hidden email]



"Nagy Zoltán Márk" <[hidden email]>
Sent by: [hidden email]

03/29/2006 10:16 AM

Please respond to
[hidden email]

To
[hidden email]
cc

Subject
struct problem







Dear all

I would like to create a data structure in C.
Below you can see what I have created, but it doesn't work correctly.
My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?

#define ORANGE 0xffa500

struct ciphers_name
{
  unsigned char *name;
  unsigned char *description;
  const EVP_CIPHER *cipher;
  unsigned int color;
};


struct ciphers_name ciphers[] =
{
  { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
};

Thank you in advance,
King regards,
mark
______________________________________________________________________
OpenSSL Project                                 <a href="http://www.openssl.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Dr. Stephen Henson
In reply to this post by Nagy Zoltán Márk
On Wed, Mar 29, 2006, Nagy Zoltn Mrk wrote:

> Dear all
>
> I would like to create a data structure in C.
> Below you can see what I have created, but it doesn't work correctly.
> My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?
>
> #define ORANGE 0xffa500
>
> struct ciphers_name
> {
>    unsigned char *name;
>    unsigned char *description;
>    const EVP_CIPHER *cipher;
>    unsigned int color;
> };
>
>
> struct ciphers_name ciphers[] =
> {
>    { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
> };
>

That wont work in many cases because you are trying to initialize the
structure with the return value from a function.

The initialization is done at compile time but that return value is only
available at runtime.

You have a couple of options. One is to change that definition to a function
pointer which you set to EVP_aes_128_cbc note *NOT* EVP_aes_128_cbc(). Then at
runtime you call that function pointer to get the EVP_CIPHER.

The alternative is to include something which you can lookup to get that
cipher. An example would be NID_aes_128_cbc which you can then lookup using
EVP_getcipherbynid().

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Nagy Zoltán Márk
Thank!
but how can I use EVP_get_cipherbyname(const char *name);?

ciphers[0].cipher = EVP_get_cipherbyname("BLABLABLABLA");
perror("EVP_get_cipherbyname()");

./evp
EVP_get_cipherbyname(): Success

And always: success :-) but doesn't work.

King regards,
 mark


> That wont work in many cases because you are trying to initialize the
> structure with the return value from a function.
>
> The initialization is done at compile time but that return value is only
> available at runtime.
>
> You have a couple of options. One is to change that definition to a function
> pointer which you set to EVP_aes_128_cbc note *NOT* EVP_aes_128_cbc(). Then at
> runtime you call that function pointer to get the EVP_CIPHER.
>
> The alternative is to include something which you can lookup to get that
> cipher. An example would be NID_aes_128_cbc which you can then lookup using
> EVP_getcipherbynid().
>
> Steve.
> --
> Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
> OpenSSL project core developer and freelance consultant.
> Funding needed! Details on homepage.
> Homepage: http://www.drh-consultancy.demon.co.uk
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    [hidden email]
> Automated List Manager                           [hidden email]
>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Nagy Zoltán Márk
In reply to this post by Dr. Stephen Henson
hi!

if i use:
{
EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), key, NULL);
}
is work

if i use:
{
const EVP_CIPHER *c;
c = EVP_aes_128_cbc();
EVP_EncryptInit(&ctx, c, key, NULL);
}
is work

but, if i use:
{
const EVP_CIPHER *c;
c = EVP_get_cipherbyname("aes-128-cbc");
EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), key, NULL);
}
doesn't work
(segmentation fault)

mark


On 3/29/06, Dr. Stephen Henson <[hidden email]> wrote:

> On Wed, Mar 29, 2006, Nagy Zoltn Mrk wrote:
>
> > Dear all
> >
> > I would like to create a data structure in C.
> > Below you can see what I have created, but it doesn't work correctly.
> > My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?
> >
> > #define ORANGE 0xffa500
> >
> > struct ciphers_name
> > {
> >    unsigned char *name;
> >    unsigned char *description;
> >    const EVP_CIPHER *cipher;
> >    unsigned int color;
> > };
> >
> >
> > struct ciphers_name ciphers[] =
> > {
> >    { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
> > };
> >
>
> That wont work in many cases because you are trying to initialize the
> structure with the return value from a function.
>
> The initialization is done at compile time but that return value is only
> available at runtime.
>
> You have a couple of options. One is to change that definition to a function
> pointer which you set to EVP_aes_128_cbc note *NOT* EVP_aes_128_cbc(). Then at
> runtime you call that function pointer to get the EVP_CIPHER.
>
> The alternative is to include something which you can lookup to get that
> cipher. An example would be NID_aes_128_cbc which you can then lookup using
> EVP_getcipherbynid().
>
> Steve.
> --
> Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
> OpenSSL project core developer and freelance consultant.
> Funding needed! Details on homepage.
> Homepage: http://www.drh-consultancy.demon.co.uk
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    [hidden email]
> Automated List Manager                           [hidden email]
>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Nagy Zoltán Márk
ohh sorry...
in the last example:
but, if i use:
{
const EVP_CIPHER *c;
c = EVP_get_cipherbyname("aes-128-cbc");
EVP_EncryptInit(&ctx, c, key, NULL);
}
doesn't work
(segmentation fault)

mark

> hi!
>
> if i use:
> {
> EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), key, NULL);
> }
> is work
>
> if i use:
> {
> const EVP_CIPHER *c;
> c = EVP_aes_128_cbc();
> EVP_EncryptInit(&ctx, c, key, NULL);
> }
> is work
>
> but, if i use:
> {
> const EVP_CIPHER *c;
> c = EVP_get_cipherbyname("aes-128-cbc");
> EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), key, NULL);
> }
> doesn't work
> (segmentation fault)
>
> mark
>
>
> On 3/29/06, Dr. Stephen Henson <[hidden email]> wrote:
> > On Wed, Mar 29, 2006, Nagy Zoltn Mrk wrote:
> >
> > > Dear all
> > >
> > > I would like to create a data structure in C.
> > > Below you can see what I have created, but it doesn't work correctly.
> > > My question is: why doesn't initialised EVP_aes_128_cbc() into cipher?
> > >
> > > #define ORANGE 0xffa500
> > >
> > > struct ciphers_name
> > > {
> > >    unsigned char *name;
> > >    unsigned char *description;
> > >    const EVP_CIPHER *cipher;
> > >    unsigned int color;
> > > };
> > >
> > >
> > > struct ciphers_name ciphers[] =
> > > {
> > >    { "aes128cbc","AES 128bit CBC",EVP_aes_128_cbc(),ORANGE}
> > > };
> > >
> >
> > That wont work in many cases because you are trying to initialize the
> > structure with the return value from a function.
> >
> > The initialization is done at compile time but that return value is only
> > available at runtime.
> >
> > You have a couple of options. One is to change that definition to a function
> > pointer which you set to EVP_aes_128_cbc note *NOT* EVP_aes_128_cbc(). Then at
> > runtime you call that function pointer to get the EVP_CIPHER.
> >
> > The alternative is to include something which you can lookup to get that
> > cipher. An example would be NID_aes_128_cbc which you can then lookup using
> > EVP_getcipherbynid().
> >
> > Steve.
> > --
> > Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
> > OpenSSL project core developer and freelance consultant.
> > Funding needed! Details on homepage.
> > Homepage: http://www.drh-consultancy.demon.co.uk
> > ______________________________________________________________________
> > OpenSSL Project                                 http://www.openssl.org
> > User Support Mailing List                    [hidden email]
> > Automated List Manager                           [hidden email]
> >
>
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: struct problem

Dr. Stephen Henson
On Wed, Mar 29, 2006, Nagy Zoltn Mrk wrote:

> ohh sorry...
> in the last example:
> but, if i use:
> {
> const EVP_CIPHER *c;
> c = EVP_get_cipherbyname("aes-128-cbc");
> EVP_EncryptInit(&ctx, c, key, NULL);
> }
> doesn't work
> (segmentation fault)
>

Check to see if "c" is NULL before using it. My guess is that you haven't
initialised the algorithm tables with OpenSSL_add_all_algorithms().

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: struct problem

JoelKatz
In reply to this post by Nagy Zoltán Márk

> Thank!
> but how can I use EVP_get_cipherbyname(const char *name);?
>
> ciphers[0].cipher = EVP_get_cipherbyname("BLABLABLABLA");
> perror("EVP_get_cipherbyname()");
>
> ./evp
> EVP_get_cipherbyname(): Success
>
> And always: success :-) but doesn't work.

        Why are you calling 'perror'?

        I don't mean to be rude, but it doesn't seem that you have any idea what
you're doing. You're missing basic C concepts that are a pre-requisite to
working with a complicated library like OpenSSL.

        DS



______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]