Lines Matching refs:ctx

51 static void SHA1_Transform(SHA_CTX* ctx) {
56 A = ctx->state[0];
57 B = ctx->state[1];
58 C = ctx->state[2];
59 D = ctx->state[3];
60 E = ctx->state[4];
64 (W[t] = bswap_32(ctx->buf.w[t])) + \
140 ctx->state[0] += A;
141 ctx->state[1] += B;
142 ctx->state[2] += C;
143 ctx->state[3] += D;
144 ctx->state[4] += E;
147 void SHA_update(SHA_CTX* ctx, const void* data, int len) {
148 int i = ctx->count % sizeof(ctx->buf);
151 ctx->count += len;
153 while (len > sizeof(ctx->buf) - i) {
154 memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i);
155 len -= sizeof(ctx->buf) - i;
156 p += sizeof(ctx->buf) - i;
157 SHA1_Transform(ctx);
162 ctx->buf.b[i++] = *p++;
163 if (i == sizeof(ctx->buf)) {
164 SHA1_Transform(ctx);
171 const uint8_t* SHA_final(SHA_CTX* ctx) {
172 uint64_t cnt = ctx->count * 8;
175 SHA_update(ctx, (uint8_t*)"\x80", 1);
176 while ((ctx->count % sizeof(ctx->buf)) != (sizeof(ctx->buf) - 8)) {
177 SHA_update(ctx, (uint8_t*)"\0", 1);
181 SHA_update(ctx, &tmp, 1);
185 ctx->buf.w[i] = bswap_32(ctx->state[i]);
188 return ctx->buf.b;
195 static void SHA1_transform(SHA_CTX *ctx) {
198 uint8_t *p = ctx->buf;
213 A = ctx->state[0];
214 B = ctx->state[1];
215 C = ctx->state[2];
216 D = ctx->state[3];
217 E = ctx->state[4];
238 ctx->state[0] += A;
239 ctx->state[1] += B;
240 ctx->state[2] += C;
241 ctx->state[3] += D;
242 ctx->state[4] += E;
245 void SHA_update(SHA_CTX *ctx, const void *data, int len) {
246 int i = ctx->count % sizeof(ctx->buf);
249 ctx->count += len;
252 ctx->buf[i++] = *p++;
253 if (i == sizeof(ctx->buf)) {
254 SHA1_transform(ctx);
259 const uint8_t *SHA_final(SHA_CTX *ctx) {
260 uint8_t *p = ctx->buf;
261 uint64_t cnt = ctx->count * 8;
264 SHA_update(ctx, (uint8_t*)"\x80", 1);
265 while ((ctx->count % sizeof(ctx->buf)) != (sizeof(ctx->buf) - 8)) {
266 SHA_update(ctx, (uint8_t*)"\0", 1);
270 SHA_update(ctx, &tmp, 1);
274 uint32_t tmp = ctx->state[i];
281 return ctx->buf;
286 void SHA_init(SHA_CTX* ctx) {
287 ctx->state[0] = 0x67452301;
288 ctx->state[1] = 0xEFCDAB89;
289 ctx->state[2] = 0x98BADCFE;
290 ctx->state[3] = 0x10325476;
291 ctx->state[4] = 0xC3D2E1F0;
292 ctx->count = 0;
299 SHA_CTX ctx;
300 SHA_init(&ctx);
301 SHA_update(&ctx, data, len);
302 p = SHA_final(&ctx);