blake2b.h
Go to the documentation of this file.
1 /**
2  * @file blake2b.h
3  * @brief BLAKE2 cryptographic hash and MAC (BLAKE2b variant)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _BLAKE2B_H
32 #define _BLAKE2B_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //BLAKE2b block size
38 #define BLAKE2B_BLOCK_SIZE 128
39 
40 //C++ guard
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 /**
47  * @brief BLAKE2b algorithm context
48  **/
49 
50 typedef struct
51 {
52  union
53  {
54  uint64_t h[8];
55  uint8_t digest[64];
56  };
57  union
58  {
59  uint64_t m[16];
60  uint8_t buffer[128];
61  };
62  size_t size;
63  uint64_t totalSize[2];
64  size_t digestSize;
66 
67 
68 //BLAKE2b related functions
69 error_t blake2bCompute(const void *key, size_t keyLen, const void *data,
70  size_t dataLen, uint8_t *digest, size_t digestLen);
71 
72 error_t blake2bInit(Blake2bContext *context, const void *key,
73  size_t keyLen, size_t digestLen);
74 
75 void blake2bUpdate(Blake2bContext *context, const void *data, size_t length);
76 void blake2bFinal(Blake2bContext *context, uint8_t *digest);
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
error_t blake2bCompute(const void *key, size_t keyLen, const void *data, size_t dataLen, uint8_t *digest, size_t digestLen)
Digest a message using BLAKE2b.
Definition: blake2b.c:100
void blake2bUpdate(Blake2bContext *context, const void *data, size_t length)
Update the BLAKE2b context with a portion of the message being hashed.
Definition: blake2b.c:223
void blake2bProcessBlock(Blake2bContext *context, bool_t last)
Compression function F.
Definition: blake2b.c:294
void blake2bFinal(Blake2bContext *context, uint8_t *digest)
Finish the BLAKE2b message digest.
Definition: blake2b.c:261
error_t blake2bInit(Blake2bContext *context, const void *key, size_t keyLen, size_t digestLen)
Initialize BLAKE2b message digest context.
Definition: blake2b.c:156
int bool_t
Definition: compiler_port.h:53
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
uint16_t last
Definition: ipv4_frag.h:105
uint8_t h
Definition: ndp.h:302
uint8_t m
Definition: ndp.h:304
uint32_t dataLen
Definition: sftp_common.h:229
BLAKE2b algorithm context.
Definition: blake2b.h:51
size_t size
Definition: blake2b.h:62
size_t digestSize
Definition: blake2b.h:64
uint8_t length
Definition: tcp.h:368