Path: blob/main/crypto/openssl/providers/implementations/include/prov/blake2.h
48534 views
/*1* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_PROV_BLAKE2_H10# define OSSL_PROV_BLAKE2_H1112# include <openssl/opensslconf.h>1314# include <openssl/e_os2.h>15# include <stddef.h>16# include <crypto/evp.h>1718# define BLAKE2S_BLOCKBYTES 6419# define BLAKE2S_OUTBYTES 3220# define BLAKE2S_KEYBYTES 3221# define BLAKE2S_SALTBYTES 822# define BLAKE2S_PERSONALBYTES 82324# define BLAKE2B_BLOCKBYTES 12825# define BLAKE2B_OUTBYTES 6426# define BLAKE2B_KEYBYTES 6427# define BLAKE2B_SALTBYTES 1628# define BLAKE2B_PERSONALBYTES 162930struct blake2s_param_st {31uint8_t digest_length; /* 1 */32uint8_t key_length; /* 2 */33uint8_t fanout; /* 3 */34uint8_t depth; /* 4 */35uint8_t leaf_length[4];/* 8 */36uint8_t node_offset[6];/* 14 */37uint8_t node_depth; /* 15 */38uint8_t inner_length; /* 16 */39uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */40uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */41};4243typedef struct blake2s_param_st BLAKE2S_PARAM;4445struct blake2s_ctx_st {46uint32_t h[8];47uint32_t t[2];48uint32_t f[2];49uint8_t buf[BLAKE2S_BLOCKBYTES];50size_t buflen;51size_t outlen;52};5354struct blake2b_param_st {55uint8_t digest_length; /* 1 */56uint8_t key_length; /* 2 */57uint8_t fanout; /* 3 */58uint8_t depth; /* 4 */59uint8_t leaf_length[4];/* 8 */60uint8_t node_offset[8];/* 16 */61uint8_t node_depth; /* 17 */62uint8_t inner_length; /* 18 */63uint8_t reserved[14]; /* 32 */64uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */65uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */66};6768typedef struct blake2b_param_st BLAKE2B_PARAM;6970struct blake2b_ctx_st {71uint64_t h[8];72uint64_t t[2];73uint64_t f[2];74uint8_t buf[BLAKE2B_BLOCKBYTES];75size_t buflen;76size_t outlen;77};7879#define BLAKE2B_DIGEST_LENGTH 6480#define BLAKE2S_DIGEST_LENGTH 328182typedef struct blake2s_ctx_st BLAKE2S_CTX;83typedef struct blake2b_ctx_st BLAKE2B_CTX;8485struct blake2b_md_data_st {86BLAKE2B_CTX ctx;87BLAKE2B_PARAM params;88};8990struct blake2s_md_data_st {91BLAKE2S_CTX ctx;92BLAKE2S_PARAM params;93};9495int ossl_blake2b_init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P);96int ossl_blake2b_init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P,97const void *key);98int ossl_blake2b_update(BLAKE2B_CTX *c, const void *data, size_t datalen);99int ossl_blake2b_final(unsigned char *md, BLAKE2B_CTX *c);100101OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2b_get_ctx_params;102OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2b_set_ctx_params;103OSSL_FUNC_digest_gettable_ctx_params_fn ossl_blake2b_gettable_ctx_params;104OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2b_settable_ctx_params;105106/*107* These setters are internal and do not check the validity of their parameters.108* See blake2b_mac_ctrl for validation logic.109*/110111void ossl_blake2b_param_init(BLAKE2B_PARAM *P);112void ossl_blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen);113void ossl_blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen);114void ossl_blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal,115size_t length);116void ossl_blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt,117size_t length);118int ossl_blake2s_init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P);119int ossl_blake2s_init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P,120const void *key);121int ossl_blake2s_update(BLAKE2S_CTX *c, const void *data, size_t datalen);122int ossl_blake2s_final(unsigned char *md, BLAKE2S_CTX *c);123124void ossl_blake2s_param_init(BLAKE2S_PARAM *P);125void ossl_blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen);126void ossl_blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen);127void ossl_blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal,128size_t length);129void ossl_blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt,130size_t length);131132OSSL_FUNC_digest_get_ctx_params_fn ossl_blake2s_get_ctx_params;133OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2s_set_ctx_params;134OSSL_FUNC_digest_gettable_ctx_params_fn ossl_blake2s_gettable_ctx_params;135OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2s_settable_ctx_params;136137#endif /* OSSL_PROV_BLAKE2_H */138139140