sm2.h
Go to the documentation of this file.
1 /**
2  * @file sm2.h
3  * @brief SM2 signature algorithm
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 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.4.4
29  **/
30 
31 #ifndef _SM2_H
32 #define _SM2_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ecdsa.h"
37 
38 //SM2 identifiers
39 #define SM2_DEFAULT_ID "1234567812345678"
40 #define SM2_TLS13_ID "TLSv1.3+GM+Cipher+Suite"
41 
42 //C++ guard
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 //SM2 related constants
48 extern const uint8_t SM2_WITH_SM3_OID[8];
49 
50 //SM2 related functions
51 error_t sm2GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
52  const EcDomainParameters *params, const EcPrivateKey *privateKey,
53  const HashAlgo *hashAlgo, const char_t *id, size_t idLen,
54  const void *message, size_t messageLen, EcdsaSignature *signature);
55 
57  const EcPublicKey *publicKey, const HashAlgo *hashAlgo,
58  const char_t *id, size_t idLen, const void *message, size_t messageLen,
59  const EcdsaSignature *signature);
60 
61 error_t sm2ComputeZa(const HashAlgo *hashAlgo, HashContext *hashContext,
62  const EcDomainParameters *params, const EcPublicKey *pa, const char_t *ida,
63  size_t idaLen, uint8_t *za);
64 
65 //C++ guard
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif
ECDSA signature.
Definition: ecdsa.h:49
Generic hash algorithm context.
#define PrngAlgo
Definition: crypto.h:938
ECDSA (Elliptic Curve Digital Signature Algorithm)
uint8_t message[]
Definition: chap.h:154
const uint8_t SM2_WITH_SM3_OID[8]
Definition: sm2.c:44
error_t sm2GenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, const EcPrivateKey *privateKey, const HashAlgo *hashAlgo, const char_t *id, size_t idLen, const void *message, size_t messageLen, EcdsaSignature *signature)
SM2 signature generation.
Definition: sm2.c:62
EC domain parameters.
Definition: ec.h:76
error_t
Error codes.
Definition: error.h:43
General definitions for cryptographic algorithms.
EC private key.
Definition: ec.h:104
error_t sm2ComputeZa(const HashAlgo *hashAlgo, HashContext *hashContext, const EcDomainParameters *params, const EcPublicKey *pa, const char_t *ida, size_t idaLen, uint8_t *za)
Calculate ZA.
Definition: sm2.c:368
EC public key.
Definition: ec.h:94
char char_t
Definition: compiler_port.h:48
error_t sm2VerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const HashAlgo *hashAlgo, const char_t *id, size_t idLen, const void *message, size_t messageLen, const EcdsaSignature *signature)
SM2 signature verification.
Definition: sm2.c:216
Common interface for hash algorithms.
Definition: crypto.h:1046