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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tsk_sha1.h
* @brief US Secure Hash Algorithm 1 (RFC 3174)
*
* @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
*
*/
#ifndef _TINYSAK_SHA1_H_
#define _TINYSAK_SHA1_H_
#include "tinysak_config.h"
TSK_BEGIN_DECLS
/**@ingroup tsk_sha1_group
* SHA-1 error codes.
*/
typedef enum tsk_sha1_errcode_e {
shaSuccess = 0, /**< Success */
shaNull, /**< Null pointer parameter */
shaInputTooLong, /**< input data too long */
shaStateError /**< called Input after Result */
}
tsk_sha1_errcode_t;
/**@ingroup tsk_sha1_group
*@def TSK_SHA1_DIGEST_SIZE
*/
/**@ingroup tsk_sha1_group
*@def TSK_SHA1_BLOCK_SIZE
*/
/**@ingroup tsk_sha1_group
*@def TSK_SHA1_STRING_SIZE
*/
/**@ingroup tsk_sha1_group
*@def tsk_sha1string_t
* Hexadecimal SHA-1 digest string.
*/
/**@ingroup tsk_sha1_group
*@def tsk_sha1digest_t
* SHA-1 digest bytes.
*/
#define TSK_SHA1_DIGEST_SIZE 20
#define TSK_SHA1_BLOCK_SIZE 64
#define TSK_SHA1_STRING_SIZE (TSK_SHA1_DIGEST_SIZE*2)
typedef uint8_t tsk_sha1string_t[TSK_SHA1_STRING_SIZE+1];
typedef uint8_t tsk_sha1digest_t[TSK_SHA1_DIGEST_SIZE]; /**< SHA-1 digest bytes. */
/**@ingroup tsk_sha1_group
* Computes SHA-1 digest.
* @param input The input data.
* @param input_size The size of the input data.
* @param digest @ref tsk_sha1digest_t object conaining the sha1 digest result.
* @sa @ref tsk_sha1compute.
*/
#define TSK_SHA1_DIGEST_CALC(input, input_size, digest) \
{ \
tsk_sha1context_t ctx; \
tsk_sha1reset(&ctx); \
tsk_sha1input(&ctx, (input), (input_size)); \
tsk_sha1result(&ctx, (digest)); \
}
/**@ingroup tsk_sha1_group
* This structure will hold context information for the SHA-1
* hashing SSESSION
*/
typedef struct tsk_sha1context_s {
uint32_t Intermediate_Hash[TSK_SHA1_DIGEST_SIZE/4]; /* Message Digest */
uint32_t Length_Low; /**< Message length in bits */
uint32_t Length_High; /**< Message length in bits */
int_least16_t Message_Block_Index;/**< Index into message block array */
uint8_t Message_Block[64]; /**< 512-bit message blocks */
int32_t Computed; /**< Is the digest computed? */
int32_t Corrupted; /**< Is the message digest corrupted? */
}
tsk_sha1context_t;
/*
* Function Prototypes
*/
TINYSAK_API tsk_sha1_errcode_t tsk_sha1reset(tsk_sha1context_t *);
TINYSAK_API tsk_sha1_errcode_t tsk_sha1input(tsk_sha1context_t *, const uint8_t *, unsigned length);
TINYSAK_API tsk_sha1_errcode_t tsk_sha1result(tsk_sha1context_t *, tsk_sha1digest_t Message_Digest);
TINYSAK_API void tsk_sha1final(uint8_t *Message_Digest, tsk_sha1context_t *context);
TINYSAK_API tsk_sha1_errcode_t tsk_sha1compute(const char* input, tsk_size_t size, tsk_sha1string_t *result);
TSK_END_DECLS
#endif /* _TINYSAK_SHA1_H_ */
|