sm2.h File Reference

SM2 signature algorithm. More...

#include "core/crypto.h"
#include "ecc/ecdsa.h"

Go to the source code of this file.

Macros

#define SM2_DEFAULT_ID   "1234567812345678"
 
#define SM2_TLS13_ID   "TLSv1.3+GM+Cipher+Suite"
 

Functions

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. More...
 
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. More...
 
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. More...
 

Variables

const uint8_t SM2_WITH_SM3_OID [8]
 

Detailed Description

SM2 signature algorithm.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file sm2.h.

Macro Definition Documentation

◆ SM2_DEFAULT_ID

#define SM2_DEFAULT_ID   "1234567812345678"

Definition at line 39 of file sm2.h.

◆ SM2_TLS13_ID

#define SM2_TLS13_ID   "TLSv1.3+GM+Cipher+Suite"

Definition at line 40 of file sm2.h.

Function Documentation

◆ sm2ComputeZa()

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.

Parameters
[in]hashAlgoHash function
[in]hashContextHash function context
[in]paramsEC domain parameters
[in]paPublic key of user A
[in]idaDistinguishing identifier of user A
[in]idaLenLength of the identifier
[out]zaHash value of the distinguishing identifier of user A

Definition at line 368 of file sm2.c.

◆ sm2GenerateSignature()

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.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]paramsEC domain parameters
[in]privateKeySigner's EC private key
[in]hashAlgoUnderlying hash function
[in]idUser's identity
[in]idLenLength of the user's identity
[in]messageMessage to be signed
[in]messageLenLength of the message, in bytes
[out]signature(r, s) integer pair
Returns
Error code

Definition at line 62 of file sm2.c.

◆ sm2VerifySignature()

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.

Parameters
[in]paramsEC domain parameters
[in]publicKeySigner's SM2 public key
[in]hashAlgoUnderlying hash function
[in]idUser's identity
[in]idLenLength of the user's identity
[in]messageMessage whose signature is to be verified
[in]messageLenLength of the message, in bytes
[in]signature(r, s) integer pair
Returns
Error code

Definition at line 216 of file sm2.c.

Variable Documentation

◆ SM2_WITH_SM3_OID

const uint8_t SM2_WITH_SM3_OID[8]
extern

Definition at line 44 of file sm2.c.