sm2.c File Reference

SM2 signature algorithm. More...

#include "core/crypto.h"
#include "hash/hash_algorithms.h"
#include "ecc/sm2.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

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] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x83, 0x75}
 

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

Definition in file sm2.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file sm2.c.

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] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x83, 0x75}

Definition at line 44 of file sm2.c.