blake2s224.c
Go to the documentation of this file.
1 /**
2  * @file blake2s224.c
3  * @brief BLAKE2s-224 hash function
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
31 
32 //Dependencies
33 #include "core/crypto.h"
34 #include "hash/blake2s224.h"
35 
36 //Check crypto library configuration
37 #if (BLAKE2S224_SUPPORT == ENABLED)
38 
39 //BLAKE2s-224 object identifier (1.3.6.1.4.1.1722.12.2.2.7)
40 const uint8_t blake2s224Oid[11] = {0x43, 0x06, 0x01, 0x04, 0x01, 0x8D, 0x3A, 0x0C, 0x02, 0x02, 0x07};
41 
42 //Common interface for hash algorithms
44 {
45  "BLAKE2s-224",
47  sizeof(blake2s224Oid),
48  sizeof(Blake2s224Context),
55 };
56 
57 
58 /**
59  * @brief Digest a message using BLAKE2s-224
60  * @param[in] data Pointer to the message being hashed
61  * @param[in] length Length of the message
62  * @param[out] digest Pointer to the calculated digest
63  * @return Error code
64  **/
65 
66 error_t blake2s224Compute(const void *data, size_t length, uint8_t *digest)
67 {
68  //Compute the unkeyed hash with BLAKE2s-224
69  return blake2sCompute(NULL, 0, data, length, digest, BLAKE2S224_DIGEST_SIZE);
70 }
71 
72 
73 /**
74  * @brief Initialize BLAKE2s-224 hash computation
75  * @param[in] context Pointer to the BLAKE2s context to initialize
76  **/
77 
79 {
80  //Initialize the hashing context
81  blake2sInit(context, NULL, 0, BLAKE2S224_DIGEST_SIZE);
82 }
83 
84 
85 /**
86  * @brief Update BLAKE2s-224 hash computation
87  * @param[in] context Pointer to the BLAKE2s context
88  * @param[in] data Pointer to the buffer being hashed
89  * @param[in] length Length of the buffer
90  **/
91 
92 void blake2s224Update(Blake2s224Context *context, const void *data, size_t length)
93 {
94  //Digest the data
95  blake2sUpdate(context, data, length);
96 }
97 
98 
99 /**
100  * @brief Finish BLAKE2s-224 hash computation
101  * @param[in] context Pointer to the BLAKE2s context
102  * @param[out] digest Calculated digest (optional parameter)
103  **/
104 
105 void blake2s224Final(Blake2s224Context *context, uint8_t *digest)
106 {
107  //Generate the message digest
108  blake2sFinal(context, digest);
109 }
110 
111 #endif
error_t blake2s224Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using BLAKE2s-224.
Definition: blake2s224.c:66
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
Definition: crypto.h:1020
void blake2s224Update(Blake2s224Context *context, const void *data, size_t length)
Update BLAKE2s-224 hash computation.
Definition: blake2s224.c:92
General definitions for cryptographic algorithms.
void blake2s224Final(Blake2s224Context *context, uint8_t *digest)
Finish BLAKE2s-224 hash computation.
Definition: blake2s224.c:105
void blake2sUpdate(Blake2sContext *context, const void *data, size_t length)
Update the BLAKE2s context with a portion of the message being hashed.
Definition: blake2s.c:203
void blake2s224Init(Blake2s224Context *context)
Initialize BLAKE2s-224 hash computation.
Definition: blake2s224.c:78
void(* HashAlgoInit)(void *context)
Definition: crypto.h:1021
const HashAlgo blake2s224HashAlgo
Definition: blake2s224.c:43
const uint8_t blake2s224Oid[11]
Definition: blake2s224.c:40
error_t blake2sInit(Blake2sContext *context, const void *key, size_t keyLen, size_t digestLen)
Initialize BLAKE2s message digest context.
Definition: blake2s.c:143
#define BLAKE2S224_DIGEST_SIZE
Definition: blake2s224.h:39
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
Definition: crypto.h:1022
error_t
Error codes.
Definition: error.h:40
error_t blake2sCompute(const void *key, size_t keyLen, const void *data, size_t dataLen, uint8_t *digest, size_t digestLen)
Digest a message using BLAKE2s.
Definition: blake2s.c:96
#define BLAKE2S224_BLOCK_SIZE
Definition: blake2s224.h:37
BLAKE2s algorithm context.
Definition: blake2s.h:48
uint8_t data[]
Definition: dtls_misc.h:167
Common interface for hash algorithms.
Definition: crypto.h:1054
uint8_t length
Definition: dtls_misc.h:140
void blake2sFinal(Blake2sContext *context, uint8_t *digest)
Finish the BLAKE2s message digest.
Definition: blake2s.c:241
BLAKE2s-224 hash function.
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Definition: crypto.h:1023