summaryrefslogtreecommitdiff
path: root/sshbuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'sshbuf.h')
-rw-r--r--sshbuf.h53
1 files changed, 50 insertions, 3 deletions
diff --git a/sshbuf.h b/sshbuf.h
index 7900b82ba..ebd64b10e 100644
--- a/sshbuf.h
+++ b/sshbuf.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshbuf.h,v 1.13 2019/01/21 09:54:11 djm Exp $ */ 1/* $OpenBSD: sshbuf.h,v 1.18 2019/09/06 05:23:55 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller 3 * Copyright (c) 2011 Damien Miller
4 * 4 *
@@ -176,6 +176,26 @@ int sshbuf_put_u32(struct sshbuf *buf, u_int32_t val);
176int sshbuf_put_u16(struct sshbuf *buf, u_int16_t val); 176int sshbuf_put_u16(struct sshbuf *buf, u_int16_t val);
177int sshbuf_put_u8(struct sshbuf *buf, u_char val); 177int sshbuf_put_u8(struct sshbuf *buf, u_char val);
178 178
179/* Functions to peek at the contents of a buffer without modifying it. */
180int sshbuf_peek_u64(const struct sshbuf *buf, size_t offset,
181 u_int64_t *valp);
182int sshbuf_peek_u32(const struct sshbuf *buf, size_t offset,
183 u_int32_t *valp);
184int sshbuf_peek_u16(const struct sshbuf *buf, size_t offset,
185 u_int16_t *valp);
186int sshbuf_peek_u8(const struct sshbuf *buf, size_t offset,
187 u_char *valp);
188
189/*
190 * Functions to poke values into an exisiting buffer (e.g. a length header
191 * to a packet). The destination bytes must already exist in the buffer.
192 */
193int sshbuf_poke_u64(struct sshbuf *buf, size_t offset, u_int64_t val);
194int sshbuf_poke_u32(struct sshbuf *buf, size_t offset, u_int32_t val);
195int sshbuf_poke_u16(struct sshbuf *buf, size_t offset, u_int16_t val);
196int sshbuf_poke_u8(struct sshbuf *buf, size_t offset, u_char val);
197int sshbuf_poke(struct sshbuf *buf, size_t offset, void *v, size_t len);
198
179/* 199/*
180 * Functions to extract or store SSH wire encoded strings (u32 len || data) 200 * Functions to extract or store SSH wire encoded strings (u32 len || data)
181 * The "cstring" variants admit no \0 characters in the string contents. 201 * The "cstring" variants admit no \0 characters in the string contents.
@@ -202,7 +222,6 @@ int sshbuf_get_string_direct(struct sshbuf *buf, const u_char **valp,
202/* Another variant: "peeks" into the buffer without modifying it */ 222/* Another variant: "peeks" into the buffer without modifying it */
203int sshbuf_peek_string_direct(const struct sshbuf *buf, const u_char **valp, 223int sshbuf_peek_string_direct(const struct sshbuf *buf, const u_char **valp,
204 size_t *lenp); 224 size_t *lenp);
205/* XXX peek_u8 / peek_u32 */
206 225
207/* 226/*
208 * Functions to extract or store SSH wire encoded bignums and elliptic 227 * Functions to extract or store SSH wire encoded bignums and elliptic
@@ -232,12 +251,40 @@ void sshbuf_dump_data(const void *s, size_t len, FILE *f);
232char *sshbuf_dtob16(struct sshbuf *buf); 251char *sshbuf_dtob16(struct sshbuf *buf);
233 252
234/* Encode the contents of the buffer as base64 */ 253/* Encode the contents of the buffer as base64 */
235char *sshbuf_dtob64(struct sshbuf *buf); 254char *sshbuf_dtob64_string(const struct sshbuf *buf, int wrap);
255int sshbuf_dtob64(const struct sshbuf *d, struct sshbuf *b64, int wrap);
236 256
237/* Decode base64 data and append it to the buffer */ 257/* Decode base64 data and append it to the buffer */
238int sshbuf_b64tod(struct sshbuf *buf, const char *b64); 258int sshbuf_b64tod(struct sshbuf *buf, const char *b64);
239 259
240/* 260/*
261 * Tests whether the buffer contains the specified byte sequence at the
262 * specified offset. Returns 0 on successful match, or a ssherr.h code
263 * otherwise. SSH_ERR_INVALID_FORMAT indicates sufficient bytes were
264 * present but the buffer contents did not match those supplied. Zero-
265 * length comparisons are not allowed.
266 *
267 * If sufficient data is present to make a comparison, then it is
268 * performed with timing independent of the value of the data. If
269 * insufficient data is present then the comparison is not attempted at
270 * all.
271 */
272int sshbuf_cmp(const struct sshbuf *b, size_t offset,
273 const void *s, size_t len);
274
275/*
276 * Searches the buffer for the specified string. Returns 0 on success
277 * and updates *offsetp with the offset of the first match, relative to
278 * the start of the buffer. Otherwise sshbuf_find will return a ssherr.h
279 * error code. SSH_ERR_INVALID_FORMAT indicates sufficient bytes were
280 * present in the buffer for a match to be possible but none was found.
281 * Searches for zero-length data are not allowed.
282 */
283int
284sshbuf_find(const struct sshbuf *b, size_t start_offset,
285 const void *s, size_t len, size_t *offsetp);
286
287/*
241 * Duplicate the contents of a buffer to a string (caller to free). 288 * Duplicate the contents of a buffer to a string (caller to free).
242 * Returns NULL on buffer error, or if the buffer contains a premature 289 * Returns NULL on buffer error, or if the buffer contains a premature
243 * nul character. 290 * nul character.