#include <stdlib.h>
#include <sec/util.h>
-#define SHA1_BLOCK_LEN 16
-#define SHA1_DIGEST_LEN 16
+#define SHA1_BLOCK_LEN 64
+#define SHA1_DIGEST_LEN 20
static void SHA1Transform(uint32_t state[5], const uint8_t buffer[64]);
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
-#define blk0(i) (block->l[i] = be32_to_cpu(block->l[i]))
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
- ^block->l[(i+2)&15]^block->l[i&15],1))
+#define blk0(i) (block[i] = be32_to_cpu(block[i]))
+#define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
+ ^block[(i+2)&15]^block[i&15],1))
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
-typedef union {
- uint8_t c[64];
- uint32_t l[16];
-} CHAR64LONG16;
-static CHAR64LONG16 workspace;
-
static void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
+ uint32_t block[16];
- CHAR64LONG16* block = &workspace;
- memcpy(block, buffer, 64);
+ memcpy(&block, buffer, 64);
/* Copy context->state[] to working vars */
a = state[0];
ctx->h.update = SHA1_update;
ctx->h.final = SHA1_final;
}
-
-#include <drv/timer.h>
-
-void SHA1_benchmark(int numk)
-{
- SHA1_Context context;
- SHA1_init(&context);
-
- static uint8_t buf[512];
- memset(buf, 0x12, sizeof(buf));
-
- ticks_t t = timer_clock();
-
- for (int j=0;j<64;++j) {
- SHA1_begin(&context.h);
- for (int i=0; i<numk*2; ++i)
- SHA1_update(&context.h, buf, 512);
- SHA1_final(&context.h);
- }
-
- t = timer_clock() - t;
-
- utime_t usec = ticks_to_us(t) / 64;
- kprintf("%s @ %dMhz: SHA1 of %dKiB of data: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, numk, (usec/1000), (usec % 1000));
-}
-
-#if 0
-/*
-Test Vectors (from FIPS PUB 180-1)
-"abc"
- A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
-"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
- 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
-A million repetitions of "a"
- 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
-*/
-
-int main(int argc, char** argv)
-{
- SHA1_test();
-}
-
-#endif