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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _DSA_H
30 #define _DSA_H
31 
32 //Dependencies
33 #include "core/crypto.h"
34 #include "mpi/mpi.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 
42 /**
43  * @brief DSA public key
44  **/
45 
46 typedef struct
47 {
48  Mpi p; ///<Prime modulus
49  Mpi q; ///<Prime divisor
50  Mpi g; ///<Generator of the subgroup
51  Mpi y; ///<Public key
52 } DsaPublicKey;
53 
54 
55 /**
56  * @brief DSA private key
57  **/
58 
59 typedef struct
60 {
61  Mpi p; ///<Prime modulus
62  Mpi q; ///<<Prime divisor
63  Mpi g; ///<Generator of the subgroup
64  Mpi x; ///<Private key
66 
67 
68 /**
69  * @brief DSA signature
70  **/
71 
72 typedef struct
73 {
74  Mpi r;
75  Mpi s;
76 } DsaSignature;
77 
78 
79 //DSA related constants
80 extern const uint8_t DSA_OID[7];
81 extern const uint8_t DSA_WITH_SHA1_OID[7];
82 extern const uint8_t DSA_WITH_SHA224_OID[9];
83 extern const uint8_t DSA_WITH_SHA256_OID[9];
84 extern const uint8_t DSA_WITH_SHA384_OID[9];
85 extern const uint8_t DSA_WITH_SHA512_OID[9];
86 extern const uint8_t DSA_WITH_SHA3_224_OID[9];
87 extern const uint8_t DSA_WITH_SHA3_256_OID[9];
88 extern const uint8_t DSA_WITH_SHA3_384_OID[9];
89 extern const uint8_t DSA_WITH_SHA3_512_OID[9];
90 
91 //DSA related functions
94 
97 
100 
101 error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length);
102 error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature);
103 
104 error_t dsaGenerateSignature(const PrngAlgo *prngAlgo, void *prngContext,
105  const DsaPrivateKey *key, const uint8_t *digest, size_t digestLen,
107 
109  const uint8_t *digest, size_t digestLen, const DsaSignature *signature);
110 
111 //C++ guard
112 #ifdef __cplusplus
113  }
114 #endif
115 
116 #endif
error_t dsaVerifySignature(const DsaPublicKey *key, const uint8_t *digest, size_t digestLen, const DsaSignature *signature)
DSA signature verification.
Definition: dsa.c:526
Arbitrary precision integer.
Definition: mpi.h:67
Mpi g
Generator of the subgroup.
Definition: dsa.h:50
const uint8_t DSA_WITH_SHA3_512_OID[9]
Definition: dsa.c:67
Mpi r
Definition: dsa.h:74
const uint8_t DSA_OID[7]
Definition: dsa.c:49
General definitions for cryptographic algorithms.
void dsaFreePublicKey(DsaPublicKey *key)
Release a DSA public key.
Definition: dsa.c:90
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:420
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
Definition: dsa.c:320
DSA public key.
Definition: dsa.h:46
const uint8_t DSA_WITH_SHA1_OID[7]
Definition: dsa.c:51
Mpi g
Generator of the subgroup.
Definition: dsa.h:63
const uint8_t DSA_WITH_SHA384_OID[9]
Definition: dsa.c:57
void dsaInitSignature(DsaSignature *signature)
Initialize a DSA signature.
Definition: dsa.c:135
Mpi q
Prime divisor.
Definition: dsa.h:49
uint8_t signature
Definition: tls.h:1364
const uint8_t DSA_WITH_SHA256_OID[9]
Definition: dsa.c:55
Mpi x
Private key.
Definition: dsa.h:64
Mpi p
Prime modulus.
Definition: dsa.h:61
void dsaFreePrivateKey(DsaPrivateKey *key)
Release a DSA private key.
Definition: dsa.c:120
Mpi p
Prime modulus.
Definition: dsa.h:48
const uint8_t DSA_WITH_SHA3_224_OID[9]
Definition: dsa.c:61
const uint8_t DSA_WITH_SHA512_OID[9]
Definition: dsa.c:59
error_t
Error codes.
Definition: error.h:40
MPI (Multiple Precision Integer Arithmetic)
void dsaFreeSignature(DsaSignature *signature)
Release a DSA signature.
Definition: dsa.c:148
const uint8_t DSA_WITH_SHA224_OID[9]
Definition: dsa.c:53
Mpi y
Public key.
Definition: dsa.h:51
Mpi s
Definition: dsa.h:75
uint8_t data[]
Definition: dtls_misc.h:167
error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length)
Encode DSA signature using ASN.1.
Definition: dsa.c:164
DSA private key.
Definition: dsa.h:59
Common interface for pseudo-random number generators.
Definition: crypto.h:1091
void dsaInitPrivateKey(DsaPrivateKey *key)
Initialize a DSA private key.
Definition: dsa.c:105
const uint8_t DSA_WITH_SHA3_256_OID[9]
Definition: dsa.c:63
Mpi q
<Prime divisor
Definition: dsa.h:62
const uint8_t DSA_WITH_SHA3_384_OID[9]
Definition: dsa.c:65
uint8_t length
Definition: dtls_misc.h:140
DSA signature.
Definition: dsa.h:72
void dsaInitPublicKey(DsaPublicKey *key)
Initialize a DSA public key.
Definition: dsa.c:75