dsa.h
Go to the documentation of this file.
1 /**
2  * @file dsa.h
3  * @brief DSA (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 _DSA_H
32 #define _DSA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "mpi/mpi.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief DSA domain parameters
46  **/
47 
48 typedef struct
49 {
50  Mpi p; ///<Prime modulus
51  Mpi q; ///<Group order
52  Mpi g; ///<Group generator
54 
55 
56 /**
57  * @brief DSA public key
58  **/
59 
60 typedef struct
61 {
62  DsaDomainParameters params; ///<DSA domain parameters
63  Mpi y; ///<Public key value
64 } DsaPublicKey;
65 
66 
67 /**
68  * @brief DSA private key
69  **/
70 
71 typedef struct
72 {
73  DsaDomainParameters params; ///<DSA domain parameters
74  Mpi x; ///<Secret exponent
75  int_t slot; ///<Private key slot
77 
78 
79 /**
80  * @brief DSA signature
81  **/
82 
83 typedef struct
84 {
85  Mpi r;
86  Mpi s;
87 } DsaSignature;
88 
89 
90 //DSA related constants
91 extern const uint8_t DSA_OID[7];
92 extern const uint8_t DSA_WITH_SHA1_OID[7];
93 extern const uint8_t DSA_WITH_SHA224_OID[9];
94 extern const uint8_t DSA_WITH_SHA256_OID[9];
95 extern const uint8_t DSA_WITH_SHA384_OID[9];
96 extern const uint8_t DSA_WITH_SHA512_OID[9];
97 extern const uint8_t DSA_WITH_SHA3_224_OID[9];
98 extern const uint8_t DSA_WITH_SHA3_256_OID[9];
99 extern const uint8_t DSA_WITH_SHA3_384_OID[9];
100 extern const uint8_t DSA_WITH_SHA3_512_OID[9];
101 
102 //DSA related functions
105 
106 void dsaInitPublicKey(DsaPublicKey *key);
107 void dsaFreePublicKey(DsaPublicKey *key);
108 
111 
112 void dsaInitSignature(DsaSignature *signature);
113 void dsaFreeSignature(DsaSignature *signature);
114 
115 error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length);
116 error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature);
117 
118 error_t dsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
119  const DsaPrivateKey *key, const uint8_t *digest, size_t digestLen,
120  DsaSignature *signature);
121 
123  const uint8_t *digest, size_t digestLen, const DsaSignature *signature);
124 
125 //C++ guard
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
const uint8_t DSA_OID[7]
Definition: dsa.c:51
Mpi s
Definition: dsa.h:86
void dsaFreeDomainParameters(DsaDomainParameters *params)
Release DSA domain parameters.
Definition: dsa.c:91
Arbitrary precision integer.
Definition: mpi.h:80
signed int int_t
Definition: compiler_port.h:49
#define PrngAlgo
Definition: crypto.h:938
const uint8_t DSA_WITH_SHA384_OID[9]
Definition: dsa.c:59
Mpi q
Group order.
Definition: dsa.h:51
uint8_t data[]
Definition: ethernet.h:222
error_t dsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext, const DsaPrivateKey *key, const uint8_t *digest, size_t digestLen, DsaSignature *signature)
DSA signature generation.
Definition: dsa.c:484
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:349
Mpi r
Definition: dsa.h:85
Mpi p
Prime modulus.
Definition: dsa.h:50
error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length)
Encode DSA signature using ASN.1.
Definition: dsa.c:193
void dsaFreePrivateKey(DsaPrivateKey *key)
Release a DSA private key.
Definition: dsa.c:150
const uint8_t DSA_WITH_SHA3_256_OID[9]
Definition: dsa.c:65
DSA public key.
Definition: dsa.h:61
const uint8_t DSA_WITH_SHA224_OID[9]
Definition: dsa.c:55
error_t
Error codes.
Definition: error.h:43
Mpi g
Group generator.
Definition: dsa.h:52
const uint8_t DSA_WITH_SHA3_512_OID[9]
Definition: dsa.c:69
const uint8_t DSA_WITH_SHA1_OID[7]
Definition: dsa.c:53
DSA domain parameters.
Definition: dsa.h:49
MPI (Multiple Precision Integer Arithmetic)
General definitions for cryptographic algorithms.
DsaDomainParameters params
DSA domain parameters.
Definition: dsa.h:62
DSA private key.
Definition: dsa.h:72
uint8_t length
Definition: tcp.h:368
const uint8_t DSA_WITH_SHA3_384_OID[9]
Definition: dsa.c:67
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:177
void dsaInitDomainParameters(DsaDomainParameters *params)
Initialize DSA domain parameters.
Definition: dsa.c:77
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:164
int_t slot
Private key slot.
Definition: dsa.h:75
const uint8_t DSA_WITH_SHA256_OID[9]
Definition: dsa.c:57
Mpi x
Secret exponent.
Definition: dsa.h:74
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:585
Mpi y
Public key value.
Definition: dsa.h:63
void dsaInitPublicKey(DsaPublicKey *key)
Initialize a DSA public key.
Definition: dsa.c:105
DsaDomainParameters params
DSA domain parameters.
Definition: dsa.h:73
DSA signature.
Definition: dsa.h:84
const uint8_t DSA_WITH_SHA512_OID[9]
Definition: dsa.c:61
void dsaFreePublicKey(DsaPublicKey *key)
Release a DSA public key.
Definition: dsa.c:119
void dsaInitPrivateKey(DsaPrivateKey *key)
Initialize a DSA private key.
Definition: dsa.c:133
const uint8_t DSA_WITH_SHA3_224_OID[9]
Definition: dsa.c:63