diff options
author | markus@openbsd.org <markus@openbsd.org> | 2018-07-09 21:56:06 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-07-10 16:44:17 +1000 |
commit | cb30cd47041edb03476be1c8ef7bc1f4b69d1555 (patch) | |
tree | b6bd48d3ab741d48bbba182dcce30654286c8627 | |
parent | 235c7c4e3bf046982c2d8242f30aacffa01073d1 (diff) |
upstream: remove legacy buffer API emulation layer; ok djm@
OpenBSD-Commit-ID: 2dd5dc17cbc23195be4299fa93be2707a0e08ad9
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | bufaux.c | 259 | ||||
-rw-r--r-- | bufbn.c | 69 | ||||
-rw-r--r-- | bufec.c | 74 | ||||
-rw-r--r-- | buffer.c | 118 | ||||
-rw-r--r-- | buffer.h | 95 | ||||
-rw-r--r-- | kex.h | 3 | ||||
-rw-r--r-- | sshbuf.c | 22 | ||||
-rw-r--r-- | sshbuf.h | 11 |
9 files changed, 6 insertions, 649 deletions
diff --git a/Makefile.in b/Makefile.in index 2cd485538..277418cfe 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -84,7 +84,7 @@ LIBOPENSSH_OBJS=\ | |||
84 | ${XMSS_OBJS} | 84 | ${XMSS_OBJS} |
85 | 85 | ||
86 | LIBSSH_OBJS=${LIBOPENSSH_OBJS} \ | 86 | LIBSSH_OBJS=${LIBOPENSSH_OBJS} \ |
87 | authfd.o authfile.o bufaux.o bufbn.o bufec.o buffer.o \ | 87 | authfd.o authfile.o \ |
88 | canohost.o channels.o cipher.o cipher-aes.o cipher-aesctr.o \ | 88 | canohost.o channels.o cipher.o cipher-aes.o cipher-aesctr.o \ |
89 | cipher-ctr.o cleanup.o \ | 89 | cipher-ctr.o cleanup.o \ |
90 | compat.o crc32.o fatal.o hostfile.o \ | 90 | compat.o crc32.o fatal.o hostfile.o \ |
@@ -175,7 +175,7 @@ sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS) | |||
175 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS) | 175 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS) |
176 | 176 | ||
177 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o | 177 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o |
178 | $(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 178 | $(LD) -o $@ scp.o progressmeter.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
179 | 179 | ||
180 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o | 180 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o |
181 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 181 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
diff --git a/bufaux.c b/bufaux.c deleted file mode 100644 index 3976896a9..000000000 --- a/bufaux.c +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
1 | /* $OpenBSD: bufaux.c,v 1.60 2014/04/30 05:29:56 djm Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ | ||
19 | |||
20 | #include "includes.h" | ||
21 | |||
22 | #include <sys/types.h> | ||
23 | |||
24 | #include "buffer.h" | ||
25 | #include "log.h" | ||
26 | #include "ssherr.h" | ||
27 | |||
28 | int | ||
29 | buffer_get_short_ret(u_short *v, Buffer *buffer) | ||
30 | { | ||
31 | int ret; | ||
32 | |||
33 | if ((ret = sshbuf_get_u16(buffer, v)) != 0) { | ||
34 | error("%s: %s", __func__, ssh_err(ret)); | ||
35 | return -1; | ||
36 | } | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | u_short | ||
41 | buffer_get_short(Buffer *buffer) | ||
42 | { | ||
43 | u_short ret; | ||
44 | |||
45 | if (buffer_get_short_ret(&ret, buffer) == -1) | ||
46 | fatal("%s: buffer error", __func__); | ||
47 | |||
48 | return (ret); | ||
49 | } | ||
50 | |||
51 | int | ||
52 | buffer_get_int_ret(u_int *v, Buffer *buffer) | ||
53 | { | ||
54 | int ret; | ||
55 | |||
56 | if ((ret = sshbuf_get_u32(buffer, v)) != 0) { | ||
57 | error("%s: %s", __func__, ssh_err(ret)); | ||
58 | return -1; | ||
59 | } | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | u_int | ||
64 | buffer_get_int(Buffer *buffer) | ||
65 | { | ||
66 | u_int ret; | ||
67 | |||
68 | if (buffer_get_int_ret(&ret, buffer) == -1) | ||
69 | fatal("%s: buffer error", __func__); | ||
70 | |||
71 | return (ret); | ||
72 | } | ||
73 | |||
74 | int | ||
75 | buffer_get_int64_ret(u_int64_t *v, Buffer *buffer) | ||
76 | { | ||
77 | int ret; | ||
78 | |||
79 | if ((ret = sshbuf_get_u64(buffer, v)) != 0) { | ||
80 | error("%s: %s", __func__, ssh_err(ret)); | ||
81 | return -1; | ||
82 | } | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | u_int64_t | ||
87 | buffer_get_int64(Buffer *buffer) | ||
88 | { | ||
89 | u_int64_t ret; | ||
90 | |||
91 | if (buffer_get_int64_ret(&ret, buffer) == -1) | ||
92 | fatal("%s: buffer error", __func__); | ||
93 | |||
94 | return (ret); | ||
95 | } | ||
96 | |||
97 | void | ||
98 | buffer_put_short(Buffer *buffer, u_short value) | ||
99 | { | ||
100 | int ret; | ||
101 | |||
102 | if ((ret = sshbuf_put_u16(buffer, value)) != 0) | ||
103 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
104 | } | ||
105 | |||
106 | void | ||
107 | buffer_put_int(Buffer *buffer, u_int value) | ||
108 | { | ||
109 | int ret; | ||
110 | |||
111 | if ((ret = sshbuf_put_u32(buffer, value)) != 0) | ||
112 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
113 | } | ||
114 | |||
115 | void | ||
116 | buffer_put_int64(Buffer *buffer, u_int64_t value) | ||
117 | { | ||
118 | int ret; | ||
119 | |||
120 | if ((ret = sshbuf_put_u64(buffer, value)) != 0) | ||
121 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
122 | } | ||
123 | |||
124 | void * | ||
125 | buffer_get_string_ret(Buffer *buffer, u_int *length_ptr) | ||
126 | { | ||
127 | size_t len; | ||
128 | int ret; | ||
129 | u_char *value; | ||
130 | |||
131 | if ((ret = sshbuf_get_string(buffer, &value, &len)) != 0) { | ||
132 | error("%s: %s", __func__, ssh_err(ret)); | ||
133 | return NULL; | ||
134 | } | ||
135 | if (length_ptr != NULL) | ||
136 | *length_ptr = len; /* Safe: sshbuf never stores len > 2^31 */ | ||
137 | return value; | ||
138 | } | ||
139 | |||
140 | void * | ||
141 | buffer_get_string(Buffer *buffer, u_int *length_ptr) | ||
142 | { | ||
143 | void *ret; | ||
144 | |||
145 | if ((ret = buffer_get_string_ret(buffer, length_ptr)) == NULL) | ||
146 | fatal("%s: buffer error", __func__); | ||
147 | return (ret); | ||
148 | } | ||
149 | |||
150 | char * | ||
151 | buffer_get_cstring_ret(Buffer *buffer, u_int *length_ptr) | ||
152 | { | ||
153 | size_t len; | ||
154 | int ret; | ||
155 | char *value; | ||
156 | |||
157 | if ((ret = sshbuf_get_cstring(buffer, &value, &len)) != 0) { | ||
158 | error("%s: %s", __func__, ssh_err(ret)); | ||
159 | return NULL; | ||
160 | } | ||
161 | if (length_ptr != NULL) | ||
162 | *length_ptr = len; /* Safe: sshbuf never stores len > 2^31 */ | ||
163 | return value; | ||
164 | } | ||
165 | |||
166 | char * | ||
167 | buffer_get_cstring(Buffer *buffer, u_int *length_ptr) | ||
168 | { | ||
169 | char *ret; | ||
170 | |||
171 | if ((ret = buffer_get_cstring_ret(buffer, length_ptr)) == NULL) | ||
172 | fatal("%s: buffer error", __func__); | ||
173 | return ret; | ||
174 | } | ||
175 | |||
176 | const void * | ||
177 | buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr) | ||
178 | { | ||
179 | size_t len; | ||
180 | int ret; | ||
181 | const u_char *value; | ||
182 | |||
183 | if ((ret = sshbuf_get_string_direct(buffer, &value, &len)) != 0) { | ||
184 | error("%s: %s", __func__, ssh_err(ret)); | ||
185 | return NULL; | ||
186 | } | ||
187 | if (length_ptr != NULL) | ||
188 | *length_ptr = len; /* Safe: sshbuf never stores len > 2^31 */ | ||
189 | return value; | ||
190 | } | ||
191 | |||
192 | const void * | ||
193 | buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) | ||
194 | { | ||
195 | const void *ret; | ||
196 | |||
197 | if ((ret = buffer_get_string_ptr_ret(buffer, length_ptr)) == NULL) | ||
198 | fatal("%s: buffer error", __func__); | ||
199 | return (ret); | ||
200 | } | ||
201 | |||
202 | void | ||
203 | buffer_put_string(Buffer *buffer, const void *buf, u_int len) | ||
204 | { | ||
205 | int ret; | ||
206 | |||
207 | if ((ret = sshbuf_put_string(buffer, buf, len)) != 0) | ||
208 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
209 | } | ||
210 | |||
211 | void | ||
212 | buffer_put_cstring(Buffer *buffer, const char *s) | ||
213 | { | ||
214 | int ret; | ||
215 | |||
216 | if ((ret = sshbuf_put_cstring(buffer, s)) != 0) | ||
217 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
218 | } | ||
219 | |||
220 | int | ||
221 | buffer_get_char_ret(char *v, Buffer *buffer) | ||
222 | { | ||
223 | int ret; | ||
224 | |||
225 | if ((ret = sshbuf_get_u8(buffer, (u_char *)v)) != 0) { | ||
226 | error("%s: %s", __func__, ssh_err(ret)); | ||
227 | return -1; | ||
228 | } | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | int | ||
233 | buffer_get_char(Buffer *buffer) | ||
234 | { | ||
235 | char ch; | ||
236 | |||
237 | if (buffer_get_char_ret(&ch, buffer) == -1) | ||
238 | fatal("%s: buffer error", __func__); | ||
239 | return (u_char) ch; | ||
240 | } | ||
241 | |||
242 | void | ||
243 | buffer_put_char(Buffer *buffer, int value) | ||
244 | { | ||
245 | int ret; | ||
246 | |||
247 | if ((ret = sshbuf_put_u8(buffer, value)) != 0) | ||
248 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
249 | } | ||
250 | |||
251 | void | ||
252 | buffer_put_bignum2_from_string(Buffer *buffer, const u_char *s, u_int l) | ||
253 | { | ||
254 | int ret; | ||
255 | |||
256 | if ((ret = sshbuf_put_bignum2_bytes(buffer, s, l)) != 0) | ||
257 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
258 | } | ||
259 | |||
diff --git a/bufbn.c b/bufbn.c deleted file mode 100644 index 98f9466bc..000000000 --- a/bufbn.c +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* $OpenBSD: bufbn.c,v 1.13 2017/04/30 23:23:54 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ | ||
20 | |||
21 | #include "includes.h" | ||
22 | |||
23 | #ifdef WITH_OPENSSL | ||
24 | |||
25 | #include <sys/types.h> | ||
26 | |||
27 | #include "buffer.h" | ||
28 | #include "log.h" | ||
29 | #include "ssherr.h" | ||
30 | |||
31 | int | ||
32 | buffer_put_bignum2_ret(Buffer *buffer, const BIGNUM *value) | ||
33 | { | ||
34 | int ret; | ||
35 | |||
36 | if ((ret = sshbuf_put_bignum2(buffer, value)) != 0) { | ||
37 | error("%s: %s", __func__, ssh_err(ret)); | ||
38 | return -1; | ||
39 | } | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | void | ||
44 | buffer_put_bignum2(Buffer *buffer, const BIGNUM *value) | ||
45 | { | ||
46 | if (buffer_put_bignum2_ret(buffer, value) == -1) | ||
47 | fatal("%s: buffer error", __func__); | ||
48 | } | ||
49 | |||
50 | int | ||
51 | buffer_get_bignum2_ret(Buffer *buffer, BIGNUM *value) | ||
52 | { | ||
53 | int ret; | ||
54 | |||
55 | if ((ret = sshbuf_get_bignum2(buffer, value)) != 0) { | ||
56 | error("%s: %s", __func__, ssh_err(ret)); | ||
57 | return -1; | ||
58 | } | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | void | ||
63 | buffer_get_bignum2(Buffer *buffer, BIGNUM *value) | ||
64 | { | ||
65 | if (buffer_get_bignum2_ret(buffer, value) == -1) | ||
66 | fatal("%s: buffer error", __func__); | ||
67 | } | ||
68 | |||
69 | #endif /* WITH_OPENSSL */ | ||
diff --git a/bufec.c b/bufec.c deleted file mode 100644 index 749ce9d4c..000000000 --- a/bufec.c +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | /* $OpenBSD: bufec.c,v 1.4 2014/04/30 05:29:56 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ | ||
20 | |||
21 | #include "includes.h" | ||
22 | |||
23 | #include <sys/types.h> | ||
24 | |||
25 | #include "buffer.h" | ||
26 | #include "log.h" | ||
27 | #include "ssherr.h" | ||
28 | |||
29 | #ifdef OPENSSL_HAS_ECC | ||
30 | |||
31 | int | ||
32 | buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve, | ||
33 | const EC_POINT *point) | ||
34 | { | ||
35 | int ret; | ||
36 | |||
37 | if ((ret = sshbuf_put_ec(buffer, point, curve)) != 0) { | ||
38 | error("%s: %s", __func__, ssh_err(ret)); | ||
39 | return -1; | ||
40 | } | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | void | ||
45 | buffer_put_ecpoint(Buffer *buffer, const EC_GROUP *curve, | ||
46 | const EC_POINT *point) | ||
47 | { | ||
48 | if (buffer_put_ecpoint_ret(buffer, curve, point) == -1) | ||
49 | fatal("%s: buffer error", __func__); | ||
50 | } | ||
51 | |||
52 | int | ||
53 | buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve, | ||
54 | EC_POINT *point) | ||
55 | { | ||
56 | int ret; | ||
57 | |||
58 | if ((ret = sshbuf_get_ec(buffer, point, curve)) != 0) { | ||
59 | error("%s: %s", __func__, ssh_err(ret)); | ||
60 | return -1; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | void | ||
66 | buffer_get_ecpoint(Buffer *buffer, const EC_GROUP *curve, | ||
67 | EC_POINT *point) | ||
68 | { | ||
69 | if (buffer_get_ecpoint_ret(buffer, curve, point) == -1) | ||
70 | fatal("%s: buffer error", __func__); | ||
71 | } | ||
72 | |||
73 | #endif /* OPENSSL_HAS_ECC */ | ||
74 | |||
diff --git a/buffer.c b/buffer.c deleted file mode 100644 index c5f708ab2..000000000 --- a/buffer.c +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /* $OpenBSD: buffer.c,v 1.36 2014/04/30 05:29:56 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ | ||
20 | |||
21 | #include "includes.h" | ||
22 | |||
23 | #include <sys/types.h> | ||
24 | |||
25 | #include "buffer.h" | ||
26 | #include "log.h" | ||
27 | #include "ssherr.h" | ||
28 | |||
29 | void | ||
30 | buffer_append(Buffer *buffer, const void *data, u_int len) | ||
31 | { | ||
32 | int ret; | ||
33 | |||
34 | if ((ret = sshbuf_put(buffer, data, len)) != 0) | ||
35 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
36 | } | ||
37 | |||
38 | void * | ||
39 | buffer_append_space(Buffer *buffer, u_int len) | ||
40 | { | ||
41 | int ret; | ||
42 | u_char *p; | ||
43 | |||
44 | if ((ret = sshbuf_reserve(buffer, len, &p)) != 0) | ||
45 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
46 | return p; | ||
47 | } | ||
48 | |||
49 | int | ||
50 | buffer_check_alloc(Buffer *buffer, u_int len) | ||
51 | { | ||
52 | int ret = sshbuf_check_reserve(buffer, len); | ||
53 | |||
54 | if (ret == 0) | ||
55 | return 1; | ||
56 | if (ret == SSH_ERR_NO_BUFFER_SPACE) | ||
57 | return 0; | ||
58 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
59 | } | ||
60 | |||
61 | int | ||
62 | buffer_get_ret(Buffer *buffer, void *buf, u_int len) | ||
63 | { | ||
64 | int ret; | ||
65 | |||
66 | if ((ret = sshbuf_get(buffer, buf, len)) != 0) { | ||
67 | error("%s: %s", __func__, ssh_err(ret)); | ||
68 | return -1; | ||
69 | } | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | void | ||
74 | buffer_get(Buffer *buffer, void *buf, u_int len) | ||
75 | { | ||
76 | if (buffer_get_ret(buffer, buf, len) == -1) | ||
77 | fatal("%s: buffer error", __func__); | ||
78 | } | ||
79 | |||
80 | int | ||
81 | buffer_consume_ret(Buffer *buffer, u_int bytes) | ||
82 | { | ||
83 | int ret = sshbuf_consume(buffer, bytes); | ||
84 | |||
85 | if (ret == 0) | ||
86 | return 0; | ||
87 | if (ret == SSH_ERR_MESSAGE_INCOMPLETE) | ||
88 | return -1; | ||
89 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
90 | } | ||
91 | |||
92 | void | ||
93 | buffer_consume(Buffer *buffer, u_int bytes) | ||
94 | { | ||
95 | if (buffer_consume_ret(buffer, bytes) == -1) | ||
96 | fatal("%s: buffer error", __func__); | ||
97 | } | ||
98 | |||
99 | int | ||
100 | buffer_consume_end_ret(Buffer *buffer, u_int bytes) | ||
101 | { | ||
102 | int ret = sshbuf_consume_end(buffer, bytes); | ||
103 | |||
104 | if (ret == 0) | ||
105 | return 0; | ||
106 | if (ret == SSH_ERR_MESSAGE_INCOMPLETE) | ||
107 | return -1; | ||
108 | fatal("%s: %s", __func__, ssh_err(ret)); | ||
109 | } | ||
110 | |||
111 | void | ||
112 | buffer_consume_end(Buffer *buffer, u_int bytes) | ||
113 | { | ||
114 | if (buffer_consume_end_ret(buffer, bytes) == -1) | ||
115 | fatal("%s: buffer error", __func__); | ||
116 | } | ||
117 | |||
118 | |||
diff --git a/buffer.h b/buffer.h deleted file mode 100644 index 56174394c..000000000 --- a/buffer.h +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* $OpenBSD: buffer.h,v 1.26 2017/04/30 23:23:54 djm Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2012 Damien Miller <djm@mindrot.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Emulation wrappers for legacy OpenSSH buffer API atop sshbuf */ | ||
20 | |||
21 | #ifndef BUFFER_H | ||
22 | #define BUFFER_H | ||
23 | |||
24 | #include "sshbuf.h" | ||
25 | |||
26 | typedef struct sshbuf Buffer; | ||
27 | |||
28 | #define buffer_init(b) sshbuf_init(b) | ||
29 | #define buffer_clear(b) sshbuf_reset(b) | ||
30 | #define buffer_free(b) sshbuf_free(b) | ||
31 | #define buffer_dump(b) sshbuf_dump(b, stderr) | ||
32 | |||
33 | /* XXX cast is safe: sshbuf never stores more than len 2^31 */ | ||
34 | #define buffer_len(b) ((u_int) sshbuf_len(b)) | ||
35 | #define buffer_ptr(b) sshbuf_mutable_ptr(b) | ||
36 | |||
37 | void buffer_append(Buffer *, const void *, u_int); | ||
38 | void *buffer_append_space(Buffer *, u_int); | ||
39 | int buffer_check_alloc(Buffer *, u_int); | ||
40 | void buffer_get(Buffer *, void *, u_int); | ||
41 | |||
42 | void buffer_consume(Buffer *, u_int); | ||
43 | void buffer_consume_end(Buffer *, u_int); | ||
44 | |||
45 | |||
46 | int buffer_get_ret(Buffer *, void *, u_int); | ||
47 | int buffer_consume_ret(Buffer *, u_int); | ||
48 | int buffer_consume_end_ret(Buffer *, u_int); | ||
49 | |||
50 | #include <openssl/objects.h> | ||
51 | #include <openssl/bn.h> | ||
52 | void buffer_put_bignum2(Buffer *, const BIGNUM *); | ||
53 | void buffer_get_bignum2(Buffer *, BIGNUM *); | ||
54 | void buffer_put_bignum2_from_string(Buffer *, const u_char *, u_int); | ||
55 | |||
56 | u_short buffer_get_short(Buffer *); | ||
57 | void buffer_put_short(Buffer *, u_short); | ||
58 | |||
59 | u_int buffer_get_int(Buffer *); | ||
60 | void buffer_put_int(Buffer *, u_int); | ||
61 | |||
62 | u_int64_t buffer_get_int64(Buffer *); | ||
63 | void buffer_put_int64(Buffer *, u_int64_t); | ||
64 | |||
65 | int buffer_get_char(Buffer *); | ||
66 | void buffer_put_char(Buffer *, int); | ||
67 | |||
68 | void *buffer_get_string(Buffer *, u_int *); | ||
69 | const void *buffer_get_string_ptr(Buffer *, u_int *); | ||
70 | void buffer_put_string(Buffer *, const void *, u_int); | ||
71 | char *buffer_get_cstring(Buffer *, u_int *); | ||
72 | void buffer_put_cstring(Buffer *, const char *); | ||
73 | |||
74 | #define buffer_skip_string(b) (void)buffer_get_string_ptr(b, NULL); | ||
75 | |||
76 | int buffer_put_bignum2_ret(Buffer *, const BIGNUM *); | ||
77 | int buffer_get_bignum2_ret(Buffer *, BIGNUM *); | ||
78 | int buffer_get_short_ret(u_short *, Buffer *); | ||
79 | int buffer_get_int_ret(u_int *, Buffer *); | ||
80 | int buffer_get_int64_ret(u_int64_t *, Buffer *); | ||
81 | void *buffer_get_string_ret(Buffer *, u_int *); | ||
82 | char *buffer_get_cstring_ret(Buffer *, u_int *); | ||
83 | const void *buffer_get_string_ptr_ret(Buffer *, u_int *); | ||
84 | int buffer_get_char_ret(char *, Buffer *); | ||
85 | |||
86 | #ifdef OPENSSL_HAS_ECC | ||
87 | #include <openssl/ec.h> | ||
88 | int buffer_put_ecpoint_ret(Buffer *, const EC_GROUP *, const EC_POINT *); | ||
89 | void buffer_put_ecpoint(Buffer *, const EC_GROUP *, const EC_POINT *); | ||
90 | int buffer_get_ecpoint_ret(Buffer *, const EC_GROUP *, EC_POINT *); | ||
91 | void buffer_get_ecpoint(Buffer *, const EC_GROUP *, EC_POINT *); | ||
92 | #endif | ||
93 | |||
94 | #endif /* BUFFER_H */ | ||
95 | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: kex.h,v 1.88 2018/07/09 13:37:10 sf Exp $ */ | 1 | /* $OpenBSD: kex.h,v 1.89 2018/07/09 21:56:06 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
@@ -27,7 +27,6 @@ | |||
27 | #define KEX_H | 27 | #define KEX_H |
28 | 28 | ||
29 | #include "mac.h" | 29 | #include "mac.h" |
30 | #include "buffer.h" /* XXX for typedef */ | ||
31 | #include "key.h" /* XXX for typedef */ | 30 | #include "key.h" /* XXX for typedef */ |
32 | 31 | ||
33 | #ifdef WITH_LEAKMALLOC | 32 | #ifdef WITH_LEAKMALLOC |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshbuf.c,v 1.11 2017/06/01 06:58:25 djm Exp $ */ | 1 | /* $OpenBSD: sshbuf.c,v 1.12 2018/07/09 21:56:06 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller | 3 | * Copyright (c) 2011 Damien Miller |
4 | * | 4 | * |
@@ -36,7 +36,6 @@ sshbuf_check_sanity(const struct sshbuf *buf) | |||
36 | (!buf->readonly && buf->d != buf->cd) || | 36 | (!buf->readonly && buf->d != buf->cd) || |
37 | buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX || | 37 | buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX || |
38 | buf->cd == NULL || | 38 | buf->cd == NULL || |
39 | (buf->dont_free && (buf->readonly || buf->parent != NULL)) || | ||
40 | buf->max_size > SSHBUF_SIZE_MAX || | 39 | buf->max_size > SSHBUF_SIZE_MAX || |
41 | buf->alloc > buf->max_size || | 40 | buf->alloc > buf->max_size || |
42 | buf->size > buf->alloc || | 41 | buf->size > buf->alloc || |
@@ -132,23 +131,8 @@ sshbuf_fromb(struct sshbuf *buf) | |||
132 | } | 131 | } |
133 | 132 | ||
134 | void | 133 | void |
135 | sshbuf_init(struct sshbuf *ret) | ||
136 | { | ||
137 | explicit_bzero(ret, sizeof(*ret)); | ||
138 | ret->alloc = SSHBUF_SIZE_INIT; | ||
139 | ret->max_size = SSHBUF_SIZE_MAX; | ||
140 | ret->readonly = 0; | ||
141 | ret->dont_free = 1; | ||
142 | ret->refcount = 1; | ||
143 | if ((ret->cd = ret->d = calloc(1, ret->alloc)) == NULL) | ||
144 | ret->alloc = 0; | ||
145 | } | ||
146 | |||
147 | void | ||
148 | sshbuf_free(struct sshbuf *buf) | 134 | sshbuf_free(struct sshbuf *buf) |
149 | { | 135 | { |
150 | int dont_free = 0; | ||
151 | |||
152 | if (buf == NULL) | 136 | if (buf == NULL) |
153 | return; | 137 | return; |
154 | /* | 138 | /* |
@@ -173,14 +157,12 @@ sshbuf_free(struct sshbuf *buf) | |||
173 | buf->refcount--; | 157 | buf->refcount--; |
174 | if (buf->refcount > 0) | 158 | if (buf->refcount > 0) |
175 | return; | 159 | return; |
176 | dont_free = buf->dont_free; | ||
177 | if (!buf->readonly) { | 160 | if (!buf->readonly) { |
178 | explicit_bzero(buf->d, buf->alloc); | 161 | explicit_bzero(buf->d, buf->alloc); |
179 | free(buf->d); | 162 | free(buf->d); |
180 | } | 163 | } |
181 | explicit_bzero(buf, sizeof(*buf)); | 164 | explicit_bzero(buf, sizeof(*buf)); |
182 | if (!dont_free) | 165 | free(buf); |
183 | free(buf); | ||
184 | } | 166 | } |
185 | 167 | ||
186 | void | 168 | void |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshbuf.h,v 1.10 2018/04/10 00:10:49 djm Exp $ */ | 1 | /* $OpenBSD: sshbuf.h,v 1.11 2018/07/09 21:56:06 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller | 3 | * Copyright (c) 2011 Damien Miller |
4 | * | 4 | * |
@@ -50,15 +50,6 @@ struct sshbuf { | |||
50 | struct sshbuf *parent; /* If child, pointer to parent */ | 50 | struct sshbuf *parent; /* If child, pointer to parent */ |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #ifndef SSHBUF_NO_DEPREACTED | ||
54 | /* | ||
55 | * NB. Please do not use sshbuf_init() in new code. Please use sshbuf_new() | ||
56 | * instead. sshbuf_init() is deprecated and will go away soon (it is | ||
57 | * only included to allow compat with buffer_* in OpenSSH) | ||
58 | */ | ||
59 | void sshbuf_init(struct sshbuf *buf); | ||
60 | #endif | ||
61 | |||
62 | /* | 53 | /* |
63 | * Create a new sshbuf buffer. | 54 | * Create a new sshbuf buffer. |
64 | * Returns pointer to buffer on success, or NULL on allocation failure. | 55 | * Returns pointer to buffer on success, or NULL on allocation failure. |