1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import absolute_import, division, print_function
6
7INCLUDES = """
8#include <openssl/dsa.h>
9"""
10
11TYPES = """
12typedef ... DSA;
13"""
14
15FUNCTIONS = """
16int DSA_generate_key(DSA *);
17DSA *DSA_new(void);
18void DSA_free(DSA *);
19DSA *DSAparams_dup(DSA *);
20int DSA_size(const DSA *);
21int DSA_sign(int, const unsigned char *, int, unsigned char *, unsigned int *,
22             DSA *);
23int DSA_verify(int, const unsigned char *, int, const unsigned char *, int,
24               DSA *);
25
26/* added in 1.1.0 to access the opaque struct */
27void DSA_get0_pqg(const DSA *, const BIGNUM **, const BIGNUM **,
28                  const BIGNUM **);
29int DSA_set0_pqg(DSA *, BIGNUM *, BIGNUM *, BIGNUM *);
30void DSA_get0_key(const DSA *, const BIGNUM **, const BIGNUM **);
31int DSA_set0_key(DSA *, BIGNUM *, BIGNUM *);
32int DSA_generate_parameters_ex(DSA *, int, unsigned char *, int,
33                               int *, unsigned long *, BN_GENCB *);
34"""
35
36CUSTOMIZATIONS = """
37/* These functions were added in OpenSSL 1.1.0 */
38#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 && !CRYPTOGRAPHY_LIBRESSL_27_OR_GREATER
39void DSA_get0_pqg(const DSA *d,
40                  const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
41{
42    if (p != NULL)
43        *p = d->p;
44    if (q != NULL)
45        *q = d->q;
46    if (g != NULL)
47        *g = d->g;
48}
49int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
50{
51    /* If the fields p, q and g in d are NULL, the corresponding input
52     * parameters MUST be non-NULL.
53     */
54    if ((d->p == NULL && p == NULL)
55        || (d->q == NULL && q == NULL)
56        || (d->g == NULL && g == NULL))
57        return 0;
58
59    if (p != NULL) {
60        BN_free(d->p);
61        d->p = p;
62    }
63    if (q != NULL) {
64        BN_free(d->q);
65        d->q = q;
66    }
67    if (g != NULL) {
68        BN_free(d->g);
69        d->g = g;
70    }
71
72    return 1;
73}
74void DSA_get0_key(const DSA *d,
75                  const BIGNUM **pub_key, const BIGNUM **priv_key)
76{
77    if (pub_key != NULL)
78        *pub_key = d->pub_key;
79    if (priv_key != NULL)
80        *priv_key = d->priv_key;
81}
82int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
83{
84    /* If the field pub_key in d is NULL, the corresponding input
85     * parameters MUST be non-NULL.  The priv_key field may
86     * be left NULL.
87     */
88    if (d->pub_key == NULL && pub_key == NULL)
89        return 0;
90
91    if (pub_key != NULL) {
92        BN_free(d->pub_key);
93        d->pub_key = pub_key;
94    }
95    if (priv_key != NULL) {
96        BN_free(d->priv_key);
97        d->priv_key = priv_key;
98    }
99
100    return 1;
101}
102#endif
103"""
104