16 |
* stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor |
* stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor |
17 |
*/ |
*/ |
18 |
|
|
|
#include <fcntl.h> |
|
|
#include <limits.h> |
|
|
#include <stdio.h> |
|
|
#include <stdint.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <unistd.h> |
|
|
|
|
19 |
#include "libbb.h" |
#include "libbb.h" |
20 |
|
|
21 |
#define SHA1_BLOCK_SIZE 64 |
#define SHA1_BLOCK_SIZE 64 |
83 |
ctx->hash[4] += e; |
ctx->hash[4] += e; |
84 |
} |
} |
85 |
|
|
86 |
void sha1_begin(sha1_ctx_t *ctx) |
void FAST_FUNC sha1_begin(sha1_ctx_t *ctx) |
87 |
{ |
{ |
88 |
ctx->count[0] = ctx->count[1] = 0; |
ctx->count[0] = ctx->count[1] = 0; |
89 |
ctx->hash[0] = 0x67452301; |
ctx->hash[0] = 0x67452301; |
95 |
|
|
96 |
/* SHA1 hash data in an array of bytes into hash buffer and call the */ |
/* SHA1 hash data in an array of bytes into hash buffer and call the */ |
97 |
/* hash_compile function as required. */ |
/* hash_compile function as required. */ |
98 |
void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) |
void FAST_FUNC sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) |
99 |
{ |
{ |
100 |
uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK); |
uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK); |
101 |
uint32_t freeb = SHA1_BLOCK_SIZE - pos; |
uint32_t freeb = SHA1_BLOCK_SIZE - pos; |
116 |
memcpy(((unsigned char *) ctx->wbuf) + pos, sp, length); |
memcpy(((unsigned char *) ctx->wbuf) + pos, sp, length); |
117 |
} |
} |
118 |
|
|
119 |
void *sha1_end(void *resbuf, sha1_ctx_t *ctx) |
void* FAST_FUNC sha1_end(void *resbuf, sha1_ctx_t *ctx) |
120 |
{ |
{ |
121 |
/* SHA1 Final padding and digest calculation */ |
/* SHA1 Final padding and digest calculation */ |
122 |
#if BB_BIG_ENDIAN |
#if BB_BIG_ENDIAN |