Mercurial > dropbear
annotate dss.c @ 641:2b1bb792cd4d dropbear-tfm
- Update tfm changes to current default tip
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 21 Nov 2011 19:52:28 +0800 |
parents | 76097ec1a29a a98a2138364a |
children | 33fd2f3499d2 |
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 "bignum.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "dss.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "buffer.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "ssh.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "random.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 /* Handle DSS (Digital Signature Standard), aka DSA (D.S. Algorithm), |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 * operations, such as key reading, signing, verification. Key generation |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 * is in gendss.c, since it isn't required in the server itself. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 * See FIPS186 or the Handbook of Applied Cryptography for details of the |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 * algorithm */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 #ifdef DROPBEAR_DSS |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 /* Load a dss key from a buffer, initialising the values. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 * The key will have the same format as buf_put_dss_key. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 * These should be freed with dss_key_free. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 int buf_get_dss_pub_key(buffer* buf, dss_key *key) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
48 TRACE(("enter buf_get_dss_pub_key")) |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
49 dropbear_assert(key != NULL); |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
50 key->p = m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
51 key->q = m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
52 key->g = m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
53 key->y = m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
54 fp_init(key->p); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
55 fp_init(key->q); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
56 fp_init(key->g); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
57 fp_init(key->y); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 key->x = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 buf_incrpos(buf, 4+SSH_SIGNKEY_DSS_LEN); /* int + "ssh-dss" */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
61 if (buf_getfpint(buf, key->p) == DROPBEAR_FAILURE |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
62 || buf_getfpint(buf, key->q) == DROPBEAR_FAILURE |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
63 || buf_getfpint(buf, key->g) == DROPBEAR_FAILURE |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
64 || buf_getfpint(buf, key->y) == DROPBEAR_FAILURE) { |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
65 TRACE(("leave buf_get_dss_pub_key: failed reading fpints")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
69 if (fp_count_bits(key->p) < MIN_DSS_KEYLEN) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 dropbear_log(LOG_WARNING, "DSS key too short"); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
71 TRACE(("leave buf_get_dss_pub_key: short key")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
75 TRACE(("leave buf_get_dss_pub_key: success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 return DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 /* Same as buf_get_dss_pub_key, but reads a private "x" key at the end. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 * Loads a private dss key from a buffer |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 int buf_get_dss_priv_key(buffer* buf, dss_key *key) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 int ret = DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
86 dropbear_assert(key != NULL); |
4
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 ret = buf_get_dss_pub_key(buf, key); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 if (ret == DROPBEAR_FAILURE) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
93 key->x = m_malloc(sizeof(fp_int)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
94 m_fp_init(key->x); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
95 ret = buf_getfpint(buf, key->x); |
368
ed910547d449
Free x component of DSS key upon failure to load
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
96 if (ret == DROPBEAR_FAILURE) { |
ed910547d449
Free x component of DSS key upon failure to load
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
97 m_free(key->x); |
ed910547d449
Free x component of DSS key upon failure to load
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
98 } |
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 return ret; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 |
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 /* Clear and free the memory used by a public or private key */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 void dss_key_free(dss_key *key) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
107 TRACE(("enter dsa_key_free")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 if (key == NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
109 TRACE(("enter dsa_key_free: key == NULL")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 if (key->p) { |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
113 fp_zero(key->p); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 m_free(key->p); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 if (key->q) { |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
117 fp_zero(key->q); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 m_free(key->q); |
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 if (key->g) { |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
121 fp_zero(key->g); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 m_free(key->g); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 if (key->y) { |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
125 fp_zero(key->y); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 m_free(key->y); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 if (key->x) { |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
129 fp_zero(key->x); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 m_free(key->x); |
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 m_free(key); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
133 TRACE(("leave dsa_key_free")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 /* put the dss public key into the buffer in the required format: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 * string "ssh-dss" |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
139 * fpint p |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
140 * fpint q |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
141 * fpint g |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
142 * fpint y |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 void buf_put_dss_pub_key(buffer* buf, dss_key *key) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
146 dropbear_assert(key != NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
148 buf_putfpint(buf, key->p); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
149 buf_putfpint(buf, key->q); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
150 buf_putfpint(buf, key->g); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
151 buf_putfpint(buf, key->y); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 /* Same as buf_put_dss_pub_key, but with the private "x" key appended */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 void buf_put_dss_priv_key(buffer* buf, dss_key *key) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
158 dropbear_assert(key != NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 buf_put_dss_pub_key(buf, key); |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
160 buf_putfpint(buf, key->x); |
4
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 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 #ifdef DROPBEAR_SIGNKEY_VERIFY |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 /* Verify a DSS signature (in buf) made on data by the key given. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 int buf_dss_verify(buffer* buf, dss_key *key, const unsigned char* data, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 unsigned int len) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 unsigned char msghash[SHA1_HASH_SIZE]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 hash_state hs; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 int ret = DROPBEAR_FAILURE; |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
173 DEF_FP_INT(val1); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
174 DEF_FP_INT(val2); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
175 DEF_FP_INT(val3); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
176 DEF_FP_INT(val4); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 char * string = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 int stringlen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
180 TRACE(("enter buf_dss_verify")) |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
181 dropbear_assert(key != NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
183 fp_init(&val1); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
184 fp_init(&val2); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
185 fp_init(&val3); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
186 fp_init(&val4); |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
187 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 /* get blob, check length */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
189 string = buf_getstring(buf, &stringlen); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 if (stringlen != 2*SHA1_HASH_SIZE) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
192 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 /* hash the data */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 sha1_init(&hs); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 sha1_process(&hs, data, len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 sha1_done(&hs, msghash); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
198 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
199 /* create the signature - s' and r' are the received signatures in buf */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 /* w = (s')-1 mod q */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
201 /* let val1 = s' */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
202 bytes_to_fp(&val1, &string[SHA1_HASH_SIZE], SHA1_HASH_SIZE); |
188
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
186
diff
changeset
|
203 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
204 if (fp_cmp(&val1, key->q) != FP_LT) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
205 TRACE(("verify failed, s' >= q")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
206 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
207 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
208 /* let val2 = w = (s')^-1 mod q*/ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
209 if (fp_invmod(&val1, key->q, &val2) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 /* u1 = ((SHA(M')w) mod q */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 /* let val1 = SHA(M') = msghash */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
215 bytes_to_fp(&val1, msghash, SHA1_HASH_SIZE); |
188
c9483550701b
- refactored random mp_int generation and byte->mp_int code
Matt Johnston <matt@ucc.asn.au>
parents:
186
diff
changeset
|
216 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 /* let val3 = u1 = ((SHA(M')w) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
218 if (fp_mulmod(&val1, &val2, key->q, &val3) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 /* u2 = ((r')w) mod q */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 /* let val1 = r' */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
224 bytes_to_fp(&val1, &string[0], SHA1_HASH_SIZE); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
225 if (fp_cmp(&val1, key->q) != FP_LT) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
226 TRACE(("verify failed, r' >= q")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 /* let val4 = u2 = ((r')w) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
230 if (fp_mulmod(&val1, &val2, key->q, &val4) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 /* v = (((g)^u1 (y)^u2) mod p) mod q */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 /* val2 = g^u1 mod p */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
236 if (fp_exptmod(key->g, &val3, key->p, &val2) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 /* val3 = y^u2 mod p */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
240 if (fp_exptmod(key->y, &val4, key->p, &val3) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
241 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 /* val4 = ((g)^u1 (y)^u2) mod p */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
244 if (fp_mulmod(&val2, &val3, key->p, &val4) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
247 /* val2 = v = (((g)^u1 (y)^u2) mod p) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
248 if (fp_mod(&val4, key->q, &val2) != FP_OKAY) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
249 goto out; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
250 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
251 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
252 /* check whether signatures verify */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
253 if (fp_cmp(&val2, &val1) == FP_EQ) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 /* good sig */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 ret = DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 out: |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
259 m_fp_zero_multi(&val1, &val2, &val3, &val4, NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 m_free(string); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
262 return ret; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
265 #endif /* DROPBEAR_SIGNKEY_VERIFY */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
267 #ifdef DSS_PROTOK |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
268 /* convert an unsigned mp into an array of bytes, malloced. |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
269 * This array must be freed after use, len contains the length of the array, |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
270 * if len != NULL */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
271 static unsigned char* fptobytes(fp_int *mp, int *len) { |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
272 |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
273 unsigned char* ret; |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
274 int size; |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
275 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
276 size = fp_unsigned_bin_size(mp); |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
277 ret = m_malloc(size); |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
278 fp_to_unsigned_bin(mp, ret); |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
279 if (len != NULL) { |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
280 *len = size; |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
281 } |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
282 return ret; |
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
283 } |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
284 #endif |
150
82fcf3185616
Cleaning out various dead wood found with -dead_strip
Matt Johnston <matt@ucc.asn.au>
parents:
84
diff
changeset
|
285 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
286 /* Sign the data presented with key, writing the signature contents |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
287 * to the buffer |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 * When DSS_PROTOK is #defined: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 * The alternate k generation method is based on the method used in PuTTY. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
291 * In particular to avoid being vulnerable to attacks using flaws in random |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 * generation of k, we use the following: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
293 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
294 * proto_k = SHA512 ( SHA512(x) || SHA160(message) ) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
295 * k = proto_k mod q |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
296 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
297 * Now we aren't relying on the random number generation to protect the private |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
298 * key x, which is a long term secret */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
299 void buf_put_dss_sign(buffer* buf, dss_key *key, const unsigned char* data, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
300 unsigned int len) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
301 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
302 unsigned char msghash[SHA1_HASH_SIZE]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
303 unsigned int writelen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
304 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
305 #ifdef DSS_PROTOK |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
306 unsigned char privkeyhash[SHA512_HASH_SIZE]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
307 unsigned char *privkeytmp; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
308 unsigned char proto_k[SHA512_HASH_SIZE]; |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
309 DEF_FP_INT(dss_protok); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
310 #endif |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
311 DEF_FP_INT(dss_k); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
312 DEF_FP_INT(dss_m); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
313 DEF_FP_INT(dss_temp1); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
314 DEF_FP_INT(dss_temp2); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
315 DEF_FP_INT(dss_r); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
316 DEF_FP_INT(dss_s); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
317 hash_state hs; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
318 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
319 TRACE(("enter buf_put_dss_sign")) |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
320 dropbear_assert(key != NULL); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
321 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
322 /* hash the data */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
323 sha1_init(&hs); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
324 sha1_process(&hs, data, len); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
325 sha1_done(&hs, msghash); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
326 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
327 m_fp_init_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
328 &dss_m, NULL); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
329 #ifdef DSS_PROTOK |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
330 /* hash the privkey */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
331 privkeytmp = fptobytes(key->x, &i); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
332 sha512_init(&hs); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
333 sha512_process(&hs, "the quick brown fox jumped over the lazy dog", 44); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
334 sha512_process(&hs, privkeytmp, i); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
335 sha512_done(&hs, privkeyhash); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
336 m_burn(privkeytmp, i); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
337 m_free(privkeytmp); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
338 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
339 /* calculate proto_k */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
340 sha512_init(&hs); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
341 sha512_process(&hs, privkeyhash, SHA512_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
342 sha512_process(&hs, msghash, SHA1_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
343 sha512_done(&hs, proto_k); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
344 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
345 /* generate k */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
346 m_fp_init(&dss_protok); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
347 bytes_to_fp(&dss_protok, proto_k, SHA512_HASH_SIZE); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
348 if (fp_mod(&dss_protok, key->q, &dss_k) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
349 dropbear_exit("DSS error"); |
340 | 350 } |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
351 m_fp_zero(&dss_protok); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
352 m_burn(proto_k, SHA512_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
353 #else /* DSS_PROTOK not defined*/ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
354 gen_random_fpint(key->q, &dss_k); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
355 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
356 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
357 /* now generate the actual signature */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
358 bytes_to_fp(&dss_m, msghash, SHA1_HASH_SIZE); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
359 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
360 /* g^k mod p */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
361 if (fp_exptmod(key->g, &dss_k, key->p, &dss_temp1) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
362 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
363 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
364 /* r = (g^k mod p) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
365 if (fp_mod(&dss_temp1, key->q, &dss_r) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
366 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
367 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
368 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
369 /* x*r mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
370 if (fp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
371 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
372 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
373 /* (SHA1(M) + xr) mod q) */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
374 if (fp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
375 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
376 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
377 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
378 /* (k^-1) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
379 if (fp_invmod(&dss_k, key->q, &dss_temp1) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
380 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
381 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
382 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
383 /* s = (k^-1(SHA1(M) + xr)) mod q */ |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
384 if (fp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != FP_OKAY) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
586
diff
changeset
|
385 dropbear_exit("DSS error"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
386 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
387 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
388 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
389 buf_putint(buf, 2*SHA1_HASH_SIZE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
390 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
391 writelen = fp_unsigned_bin_size(&dss_r); |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
392 dropbear_assert(writelen <= SHA1_HASH_SIZE); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
393 /* need to pad to 160 bits with leading zeros */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
394 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
395 buf_putbyte(buf, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
396 } |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
397 fp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
398 fp_zero(&dss_r); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
399 buf_incrwritepos(buf, writelen); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
400 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
401 writelen = fp_unsigned_bin_size(&dss_s); |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
188
diff
changeset
|
402 dropbear_assert(writelen <= SHA1_HASH_SIZE); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
403 /* need to pad to 160 bits with leading zeros */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
404 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
405 buf_putbyte(buf, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
406 } |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
407 fp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen)); |
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
408 fp_zero(&dss_s); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
409 buf_incrwritepos(buf, writelen); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
410 |
640
76097ec1a29a
- Bring in original tomsfastmath patch against 0.52 from Peter Turczak
Matt Johnston <matt@ucc.asn.au>
parents:
378
diff
changeset
|
411 m_fp_zero_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
412 &dss_m, NULL); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
413 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
414 /* create the signature to return */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
415 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
416 TRACE(("leave buf_put_dss_sign")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
417 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
418 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
419 #endif /* DROPBEAR_DSS */ |