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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#ifndef __SHA_H
#define __SHA_H
#include <stddef.h>
#include <stdint.h>
#include <libimobiledevice-glue/glue.h>
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
/* SHA-1 */
typedef struct sha1_context_ {
uint64_t length;
uint32_t state[5];
size_t curlen;
unsigned char buf[64];
} sha1_context;
#define SHA1_DIGEST_LENGTH 20
LIMD_GLUE_API int sha1_init(sha1_context * md);
LIMD_GLUE_API int sha1_final(sha1_context * md, unsigned char *out);
LIMD_GLUE_API int sha1_update(sha1_context * md, const void *data, size_t inlen);
LIMD_GLUE_API int sha1(const unsigned char *message, size_t message_len, unsigned char *out);
/* SHA-256 */
typedef struct sha256_context_ {
uint64_t length;
uint32_t state[8];
size_t curlen;
unsigned char buf[64];
int num_dwords;
} sha256_context;
#define SHA256_DIGEST_LENGTH 32
LIMD_GLUE_API int sha256_init(sha256_context * md);
LIMD_GLUE_API int sha256_final(sha256_context * md, unsigned char *out);
LIMD_GLUE_API int sha256_update(sha256_context * md, const void *data, size_t inlen);
LIMD_GLUE_API int sha256(const unsigned char *message, size_t message_len, unsigned char *out);
/* SHA-224 */
#define sha224_context sha256_context
#define SHA224_DIGEST_LENGTH 28
LIMD_GLUE_API int sha224_init(sha224_context * md);
LIMD_GLUE_API int sha224_final(sha224_context * md, unsigned char *out);
LIMD_GLUE_API int sha224_update(sha224_context * md, const void *data, size_t inlen);
LIMD_GLUE_API int sha224(const unsigned char *message, size_t message_len, unsigned char *out);
/* SHA-512 */
typedef struct sha512_context_ {
uint64_t length, state[8];
size_t curlen;
unsigned char buf[128];
int num_qwords;
} sha512_context;
#define SHA512_DIGEST_LENGTH 64
LIMD_GLUE_API int sha512_init(sha512_context * md);
LIMD_GLUE_API int sha512_final(sha512_context * md, unsigned char *out);
LIMD_GLUE_API int sha512_update(sha512_context * md, const void *data, size_t inlen);
LIMD_GLUE_API int sha512(const unsigned char *message, size_t message_len, unsigned char *out);
/* SHA-384 */
#define sha384_context sha512_context
#define SHA384_DIGEST_LENGTH 48
LIMD_GLUE_API int sha384_init(sha384_context * md);
LIMD_GLUE_API int sha384_final(sha384_context * md, unsigned char *out);
LIMD_GLUE_API int sha384_update(sha384_context * md, const void *data, size_t inlen);
LIMD_GLUE_API int sha384(const unsigned char *message, size_t message_len, unsigned char *out);
#endif
|