/src/gnutls/lib/nettle/int/dsa-fips.h
Line | Count | Source |
1 | | /* dsa.h |
2 | | * |
3 | | * The DSA publickey algorithm. |
4 | | */ |
5 | | |
6 | | /* Copyright (C) 2013 Red Hat |
7 | | * |
8 | | * The gnutls library is free software; you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation; either version 2.1 of the License, or (at your |
11 | | * option) any later version. |
12 | | * |
13 | | * The nettle library is distributed in the hope that it will be useful, but |
14 | | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 | | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
16 | | * License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with the nettle library. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #ifndef GNUTLS_LIB_NETTLE_INT_DSA_FIPS_H |
23 | | #define GNUTLS_LIB_NETTLE_INT_DSA_FIPS_H |
24 | | |
25 | | #include <nettle/bignum.h> /* includes gmp.h */ |
26 | | #include <nettle/dsa.h> |
27 | | #include <nettle/sha2.h> |
28 | | #include <nettle/version.h> |
29 | | #include "fips.h" |
30 | | |
31 | 0 | #define div_ceil(x, y) ((x + (y) - 1) / (y)) |
32 | | |
33 | | struct dss_params_validation_seeds { |
34 | | unsigned seed_length; /* first seed */ |
35 | | uint8_t seed[MAX_PVP_SEED_SIZE + 1]; |
36 | | |
37 | | unsigned pseed_length; |
38 | | uint8_t pseed[MAX_PVP_SEED_SIZE + 1]; |
39 | | unsigned qseed_length; |
40 | | uint8_t qseed[MAX_PVP_SEED_SIZE + 1]; |
41 | | unsigned pgen_counter; |
42 | | unsigned qgen_counter; |
43 | | }; |
44 | | |
45 | | int st_provable_prime(mpz_t p, unsigned *prime_seed_length, void *prime_seed, |
46 | | unsigned *prime_gen_counter, unsigned bits, |
47 | | unsigned seed_length, const void *seed, |
48 | | void *progress_ctx, nettle_progress_func *progress); |
49 | | |
50 | | int dsa_generate_dss_pqg(struct dsa_params *params, |
51 | | struct dss_params_validation_seeds *cert, |
52 | | unsigned index, void *random_ctx, |
53 | | nettle_random_func *random, void *progress_ctx, |
54 | | nettle_progress_func *progress, |
55 | | unsigned p_bits /* = L */, unsigned q_bits /* = N */); |
56 | | |
57 | | int _dsa_generate_dss_pqg(struct dsa_params *params, |
58 | | struct dss_params_validation_seeds *cert, |
59 | | unsigned index, unsigned seed_size, void *seed, |
60 | | void *progress_ctx, nettle_progress_func *progress, |
61 | | unsigned p_bits /* = L */, unsigned q_bits /* = N */); |
62 | | |
63 | | int dsa_generate_dss_keypair(struct dsa_params *params, mpz_t y, mpz_t x, |
64 | | void *random_ctx, nettle_random_func *random, |
65 | | void *progress_ctx, |
66 | | nettle_progress_func *progress); |
67 | | |
68 | | int dsa_validate_dss_pqg(struct dsa_params *pub, |
69 | | struct dss_params_validation_seeds *cert, |
70 | | unsigned index); |
71 | | |
72 | | int _dsa_validate_dss_pq(struct dsa_params *pub, |
73 | | struct dss_params_validation_seeds *cert); |
74 | | |
75 | | int _dsa_validate_dss_g(struct dsa_params *pub, unsigned domain_seed_size, |
76 | | const uint8_t *domain_seed, unsigned index); |
77 | | |
78 | | unsigned _dsa_check_qp_sizes(unsigned q_bits, unsigned p_bits, |
79 | | unsigned generate); |
80 | | |
81 | | /* The following low-level functions can be used for DH key exchange as well |
82 | | */ |
83 | | int _dsa_generate_dss_pq(struct dsa_params *pub, |
84 | | struct dss_params_validation_seeds *cert, |
85 | | unsigned seed_length, void *seed, void *progress_ctx, |
86 | | nettle_progress_func *progress, unsigned p_bits, |
87 | | unsigned q_bits); |
88 | | |
89 | | int _dsa_generate_dss_g(struct dsa_params *pub, unsigned domain_seed_size, |
90 | | const uint8_t *domain_seed, void *progress_ctx, |
91 | | nettle_progress_func *progress, unsigned index); |
92 | | |
93 | | void _dsa_generate_dss_xy(struct dsa_params *pub, mpz_t y, mpz_t x, |
94 | | void *random_ctx, nettle_random_func *random); |
95 | | |
96 | 0 | #define DIGEST_SIZE SHA384_DIGEST_SIZE |
97 | | inline static void hash(uint8_t digest[DIGEST_SIZE], unsigned length, |
98 | | void *data) |
99 | 0 | { |
100 | 0 | struct sha384_ctx ctx; |
101 | |
|
102 | 0 | sha384_init(&ctx); |
103 | 0 | sha384_update(&ctx, length, data); |
104 | | #if NETTLE_VERSION_MAJOR >= 4 |
105 | | sha384_digest(&ctx, digest); |
106 | | #else |
107 | 0 | sha384_digest(&ctx, DIGEST_SIZE, digest); |
108 | 0 | #endif |
109 | |
|
110 | 0 | return; |
111 | 0 | } Unexecuted instantiation: pk.c:hash Unexecuted instantiation: rsa-keygen-fips186.c:hash Unexecuted instantiation: dsa-keygen-fips186.c:hash Unexecuted instantiation: dsa-validate.c:hash Unexecuted instantiation: provable-prime.c:hash |
112 | | |
113 | | unsigned mpz_seed_sizeinbase_256_u(mpz_t s, unsigned nominal); |
114 | | |
115 | | #endif /* GNUTLS_LIB_NETTLE_INT_DSA_FIPS_H */ |