]> git.ipfire.org Git - thirdparty/iw.git/blame - sha256.h
update nl80211.h
[thirdparty/iw.git] / sha256.h
CommitLineData
63d6aac5
RZ
1#ifndef SHA256
2#define SHA256
3
4#include "iw.h"
5#define SHA256_BLOCK_SIZE 64
6
7#define LOAD32B(addr) \
8 ((__u32)((addr)[0] << 24) | ((addr)[1] << 16) | \
9 ((addr)[2] << 8) | (addr)[3])
10
11#define STORE64B(addr, data) \
12do { (addr)[0] = (__u8)((data) >> 56); (addr)[1] = (__u8)((data) >> 48); \
13 (addr)[2] = (__u8)((data) >> 40); (addr)[3] = (__u8)((data) >> 32); \
14 (addr)[4] = (__u8)((data) >> 24); (addr)[5] = (__u8)((data) >> 16); \
15 (addr)[6] = (__u8)((data) >> 8); (addr)[7] = (__u8)((data) & 0xff); \
16 } while (0)
17
18#define STORE32B(addr, data) \
19do { (addr)[0] = (__u8)(((data) >> 24) & 0xff); \
20 (addr)[1] = (__u8)(((data) >> 16) & 0xff); \
21 (addr)[2] = (__u8)(((data) >> 8) & 0xff); \
22 (addr)[3] = (__u8)((data) & 0xff); } while (0)
23
24struct sha256_state {
25 __u64 length;
26 __u32 state[8], curlen;
27 __u8 buf[SHA256_BLOCK_SIZE];
28};
29
30/**
31 * SHA256 Hashing
32 * @addr: pointers to the data area
33 * @len: Lengths of the data block
34 * @res: Buffer for the digest
35 * Returns: 0 on success, -1 of failure
36 */
37int sha256(const unsigned char *addr, const size_t len,
38 unsigned char *res);
39
40/* Initialize the hash state */
41void sha256_init(struct sha256_state *md);
42
43/**
44 * Process a block of memory though the hash
45 * @param md The hash state
46 * @param in The data to hash
47 * @param inlen The length of the data (octets)
48 * @return CRYPT_OK if successful
49*/
50int sha256_process(struct sha256_state *md, const unsigned char *in,
51 unsigned long inlen);
52
53/**
54 * Terminate the hash to get the digest
55 * @param md The hash state
56 * @param out [out] The destination of the hash (32 bytes)
57 * @return CRYPT_OK if successful
58*/
59int sha256_done(struct sha256_state *md, unsigned char *out);
60
61#endif