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