CRYPTO-C v1.1.3
C/C++ Documentation
sha1.h
Go to the documentation of this file.
1
15/* include guard */
16#ifndef CRYPTO_SHA1_H
17#define CRYPTO_SHA1_H
18
19
20#include "utildev.h"
21
22#define SHA1LEN 20
24/* SHA1 transform routines */
25#define sha1_blk0(i) ( W[i] = bswap32(W[i]) )
26#define sha1_blk_xor4(i) \
27 xor4(W[(i + 13) & 15], W[(i + 8) & 15], W[(i + 2) & 15], W[i & 15])
28#define sha1_blk(i) ( W[i & 15] = rol32(sha1_blk_xor4(i), 1) )
29/* SHA1 round1 input */
30#define sha1_r0(a, b, c, d, e, i) \
31 e += xandx(b, c, d) + sha1_blk0(i) + k[0] + rol32(a, 5); \
32 b = rol32(b, 30)
33/* SHA1 round1 extended */
34#define sha1_r1(a, b, c, d, e, i) \
35 e += xandx(b, c, d) + sha1_blk(i) + k[0] + rol32(a, 5); \
36 b = rol32(b, 30)
37/* SHA1 rounds 2/3/4 */
38#define sha1_r2(a, b, c, d, e, i) \
39 e += xor3(b, c, d) + sha1_blk(i) + k[1] + rol32(a, 5); \
40 b = rol32(b, 30)
41#define sha1_r3(a, b, c, d, e, i) \
42 e += (((b | c) & d) | (b & c)) + sha1_blk(i) + k[2] + rol32(a, 5); \
43 b = rol32(b, 30)
44#define sha1_r4(a, b, c, d, e, i) \
45 e += xor3(b, c, d) + sha1_blk(i) + k[3] + rol32(a, 5); \
46 b = rol32(b, 30)
47
48typedef struct {
49 uint8_t data[64];
50 uint32_t bitlen[2];
51 uint32_t state[5];
52 uint32_t datalen;
53} SHA1_CTX;
55/* C/C++ compatible function prototypes */
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60void sha1_init(SHA1_CTX *ctx);
61void sha1_update(SHA1_CTX *ctx, const void *in, size_t inlen);
62void sha1_final(SHA1_CTX *ctx, void *out);
63void sha1(const void *in, size_t inlen, void *out);
64
65/* CUDA testing functions */
66#ifdef CUDA
67 void test_kcu_sha1(const void *in, size_t *inlen, size_t max_inlen,
68 void *out, int num);
69#endif
70
71/* end extern "C" {} for C++ */
72#ifdef __cplusplus
73}
74#endif
75
76/* end include guard */
77#endif
void sha1_final(SHA1_CTX *ctx, void *out)
Finalize a SHA1 message digest.
Definition: sha1.c:185
void sha1_update(SHA1_CTX *ctx, const void *in, size_t inlen)
Add inlen bytes from in to a SHA1 context for hashing.
Definition: sha1.c:158
void sha1(const void *in, size_t inlen, void *out)
Convenient all-in-one SHA1 computation.
Definition: sha1.c:230
void sha1_init(SHA1_CTX *ctx)
Initialize a SHA1 context.
Definition: sha1.c:141
Definition: sha1.h:48
uint32_t datalen
Length of buffered input.
Definition: sha1.h:52
Device utilities and includes support.