sm3.h
Go to the documentation of this file.
1 /**
2  * @file sm3.h
3  * @brief SM3 hash function
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 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.5.0
29  **/
30 
31 #ifndef _SM3_H
32 #define _SM3_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef SM3_PRIVATE_CONTEXT
39  #define SM3_PRIVATE_CONTEXT
40 #endif
41 
42 //SM3 block size
43 #define SM3_BLOCK_SIZE 64
44 //SM3 digest size
45 #define SM3_DIGEST_SIZE 32
46 //Minimum length of the padding string
47 #define SM3_MIN_PAD_SIZE 9
48 //Common interface for hash algorithms
49 #define SM3_HASH_ALGO (&sm3HashAlgo)
50 
51 //C++ guard
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 
57 /**
58  * @brief SM3 algorithm context
59  **/
60 
61 typedef struct
62 {
63  uint32_t h[8];
64  union
65  {
66  uint32_t w[16];
67  uint8_t buffer[64];
68  };
69  size_t size;
70  uint64_t totalSize;
72 } Sm3Context;
73 
74 
75 //SM3 related constants
76 extern const uint8_t SM3_OID[6];
77 extern const HashAlgo sm3HashAlgo;
78 
79 //SM3 related functions
80 error_t sm3Compute(const void *data, size_t length, uint8_t *digest);
81 void sm3Init(Sm3Context *context);
82 void sm3Update(Sm3Context *context, const void *data, size_t length);
83 void sm3Final(Sm3Context *context, uint8_t *digest);
84 void sm3ProcessBlock(Sm3Context *context);
85 
86 //C++ guard
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif
const uint8_t SM3_OID[6]
Definition: sm3.c:66
void sm3ProcessBlock(Sm3Context *context)
Process message in 16-word blocks.
void sm3Final(Sm3Context *context, uint8_t *digest)
Finish the SM3 message digest.
Definition: sm3.c:205
#define SM3_PRIVATE_CONTEXT
Definition: sm3.h:39
uint8_t data[]
Definition: ethernet.h:222
SM3 algorithm context.
Definition: sm3.h:62
uint64_t totalSize
Definition: sm3.h:70
uint8_t h
Definition: ndp.h:302
error_t
Error codes.
Definition: error.h:43
void sm3Update(Sm3Context *context, const void *data, size_t length)
Update the SM3 context with a portion of the message being hashed.
General definitions for cryptographic algorithms.
uint8_t length
Definition: tcp.h:375
error_t sm3Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SM3.
Definition: sm3.c:95
const HashAlgo sm3HashAlgo
Definition: sm3.c:69
Common interface for hash algorithms.
Definition: crypto.h:1082
size_t size
Definition: sm3.h:69
void sm3Init(Sm3Context *context)
Initialize SM3 message digest context.
Definition: sm3.c:140