blake2b160.c
Go to the documentation of this file.
1 /**
2  * @file blake2b160.c
3  * @brief BLAKE2b-160 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/blake2b160.h"
35 
36 //Check crypto library configuration
37 #if (BLAKE2B160_SUPPORT == ENABLED)
38 
39 //BLAKE2b-160 object identifier (1.3.6.1.4.1.1722.12.2.1.5)
40 const uint8_t blake2b160Oid[11] = {0x43, 0x06, 0x01, 0x04, 0x01, 0x8D, 0x3A, 0x0C, 0x02, 0x01, 0x05};
41 
42 //Common interface for hash algorithms
44 {
45  "BLAKE2b-160",
47  sizeof(blake2b160Oid),
48  sizeof(Blake2b160Context),
55 };
56 
57 
58 /**
59  * @brief Digest a message using BLAKE2b-160
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 blake2b160Compute(const void *data, size_t length, uint8_t *digest)
67 {
68  //Compute the unkeyed hash with BLAKE2b-160
69  return blake2bCompute(NULL, 0, data, length, digest, BLAKE2B160_DIGEST_SIZE);
70 }
71 
72 
73 /**
74  * @brief Initialize BLAKE2b-160 hash computation
75  * @param[in] context Pointer to the BLAKE2b context to initialize
76  **/
77 
79 {
80  //Initialize the hashing context
81  blake2bInit(context, NULL, 0, BLAKE2B160_DIGEST_SIZE);
82 }
83 
84 
85 /**
86  * @brief Update BLAKE2b-160 hash computation
87  * @param[in] context Pointer to the BLAKE2b context
88  * @param[in] data Pointer to the buffer being hashed
89  * @param[in] length Length of the buffer
90  **/
91 
92 void blake2b160Update(Blake2b160Context *context, const void *data, size_t length)
93 {
94  //Digest the data
95  blake2bUpdate(context, data, length);
96 }
97 
98 
99 /**
100  * @brief Finish BLAKE2b-160 hash computation
101  * @param[in] context Pointer to the BLAKE2b context
102  * @param[out] digest Calculated digest (optional parameter)
103  **/
104 
105 void blake2b160Final(Blake2b160Context *context, uint8_t *digest)
106 {
107  //Generate the message digest
108  blake2bFinal(context, digest);
109 }
110 
111 #endif
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
Definition: crypto.h:1020
const uint8_t blake2b160Oid[11]
Definition: blake2b160.c:40
error_t blake2bInit(Blake2bContext *context, const void *key, size_t keyLen, size_t digestLen)
Initialize BLAKE2b message digest context.
Definition: blake2b.c:145
General definitions for cryptographic algorithms.
#define BLAKE2B160_BLOCK_SIZE
Definition: blake2b160.h:37
BLAKE2b-160 hash function.
void(* HashAlgoInit)(void *context)
Definition: crypto.h:1021
void blake2bFinal(Blake2bContext *context, uint8_t *digest)
Finish the BLAKE2b message digest.
Definition: blake2b.c:243
error_t blake2b160Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using BLAKE2b-160.
Definition: blake2b160.c:66
#define BLAKE2B160_DIGEST_SIZE
Definition: blake2b160.h:39
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
Definition: crypto.h:1022
const HashAlgo blake2b160HashAlgo
Definition: blake2b160.c: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:205
error_t
Error codes.
Definition: error.h:40
void blake2b160Init(Blake2b160Context *context)
Initialize BLAKE2b-160 hash computation.
Definition: blake2b160.c:78
uint8_t data[]
Definition: dtls_misc.h:167
BLAKE2b algorithm context.
Definition: blake2b.h:48
void blake2b160Final(Blake2b160Context *context, uint8_t *digest)
Finish BLAKE2b-160 hash computation.
Definition: blake2b160.c:105
Common interface for hash algorithms.
Definition: crypto.h:1054
uint8_t length
Definition: dtls_misc.h:140
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Definition: crypto.h:1023
void blake2b160Update(Blake2b160Context *context, const void *data, size_t length)
Update BLAKE2b-160 hash computation.
Definition: blake2b160.c:92
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:98