Geremia's HMAC and SHA1 functions

I don't know how to use the function with class

 
HMAC(HashAlgorithm *hashAlgo, uint8_t *k, uint32_t kl);


I tried I guess any combination and it still getting red strike.

 
HMAC hmac( ? , (unsigned char*)key, strlen(p1));

I tried
1
2
3
4
SHA1 sha1;
HMAC hmac( sha1 , (unsigned char*)key, strlen(p1));
or
HMAC hmac( SHA1, (unsigned char*)key, strlen(p1));

Nothing work.

The functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef HMAC_H
#define HMAC_H

#include "HashAlgorithm.h"

class HMAC
{
    public :
        
        HMAC(HashAlgorithm *hashAlgo, uint8_t *k, uint32_t kl);
        virtual ~HMAC();
        
        void update(uint8_t *data, uint32_t length);
        void finalize(uint8_t *hash);
        
    private :
    
        HashAlgorithm *algo;
        uint8_t key[64];
        uint32_t keyLength;
};

#endif


and SHA:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef SHA1_H
#define SHA1_H

#include "HashAlgorithm.h"


class SHA1 : public HashAlgorithm
{
    public :
    
        SHA1();

        virtual uint8_t outputSize() const;        
        virtual void update(uint8_t *data, uint32_t length);
        virtual void finalize(uint8_t *hash);
        
        static void computeHash(uint8_t *hash, uint8_t *data, uint32_t length);
        
    private :
        static void computeBlock(uint32_t *h02, uint32_t *h12, uint32_t *h22, uint32_t *h32, uint32_t *h42, uint8_t *buffer);
    
        uint32_t h0, h1, h2, h3, h4;
        uint32_t totalBufferLength;
        uint8_t buffer[64];
        uint8_t bufferLength;       
};

#endif

The class HMAC expects a pointer to a class of type HashAlgorithm, a pointer to an uint8_t and a var of type uint32_t kl.

Try the following:
1
2
3
4
SHA1 sha1;
uint8_t buf[1024];

HMAC hmac(&sha1, buf, sizeof(buf));
Thanks, strange that I didn't tried with & :)
Topic archived. No new replies allowed.