dsa.h
Go to the documentation of this file.
1 /* dsa.h
2  *
3  * Copyright (C) 2006-2020 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * wolfSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20  */
21 
26 #ifndef WOLF_CRYPT_DSA_H
27 #define WOLF_CRYPT_DSA_H
28 
30 
31 #ifndef NO_DSA
32 
33 #include <wolfssl/wolfcrypt/integer.h>
35 
36 /* for DSA reverse compatibility */
37 #define InitDsaKey wc_InitDsaKey
38 #define FreeDsaKey wc_FreeDsaKey
39 #define DsaSign wc_DsaSign
40 #define DsaVerify wc_DsaVerify
41 #define DsaPublicKeyDecode wc_DsaPublicKeyDecode
42 #define DsaPrivateKeyDecode wc_DsaPrivateKeyDecode
43 #define DsaKeyToDer wc_DsaKeyToDer
44 
45 #ifdef __cplusplus
46  extern "C" {
47 #endif
48 
49 
50 enum {
51  DSA_PUBLIC = 0,
52  DSA_PRIVATE = 1
53 };
54 
55 enum {
56  DSA_HALF_SIZE = 20, /* r and s size */
57  DSA_SIG_SIZE = 40 /* signature size */
58 };
59 
60 /* DSA */
61 typedef struct DsaKey {
62  mp_int p, q, g, y, x;
63  int type; /* public or private */
64  void* heap; /* memory hint */
65 } DsaKey;
66 
67 WOLFSSL_API int wc_InitDsaKey(DsaKey* key);
68 WOLFSSL_API int wc_InitDsaKey_h(DsaKey* key, void* h);
69 WOLFSSL_API void wc_FreeDsaKey(DsaKey* key);
70 WOLFSSL_API int wc_DsaSign(const byte* digest, byte* out,
71  DsaKey* key, WC_RNG* rng);
72 WOLFSSL_API int wc_DsaVerify(const byte* digest, const byte* sig,
73  DsaKey* key, int* answer);
74 WOLFSSL_API int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx,
75  DsaKey*, word32);
76 WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
77  DsaKey*, word32);
78 WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
79 WOLFSSL_API int wc_SetDsaPublicKey(byte* output, DsaKey* key,
80  int outLen, int with_header);
81 WOLFSSL_API int wc_DsaKeyToPublicDer(DsaKey* key, byte* output, word32 inLen);
82 
83 #ifdef WOLFSSL_KEY_GEN
84 WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
85 WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);
86 #endif
87 
88 /* raw export functions */
89 WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p,
90  const char* q, const char* g);
91 WOLFSSL_API int wc_DsaImportParamsRawCheck(DsaKey* dsa, const char* p,
92  const char* q, const char* g,
93  int trusted, WC_RNG* rng);
94 WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz,
95  byte* q, word32* qSz, byte* g,
96  word32* gSz);
97 WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y,
98  word32* ySz);
99 #ifdef __cplusplus
100  } /* extern "C" */
101 #endif
102 
103 #endif /* NO_DSA */
104 #endif /* WOLF_CRYPT_DSA_H */
105 
WOLFSSL_API int wc_DsaSign(const byte *digest, byte *out, DsaKey *key, WC_RNG *rng)
This function signs the input digest and stores the result in the output buffer, out.
Definition: dsa.c:655
WOLFSSL_API void wc_FreeDsaKey(DsaKey *key)
This function frees a DsaKey object after it has been used.
Definition: dsa.c:77
WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte *input, word32 *inOutIdx, DsaKey *, word32)
This function decodes a DER formatted certificate buffer containing a DSA private key...
WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa)
Create a DSA key.
Definition: dsa.c:133
WOLFSSL_API int wc_DsaKeyToDer(DsaKey *key, byte *output, word32 inLen)
Convert DsaKey key to DER format, write to output (inLen), return bytes written.
Definition: asn.c:4858
WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa)
FIPS 186-4 defines valid for modulus_size values as (1024, 160) (2048, 256) (3072, 256)
Definition: dsa.c:220
Definition: integer.h:200
WOLFSSL_API int wc_InitDsaKey(DsaKey *key)
This function initializes a DsaKey object in order to use it for authentication via the Digital Signa...
Definition: dsa.c:45
WOLFSSL_API int wc_DsaVerify(const byte *digest, const byte *sig, DsaKey *key, int *answer)
This function verifies the signature of a digest, given a private key. It stores whether the key prop...
Definition: dsa.c:848
Definition: dsa.h:61
Definition: random.h:153
WOLFSSL_API int wc_DsaPublicKeyDecode(const byte *input, word32 *inOutIdx, DsaKey *, word32)
This function decodes a DER formatted certificate buffer containing a DSA public key, and stores the key in the given DsaKey structure. It also sets the inOutIdx parameter according to the length of the input read.