ecdsa.c File Reference

ECDSA (Elliptic Curve Digital Signature Algorithm) More...

#include "core/crypto.h"
#include "ecc/ecdsa.h"
#include "ecc/ec_misc.h"
#include "encoding/asn1.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

void ecdsaInitSignature (EcdsaSignature *signature)
 Initialize an ECDSA signature. More...
 
void ecdsaFreeSignature (EcdsaSignature *signature)
 Release an ECDSA signature. More...
 
error_t ecdsaImportSignature (EcdsaSignature *signature, const EcCurve *curve, const uint8_t *data, size_t length, EcdsaSignatureFormat format)
 Import an ECDSA signature. More...
 
error_t ecdsaExportSignature (const EcdsaSignature *signature, uint8_t *data, size_t *length, EcdsaSignatureFormat format)
 Export an ECDSA signature. More...
 
__weak_func error_t ecdsaGenerateSignature (const PrngAlgo *prngAlgo, void *prngContext, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
 ECDSA signature generation. More...
 
__weak_func error_t ecdsaVerifySignature (const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
 ECDSA signature verification. More...
 

Variables

const uint8_t ECDSA_WITH_SHA1_OID [7] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x01}
 
const uint8_t ECDSA_WITH_SHA224_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01}
 
const uint8_t ECDSA_WITH_SHA256_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02}
 
const uint8_t ECDSA_WITH_SHA384_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x03}
 
const uint8_t ECDSA_WITH_SHA512_OID [8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x04}
 
const uint8_t ECDSA_WITH_SHA3_224_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x09}
 
const uint8_t ECDSA_WITH_SHA3_256_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0A}
 
const uint8_t ECDSA_WITH_SHA3_384_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0B}
 
const uint8_t ECDSA_WITH_SHA3_512_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0C}
 
const uint8_t ECDSA_WITH_SHAKE128_OID [8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x20}
 
const uint8_t ECDSA_WITH_SHAKE256_OID [8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x21}
 

Detailed Description

ECDSA (Elliptic Curve Digital Signature Algorithm)

License

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

Copyright (C) 2010-2025 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.5.0

Definition in file ecdsa.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file ecdsa.c.

Function Documentation

◆ ecdsaExportSignature()

error_t ecdsaExportSignature ( const EcdsaSignature signature,
uint8_t *  data,
size_t *  length,
EcdsaSignatureFormat  format 
)

Export an ECDSA signature.

Parameters
[in]signatureECDSA signature
[out]dataPointer to the octet string
[out]lengthLength of the octet string, in bytes
[in]formatECDSA signature format (ASN.1 or raw format)
Returns
Error code

Definition at line 272 of file ecdsa.c.

◆ ecdsaFreeSignature()

void ecdsaFreeSignature ( EcdsaSignature signature)

Release an ECDSA signature.

Parameters
[in]signaturePointer to the ECDSA signature to free

Definition at line 86 of file ecdsa.c.

◆ ecdsaGenerateSignature()

__weak_func error_t ecdsaGenerateSignature ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcPrivateKey privateKey,
const uint8_t *  digest,
size_t  digestLen,
EcdsaSignature signature 
)

ECDSA signature generation.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]privateKeySigner's EC private key
[in]digestDigest of the message to be signed
[in]digestLenLength in octets of the digest
[out]signature(R, S) integer pair
Returns
Error code

Definition at line 509 of file ecdsa.c.

◆ ecdsaImportSignature()

error_t ecdsaImportSignature ( EcdsaSignature signature,
const EcCurve curve,
const uint8_t *  data,
size_t  length,
EcdsaSignatureFormat  format 
)

Import an ECDSA signature.

Parameters
[out]signatureECDSA signature
[in]curveElliptic curve parameters
[in]dataPointer to the octet string
[in]lengthLength of the octet string, in bytes
[in]formatECDSA signature format (ASN.1 or raw format)
Returns
Error code

Definition at line 104 of file ecdsa.c.

◆ ecdsaInitSignature()

void ecdsaInitSignature ( EcdsaSignature signature)

Initialize an ECDSA signature.

Parameters
[in]signaturePointer to the ECDSA signature to initialize

Definition at line 73 of file ecdsa.c.

◆ ecdsaVerifySignature()

__weak_func error_t ecdsaVerifySignature ( const EcPublicKey publicKey,
const uint8_t *  digest,
size_t  digestLen,
const EcdsaSignature signature 
)

ECDSA signature verification.

Parameters
[in]publicKeySigner's EC public key
[in]digestDigest of the message whose signature is to be verified
[in]digestLenLength in octets of the digest
[in]signature(R, S) integer pair
Returns
Error code

Definition at line 655 of file ecdsa.c.

Variable Documentation

◆ ECDSA_WITH_SHA1_OID

const uint8_t ECDSA_WITH_SHA1_OID[7] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x01}

Definition at line 45 of file ecdsa.c.

◆ ECDSA_WITH_SHA224_OID

const uint8_t ECDSA_WITH_SHA224_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01}

Definition at line 47 of file ecdsa.c.

◆ ECDSA_WITH_SHA256_OID

const uint8_t ECDSA_WITH_SHA256_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02}

Definition at line 49 of file ecdsa.c.

◆ ECDSA_WITH_SHA384_OID

const uint8_t ECDSA_WITH_SHA384_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x03}

Definition at line 51 of file ecdsa.c.

◆ ECDSA_WITH_SHA3_224_OID

const uint8_t ECDSA_WITH_SHA3_224_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x09}

Definition at line 55 of file ecdsa.c.

◆ ECDSA_WITH_SHA3_256_OID

const uint8_t ECDSA_WITH_SHA3_256_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0A}

Definition at line 57 of file ecdsa.c.

◆ ECDSA_WITH_SHA3_384_OID

const uint8_t ECDSA_WITH_SHA3_384_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0B}

Definition at line 59 of file ecdsa.c.

◆ ECDSA_WITH_SHA3_512_OID

const uint8_t ECDSA_WITH_SHA3_512_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0C}

Definition at line 61 of file ecdsa.c.

◆ ECDSA_WITH_SHA512_OID

const uint8_t ECDSA_WITH_SHA512_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x04}

Definition at line 53 of file ecdsa.c.

◆ ECDSA_WITH_SHAKE128_OID

const uint8_t ECDSA_WITH_SHAKE128_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x20}

Definition at line 63 of file ecdsa.c.

◆ ECDSA_WITH_SHAKE256_OID

const uint8_t ECDSA_WITH_SHAKE256_OID[8] = {0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x21}

Definition at line 65 of file ecdsa.c.