diff options
Diffstat (limited to 'src/libstdcrypto')
-rw-r--r-- | src/libstdcrypto/md5-internal.h | 11 | ||||
-rw-r--r-- | src/libstdcrypto/md5_final.c | 30 | ||||
-rw-r--r-- | src/libstdcrypto/md5_init.c | 13 | ||||
-rw-r--r-- | src/libstdcrypto/md5_transform.c | 90 | ||||
-rw-r--r-- | src/libstdcrypto/md5_update.c | 37 | ||||
-rw-r--r-- | src/libstdcrypto/rc4.c | 20 | ||||
-rw-r--r-- | src/libstdcrypto/rc4_init.c | 27 | ||||
-rw-r--r-- | src/libstdcrypto/sha1_feed.c | 3 | ||||
-rw-r--r-- | src/libstdcrypto/sha1_final.c | 3 | ||||
-rw-r--r-- | src/libstdcrypto/sha1_init.c | 3 | ||||
-rw-r--r-- | src/libstdcrypto/sha1_transform.c | 2 | ||||
-rw-r--r-- | src/libstdcrypto/sha256_feed.c | 4 | ||||
-rw-r--r-- | src/libstdcrypto/sha256_final.c | 4 | ||||
-rw-r--r-- | src/libstdcrypto/sha256_update.c | 3 | ||||
-rw-r--r-- | src/libstdcrypto/sha512-internal.h | 2 | ||||
-rw-r--r-- | src/libstdcrypto/sha512_final.c | 12 | ||||
-rw-r--r-- | src/libstdcrypto/sha512_update.c | 1 |
17 files changed, 18 insertions, 247 deletions
diff --git a/src/libstdcrypto/md5-internal.h b/src/libstdcrypto/md5-internal.h deleted file mode 100644 index 59ffeea..0000000 --- a/src/libstdcrypto/md5-internal.h +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#ifndef MD5_INTERNAL_H -#define MD5_INTERNAL_H - -#include <stdint.h> -#include <skalibs/md5.h> - -extern void md5_transform (uint32_t * /* 4 uint32s */, uint32_t const * /* 16 uint32s */) ; - -#endif diff --git a/src/libstdcrypto/md5_final.c b/src/libstdcrypto/md5_final.c deleted file mode 100644 index 72d6529..0000000 --- a/src/libstdcrypto/md5_final.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/md5.h> -#include "md5-internal.h" - -void md5_final (MD5Schedule *ctx, char *digest /* 16 chars */) -{ - unsigned int count = (ctx->bits[0] >> 3) & 0x3F ; - unsigned char *p = ctx->in + count ; - *p++ = 0x80; - count = 63 - count ; - if (count < 8) - { - memset(p, 0, count) ; - uint32_little_endian((char *)ctx->in, 16) ; - md5_transform(ctx->buf, (uint32_t *)ctx->in) ; - memset(ctx->in, 0, 56) ; - } - else memset(p, 0, count - 8) ; - uint32_little_endian((char *)ctx->in, 14) ; - - memcpy(ctx->in + 56, &ctx->bits[0], 4) ; - memcpy(ctx->in + 60, &ctx->bits[1], 4) ; - - md5_transform(ctx->buf, (uint32_t *)ctx->in) ; - uint32_little_endian((char *)ctx->buf, 4) ; - memcpy(digest, ctx->buf, 16) ; -} diff --git a/src/libstdcrypto/md5_init.c b/src/libstdcrypto/md5_init.c deleted file mode 100644 index eac96b0..0000000 --- a/src/libstdcrypto/md5_init.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include <skalibs/md5.h> - -void md5_init (MD5Schedule *ctx) -{ - ctx->buf[0] = 0x67452301U ; - ctx->buf[1] = 0xefcdab89U ; - ctx->buf[2] = 0x98badcfeU ; - ctx->buf[3] = 0x10325476U ; - ctx->bits[0] = 0 ; - ctx->bits[1] = 0 ; -} diff --git a/src/libstdcrypto/md5_transform.c b/src/libstdcrypto/md5_transform.c deleted file mode 100644 index 90be9ab..0000000 --- a/src/libstdcrypto/md5_transform.c +++ /dev/null @@ -1,90 +0,0 @@ -/* ISC license. */ - -#include "md5-internal.h" - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) - -void md5_transform (uint32_t *buf /* 4 uint32s */, uint32_t const *in /* 16 uint32s */) -{ - uint32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3] ; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478U, 7) ; - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756U, 12) ; - MD5STEP(F1, c, d, a, b, in[2] + 0x242070dbU, 17) ; - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceeeU, 22) ; - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0fafU, 7) ; - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62aU, 12) ; - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613U, 17) ; - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501U, 22) ; - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8U, 7) ; - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7afU, 12) ; - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1U, 17) ; - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7beU, 22) ; - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122U, 7) ; - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193U, 12) ; - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438eU, 17) ; - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821U, 22) ; - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562U, 5) ; - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340U, 9) ; - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51U, 14) ; - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aaU, 20) ; - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105dU, 5) ; - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453U, 9) ; - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681U, 14) ; - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8U, 20) ; - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6U, 5) ; - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6U, 9) ; - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87U, 14) ; - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14edU, 20) ; - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905U, 5) ; - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8U, 9) ; - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9U, 14) ; - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8aU, 20) ; - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942U, 4) ; - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681U, 11) ; - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122U, 16) ; - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380cU, 23) ; - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44U, 4) ; - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9U, 11) ; - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60U, 16) ; - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70U, 23) ; - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6U, 4) ; - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127faU, 11) ; - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085U, 16) ; - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05U, 23) ; - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039U, 4) ; - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5U, 11) ; - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8U, 16) ; - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665U, 23) ; - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244U, 6) ; - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97U, 10) ; - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7U, 15) ; - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039U, 21) ; - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3U, 6) ; - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92U, 10) ; - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47dU, 15) ; - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1U, 21) ; - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4fU, 6) ; - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0U, 10) ; - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314U, 15) ; - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1U, 21) ; - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82U, 6) ; - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235U, 10) ; - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bbU, 15) ; - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391U, 21) ; - - buf[0] += a ; - buf[1] += b ; - buf[2] += c ; - buf[3] += d ; -} diff --git a/src/libstdcrypto/md5_update.c b/src/libstdcrypto/md5_update.c deleted file mode 100644 index d61cd3f..0000000 --- a/src/libstdcrypto/md5_update.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/md5.h> -#include "md5-internal.h" - -void md5_update (MD5Schedule *ctx, char const *s, size_t len) -{ - uint32_t t = ctx->bits[0] ; - if ((ctx->bits[0] = t + (len << 3)) < t) - ctx->bits[1]++ ; - ctx->bits[1] += len >> 29 ; - t = (t >> 3) & 0x3f ; - if (t) - { - unsigned char *p = ctx->in + t ; - t = 64 - t ; - if (len < t) - { - memcpy(p, s, len) ; - return ; - } - memcpy(p, s, t) ; - uint32_little_endian((char *)ctx->in, 16) ; - md5_transform(ctx->buf, (uint32_t *)ctx->in) ; - s += t ; len -= t ; - } - while (len >= 64) - { - memcpy(ctx->in, s, 64) ; - uint32_little_endian((char *)ctx->in, 16) ; - md5_transform(ctx->buf, (uint32_t *)ctx->in) ; - s += 64 ; len -= 64 ; - } - memcpy(ctx->in, s, len) ; -} diff --git a/src/libstdcrypto/rc4.c b/src/libstdcrypto/rc4.c deleted file mode 100644 index 482c31a..0000000 --- a/src/libstdcrypto/rc4.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ISC license. */ -/* Thanks to Thomas Pornin <pornin@bolet.org> */ - -#include <skalibs/bytestr.h> -#include <skalibs/rc4.h> - -void rc4 (RC4Schedule *r, char const *in, char *out, size_t n) -{ - size_t i = 0 ; - for (; i < n ; i++) - { - unsigned char t ; - r->x = T8(r->x + 1) ; - t = r->tab[r->x] ; - r->y = T8(r->y + t) ; - r->tab[r->x] = r->tab[r->y] ; - r->tab[r->y] = t ; - out[i] = (unsigned char)in[i] ^ T8(r->tab[r->x] + r->tab[r->y]) ; - } -} diff --git a/src/libstdcrypto/rc4_init.c b/src/libstdcrypto/rc4_init.c deleted file mode 100644 index bbcefda..0000000 --- a/src/libstdcrypto/rc4_init.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ISC license. */ -/* Thanks to Thomas Pornin <pornin@bolet.org> */ - -#include <skalibs/bytestr.h> -#include <skalibs/rc4.h> - -void rc4_init (RC4Schedule *r, char const *key, size_t ksize) -{ - size_t j = 0 ; - unsigned int i = 0 ; - unsigned char c = 0; - - r->x = r->y = 0 ; - for (; i < 256 ; i++) r->tab[i] = i ; - for (i = 0 ; i < 256 ; i++) - { - unsigned char t = r->tab[i] ; - c = T8(c + (unsigned char)key[j] + t) ; - r->tab[i] = r->tab[c] ; - r->tab[c] = t ; - if (++j == ksize) j = 0 ; - } - { - char tmp[RC4_THROWAWAY] ; - rc4(r, tmp, tmp, RC4_THROWAWAY) ; - } -} diff --git a/src/libstdcrypto/sha1_feed.c b/src/libstdcrypto/sha1_feed.c index cb00852..0ca6f85 100644 --- a/src/libstdcrypto/sha1_feed.c +++ b/src/libstdcrypto/sha1_feed.c @@ -12,10 +12,9 @@ void sha1_feed (SHA1Schedule *ctx, unsigned char inb) ctx->in[ctx->b>>2] |= T8(inb) ; if (++ctx->b >= 64) { - unsigned int i = 0 ; sha1_transform(ctx->buf, ctx->in) ; ctx->b = 0 ; - for (i = 0 ; i < 16 ; i++) ctx->in[i] = 0 ; + for (uint32_t i = 0 ; i < 16 ; i++) ctx->in[i] = 0 ; } tmp = ctx->bits[0] ; ctx->bits[0] += 8 ; diff --git a/src/libstdcrypto/sha1_final.c b/src/libstdcrypto/sha1_final.c index d29a621..7205ed3 100644 --- a/src/libstdcrypto/sha1_final.c +++ b/src/libstdcrypto/sha1_final.c @@ -7,12 +7,11 @@ void sha1_final (SHA1Schedule *ctx, char *digest) { char pack[8] ; - unsigned int i = 0 ; uint32_pack_big(pack, ctx->bits[1]) ; uint32_pack_big(pack+4, ctx->bits[0]) ; sha1_feed(ctx, 0x80) ; while (ctx->b != 56) sha1_feed(ctx, 0) ; sha1_update(ctx, pack, 8) ; - for (; i < 5 ; i++) + for (unsigned int i = 0 ; i < 5 ; i++) uint32_pack_big(digest + (i<<2), ctx->buf[i]) ; } diff --git a/src/libstdcrypto/sha1_init.c b/src/libstdcrypto/sha1_init.c index 589230d..f8ca1f2 100644 --- a/src/libstdcrypto/sha1_init.c +++ b/src/libstdcrypto/sha1_init.c @@ -4,13 +4,12 @@ void sha1_init (SHA1Schedule *ctx) { - unsigned int i = 16 ; ctx->buf[0] = 0x67452301U ; ctx->buf[1] = 0xefcdab89U ; ctx->buf[2] = 0x98badcfeU ; ctx->buf[3] = 0x10325476U ; ctx->buf[4] = 0xc3d2e1f0U ; ctx->bits[0] = ctx->bits[1] = 0 ; - while (i--) ctx->in[i] = 0 ; + for (unsigned int i = 0 ; i < 16 ; i++) ctx->in[i] = 0 ; ctx->b = 0 ; } diff --git a/src/libstdcrypto/sha1_transform.c b/src/libstdcrypto/sha1_transform.c index c323c66..78f5137 100644 --- a/src/libstdcrypto/sha1_transform.c +++ b/src/libstdcrypto/sha1_transform.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include <stdint.h> + #include "sha1-internal.h" #define F1(x, y, z) ((x & y) | ((~x) & z)) diff --git a/src/libstdcrypto/sha256_feed.c b/src/libstdcrypto/sha256_feed.c index 197b8f0..335f4ea 100644 --- a/src/libstdcrypto/sha256_feed.c +++ b/src/libstdcrypto/sha256_feed.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <stdint.h> + #include <skalibs/bytestr.h> #include <skalibs/sha256.h> #include "sha256-internal.h" @@ -12,10 +13,9 @@ void sha256_feed (SHA256Schedule *ctx, unsigned char inb) ctx->in[ctx->b>>2] |= T8(inb) ; if (++ctx->b >= 64) { - unsigned int i = 0 ; sha256_transform(ctx->buf, ctx->in) ; ctx->b = 0 ; - for (; i < 16 ; i++) ctx->in[i] = 0 ; + for (uint32_t i = 0; i < 16 ; i++) ctx->in[i] = 0 ; } tmp = ctx->bits[0] ; ctx->bits[0] += 8 ; diff --git a/src/libstdcrypto/sha256_final.c b/src/libstdcrypto/sha256_final.c index ba4b5ea..67fc100 100644 --- a/src/libstdcrypto/sha256_final.c +++ b/src/libstdcrypto/sha256_final.c @@ -1,13 +1,13 @@ /* ISC license. */ #include <stdint.h> + #include <skalibs/bytestr.h> #include <skalibs/sha256.h> #include "sha256-internal.h" void sha256_final (SHA256Schedule *ctx, char *digest) { - unsigned int i = 0 ; unsigned char *p = (unsigned char *)digest ; uint32_t bits[2] = { ctx->bits[0], ctx->bits[1] } ; @@ -21,7 +21,7 @@ void sha256_final (SHA256Schedule *ctx, char *digest) sha256_feed(ctx, T8(bits[0]>>16)) ; sha256_feed(ctx, T8(bits[0]>>8)) ; sha256_feed(ctx, T8(bits[0])) ; - for (; i < 8 ; i++) + for (uint32_t i = 0 ; i < 8 ; i++) { *p++ = T8(ctx->buf[i]>>24) ; *p++ = T8(ctx->buf[i]>>16) ; diff --git a/src/libstdcrypto/sha256_update.c b/src/libstdcrypto/sha256_update.c index 70322ee..4eb44fc 100644 --- a/src/libstdcrypto/sha256_update.c +++ b/src/libstdcrypto/sha256_update.c @@ -5,6 +5,5 @@ void sha256_update (SHA256Schedule *ctx, char const *buf, size_t len) { - size_t i = 0 ; - for (; i < len ; i++) sha256_feed(ctx, (unsigned char)buf[i]) ; + for (size_t i = 0 ; i < len ; i++) sha256_feed(ctx, (unsigned char)buf[i]) ; } diff --git a/src/libstdcrypto/sha512-internal.h b/src/libstdcrypto/sha512-internal.h index cd6bcbd..16d1e93 100644 --- a/src/libstdcrypto/sha512-internal.h +++ b/src/libstdcrypto/sha512-internal.h @@ -5,6 +5,6 @@ #include <skalibs/sha512.h> -extern void sha512_transform (SHA512Schedule *ctx, unsigned char const *block) ; +extern void sha512_transform (SHA512Schedule *, unsigned char const *) ; #endif diff --git a/src/libstdcrypto/sha512_final.c b/src/libstdcrypto/sha512_final.c index ebda597..a24a03c 100644 --- a/src/libstdcrypto/sha512_final.c +++ b/src/libstdcrypto/sha512_final.c @@ -1,25 +1,25 @@ /* ISC license. */ -#include <skalibs/bytestr.h> +#include <string.h> + #include <skalibs/uint64.h> #include <skalibs/sha512.h> #include "sha512-internal.h" void sha512_final (SHA512Schedule *ctx, char *digest) { - unsigned int i = 0 ; - unsigned int pad = ctx->len % 128; + unsigned int pad = ctx->len & 0x7fU ; ctx->buf[pad++] = 0x80 ; if (pad > 112) { - byte_zero(ctx->buf + pad, 128 - pad) ; + memset(ctx->buf + pad, 0, 128 - pad) ; sha512_transform(ctx, ctx->buf) ; pad = 0 ; } - byte_zero(ctx->buf + pad, 120 - pad) ; + memset(ctx->buf + pad, 0, 120 - pad) ; uint64_pack_big((char *)ctx->buf + 120, ctx->len << 3) ; sha512_transform(ctx, ctx->buf) ; - for (; i < 8 ; i++) uint64_pack_big(digest + (i << 3), ctx->h[i]) ; + for (unsigned int i = 0 ; i < 8 ; i++) uint64_pack_big(digest + (i << 3), ctx->h[i]) ; } diff --git a/src/libstdcrypto/sha512_update.c b/src/libstdcrypto/sha512_update.c index a6c004f..7235226 100644 --- a/src/libstdcrypto/sha512_update.c +++ b/src/libstdcrypto/sha512_update.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <string.h> + #include <skalibs/sha512.h> #include "sha512-internal.h" |