cfb8: Fix decrypt path
[gd/nettle] / dsa-compat-keygen.c
1 /* dsa-compat-keygen.c
2
3    Generation of DSA keypairs
4
5    Copyright (C) 2002, 2014 Niels Möller
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
12      * the GNU Lesser General Public License as published by the Free
13        Software Foundation; either version 3 of the License, or (at your
14        option) any later version.
15
16    or
17
18      * the GNU General Public License as published by the Free
19        Software Foundation; either version 2 of the License, or (at your
20        option) any later version.
21
22    or both in parallel, as here.
23
24    GNU Nettle is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28
29    You should have received copies of the GNU General Public License and
30    the GNU Lesser General Public License along with this program.  If
31    not, see http://www.gnu.org/licenses/.
32 */
33
34 #if HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <assert.h>
39 #include <stdlib.h>
40
41 #include "dsa-compat.h"
42
43 #include "bignum.h"
44
45 /* Undo name mangling */
46 #undef dsa_generate_keypair
47 #define dsa_generate_keypair nettle_dsa_generate_keypair
48
49 /* Valid sizes, according to FIPS 186-3 are (1024, 160), (2048, 224),
50    (2048, 256), (3072, 256). */
51 int
52 dsa_compat_generate_keypair(struct dsa_public_key *pub,
53                             struct dsa_private_key *key,
54                             void *random_ctx, nettle_random_func *random,
55                             void *progress_ctx, nettle_progress_func *progress,
56                             unsigned p_bits, unsigned q_bits)
57 {
58   struct dsa_params *params;
59
60   switch (q_bits)
61     {
62     case 160:
63       if (p_bits < DSA_SHA1_MIN_P_BITS)
64         return 0;
65       break;
66     case 224:
67     case 256:
68       if (p_bits < DSA_SHA256_MIN_P_BITS)
69         return 0;
70       break;
71     default:
72       return 0;
73     }
74
75   /* NOTE: Depends on identical layout! */
76   params = (struct dsa_params *) pub;
77
78   if (!dsa_generate_params (params,
79                             random_ctx, random,
80                             progress_ctx, progress,
81                             p_bits, q_bits))
82     return 0;
83
84   dsa_generate_keypair (params, pub->y, key->x, random_ctx, random);
85
86   return 1;
87 }