diff options
author | Paul Mackerras <paulus@samba.org> | 2005-04-22 23:08:43 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-22 23:08:43 -0700 |
commit | a6ef3518f9ac8a1c46a36c8d27173b1f73d839c4 (patch) | |
tree | e6d3a81c30ad237102e2ca82f3dfc57d0b9f0ddf /ppc/sha1.c | |
parent | b5af9107270171b79d46b099ee0b198e653f3a24 (diff) | |
download | git-a6ef3518f9ac8a1c46a36c8d27173b1f73d839c4.tar.gz |
[PATCH] PPC assembly implementation of SHA1
Here is a SHA1 implementation with the core written in PPC assembly.
On my 2GHz G5, it does 218MB/s, compared to 135MB/s for the openssl
version or 45MB/s for the mozilla version.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'ppc/sha1.c')
-rw-r--r-- | ppc/sha1.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ppc/sha1.c b/ppc/sha1.c new file mode 100644 index 0000000000..5ba4fc5259 --- /dev/null +++ b/ppc/sha1.c @@ -0,0 +1,72 @@ +/* + * SHA-1 implementation. + * + * Copyright (C) 2005 Paul Mackerras <paulus@samba.org> + * + * This version assumes we are running on a big-endian machine. + * It calls an external sha1_core() to process blocks of 64 bytes. + */ +#include <stdio.h> +#include <string.h> +#include "sha1.h" + +extern void sha1_core(uint32_t *hash, const unsigned char *p, + unsigned int nblocks); + +int SHA1_Init(SHA_CTX *c) +{ + c->hash[0] = 0x67452301; + c->hash[1] = 0xEFCDAB89; + c->hash[2] = 0x98BADCFE; + c->hash[3] = 0x10325476; + c->hash[4] = 0xC3D2E1F0; + c->len = 0; + c->cnt = 0; + return 0; +} + +int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n) +{ + unsigned long nb; + const unsigned char *p = ptr; + + c->len += n << 3; + while (n != 0) { + if (c->cnt || n < 64) { + nb = 64 - c->cnt; + if (nb > n) + nb = n; + memcpy(&c->buf.b[c->cnt], p, nb); + if ((c->cnt += nb) == 64) { + sha1_core(c->hash, c->buf.b, 1); + c->cnt = 0; + } + } else { + nb = n >> 6; + sha1_core(c->hash, p, nb); + nb <<= 6; + } + n -= nb; + p += nb; + } + return 0; +} + +int SHA1_Final(unsigned char *hash, SHA_CTX *c) +{ + unsigned int cnt = c->cnt; + + c->buf.b[cnt++] = 0x80; + if (cnt > 56) { + if (cnt < 64) + memset(&c->buf.b[cnt], 0, 64 - cnt); + sha1_core(c->hash, c->buf.b, 1); + cnt = 0; + } + if (cnt < 56) + memset(&c->buf.b[cnt], 0, 56 - cnt); + c->buf.l[7] = c->len; + sha1_core(c->hash, c->buf.b, 1); + memcpy(hash, c->hash, 20); + return 0; +} |