ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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)
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 20 of file sha1.h.

Referenced by SHA1Transform().

◆ SHA1_DIGEST_LENGTH

#define SHA1_DIGEST_LENGTH   20

Definition at line 21 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 233 of file sha1.c.

233 {
234 unsigned int i;
235 unsigned char finalcount[8];
236
237 for (i = 0; i < 8; i++) {
238 finalcount[i] = (unsigned char)((context->count >> ((7 - (i & 7)) * 8)) &
239 255); /* Endian independent */
240 }
241 SHA1Update(context, "\200", 1);
242 while ((context->count & 504) != 448) {
243 SHA1Update(context, "\0", 1);
244 }
245 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
246
247 for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
248 digest[i] =
249 (unsigned char)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
250 }
251 memset(&finalcount, 0, sizeof(finalcount));
252 memset(context, 0, sizeof(*context));
253}
void SHA1Update(SHA1_CTX *context, const void *dataptr, unsigned int len)
Definition sha1.c:212
#define SHA1_DIGEST_LENGTH
Definition sha1.h:21
uint64_t count
Definition sha1.h:25
uint32_t state[5]
Definition sha1.h:24

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

◆ SHA1Init()

void SHA1Init ( SHA1_CTX * context)

Definition at line 200 of file sha1.c.

200 {
201 /* SHA1 initialization constants */
202 context->count = 0;
203 context->state[0] = 0x67452301;
204 context->state[1] = 0xEFCDAB89;
205 context->state[2] = 0x98BADCFE;
206 context->state[3] = 0x10325476;
207 context->state[4] = 0xC3D2E1F0;
208}

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

◆ SHA1Transform()

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

Definition at line 84 of file sha1.c.

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

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 212 of file sha1.c.

212 {
213 const uint8_t *data = dataptr;
214 unsigned int i;
215 unsigned int j;
216
217 j = (uint32_t)((context->count >> 3) & 63);
218 context->count += (uint64_t)len << 3;
219 if ((j + len) > 63) {
220 memcpy(&context->buffer[j], data, (i = 64 - j));
221 SHA1Transform(context->state, context->buffer);
222 for (; i + 63 < len; i += 64) {
223 SHA1Transform(context->state, &data[i]);
224 }
225 j = 0;
226 } else
227 i = 0;
228 memcpy(&context->buffer[j], &data[i], len - i);
229}
unsigned char uint8_t
void SHA1Transform(uint32_t state[5], const unsigned char *buffer)
Definition sha1.c:84
unsigned char buffer[64]
Definition sha1.h:26

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

Referenced by SHA1Final().