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-2019 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.6
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  Mpi p; ///<Prime modulus
63  Mpi q; ///<Group order
64  Mpi g; ///<Group generator
65  Mpi y; ///<Public key value
66 } DsaPublicKey;
67 
68 
69 /**
70  * @brief DSA private key
71  **/
72 
73 typedef struct
74 {
75  Mpi p; ///<Prime modulus
76  Mpi q; ///<Group order
77  Mpi g; ///<Group generator
78  Mpi x; ///<Secret exponent
80 
81 
82 /**
83  * @brief DSA signature
84  **/
85 
86 typedef struct
87 {
88  Mpi r;
89  Mpi s;
90 } DsaSignature;
91 
92 
93 //DSA related constants
94 extern const uint8_t DSA_OID[7];
95 extern const uint8_t DSA_WITH_SHA1_OID[7];
96 extern const uint8_t DSA_WITH_SHA224_OID[9];
97 extern const uint8_t DSA_WITH_SHA256_OID[9];
98 extern const uint8_t DSA_WITH_SHA384_OID[9];
99 extern const uint8_t DSA_WITH_SHA512_OID[9];
100 extern const uint8_t DSA_WITH_SHA3_224_OID[9];
101 extern const uint8_t DSA_WITH_SHA3_256_OID[9];
102 extern const uint8_t DSA_WITH_SHA3_384_OID[9];
103 extern const uint8_t DSA_WITH_SHA3_512_OID[9];
104 
105 //DSA related functions
106 void dsaInitPublicKey(DsaPublicKey *key);
107 void dsaFreePublicKey(DsaPublicKey *key);
108 
111 
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,
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:89
uint8_t length
Definition: dtls_misc.h:149
Arbitrary precision integer.
Definition: mpi.h:69
Common interface for pseudo-random number generators.
Definition: crypto.h:1168
const uint8_t DSA_WITH_SHA384_OID[9]
Definition: dsa.c:59
Mpi q
Group order.
Definition: dsa.h:51
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:457
uint8_t signature
Definition: tls.h:1370
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:322
Mpi r
Definition: dsa.h:88
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:166
void dsaFreePrivateKey(DsaPrivateKey *key)
Release a DSA private key.
Definition: dsa.c:122
const uint8_t DSA_WITH_SHA3_256_OID[9]
Definition: dsa.c:65
DSA public key.
Definition: dsa.h:60
const uint8_t DSA_WITH_SHA224_OID[9]
Definition: dsa.c:55
error_t
Error codes.
Definition: error.h:42
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:48
MPI (Multiple Precision Integer Arithmetic)
General definitions for cryptographic algorithms.
DSA private key.
Definition: dsa.h:73
Mpi p
Prime modulus.
Definition: dsa.h:75
const uint8_t DSA_WITH_SHA3_384_OID[9]
Definition: dsa.c:67
Mpi g
Group generator.
Definition: dsa.h:77
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:150
Mpi q
Group order.
Definition: dsa.h:63
Mpi p
Prime modulus.
Definition: dsa.h:62
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:137
const uint8_t DSA_WITH_SHA256_OID[9]
Definition: dsa.c:57
Mpi x
Secret exponent.
Definition: dsa.h:78
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:563
Mpi y
Public key value.
Definition: dsa.h:65
void dsaInitPublicKey(DsaPublicKey *key)
Initialize a DSA public key.
Definition: dsa.c:77
Mpi q
Group order.
Definition: dsa.h:76
DSA signature.
Definition: dsa.h:86
const uint8_t DSA_WITH_SHA512_OID[9]
Definition: dsa.c:61
uint8_t data[]
Definition: dtls_misc.h:176
void dsaFreePublicKey(DsaPublicKey *key)
Release a DSA public key.
Definition: dsa.c:92
Mpi g
Group generator.
Definition: dsa.h:64
void dsaInitPrivateKey(DsaPrivateKey *key)
Initialize a DSA private key.
Definition: dsa.c:107
const uint8_t DSA_WITH_SHA3_224_OID[9]
Definition: dsa.c:63