Got it working now and printing out the result with the printf
function so really happy with that! Thankyou.

I could not get it working with the String Source bit though. I
included #include "hex.h but got these errors:

auth.cpp: In function ‘int main(int, char**)’:
auth.cpp:32: error: expected type-specifier before ‘HexEncoder’
auth.cpp:32: error: expected `)' before ‘HexEncoder’
auth.cpp:32: error: ‘StringSource’ was not declared in this scope


And lastly just want to just use some of the RFC test cases, so just a
few question on that and that should be it really!

Here are  two test cases:

test_case =     1
key =           0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
key_len =       20
data =          "Hi There"
data_len =      8
digest =        0xb617318655057264e28bc0b6fb378c8ef146be00

test_case =     2
key =           "Jefe"
key_len =       4
data =          "what do ya want for nothing?"
data_len =      28
digest =        0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79


So is the "digest =" the result I should also be getting from my mac
print out if I use the same key and data?

With the first test case I copied in the full key

byte key [ HMAC<SHA1>::DIGESTSIZE ] =
{0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b}; and changed the string
to "Hi There", but it said the key was too long.

On the 2nd test case I did:   byte key [ HMAC<SHA1>::DIGESTSIZE ] =
{"Jefe"};
and changed the string  "what do ya want for nothing?". It compiled
and I got a result but it did not match the digest listed on the test
case.

What other changes would I need to do to use those test cases etc?

Thanks alot.
Adam.

On Jun 10, 5:00 pm, "Jeffrey Walton" <[EMAIL PROTECTED]> wrote:
> Hi Adam,
>
> > Yeah I think the actual code is fine
>
> It is. I ran it. Every now and agian I get lazy and shoot from the
> hip, but not this time.
>
> > Does the key need to be entered into the code before a calculation can
> > be made?
>
> Yes. It is a keyed hash. See [1] and [2].
>
> > How would I go about that if i wanted to hard code it in?
>
> Initialize the byte array key[] to the agreed upon value.
>
> > Is the string "hello world" the data to be hashed?
>
> Yes. It can be any data. Crypto++ is bytes/bytes out. Just present
> your data as a byte*.
>
> > Where abouts should I add that code to print the result?
>
> It can be dumped after the mac is calculated. It would not make sense
> to dump it before the mac is calculated.
>
> string encoded;
> StringSource( mac, true,
>     new HexEncoder(  new StringSink( encoded ),
>         true,   // uppercase
>         2       // grouping size
>     )
> );
>
> cout << encoded << endl;
>
> Or, you could use a printf string:
>
> printf("%02X %02X ... %02X %02X", digest[0], digest[1]...);
>
> > Is the variable mac the variable that holds the result of
> > the mac calculation?
>
> Yes.
>
> > And therefore it is mac that is compared at the receiver
> > to verify for authentication?
>
> Yes.
>
> > What do the verifier pieces of code do and how do they work?
>
> The concept is the same as a digital signature. One side generates a
> signature on the message, the other verifies the signature. I placed
> it in one program separating the roles with the comment/equal signs.
>
> Jeff
>
> [1]http://en.wikipedia.org/wiki/HMAC
> [2]http://www.codeproject.com/KB/security/BlockCiphers.aspx
> On Tue, Jun 10, 2008 at 11:20 AM, Adam Harding
>
> <[EMAIL PROTECTED]> wrote:
>
> > Hi Jeff,
>
> > Thanks alot for your help. Really appreciate it.
>
> > Yeah I think the actual code is fine but just think I have compiled
> > the cryptopp library incorrectly or using the wrong gcc command when
> > it comes to running it on my computer. Hopefully will get it working
> > in the lab though.
>
> > Could you please quickly explain a few things about the code you gave
> > me to make sure I understand it?
>
> > Does the key need to be entered into the code before a calculation can
> > be made? How would I go about that if i wanted to hard code it in?
> > Is the string "hello world" the data to be hashed?
> > Where abouts should I add that code to print the result?
> > Is the variable mac the variable that holds the result of the mac
> > calculation? And therefore it is mac that is compared at the receiver
> > to verify for authentication?
> > What do the verifier pieces of code do and how do they work?
>
> > Cheers,
>
> > Adam.
>
> > On Jun 10, 1:45 am, "Jeffrey Walton" <[EMAIL PROTECTED]> wrote:
> >> Hi Adam,
>
> >> > Basically am just trying to implement the MAC field in a packet header
> >> > for authentication. Is the digest the result of the calculation on the
> >> > data?
>
> >> What to MAC and how to MAC it depends on your protocol. I presume it
> >> is TLS or IPSec? Unfortunately, I have not looked at the standard(s)
> >> lately, so I can't say what you should do.
>
> >> > I am just trying to find a way of calculating the MAC
>
> >> You now have the code.
>
> >> > and then printing it so I can see I have a result
>
> >> Add the following after including "hex.h":
>
> >> string encoded;
> >> StringSource( mac, true,
> >>     new HexEncoder(  new StringSink( encoded ),
> >>         true,   // uppercase
> >>         2       // grouping size
> >>     )
> >> );
>
> >> > I tried implementing the code you gave me in a file called auth.cpp
> >> > and used this makefile to try and put it all together:
>
> >> I haven't seen Tux in quite some time, but I believe you need to
> >> include the library as an arument to gcc. I think it is -lcryptlib.a
>
> >> Jeff
>
> >> [SNIP]
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to