mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-12 16:50:21 +00:00
TLS client implementation
This commit is contained in:
1 parent
091ebd8a98
commit
ba678b9ad1
27 files changed
+6176
-4564
No files matched your search
+11
-4
@@ -1,3 +1,9 @@
|
||||
// https://github.com/B-Con/crypto-algorithms
|
||||
// Author: Brad Conte (brad AT bradconte.com)
|
||||
// Disclaimer: This code is presented "as is" without any guarantees.
|
||||
// Details: Defines the API for the corresponding SHA1 implementation.
|
||||
// Copyright: public domain
|
||||
|
||||
#include "sha256.h"
|
||||
|
||||
#define ror(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
||||
@@ -39,8 +45,10 @@ static void mg_sha256_chunk(mg_sha256_ctx *ctx) {
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
uint32_t m[64];
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4)
|
||||
m[i] = (uint32_t) ((ctx->buffer[j] << 24) | (ctx->buffer[j + 1] << 16) |
|
||||
(ctx->buffer[j + 2] << 8) | (ctx->buffer[j + 3]));
|
||||
m[i] = (uint32_t) (((uint32_t) ctx->buffer[j] << 24) |
|
||||
((uint32_t) ctx->buffer[j + 1] << 16) |
|
||||
((uint32_t) ctx->buffer[j + 2] << 8) |
|
||||
((uint32_t) ctx->buffer[j + 3]));
|
||||
for (; i < 64; ++i)
|
||||
m[i] = sig1(m[i - 2]) + m[i - 7] + sig0(m[i - 15]) + m[i - 16];
|
||||
|
||||
@@ -138,7 +146,7 @@ void mg_hmac_sha256(uint8_t dst[32], uint8_t *key, size_t keysz, uint8_t *data,
|
||||
memset(i_pad, 0x36, sizeof(i_pad));
|
||||
memset(o_pad, 0x5c, sizeof(o_pad));
|
||||
if (keysz < 64) {
|
||||
memmove(k, key, keysz);
|
||||
if (keysz > 0) memmove(k, key, keysz);
|
||||
} else {
|
||||
mg_sha256_init(&ctx);
|
||||
mg_sha256_update(&ctx, key, keysz);
|
||||
@@ -157,4 +165,3 @@ void mg_hmac_sha256(uint8_t dst[32], uint8_t *key, size_t keysz, uint8_t *data,
|
||||
mg_sha256_update(&ctx, dst, 32);
|
||||
mg_sha256_final(dst, &ctx);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user