meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions

View File

@@ -1,7 +1,7 @@
#include "hash.h"
#include <blue/core/hash.h>
#include <blue/core/rope.h>
#include <fx/core/hash.h>
#include <fx/core/rope.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
@@ -10,46 +10,46 @@
#define FNV1_OFFSET_BASIS 0xcbf29ce484222325
#define FNV1_PRIME 0x100000001b3
extern struct b_hash_function_ops z__b_md4_ops;
extern struct b_hash_function_ops z__b_md5_ops;
extern struct b_hash_function_ops z__b_sha1_ops;
extern struct b_hash_function_ops z__b_sha2_224_ops;
extern struct b_hash_function_ops z__b_sha2_256_ops;
extern struct b_hash_function_ops z__b_sha2_384_ops;
extern struct b_hash_function_ops z__b_sha2_512_ops;
extern struct b_hash_function_ops z__b_sha3_224_ops;
extern struct b_hash_function_ops z__b_sha3_256_ops;
extern struct b_hash_function_ops z__b_sha3_384_ops;
extern struct b_hash_function_ops z__b_sha3_512_ops;
extern struct b_hash_function_ops z__b_shake128_ops;
extern struct b_hash_function_ops z__b_shake256_ops;
extern struct fx_hash_function_ops z__fx_md4_ops;
extern struct fx_hash_function_ops z__fx_md5_ops;
extern struct fx_hash_function_ops z__fx_sha1_ops;
extern struct fx_hash_function_ops z__fx_sha2_224_ops;
extern struct fx_hash_function_ops z__fx_sha2_256_ops;
extern struct fx_hash_function_ops z__fx_sha2_384_ops;
extern struct fx_hash_function_ops z__fx_sha2_512_ops;
extern struct fx_hash_function_ops z__fx_sha3_224_ops;
extern struct fx_hash_function_ops z__fx_sha3_256_ops;
extern struct fx_hash_function_ops z__fx_sha3_384_ops;
extern struct fx_hash_function_ops z__fx_sha3_512_ops;
extern struct fx_hash_function_ops z__fx_shake128_ops;
extern struct fx_hash_function_ops z__fx_shake256_ops;
static const struct b_hash_function_ops *hash_functions[] = {
[B_HASH_NONE] = NULL,
[B_HASH_MD4] = &z__b_md4_ops,
[B_HASH_MD5] = &z__b_md5_ops,
[B_HASH_SHA1] = &z__b_sha1_ops,
[B_HASH_SHA2_224] = &z__b_sha2_224_ops,
[B_HASH_SHA2_256] = &z__b_sha2_256_ops,
[B_HASH_SHA2_384] = &z__b_sha2_384_ops,
[B_HASH_SHA2_512] = &z__b_sha2_512_ops,
[B_HASH_SHA3_224] = &z__b_sha3_224_ops,
[B_HASH_SHA3_256] = &z__b_sha3_256_ops,
[B_HASH_SHA3_384] = &z__b_sha3_384_ops,
[B_HASH_SHA3_512] = &z__b_sha3_512_ops,
[B_HASH_SHAKE128] = &z__b_shake128_ops,
[B_HASH_SHAKE256] = &z__b_shake256_ops,
static const struct fx_hash_function_ops *hash_functions[] = {
[FX_HASH_NONE] = NULL,
[FX_HASH_MD4] = &z__fx_md4_ops,
[FX_HASH_MD5] = &z__fx_md5_ops,
[FX_HASH_SHA1] = &z__fx_sha1_ops,
[FX_HASH_SHA2_224] = &z__fx_sha2_224_ops,
[FX_HASH_SHA2_256] = &z__fx_sha2_256_ops,
[FX_HASH_SHA2_384] = &z__fx_sha2_384_ops,
[FX_HASH_SHA2_512] = &z__fx_sha2_512_ops,
[FX_HASH_SHA3_224] = &z__fx_sha3_224_ops,
[FX_HASH_SHA3_256] = &z__fx_sha3_256_ops,
[FX_HASH_SHA3_384] = &z__fx_sha3_384_ops,
[FX_HASH_SHA3_512] = &z__fx_sha3_512_ops,
[FX_HASH_SHAKE128] = &z__fx_shake128_ops,
[FX_HASH_SHAKE256] = &z__fx_shake256_ops,
};
static const size_t nr_hash_functions
= sizeof hash_functions / sizeof hash_functions[0];
uint64_t b_hash_cstr(const char *s)
uint64_t fx_hash_cstr(const char *s)
{
size_t x = 0;
return b_hash_cstr_ex(s, &x);
return fx_hash_cstr_ex(s, &x);
}
uint64_t b_hash_cstr_ex(const char *s, size_t *len)
uint64_t fx_hash_cstr_ex(const char *s, size_t *len)
{
uint64_t hash = FNV1_OFFSET_BASIS;
size_t i = 0;
@@ -66,15 +66,15 @@ uint64_t b_hash_cstr_ex(const char *s, size_t *len)
return hash;
}
enum b_status b_hash_ctx_init(struct b_hash_ctx *ctx, enum b_hash_function func)
enum fx_status fx_hash_ctx_init(struct fx_hash_ctx *ctx, enum fx_hash_function func)
{
if (func < 0 || func >= nr_hash_functions) {
return B_ERR_NOT_SUPPORTED;
return FX_ERR_NOT_SUPPORTED;
}
const struct b_hash_function_ops *hash_function = hash_functions[func];
const struct fx_hash_function_ops *hash_function = hash_functions[func];
if (!hash_function) {
return B_ERR_NOT_SUPPORTED;
return FX_ERR_NOT_SUPPORTED;
}
memset(ctx, 0x0, sizeof *ctx);
@@ -86,13 +86,13 @@ enum b_status b_hash_ctx_init(struct b_hash_ctx *ctx, enum b_hash_function func)
hash_function->hash_init(ctx);
}
return B_SUCCESS;
return FX_SUCCESS;
}
enum b_status b_hash_ctx_reset(struct b_hash_ctx *ctx)
enum fx_status fx_hash_ctx_reset(struct fx_hash_ctx *ctx)
{
if (ctx->ctx_func == B_HASH_NONE || !ctx->ctx_ops) {
return B_ERR_BAD_STATE;
if (ctx->ctx_func == FX_HASH_NONE || !ctx->ctx_ops) {
return FX_ERR_BAD_STATE;
}
memset(&ctx->ctx_state, 0x0, sizeof ctx->ctx_state);
@@ -101,69 +101,69 @@ enum b_status b_hash_ctx_reset(struct b_hash_ctx *ctx)
ctx->ctx_ops->hash_init(ctx);
}
return B_SUCCESS;
return FX_SUCCESS;
}
enum b_status b_hash_ctx_update(struct b_hash_ctx *ctx, const void *p, size_t len)
enum fx_status fx_hash_ctx_update(struct fx_hash_ctx *ctx, const void *p, size_t len)
{
if (!ctx->ctx_ops) {
return B_ERR_BAD_STATE;
return FX_ERR_BAD_STATE;
}
if (!ctx->ctx_ops->hash_update) {
return B_ERR_NOT_SUPPORTED;
return FX_ERR_NOT_SUPPORTED;
}
ctx->ctx_ops->hash_update(ctx, p, len);
return B_SUCCESS;
return FX_SUCCESS;
}
static void update_rope(const b_rope *rope, void *arg)
static void update_rope(const fx_rope *rope, void *arg)
{
struct b_hash_ctx *ctx = arg;
unsigned int type = B_ROPE_TYPE(rope->r_flags);
struct fx_hash_ctx *ctx = arg;
unsigned int type = FX_ROPE_TYPE(rope->r_flags);
char tmp[64];
size_t len = 0;
switch (type) {
case B_ROPE_F_CHAR:
b_hash_ctx_update(ctx, &rope->r_v.v_char, sizeof rope->r_v.v_char);
case FX_ROPE_F_CHAR:
fx_hash_ctx_update(ctx, &rope->r_v.v_char, sizeof rope->r_v.v_char);
break;
case B_ROPE_F_CSTR:
case B_ROPE_F_CSTR_BORROWED:
case B_ROPE_F_CSTR_STATIC:
b_hash_ctx_update(
case FX_ROPE_F_CSTR:
case FX_ROPE_F_CSTR_BORROWED:
case FX_ROPE_F_CSTR_STATIC:
fx_hash_ctx_update(
ctx, rope->r_v.v_cstr.s, strlen(rope->r_v.v_cstr.s));
break;
case B_ROPE_F_INT:
case FX_ROPE_F_INT:
len = snprintf(tmp, sizeof tmp, "%" PRIdPTR, rope->r_v.v_int);
b_hash_ctx_update(ctx, tmp, len);
fx_hash_ctx_update(ctx, tmp, len);
break;
case B_ROPE_F_UINT:
case FX_ROPE_F_UINT:
len = snprintf(tmp, sizeof tmp, "%" PRIuPTR, rope->r_v.v_uint);
b_hash_ctx_update(ctx, tmp, len);
fx_hash_ctx_update(ctx, tmp, len);
break;
default:
break;
}
}
enum b_status b_hash_ctx_update_rope(
struct b_hash_ctx *ctx, const struct b_rope *rope)
enum fx_status fx_hash_ctx_update_rope(
struct fx_hash_ctx *ctx, const struct fx_rope *rope)
{
b_rope_iterate(rope, update_rope, ctx);
return B_SUCCESS;
fx_rope_iterate(rope, update_rope, ctx);
return FX_SUCCESS;
}
enum b_status b_hash_ctx_finish(
struct b_hash_ctx *ctx, void *out_digest, size_t out_max)
enum fx_status fx_hash_ctx_finish(
struct fx_hash_ctx *ctx, void *out_digest, size_t out_max)
{
if (!ctx->ctx_ops) {
return B_ERR_BAD_STATE;
return FX_ERR_BAD_STATE;
}
if (!ctx->ctx_ops->hash_finish) {
return B_ERR_NOT_SUPPORTED;
return FX_ERR_NOT_SUPPORTED;
}
ctx->ctx_ops->hash_finish(ctx, out_digest, out_max);
@@ -174,5 +174,5 @@ enum b_status b_hash_ctx_finish(
ctx->ctx_ops->hash_init(ctx);
}
return B_SUCCESS;
return FX_SUCCESS;
}

View File

@@ -3,12 +3,12 @@
#include <stddef.h>
struct b_hash_ctx;
struct fx_hash_ctx;
struct b_hash_function_ops {
void (*hash_init)(struct b_hash_ctx *);
void (*hash_update)(struct b_hash_ctx *, const void *, size_t);
void (*hash_finish)(struct b_hash_ctx *, void *, size_t);
struct fx_hash_function_ops {
void (*hash_init)(struct fx_hash_ctx *);
void (*hash_update)(struct fx_hash_ctx *, const void *, size_t);
void (*hash_finish)(struct fx_hash_ctx *, void *, size_t);
};
#endif

View File

@@ -36,7 +36,7 @@
*/
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <stdint.h>
#include <string.h>
@@ -88,7 +88,7 @@
* This processes one or more 64-byte data blocks, but does NOT update the bit
* counters. There are no alignment requirements.
*/
static const void *body(struct b_hash_ctx *ctx, const void *data, unsigned long size)
static const void *body(struct fx_hash_ctx *ctx, const void *data, unsigned long size)
{
const unsigned char *ptr;
uint32_t a, b, c, d;
@@ -178,7 +178,7 @@ static const void *body(struct b_hash_ctx *ctx, const void *data, unsigned long
return ptr;
}
void md4_init(struct b_hash_ctx *ctx)
void md4_init(struct fx_hash_ctx *ctx)
{
ctx->ctx_state.md4.a = 0x67452301;
ctx->ctx_state.md4.b = 0xefcdab89;
@@ -189,7 +189,7 @@ void md4_init(struct b_hash_ctx *ctx)
ctx->ctx_state.md4.hi = 0;
}
void md4_update(struct b_hash_ctx *ctx, const void *data, unsigned long size)
void md4_update(struct fx_hash_ctx *ctx, const void *data, unsigned long size)
{
uint32_t saved_lo;
unsigned long used, available;
@@ -229,7 +229,7 @@ void md4_update(struct b_hash_ctx *ctx, const void *data, unsigned long size)
(dst)[2] = (unsigned char)((src) >> 16); \
(dst)[3] = (unsigned char)((src) >> 24);
void md4_finish(struct b_hash_ctx *ctx, void *out, size_t max)
void md4_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char *result = out;
unsigned long used, available;
@@ -261,7 +261,7 @@ void md4_finish(struct b_hash_ctx *ctx, void *out, size_t max)
OUT(&result[12], ctx->ctx_state.md4.d)
}
struct b_hash_function_ops z__b_md4_ops = {
struct fx_hash_function_ops z__fx_md4_ops = {
.hash_init = md4_init,
.hash_update = md4_update,
.hash_finish = md4_finish,

View File

@@ -3,7 +3,7 @@
* and is in the public domain. */
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <memory.h>
#include <stdint.h>
#include <stdio.h>
@@ -19,7 +19,7 @@
#define STEP(f, a, b, c, d, x, t, s) \
(a += f(b, c, d) + x + t, a = ROTATE_LEFT(a, s), a += b)
void md5_init(struct b_hash_ctx *ctx)
void md5_init(struct fx_hash_ctx *ctx)
{
ctx->ctx_state.md5.a = 0x67452301;
ctx->ctx_state.md5.b = 0xefcdab89;
@@ -30,7 +30,7 @@ void md5_init(struct b_hash_ctx *ctx)
ctx->ctx_state.md5.count[1] = 0;
}
uint8_t *md5_transform(struct b_hash_ctx *ctx, const void *data, uintmax_t size)
uint8_t *md5_transform(struct fx_hash_ctx *ctx, const void *data, uintmax_t size)
{
uint8_t *ptr = (uint8_t *)data;
uint32_t a, b, c, d, aa, bb, cc, dd;
@@ -140,7 +140,7 @@ uint8_t *md5_transform(struct b_hash_ctx *ctx, const void *data, uintmax_t size)
return ptr;
}
void md5_update(struct b_hash_ctx *ctx, const void *buffer, size_t buffer_size)
void md5_update(struct fx_hash_ctx *ctx, const void *buffer, size_t buffer_size)
{
uint32_t saved_low = ctx->ctx_state.md5.count[0];
uint32_t used;
@@ -178,7 +178,7 @@ void md5_update(struct b_hash_ctx *ctx, const void *buffer, size_t buffer_size)
memcpy(ctx->ctx_state.md5.input, buffer, buffer_size);
}
void md5_finish(struct b_hash_ctx *ctx, void *out, size_t max)
void md5_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
uint32_t used = ctx->ctx_state.md5.count[0] & 0x3f;
ctx->ctx_state.md5.input[used++] = 0x80;
@@ -193,7 +193,7 @@ void md5_finish(struct b_hash_ctx *ctx, void *out, size_t max)
memset(&ctx->ctx_state.md5.input[used], 0, free - 8);
unsigned char digest[B_DIGEST_LENGTH_MD5];
unsigned char digest[FX_DIGEST_LENGTH_MD5];
ctx->ctx_state.md5.count[0] <<= 3;
ctx->ctx_state.md5.input[56] = (uint8_t)(ctx->ctx_state.md5.count[0]);
@@ -228,10 +228,10 @@ void md5_finish(struct b_hash_ctx *ctx, void *out, size_t max)
digest[14] = (uint8_t)(ctx->ctx_state.md5.d >> 16);
digest[15] = (uint8_t)(ctx->ctx_state.md5.d >> 24);
memcpy(out, digest, b_min(size_t, sizeof digest, max));
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
}
struct b_hash_function_ops z__b_md5_ops = {
struct fx_hash_function_ops z__fx_md5_ops = {
.hash_init = md5_init,
.hash_update = md5_update,
.hash_finish = md5_finish,

View File

@@ -19,7 +19,7 @@ A million repetitions of "a"
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <stdio.h>
#include <string.h>
@@ -187,7 +187,7 @@ void SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
/* sha_init - Initialize new context */
static void sha_init(struct b_hash_ctx *context)
static void sha_init(struct fx_hash_ctx *context)
{
/* SHA1 initialization constants */
context->ctx_state.sha1.state[0] = 0x67452301;
@@ -200,7 +200,7 @@ static void sha_init(struct b_hash_ctx *context)
/* Run your data through this. */
static void sha_update(struct b_hash_ctx *context, const void *p, size_t len)
static void sha_update(struct fx_hash_ctx *context, const void *p, size_t len)
{
const unsigned char *data = p;
uint32_t i, j;
@@ -226,7 +226,7 @@ static void sha_update(struct b_hash_ctx *context, const void *p, size_t len)
/* Add padding and return the message digest. */
static void sha_finish(struct b_hash_ctx *context, void *out, size_t max)
static void sha_finish(struct fx_hash_ctx *context, void *out, size_t max)
{
unsigned i;
@@ -241,7 +241,7 @@ static void sha_finish(struct b_hash_ctx *context, void *out, size_t max)
& 255); /* Endian independent */
}
char digest[B_DIGEST_LENGTH_SHA1];
char digest[FX_DIGEST_LENGTH_SHA1];
c = 0200;
sha_update(context, &c, 1);
while ((context->ctx_state.sha1.count[0] & 504) != 448) {
@@ -255,12 +255,12 @@ static void sha_finish(struct b_hash_ctx *context, void *out, size_t max)
& 255);
}
memcpy(out, digest, b_min(size_t, sizeof digest, max));
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
/* Wipe variables */
memset(&finalcount, '\0', sizeof(finalcount));
}
struct b_hash_function_ops z__b_sha1_ops = {
struct fx_hash_function_ops z__fx_sha1_ops = {
.hash_init = sha_init,
.hash_update = sha_update,
.hash_finish = sha_finish,

View File

@@ -1,14 +1,14 @@
// SHA-224. Adapted from LibTomCrypt. This code is Public Domain
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <string.h>
extern void z__b_sha2_256_update(
struct b_hash_ctx *md, const void *src, size_t inlen);
extern void z__b_sha2_256_finish(struct b_hash_ctx *md, void *out, size_t max);
extern void z__fx_sha2_256_update(
struct fx_hash_ctx *md, const void *src, size_t inlen);
extern void z__fx_sha2_256_finish(struct fx_hash_ctx *md, void *out, size_t max);
static void sha_init(struct b_hash_ctx *md)
static void sha_init(struct fx_hash_ctx *md)
{
md->ctx_state.sha2_256.curlen = 0;
md->ctx_state.sha2_256.length = 0;
@@ -22,20 +22,20 @@ static void sha_init(struct b_hash_ctx *md)
md->ctx_state.sha2_256.state[7] = 0xbefa4fa4UL;
}
static void sha_update(struct b_hash_ctx *md, const void *in, size_t inlen)
static void sha_update(struct fx_hash_ctx *md, const void *in, size_t inlen)
{
z__b_sha2_256_update(md, in, inlen);
z__fx_sha2_256_update(md, in, inlen);
}
static void sha_finish(struct b_hash_ctx *md, void *out, size_t max)
static void sha_finish(struct fx_hash_ctx *md, void *out, size_t max)
{
unsigned char res[B_DIGEST_LENGTH_SHA2_256];
z__b_sha2_256_finish(md, res, max);
unsigned char res[FX_DIGEST_LENGTH_SHA2_256];
z__fx_sha2_256_finish(md, res, max);
/* truncate the digest to 224 bits */
memcpy(out, res, b_min(size_t, max, B_DIGEST_LENGTH_224));
memcpy(out, res, fx_min(size_t, max, FX_DIGEST_LENGTH_224));
}
struct b_hash_function_ops z__b_sha2_224_ops = {
struct fx_hash_function_ops z__fx_sha2_224_ops = {
.hash_init = sha_init,
.hash_update = sha_update,
.hash_finish = sha_finish,

View File

@@ -1,7 +1,7 @@
// SHA-256. Adapted from LibTomCrypt. This code is Public Domain
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <string.h>
static const uint32_t K[64] = {
@@ -87,7 +87,7 @@ static void RND(
(*h) = *t0 + *t1;
}
static void sha_compress(struct b_hash_ctx *md, const unsigned char *buf)
static void sha_compress(struct fx_hash_ctx *md, const unsigned char *buf)
{
uint32_t S[8], W[64], t0, t1, t;
@@ -127,7 +127,7 @@ static void sha_compress(struct b_hash_ctx *md, const unsigned char *buf)
// Public interface
static void sha_init(struct b_hash_ctx *md)
static void sha_init(struct fx_hash_ctx *md)
{
md->ctx_state.sha2_256.curlen = 0;
md->ctx_state.sha2_256.length = 0;
@@ -141,7 +141,7 @@ static void sha_init(struct b_hash_ctx *md)
md->ctx_state.sha2_256.state[7] = 0x5BE0CD19UL;
}
void z__b_sha2_256_update(struct b_hash_ctx *md, const void *src, size_t inlen)
void z__fx_sha2_256_update(struct fx_hash_ctx *md, const void *src, size_t inlen)
{
const uint32_t block_size = sizeof md->ctx_state.sha2_256.buf;
const unsigned char *in = (const unsigned char *)(src);
@@ -171,7 +171,7 @@ void z__b_sha2_256_update(struct b_hash_ctx *md, const void *src, size_t inlen)
}
}
}
void z__b_sha2_256_finish(struct b_hash_ctx *md, void *out, size_t max)
void z__fx_sha2_256_finish(struct fx_hash_ctx *md, void *out, size_t max)
{
// Increase the length of the message
md->ctx_state.sha2_256.length += md->ctx_state.sha2_256.curlen * 8;
@@ -198,18 +198,18 @@ void z__b_sha2_256_finish(struct b_hash_ctx *md, void *out, size_t max)
store64(md->ctx_state.sha2_256.length, md->ctx_state.sha2_256.buf + 56);
sha_compress(md, md->ctx_state.sha2_256.buf);
unsigned char digest[B_DIGEST_LENGTH_SHA2_256];
unsigned char digest[FX_DIGEST_LENGTH_SHA2_256];
// Copy output
for (int i = 0; i < 8; i++)
store32(md->ctx_state.sha2_256.state[i],
(unsigned char *)&digest[(4 * i)]);
memcpy(out, digest, b_min(size_t, sizeof digest, max));
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
}
struct b_hash_function_ops z__b_sha2_256_ops = {
struct fx_hash_function_ops z__fx_sha2_256_ops = {
.hash_init = sha_init,
.hash_update = z__b_sha2_256_update,
.hash_finish = z__b_sha2_256_finish,
.hash_update = z__fx_sha2_256_update,
.hash_finish = z__fx_sha2_256_finish,
};

View File

@@ -1,14 +1,14 @@
// SHA-384. Adapted from LibTomCrypt. This code is Public Domain
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <string.h>
extern void z__b_sha2_512_update(
struct b_hash_ctx *md, const void *src, size_t inlen);
extern void z__b_sha2_512_finish(struct b_hash_ctx *md, void *out, size_t max);
extern void z__fx_sha2_512_update(
struct fx_hash_ctx *md, const void *src, size_t inlen);
extern void z__fx_sha2_512_finish(struct fx_hash_ctx *md, void *out, size_t max);
void sha_init(struct b_hash_ctx *md)
void sha_init(struct fx_hash_ctx *md)
{
md->ctx_state.sha2_512.curlen = 0;
md->ctx_state.sha2_512.length = 0;
@@ -22,20 +22,20 @@ void sha_init(struct b_hash_ctx *md)
md->ctx_state.sha2_512.state[7] = 0x47b5481dbefa4fa4ULL;
}
static void sha_update(struct b_hash_ctx *md, const void *in, size_t inlen)
static void sha_update(struct fx_hash_ctx *md, const void *in, size_t inlen)
{
z__b_sha2_512_update(md, in, inlen);
z__fx_sha2_512_update(md, in, inlen);
}
static void sha_finish(struct b_hash_ctx *md, void *out, size_t max)
static void sha_finish(struct fx_hash_ctx *md, void *out, size_t max)
{
unsigned char res[B_DIGEST_LENGTH_SHA2_512];
z__b_sha2_512_finish(md, res, max);
unsigned char res[FX_DIGEST_LENGTH_SHA2_512];
z__fx_sha2_512_finish(md, res, max);
/* truncate the digest to 384 bits */
memcpy(out, res, b_min(size_t, max, B_DIGEST_LENGTH_384));
memcpy(out, res, fx_min(size_t, max, FX_DIGEST_LENGTH_384));
}
struct b_hash_function_ops z__b_sha2_384_ops = {
struct fx_hash_function_ops z__fx_sha2_384_ops = {
.hash_init = sha_init,
.hash_update = sha_update,
.hash_finish = sha_finish,

View File

@@ -1,7 +1,7 @@
// SHA-512. Adapted from LibTomCrypt. This code is Public Domain
#include "hash.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <stdint.h>
#include <string.h>
@@ -96,7 +96,7 @@ static void RND(
*h = *t0 + *t1;
}
static void sha_compress(struct b_hash_ctx *md, const unsigned char *buf)
static void sha_compress(struct fx_hash_ctx *md, const unsigned char *buf)
{
uint64_t S[8], W[80], t0, t1;
@@ -144,7 +144,7 @@ static void sha_compress(struct b_hash_ctx *md, const unsigned char *buf)
// Public interface
static void sha_init(struct b_hash_ctx *md)
static void sha_init(struct fx_hash_ctx *md)
{
md->ctx_state.sha2_512.curlen = 0;
md->ctx_state.sha2_512.length = 0;
@@ -158,7 +158,7 @@ static void sha_init(struct b_hash_ctx *md)
md->ctx_state.sha2_512.state[7] = 0x5be0cd19137e2179ULL;
}
void z__b_sha2_512_update(struct b_hash_ctx *md, const void *src, size_t inlen)
void z__fx_sha2_512_update(struct fx_hash_ctx *md, const void *src, size_t inlen)
{
const uint32_t block_size = sizeof md->ctx_state.sha2_512.block;
const unsigned char *in = (const unsigned char *)src;
@@ -189,7 +189,7 @@ void z__b_sha2_512_update(struct b_hash_ctx *md, const void *src, size_t inlen)
}
}
void z__b_sha2_512_finish(struct b_hash_ctx *md, void *out, size_t max)
void z__fx_sha2_512_finish(struct fx_hash_ctx *md, void *out, size_t max)
{
// Increase the length of the message
md->ctx_state.sha2_512.length += md->ctx_state.sha2_512.curlen * 8ULL;
@@ -218,7 +218,7 @@ void z__b_sha2_512_finish(struct b_hash_ctx *md, void *out, size_t max)
store64(md->ctx_state.sha2_512.length, md->ctx_state.sha2_512.block + 120);
sha_compress(md, md->ctx_state.sha2_512.block);
unsigned char digest[B_DIGEST_LENGTH_SHA2_512];
unsigned char digest[FX_DIGEST_LENGTH_SHA2_512];
// Copy output
for (int i = 0; i < 8; i++) {
@@ -226,11 +226,11 @@ void z__b_sha2_512_finish(struct b_hash_ctx *md, void *out, size_t max)
(unsigned char *)&digest[(8 * i)]);
}
memcpy(out, digest, b_min(size_t, sizeof digest, max));
memcpy(out, digest, fx_min(size_t, sizeof digest, max));
}
struct b_hash_function_ops z__b_sha2_512_ops = {
struct fx_hash_function_ops z__fx_sha2_512_ops = {
.hash_init = sha_init,
.hash_update = z__b_sha2_512_update,
.hash_finish = z__b_sha2_512_finish,
.hash_update = z__fx_sha2_512_update,
.hash_finish = z__fx_sha2_512_finish,
};

View File

@@ -30,8 +30,8 @@
#include "hash.h"
#include <blue/core/hash.h>
#include <blue/core/misc.h>
#include <fx/core/hash.h>
#include <fx/core/misc.h>
#include <string.h>
#ifndef KECCAKF_ROUNDS
@@ -134,7 +134,7 @@ void sha3_keccakf(uint64_t st[25])
// Initialize the context for SHA3
int sha3_init(struct b_hash_ctx *c, int mdlen)
int sha3_init(struct fx_hash_ctx *c, int mdlen)
{
int i;
@@ -149,7 +149,7 @@ int sha3_init(struct b_hash_ctx *c, int mdlen)
// update state with more data
void sha3_update(struct b_hash_ctx *c, const void *data, size_t len)
void sha3_update(struct fx_hash_ctx *c, const void *data, size_t len)
{
size_t i;
int j;
@@ -168,7 +168,7 @@ void sha3_update(struct b_hash_ctx *c, const void *data, size_t len)
// finalize and output a hash
int sha3_final(void *md, struct b_hash_ctx *c)
int sha3_final(void *md, struct fx_hash_ctx *c)
{
int i;
@@ -187,7 +187,7 @@ int sha3_final(void *md, struct b_hash_ctx *c)
void *sha3(const void *in, size_t inlen, void *md, int mdlen)
{
struct b_hash_ctx sha3;
struct fx_hash_ctx sha3;
sha3_init(&sha3, mdlen);
sha3_update(&sha3, in, inlen);
@@ -198,7 +198,7 @@ void *sha3(const void *in, size_t inlen, void *md, int mdlen)
// SHAKE128 and SHAKE256 extensible-output functionality
void shake_xof(struct b_hash_ctx *c)
void shake_xof(struct fx_hash_ctx *c)
{
c->ctx_state.sha3.st.b[c->ctx_state.sha3.pt] ^= 0x1F;
c->ctx_state.sha3.st.b[c->ctx_state.sha3.rsiz - 1] ^= 0x80;
@@ -206,7 +206,7 @@ void shake_xof(struct b_hash_ctx *c)
c->ctx_state.sha3.pt = 0;
}
void shake_out(struct b_hash_ctx *c, void *out, size_t len)
void shake_out(struct fx_hash_ctx *c, void *out, size_t len)
{
size_t i;
int j;
@@ -222,111 +222,111 @@ void shake_out(struct b_hash_ctx *c, void *out, size_t len)
c->ctx_state.sha3.pt = j;
}
static void sha3_224_init(struct b_hash_ctx *ctx)
static void sha3_224_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHA3_224);
sha3_init(ctx, FX_DIGEST_LENGTH_SHA3_224);
}
static void sha3_224_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void sha3_224_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHA3_224];
unsigned char md[FX_DIGEST_LENGTH_SHA3_224];
sha3_final(md, ctx);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
static void sha3_256_init(struct b_hash_ctx *ctx)
static void sha3_256_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHA3_256);
sha3_init(ctx, FX_DIGEST_LENGTH_SHA3_256);
}
static void sha3_256_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void sha3_256_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHA3_256];
unsigned char md[FX_DIGEST_LENGTH_SHA3_256];
sha3_final(md, ctx);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
static void sha3_384_init(struct b_hash_ctx *ctx)
static void sha3_384_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHA3_384);
sha3_init(ctx, FX_DIGEST_LENGTH_SHA3_384);
}
static void sha3_384_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void sha3_384_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHA3_384];
unsigned char md[FX_DIGEST_LENGTH_SHA3_384];
sha3_final(md, ctx);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
static void sha3_512_init(struct b_hash_ctx *ctx)
static void sha3_512_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHA3_512);
sha3_init(ctx, FX_DIGEST_LENGTH_SHA3_512);
}
static void sha3_512_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void sha3_512_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHA3_512];
unsigned char md[FX_DIGEST_LENGTH_SHA3_512];
sha3_final(md, ctx);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
static void shake128_init(struct b_hash_ctx *ctx)
static void shake128_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHAKE128);
sha3_init(ctx, FX_DIGEST_LENGTH_SHAKE128);
}
static void shake128_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void shake128_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHAKE128];
unsigned char md[FX_DIGEST_LENGTH_SHAKE128];
shake_xof(ctx);
shake_out(ctx, md, sizeof md);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
static void shake256_init(struct b_hash_ctx *ctx)
static void shake256_init(struct fx_hash_ctx *ctx)
{
sha3_init(ctx, B_DIGEST_LENGTH_SHAKE256);
sha3_init(ctx, FX_DIGEST_LENGTH_SHAKE256);
}
static void shake256_finish(struct b_hash_ctx *ctx, void *out, size_t max)
static void shake256_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
{
unsigned char md[B_DIGEST_LENGTH_SHAKE256];
unsigned char md[FX_DIGEST_LENGTH_SHAKE256];
shake_xof(ctx);
shake_out(ctx, md, sizeof md);
memcpy(out, md, b_min(size_t, sizeof md, max));
memcpy(out, md, fx_min(size_t, sizeof md, max));
}
struct b_hash_function_ops z__b_sha3_224_ops = {
struct fx_hash_function_ops z__fx_sha3_224_ops = {
.hash_init = sha3_224_init,
.hash_update = sha3_update,
.hash_finish = sha3_224_finish,
};
struct b_hash_function_ops z__b_sha3_256_ops = {
struct fx_hash_function_ops z__fx_sha3_256_ops = {
.hash_init = sha3_256_init,
.hash_update = sha3_update,
.hash_finish = sha3_256_finish,
};
struct b_hash_function_ops z__b_sha3_384_ops = {
struct fx_hash_function_ops z__fx_sha3_384_ops = {
.hash_init = sha3_384_init,
.hash_update = sha3_update,
.hash_finish = sha3_384_finish,
};
struct b_hash_function_ops z__b_sha3_512_ops = {
struct fx_hash_function_ops z__fx_sha3_512_ops = {
.hash_init = sha3_512_init,
.hash_update = sha3_update,
.hash_finish = sha3_512_finish,
};
struct b_hash_function_ops z__b_shake128_ops = {
struct fx_hash_function_ops z__fx_shake128_ops = {
.hash_init = shake128_init,
.hash_update = sha3_update,
.hash_finish = shake128_finish,
};
struct b_hash_function_ops z__b_shake256_ops = {
struct fx_hash_function_ops z__fx_shake256_ops = {
.hash_init = shake256_init,
.hash_update = sha3_update,
.hash_finish = shake256_finish,