At 8:35 PM -0500 12/7/09, Chris Morgan wrote:
>On Mon, Dec 7, 2009 at 6:35 AM, Charlie <[email protected]> wrote:
>> Hi!
>>
>> I know how to sign a string with crypto++, but, how can I sign a C
> > struct, for example, the next struct?
> >
>Why not just think of the struct as a series of bytes? Then you could
>create your signature like:
>
>struct c myc;
>thesignature = yoursignaturefunctionhere(myc, sizeof(struct c));
>
>Then package it however you want.
I know the answer to this one ;)
Except in limited cases, this doesn't work - because a C/C++ struct
may have "holes" in it, where the compiler has inserted pad bytes so
that the fields are aligned for fastest access.
Suppose you have (on some unnamed compiler) a struct that looks like this:
struct Foo {
short s;
long l;
};
sizeof(struct Foo) may be 8 bytes. Two bytes for the short, two bytes
of padding, and four for the long.
If you calculate the signature over the entire structure, you will be
including the contents of the padding in the signature, and you will
never get a signature to match - except by chance.
This is also the reason that you can't compare two structs by saying:
if ( memcmp ( &a, &b, sizeof ( struct Foo )) == 0 ) //
structs are the same!
because this also compares the contents of the pad byte, which you
have no control over.
--
-- Marshall
Marshall Clow Idio Software <mailto:[email protected]>
It is by caffeine alone I set my mind in motion.
It is by the beans of Java that thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.