summaryrefslogtreecommitdiff
path: root/source/LCM/Hash.h
blob: e5e5343555b860c25fa040b15d924dce13828989 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/

#ifndef _HASH_H_
#define _HASH_H_

#include "t_communication_service.h"
#ifdef _WIN32
#include "WinApiWrappers.h"
#else
#include "LinuxApiWrappers.h"
#endif

struct HashRequest {
    HashType_e Type;
    uint8 *Data_p;
    uint32 Length;
    uint8 *Hash_p;
    HashCallback_fn Callback;
    void *Param_p;
};

class Hash
{
public:
    Hash();
    ~Hash();
    void Cancel(HashDevice_t **HashDevice_pp);
    void Calculate(HashType_e Type, void *Data_p, const uint32 Length, uint8 *Hash_p, HashCallback_fn Callback, void *Param_p);
    uint32 GetLength(HashType_e Type);
private:
    CThreadWrapper *m_Thread;
    CSemaphoreQueue *m_RequestQueue;

#ifdef _WIN32
    static unsigned int WINAPI WorkerThread(void *arg);
#else
    static void *WorkerThread(void *arg);
#endif

    static uint8 hashxor(const uint8 *Buf_p, uint32 Length);
    static uint16 crc16(const uint8 *p, int count, uint16 crc_in);
};

#endif // _HASH_H_