Mercurial > dropbear
annotate gendss.c @ 644:ff5cc422ba40 dropbear-tfm tomsfastmath
Somehow Makefile.in went missing
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 23 Nov 2011 18:11:51 +0700 |
parents | 2b1bb792cd4d |
children |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * Dropbear - a SSH2 server |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * Copyright (c) 2002,2003 Matt Johnston |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "signkey.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "bignum.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "random.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "buffer.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "gendss.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 #include "dss.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #define QSIZE 20 /* 160 bit */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 |
60
2ca590852f45
Just a test for merging heads
Matt Johnston <matt@ucc.asn.au>
parents:
48
diff
changeset
|
36 /* This is just a test */ |
2ca590852f45
Just a test for merging heads
Matt Johnston <matt@ucc.asn.au>
parents:
48
diff
changeset
|
37 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 #ifdef DROPBEAR_DSS |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
40 static void getq(dropbear_dss_key *key); |
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
41 static void getp(dropbear_dss_key *key, unsigned int size); |
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
42 static void getg(dropbear_dss_key *key); |
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
43 static void getx(dropbear_dss_key *key); |
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
44 static void gety(dropbear_dss_key *key); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
46 dropbear_dss_key * gen_dss_priv_key(unsigned int size) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
48 dropbear_dss_key *key; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
50 key = m_malloc(sizeof(*key)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
52 key->p = (fp_int*)m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
53 key->q = (fp_int*)m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
54 key->g = (fp_int*)m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
55 key->y = (fp_int*)m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
56 key->x = (fp_int*)m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
57 m_fp_init_multi(key->p, key->q, key->g, key->y, key->x, NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 seedrandom(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 getq(key); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 getp(key, size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 getg(key); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 getx(key); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 gety(key); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 return key; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
71 static void getq(dropbear_dss_key *key) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 char buf[QSIZE]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 /* 160 bit prime */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 genrandom(buf, QSIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 buf[0] |= 0x80; /* top bit high */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 buf[QSIZE-1] |= 0x01; /* bottom bit high */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
80 bytes_to_fp(key->q, buf, QSIZE); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 /* 18 rounds are required according to HAC */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
83 if (fp_prime_next_prime(key->q, 18, 0) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
84 fprintf(stderr, "DSS key generation failed\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 exit(1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
89 static void getp(dropbear_dss_key *key, unsigned int size) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
91 DEF_FP_INT(tempX); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
92 DEF_FP_INT(tempC); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
93 DEF_FP_INT(tempP); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
94 DEF_FP_INT(temp2q); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 int result; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 unsigned char *buf; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
98 m_fp_init_multi(&tempX, &tempC, &tempP, &temp2q, NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 /* 2*q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
102 fp_mul_d(key->q, 2, &temp2q); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 buf = (unsigned char*)m_malloc(size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 result = 0; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 do { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 genrandom(buf, size); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 buf[0] |= 0x80; /* set the top bit high */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
112 /* X is a random fp_int */ |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
113 bytes_to_fp(&tempX, buf, size); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 /* C = X mod 2q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
116 if (fp_mod(&tempX, &temp2q, &tempC) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
117 fprintf(stderr, "DSS key generation failed\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 exit(1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 /* P = X - (C - 1) = X - C + 1*/ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
122 fp_sub(&tempX, &tempC, &tempP); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
124 fp_add_d(&tempP, 1, key->p); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 /* now check for prime, 5 rounds is enough according to HAC */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 /* result == 1 => p is prime */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
128 if (fp_prime_is_prime(key->p, 5, &result) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
129 fprintf(stderr, "DSS key generation failed\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 exit(1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 } while (!result); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
134 fp_zero(&tempX); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
135 fp_zero(&tempC); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
136 fp_zero(&tempP); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
137 fp_zero(&temp2q); |
188
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
102
diff
changeset
|
138 m_burn(buf, size); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 m_free(buf); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
142 static void getg(dropbear_dss_key * key) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
144 DEF_FP_INT(div); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
145 DEF_FP_INT(h); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
146 DEF_FP_INT(val); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
148 m_fp_init_multi(&div, &h, &val, NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 /* get div=(p-1)/q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
151 fp_sub_d(key->p, 1, &val); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
152 fp_div(&val, key->q, &div, NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 /* initialise h=1 */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
155 fp_set(&h, 1); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 do { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 /* now keep going with g=h^div mod p, until g > 1 */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
158 if (fp_exptmod(&h, &div, key->p, key->g) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
159 fprintf(stderr, "DSS key generation failed\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 exit(1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
163 fp_add_d(&h, 1, &h); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
165 } while (fp_cmp_d(key->g, 1) != FP_GT); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
167 fp_zero(&div); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
168 fp_zero(&h); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
169 fp_zero(&val); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
172 static void getx(dropbear_dss_key *key) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
174 gen_random_fpint(key->q, key->x); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 |
586
b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
177 static void gety(dropbear_dss_key *key) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
179 if (fp_exptmod(key->g, key->x, key->p, key->y) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
180 fprintf(stderr, "DSS key generation failed\n"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 exit(1); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 #endif /* DROPBEAR_DSS */ |