ecdsa.c File Reference

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

#include "core/crypto.h"
#include "ecc/ecdsa.h"
#include "mpi/mpi.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 ecdsaWriteSignature (const EcdsaSignature *signature, uint8_t *data, size_t *length)
 Encode ECDSA signature using ASN.1. More...
 
error_t ecdsaReadSignature (const uint8_t *data, size_t length, EcdsaSignature *signature)
 Read an ASN.1 encoded ECDSA signature. More...
 
__weak_func error_t ecdsaGenerateSignature (const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, const EcPrivateKey *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
 ECDSA signature generation. More...
 
__weak_func error_t ecdsaVerifySignature (const EcDomainParameters *params, 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}
 

Detailed Description

ECDSA (Elliptic Curve Digital 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 ecdsa.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file ecdsa.c.

Function Documentation

◆ ecdsaFreeSignature()

void ecdsaFreeSignature ( EcdsaSignature signature)

Release an ECDSA signature.

Parameters
[in]signaturePointer to the ECDSA signature to free

Definition at line 82 of file ecdsa.c.

◆ ecdsaGenerateSignature()

__weak_func error_t ecdsaGenerateSignature ( const PrngAlgo prngAlgo,
void *  prngContext,
const EcDomainParameters params,
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]paramsEC domain parameters
[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 397 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 69 of file ecdsa.c.

◆ ecdsaReadSignature()

error_t ecdsaReadSignature ( const uint8_t *  data,
size_t  length,
EcdsaSignature signature 
)

Read an ASN.1 encoded ECDSA signature.

Parameters
[in]dataPointer to the ASN.1 structure to decode
[in]lengthLength of the ASN.1 structure
[out]signature(R, S) integer pair
Returns
Error code

Definition at line 260 of file ecdsa.c.

◆ ecdsaVerifySignature()

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

ECDSA signature verification.

Parameters
[in]paramsEC domain 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 507 of file ecdsa.c.

◆ ecdsaWriteSignature()

error_t ecdsaWriteSignature ( const EcdsaSignature signature,
uint8_t *  data,
size_t *  length 
)

Encode ECDSA signature using ASN.1.

Parameters
[in]signature(R, S) integer pair
[out]dataPointer to the buffer where to store the resulting ASN.1 structure
[out]lengthLength of the ASN.1 structure
Returns
Error code

Definition at line 98 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.