This commit is contained in:
Steffen Jaeckel
2020-03-30 15:08:28 +02:00
parent 7ac4b1cc12
commit f2c658723f
5 changed files with 7 additions and 16 deletions

View File

@@ -113,7 +113,6 @@ static void sha256_compress(sha256_context *md, const uint8_t *buf)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
md->state[i] = md->state[i] + S[i]; md->state[i] = md->state[i] + S[i];
} }
return;
} }
void sha256_init(sha256_context *md) void sha256_init(sha256_context *md)
@@ -128,7 +127,6 @@ void sha256_init(sha256_context *md)
md->state[5] = 0x9B05688CUL; md->state[5] = 0x9B05688CUL;
md->state[6] = 0x1F83D9ABUL; md->state[6] = 0x1F83D9ABUL;
md->state[7] = 0x5BE0CD19UL; md->state[7] = 0x5BE0CD19UL;
return;
} }
void sha256_process(sha256_context *md, const uint8_t *in, size_t inlen) void sha256_process(sha256_context *md, const uint8_t *in, size_t inlen)
@@ -160,7 +158,6 @@ void sha256_process(sha256_context *md, const uint8_t *in, size_t inlen)
} }
} }
} }
return;
} }
void sha256_done(sha256_context *md, uint8_t *out) void sha256_done(sha256_context *md, uint8_t *out)
@@ -175,7 +172,7 @@ void sha256_done(sha256_context *md, uint8_t *out)
md->length += md->curlen * 8; md->length += md->curlen * 8;
/* append the '1' bit */ /* append the '1' bit */
md->buf[md->curlen++] = (unsigned char)0x80; md->buf[md->curlen++] = (uint8_t)0x80;
/* if the length is currently above 56 bytes we append zeros /* if the length is currently above 56 bytes we append zeros
* then compress. Then we can fall back to padding zeros and length * then compress. Then we can fall back to padding zeros and length
@@ -183,7 +180,7 @@ void sha256_done(sha256_context *md, uint8_t *out)
*/ */
if (md->curlen > 56) { if (md->curlen > 56) {
while (md->curlen < 64) { while (md->curlen < 64) {
md->buf[md->curlen++] = (unsigned char)0; md->buf[md->curlen++] = (uint8_t)0;
} }
sha256_compress(md, md->buf); sha256_compress(md, md->buf);
md->curlen = 0; md->curlen = 0;
@@ -191,7 +188,7 @@ void sha256_done(sha256_context *md, uint8_t *out)
/* pad upto 56 bytes of zeroes */ /* pad upto 56 bytes of zeroes */
while (md->curlen < 56) { while (md->curlen < 56) {
md->buf[md->curlen++] = (unsigned char)0; md->buf[md->curlen++] = (uint8_t)0;
} }
/* store length */ /* store length */
@@ -202,7 +199,6 @@ void sha256_done(sha256_context *md, uint8_t *out)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
STORE32H(md->state[i], out + (4 * i)); STORE32H(md->state[i], out + (4 * i));
} }
return;
} }
void sha256_hash(const uint8_t *data, size_t len, uint8_t *digest) void sha256_hash(const uint8_t *data, size_t len, uint8_t *digest)

View File

@@ -1,4 +1,4 @@
/* public api for Thomas Pornin's BearSSL SHA-256 implementation */ /* public api for LibTomCrypt SHA-256 implementation */
/** @file /** @file
* SHA-256 hash API. * SHA-256 hash API.

View File

@@ -101,8 +101,6 @@ static void sha512_compress(sha512_context *md, const uint8_t *buf)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
md->state[i] = md->state[i] + S[i]; md->state[i] = md->state[i] + S[i];
} }
return;
} }
void sha512_init(sha512_context *md) void sha512_init(sha512_context *md)
@@ -117,7 +115,6 @@ void sha512_init(sha512_context *md)
md->state[5] = CONST64(0x9b05688c2b3e6c1f); md->state[5] = CONST64(0x9b05688c2b3e6c1f);
md->state[6] = CONST64(0x1f83d9abfb41bd6b); md->state[6] = CONST64(0x1f83d9abfb41bd6b);
md->state[7] = CONST64(0x5be0cd19137e2179); md->state[7] = CONST64(0x5be0cd19137e2179);
return;
} }
void sha512_process(sha512_context *md, const uint8_t *in, size_t inlen) void sha512_process(sha512_context *md, const uint8_t *in, size_t inlen)
@@ -149,7 +146,6 @@ void sha512_process(sha512_context *md, const uint8_t *in, size_t inlen)
} }
} }
} }
return;
} }
void sha512_done(sha512_context *md, uint8_t *out) void sha512_done(sha512_context *md, uint8_t *out)
@@ -194,7 +190,6 @@ void sha512_done(sha512_context *md, uint8_t *out)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
STORE64H(md->state[i], out + (8 * i)); STORE64H(md->state[i], out + (8 * i));
} }
return;
} }
void sha512_hash(const uint8_t *data, size_t len, uint8_t *digest) void sha512_hash(const uint8_t *data, size_t len, uint8_t *digest)

View File

@@ -1,4 +1,4 @@
/* public api for Thomas Pornin's BearSSL SHA-512 implementation */ /* public api for LibTomCrypt SHA-512 implementation */
/** @file /** @file
* SHA-512 hash API. * SHA-512 hash API.

View File

@@ -14,7 +14,7 @@ int main()
{ {
static const struct { static const struct {
const char *msg; const char *msg;
unsigned char hash[32]; unsigned char hash[SHA256_DIGEST_SIZE];
} tests[] = { } tests[] = {
{"abc", {"abc",
{0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40,
@@ -27,7 +27,7 @@ int main()
}; };
int i; int i;
unsigned char tmp[32]; unsigned char tmp[SHA256_DIGEST_SIZE];
sha256_context md; sha256_context md;
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {