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-2020 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 1.9.8
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
69 
71  size_t *length);
72 
73 error_t ecdsaReadSignature(const uint8_t *data, size_t length,
75 
76 error_t ecdsaGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext,
77  const EcDomainParameters *params, Mpi *privateKey, EcPoint *publicKey);
78 
79 error_t ecdsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
80  const EcDomainParameters *params, const Mpi *privateKey,
81  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
82 
84  const EcPoint *publicKey, const uint8_t *digest, size_t digestLen,
85  const EcdsaSignature *signature);
86 
87 //C++ guard
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif
uint8_t length
Definition: coap_common.h:190
ECDSA signature.
Definition: ecdsa.h:48
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
uint8_t data[]
Definition: ethernet.h:209
Arbitrary precision integer.
Definition: mpi.h:69
Common interface for pseudo-random number generators.
Definition: crypto.h:1102
const uint8_t ECDSA_WITH_SHA3_384_OID[9]
Definition: ecdsa.c:59
const uint8_t ECDSA_WITH_SHA3_256_OID[9]
Definition: ecdsa.c:57
error_t ecdsaGenerateKeyPair(const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, Mpi *privateKey, EcPoint *publicKey)
ECDSA key pair generation.
Definition: ecdsa.c:390
uint8_t signature
Definition: tls.h:1381
EC domain parameters.
Definition: ec.h:63
void ecdsaInitSignature(EcdsaSignature *signature)
Initialize an ECDSA signature.
Definition: ecdsa.c:69
error_t ecdsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const EcDomainParameters *params, const Mpi *privateKey, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature generation.
Definition: ecdsa.c:447
const uint8_t ECDSA_WITH_SHA3_512_OID[9]
Definition: ecdsa.c:61
error_t
Error codes.
Definition: error.h:42
error_t ecdsaReadSignature(const uint8_t *data, size_t length, EcdsaSignature *signature)
Read an ASN.1 encoded ECDSA signature.
Definition: ecdsa.c:255
General definitions for cryptographic algorithms.
Elliptic curve point.
Definition: ec.h:51
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
const uint8_t ECDSA_WITH_SHA512_OID[8]
Definition: ecdsa.c:53
error_t ecdsaVerifySignature(const EcDomainParameters *params, const EcPoint *publicKey, const uint8_t *digest, size_t digestLen, const EcdsaSignature *signature)
ECDSA signature verification.
Definition: ecdsa.c:562
void ecdsaFreeSignature(EcdsaSignature *signature)
Release an ECDSA signature.
Definition: ecdsa.c:82
ECC (Elliptic Curve Cryptography)