blake2b384.c
Go to the documentation of this file.
1 /**
2  * @file blake2b384.c
3  * @brief BLAKE2b-384 hash function
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "hash/blake2b384.h"
37 
38 //Check crypto library configuration
39 #if (BLAKE2B384_SUPPORT == ENABLED)
40 
41 //BLAKE2b-384 object identifier (1.3.6.1.4.1.1722.12.2.1.12)
42 const uint8_t blake2b384Oid[11] = {0x43, 0x06, 0x01, 0x04, 0x01, 0x8D, 0x3A, 0x0C, 0x02, 0x01, 0x0C};
43 
44 //Common interface for hash algorithms
46 {
47  "BLAKE2b-384",
49  sizeof(blake2b384Oid),
50  sizeof(Blake2b384Context),
54  FALSE,
59  NULL
60 };
61 
62 
63 /**
64  * @brief Digest a message using BLAKE2b-384
65  * @param[in] data Pointer to the message being hashed
66  * @param[in] length Length of the message
67  * @param[out] digest Pointer to the calculated digest
68  * @return Error code
69  **/
70 
71 error_t blake2b384Compute(const void *data, size_t length, uint8_t *digest)
72 {
73  //Compute the unkeyed hash with BLAKE2b-384
74  return blake2bCompute(NULL, 0, data, length, digest, BLAKE2B384_DIGEST_SIZE);
75 }
76 
77 
78 /**
79  * @brief Initialize BLAKE2b-384 hash computation
80  * @param[in] context Pointer to the BLAKE2b context to initialize
81  **/
82 
84 {
85  //Initialize the hashing context
86  blake2bInit(context, NULL, 0, BLAKE2B384_DIGEST_SIZE);
87 }
88 
89 
90 /**
91  * @brief Update BLAKE2b-384 hash computation
92  * @param[in] context Pointer to the BLAKE2b context
93  * @param[in] data Pointer to the buffer being hashed
94  * @param[in] length Length of the buffer
95  **/
96 
97 void blake2b384Update(Blake2b384Context *context, const void *data, size_t length)
98 {
99  //Digest the data
100  blake2bUpdate(context, data, length);
101 }
102 
103 
104 /**
105  * @brief Finish BLAKE2b-384 hash computation
106  * @param[in] context Pointer to the BLAKE2b context
107  * @param[out] digest Calculated digest (optional parameter)
108  **/
109 
110 void blake2b384Final(Blake2b384Context *context, uint8_t *digest)
111 {
112  //Generate the message digest
113  blake2bFinal(context, digest);
114 }
115 
116 #endif
uint8_t length
Definition: dtls_misc.h:149
void(* HashAlgoInit)(void *context)
Definition: crypto.h:1094
void blake2b384Final(Blake2b384Context *context, uint8_t *digest)
Finish BLAKE2b-384 hash computation.
Definition: blake2b384.c:110
const HashAlgo blake2b384HashAlgo
Definition: blake2b384.c:45
void blake2b384Init(Blake2b384Context *context)
Initialize BLAKE2b-384 hash computation.
Definition: blake2b384.c:83
error_t blake2bInit(Blake2bContext *context, const void *key, size_t keyLen, size_t digestLen)
Initialize BLAKE2b message digest context.
Definition: blake2b.c:147
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 blake2b384Update(Blake2b384Context *context, const void *data, size_t length)
Update BLAKE2b-384 hash computation.
Definition: blake2b384.c:97
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
Definition: crypto.h:1095
#define FALSE
Definition: os_port.h:46
error_t
Error codes.
Definition: error.h:42
#define BLAKE2B384_DIGEST_SIZE
Definition: blake2b384.h:41
General definitions for cryptographic algorithms.
BLAKE2b algorithm context.
Definition: blake2b.h:50
void blake2bFinal(Blake2bContext *context, uint8_t *digest)
Finish the BLAKE2b message digest.
Definition: blake2b.c:245
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Definition: crypto.h:1096
#define BLAKE2B384_BLOCK_SIZE
Definition: blake2b384.h:39
BLAKE2b-384 hash function.
#define BLAKE2B384_MIN_PAD_SIZE
Definition: blake2b384.h:43
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:207
Common interface for hash algorithms.
Definition: crypto.h:1128
const uint8_t blake2b384Oid[11]
Definition: blake2b384.c:42
uint8_t data[]
Definition: dtls_misc.h:176
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
Definition: crypto.h:1093
error_t blake2b384Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using BLAKE2b-384.
Definition: blake2b384.c:71