deployd/server/include/blake2s.h
2025-08-02 02:03:28 +03:00

48 lines
2 KiB
C

#ifndef DEPLOYD_BLAKE2S_H_
#define DEPLOYD_BLAKE2S_H_
#include "conf.h"
#include "def.h"
#define DP_BLAKE2S_STATE_SIZE 8
#define DP_BLAKE2S_INPUT_SIZE 64
#define DP_BLAKE2S_OUTPUT_SIZE_MAX 32
#define DP_BLAKE2S_OUTPUT_SIZE_MAX_HEX 64
#define DP_BLAKE2S_SALT_SIZE 16
typedef struct {
uint32_t state[DP_BLAKE2S_STATE_SIZE]; /* Hash state */
uint8_t input[DP_BLAKE2S_INPUT_SIZE]; /* Input block */
uint8_t idx; /* Index within the input block */
uint64_t inputs; /* Input count */
uint8_t outlen; /* Output length */
uint32_t work[16], message[16]; /* Block information: vorking vector (v) and
message block (m) */
uint8_t digest[DP_BLAKE2S_OUTPUT_SIZE_MAX]; /* Output hash */
} dp_Blake2sCtx;
bool dp_Blake2sCtx_init(dp_Blake2sCtx *ctx,
uint8_t outlen,
const void *key,
uint8_t keylen);
bool dp_Blake2sCtx_update(dp_Blake2sCtx *ctx, const void *data, size_t size);
bool dp_Blake2sCtx_final(dp_Blake2sCtx *ctx);
bool dp_Blake2sCtx_to_hex(dp_Blake2sCtx *ctx, void *out);
bool dp_Blake2sCtx_to_digest(dp_Blake2sCtx *ctx, void *out);
bool dp_BLAKE2s_hash_password(const void *password,
size_t password_size,
uint8_t digest[DP_BLAKE2S_OUTPUT_SIZE_MAX],
const uint8_t salt[DP_BLAKE2S_SALT_SIZE]);
bool dp_BLAKE2s_hash_password_gen(const void *password,
size_t password_size,
uint8_t digest[DP_BLAKE2S_OUTPUT_SIZE_MAX],
uint8_t salt[DP_BLAKE2S_SALT_SIZE]);
bool dp_BLAKE2s_check_password_hash(
const void *password,
size_t password_size,
const uint8_t digest[DP_BLAKE2S_OUTPUT_SIZE_MAX],
const uint8_t salt[DP_BLAKE2S_SALT_SIZE]);
#endif /* DEPLOYD_BLAKE2S_H_ */