sha1.h
Go to the documentation of this file.
1 /**
2  * @file sha1.h
3  * @brief SHA-1 (Secure Hash Algorithm 1)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 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.2.2
29  **/
30 
31 #ifndef _SHA1_H
32 #define _SHA1_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef SHA1_PRIVATE_CONTEXT
39  #define SHA1_PRIVATE_CONTEXT
40 #endif
41 
42 //SHA-1 block size
43 #define SHA1_BLOCK_SIZE 64
44 //SHA-1 digest size
45 #define SHA1_DIGEST_SIZE 20
46 //Minimum length of the padding string
47 #define SHA1_MIN_PAD_SIZE 9
48 //SHA-1 algorithm object identifier
49 #define SHA1_OID sha1Oid
50 //Common interface for hash algorithms
51 #define SHA1_HASH_ALGO (&sha1HashAlgo)
52 
53 //C++ guard
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 
59 /**
60  * @brief SHA-1 algorithm context
61  **/
62 
63 typedef struct
64 {
65  union
66  {
67  uint32_t h[5];
68  uint8_t digest[20];
69  };
70  union
71  {
72  uint32_t w[16];
73  uint8_t buffer[64];
74  };
75  size_t size;
76  uint64_t totalSize;
78 } Sha1Context;
79 
80 
81 //SHA-1 related constants
82 extern const uint8_t sha1Oid[5];
83 extern const HashAlgo sha1HashAlgo;
84 
85 //SHA-1 related functions
86 error_t sha1Compute(const void *data, size_t length, uint8_t *digest);
87 void sha1Init(Sha1Context *context);
88 void sha1Update(Sha1Context *context, const void *data, size_t length);
89 void sha1Final(Sha1Context *context, uint8_t *digest);
90 void sha1FinalRaw(Sha1Context *context, uint8_t *digest);
91 void sha1ProcessBlock(Sha1Context *context);
92 
93 //C++ guard
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif
#define SHA1_PRIVATE_CONTEXT
Definition: sha1.h:39
uint8_t length
Definition: coap_common.h:193
uint8_t data[]
Definition: ethernet.h:220
error_t sha1Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-1.
void sha1FinalRaw(Sha1Context *context, uint8_t *digest)
Finish the SHA-1 message digest (no padding added)
uint16_t w[3]
Definition: ethernet.h:191
uint64_t totalSize
Definition: sha1.h:76
uint8_t h
Definition: ndp.h:300
error_t
Error codes.
Definition: error.h:43
const HashAlgo sha1HashAlgo
Definition: sha1.c:76
void sha1Init(Sha1Context *context)
Initialize SHA-1 message digest context.
General definitions for cryptographic algorithms.
size_t size
Definition: sha1.h:75
SHA-1 algorithm context.
Definition: sha1.h:64
Common interface for hash algorithms.
Definition: crypto.h:937
const uint8_t sha1Oid[5]
Definition: sha1.c:73
void sha1ProcessBlock(Sha1Context *context)
Process message in 16-word blocks.
void sha1Update(Sha1Context *context, const void *data, size_t length)
Update the SHA-1 context with a portion of the message being hashed.
void sha1Final(Sha1Context *context, uint8_t *digest)
Finish the SHA-1 message digest.