ecdsa.h
Go to the documentation of this file.
1 /**
2  * @file ecdsa.h
3  * @brief ECDSA (Elliptic Curve Digital 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 _ECDSA_H
32 #define _ECDSA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief ECDSA signature
46  **/
47 
48 typedef struct
49 {
50  Mpi r;
51  Mpi s;
53 
54 
55 //ECDSA related constants
56 extern const uint8_t ECDSA_WITH_SHA1_OID[7];
57 extern const uint8_t ECDSA_WITH_SHA224_OID[8];
58 extern const uint8_t ECDSA_WITH_SHA256_OID[8];
59 extern const uint8_t ECDSA_WITH_SHA384_OID[8];
60 extern const uint8_t ECDSA_WITH_SHA512_OID[8];
61 extern const uint8_t ECDSA_WITH_SHA3_224_OID[9];
62 extern const uint8_t ECDSA_WITH_SHA3_256_OID[9];
63 extern const uint8_t ECDSA_WITH_SHA3_384_OID[9];
64 extern const uint8_t ECDSA_WITH_SHA3_512_OID[9];
65 
66 //ECDSA related functions
67 void ecdsaInitSignature(EcdsaSignature *signature);
68 void ecdsaFreeSignature(EcdsaSignature *signature);
69 
70 error_t ecdsaWriteSignature(const EcdsaSignature *signature, uint8_t *data,
71  size_t *length);
72 
73 error_t ecdsaReadSignature(const uint8_t *data, size_t length,
74  EcdsaSignature *signature);
75 
76 error_t ecdsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
77  const EcDomainParameters *params, const EcPrivateKey *privateKey,
78  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
79 
81  const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen,
82  const EcdsaSignature *signature);
83 
84 //C++ guard
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif
ECDSA signature.
Definition: ecdsa.h:49
const uint8_t ECDSA_WITH_SHA256_OID[8]
Definition: ecdsa.c:49
error_t ecdsaWriteSignature(const EcdsaSignature *signature, uint8_t *data, size_t *length)
Encode ECDSA signature using ASN.1.
Definition: ecdsa.c:98
Arbitrary precision integer.
Definition: mpi.h:80
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.
Definition: ecdsa.c:397
#define PrngAlgo
Definition: crypto.h:938
const uint8_t ECDSA_WITH_SHA3_384_OID[9]
Definition: ecdsa.c:59
uint8_t data[]
Definition: ethernet.h:222
const uint8_t ECDSA_WITH_SHA3_256_OID[9]
Definition: ecdsa.c:57
EC domain parameters.
Definition: ec.h:76
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:69
const uint8_t ECDSA_WITH_SHA3_512_OID[9]
Definition: ecdsa.c:61
error_t
Error codes.
Definition: error.h:43
error_t ecdsaReadSignature(const uint8_t *data, size_t length, EcdsaSignature *signature)
Read an ASN.1 encoded ECDSA signature.
Definition: ecdsa.c:260
error_t ecdsaVerifySignature(const EcDomainParameters *params, const EcPublicKey *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
Definition: ecdsa.c:507
General definitions for cryptographic algorithms.
EC private key.
Definition: ec.h:104
uint8_t length
Definition: tcp.h:368
const uint8_t ECDSA_WITH_SHA3_224_OID[9]
Definition: ecdsa.c:55
const uint8_t ECDSA_WITH_SHA384_OID[8]
Definition: ecdsa.c:51
const uint8_t ECDSA_WITH_SHA1_OID[7]
Definition: ecdsa.c:45
const uint8_t ECDSA_WITH_SHA224_OID[8]
Definition: ecdsa.c:47
EC public key.
Definition: ec.h:94
const uint8_t ECDSA_WITH_SHA512_OID[8]
Definition: ecdsa.c:53
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:82
ECC (Elliptic Curve Cryptography)