ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
sha1.h File Reference

Go to the source code of this file.

Data Structures

struct  SHA1_CTX

Macros

#define SHA1_BLOCK_LENGTH   64
#define SHA1_DIGEST_LENGTH   20

Functions

void SHA1Init (SHA1_CTX *context)
void SHA1Transform (uint32_t state[5], const unsigned char buffer[64])
void SHA1Update (SHA1_CTX *context, const void *data, unsigned int len)
void SHA1Final (unsigned char digest[20], SHA1_CTX *context)

Macro Definition Documentation

◆ SHA1_BLOCK_LENGTH

#define SHA1_BLOCK_LENGTH   64

Definition at line 16 of file sha1.h.

Referenced by SHA1Transform().

◆ SHA1_DIGEST_LENGTH

#define SHA1_DIGEST_LENGTH   20

Definition at line 17 of file sha1.h.

Referenced by SHA1Final(), and turn_generate_credentials().

Function Documentation

◆ SHA1Final()

void SHA1Final ( unsigned char digest[20],
SHA1_CTX * context )

Definition at line 221 of file sha1.c.

221 {
222 unsigned int i;
223 unsigned char finalcount[8];
224
225 for (i = 0; i < 8; i++) {
226 finalcount[i] = (unsigned char)((context->count >> ((7 - (i & 7)) * 8)) & 255); /* Endian independent */
227 }
228 SHA1Update(context, "\200", 1);
229 while ((context->count & 504) != 448) {
230 SHA1Update(context, "\0", 1);
231 }
232 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
233
234 for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
235 digest[i] = (unsigned char)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
236 }
237 memset(&finalcount, 0, sizeof(finalcount));
238 memset(context, 0, sizeof(*context));
239}
void SHA1Update(SHA1_CTX *context, const void *dataptr, unsigned int len)
Definition sha1.c:200
#define SHA1_DIGEST_LENGTH
Definition sha1.h:17
uint64_t count
Definition sha1.h:21
uint32_t state[5]
Definition sha1.h:20

References SHA1_CTX::count, SHA1_DIGEST_LENGTH, SHA1Update(), and SHA1_CTX::state.

◆ SHA1Init()

void SHA1Init ( SHA1_CTX * context)

Definition at line 188 of file sha1.c.

188 {
189 /* SHA1 initialization constants */
190 context->count = 0;
191 context->state[0] = 0x67452301;
192 context->state[1] = 0xEFCDAB89;
193 context->state[2] = 0x98BADCFE;
194 context->state[3] = 0x10325476;
195 context->state[4] = 0xC3D2E1F0;
196}

References SHA1_CTX::count, and SHA1_CTX::state.

◆ SHA1Transform()

void SHA1Transform ( uint32_t state[5],
const unsigned char buffer[64] )

Definition at line 72 of file sha1.c.

72 {
73 uint32_t a, b, c, d, e;
74 typedef union {
75 unsigned char c[SHA1_BLOCK_LENGTH];
76 uint32_t l[16];
77 } CHAR64LONG16;
78 CHAR64LONG16 *block;
79#ifdef SHA1HANDSOFF
80 unsigned char workspace[SHA1_BLOCK_LENGTH];
81
82 block = (CHAR64LONG16 *)workspace;
83 memcpy(block, buffer, SHA1_BLOCK_LENGTH);
84#else
85 block = (CHAR64LONG16 *)buffer;
86#endif
87 /* Copy context->state[] to working vars */
88 a = state[0];
89 b = state[1];
90 c = state[2];
91 d = state[3];
92 e = state[4];
93
94 /* 4 rounds of 20 operations each. Loop unrolled. */
95 R0(a, b, c, d, e, 0);
96 R0(e, a, b, c, d, 1);
97 R0(d, e, a, b, c, 2);
98 R0(c, d, e, a, b, 3);
99 R0(b, c, d, e, a, 4);
100 R0(a, b, c, d, e, 5);
101 R0(e, a, b, c, d, 6);
102 R0(d, e, a, b, c, 7);
103 R0(c, d, e, a, b, 8);
104 R0(b, c, d, e, a, 9);
105 R0(a, b, c, d, e, 10);
106 R0(e, a, b, c, d, 11);
107 R0(d, e, a, b, c, 12);
108 R0(c, d, e, a, b, 13);
109 R0(b, c, d, e, a, 14);
110 R0(a, b, c, d, e, 15);
111 R1(e, a, b, c, d, 16);
112 R1(d, e, a, b, c, 17);
113 R1(c, d, e, a, b, 18);
114 R1(b, c, d, e, a, 19);
115 R2(a, b, c, d, e, 20);
116 R2(e, a, b, c, d, 21);
117 R2(d, e, a, b, c, 22);
118 R2(c, d, e, a, b, 23);
119 R2(b, c, d, e, a, 24);
120 R2(a, b, c, d, e, 25);
121 R2(e, a, b, c, d, 26);
122 R2(d, e, a, b, c, 27);
123 R2(c, d, e, a, b, 28);
124 R2(b, c, d, e, a, 29);
125 R2(a, b, c, d, e, 30);
126 R2(e, a, b, c, d, 31);
127 R2(d, e, a, b, c, 32);
128 R2(c, d, e, a, b, 33);
129 R2(b, c, d, e, a, 34);
130 R2(a, b, c, d, e, 35);
131 R2(e, a, b, c, d, 36);
132 R2(d, e, a, b, c, 37);
133 R2(c, d, e, a, b, 38);
134 R2(b, c, d, e, a, 39);
135 R3(a, b, c, d, e, 40);
136 R3(e, a, b, c, d, 41);
137 R3(d, e, a, b, c, 42);
138 R3(c, d, e, a, b, 43);
139 R3(b, c, d, e, a, 44);
140 R3(a, b, c, d, e, 45);
141 R3(e, a, b, c, d, 46);
142 R3(d, e, a, b, c, 47);
143 R3(c, d, e, a, b, 48);
144 R3(b, c, d, e, a, 49);
145 R3(a, b, c, d, e, 50);
146 R3(e, a, b, c, d, 51);
147 R3(d, e, a, b, c, 52);
148 R3(c, d, e, a, b, 53);
149 R3(b, c, d, e, a, 54);
150 R3(a, b, c, d, e, 55);
151 R3(e, a, b, c, d, 56);
152 R3(d, e, a, b, c, 57);
153 R3(c, d, e, a, b, 58);
154 R3(b, c, d, e, a, 59);
155 R4(a, b, c, d, e, 60);
156 R4(e, a, b, c, d, 61);
157 R4(d, e, a, b, c, 62);
158 R4(c, d, e, a, b, 63);
159 R4(b, c, d, e, a, 64);
160 R4(a, b, c, d, e, 65);
161 R4(e, a, b, c, d, 66);
162 R4(d, e, a, b, c, 67);
163 R4(c, d, e, a, b, 68);
164 R4(b, c, d, e, a, 69);
165 R4(a, b, c, d, e, 70);
166 R4(e, a, b, c, d, 71);
167 R4(d, e, a, b, c, 72);
168 R4(c, d, e, a, b, 73);
169 R4(b, c, d, e, a, 74);
170 R4(a, b, c, d, e, 75);
171 R4(e, a, b, c, d, 76);
172 R4(d, e, a, b, c, 77);
173 R4(c, d, e, a, b, 78);
174 R4(b, c, d, e, a, 79);
175
176 /* Add the working vars back into context.state[] */
177 state[0] = (uint32_t)((uint64_t)state[0] + a);
178 state[1] = (uint32_t)((uint64_t)state[1] + b);
179 state[2] = (uint32_t)((uint64_t)state[2] + c);
180 state[3] = (uint32_t)((uint64_t)state[3] + d);
181 state[4] = (uint32_t)((uint64_t)state[4] + e);
182 /* Wipe variables */
183 a = b = c = d = e = 0;
184}
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
#define R1(v, w, x, y, z, i)
Definition sha1.c:57
#define R2(v, w, x, y, z, i)
Definition sha1.c:60
#define R0(v, w, x, y, z, i)
Definition sha1.c:54
#define R3(v, w, x, y, z, i)
Definition sha1.c:63
#define R4(v, w, x, y, z, i)
Definition sha1.c:66
#define SHA1_BLOCK_LENGTH
Definition sha1.h:16

References R0, R1, R2, R3, R4, and SHA1_BLOCK_LENGTH.

Referenced by SHA1Update().

◆ SHA1Update()

void SHA1Update ( SHA1_CTX * context,
const void * data,
unsigned int len )

Definition at line 200 of file sha1.c.

200 {
201 const uint8_t *data = dataptr;
202 unsigned int i;
203 unsigned int j;
204
205 j = (uint32_t)((context->count >> 3) & 63);
206 context->count += (uint64_t)len << 3;
207 if ((j + len) > 63) {
208 memcpy(&context->buffer[j], data, (i = 64 - j));
209 SHA1Transform(context->state, context->buffer);
210 for (; i + 63 < len; i += 64) {
211 SHA1Transform(context->state, &data[i]);
212 }
213 j = 0;
214 } else
215 i = 0;
216 memcpy(&context->buffer[j], &data[i], len - i);
217}
unsigned char uint8_t
Definition common.h:60
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
Definition sha1.c:72
unsigned char buffer[64]
Definition sha1.h:22

References SHA1_CTX::buffer, SHA1_CTX::count, SHA1Transform(), and SHA1_CTX::state.

Referenced by SHA1Final().