summaryrefslogtreecommitdiff
path: root/sshbuf.h
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-07-14 23:32:27 +0000
committerDamien Miller <djm@mindrot.org>2019-07-15 09:39:34 +1000
commit101d164723ffbc38f8036b6f3ea3bfef771ba250 (patch)
tree960920c2529e0b33eeade7b8e73785c38b283571 /sshbuf.h
parent7250879c72d28275a53f2f220e49646c3e42ef18 (diff)
upstream: add some functions to perform random-access read/write
operations inside buffers with bounds checking. Intended to replace manual pointer arithmetic wherever possible. feedback and ok markus@ OpenBSD-Commit-ID: 91771fde7732738f1ffed078aa5d3bee6d198409
Diffstat (limited to 'sshbuf.h')
-rw-r--r--sshbuf.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/sshbuf.h b/sshbuf.h
index 7900b82ba..1d9d5bb23 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.14 2019/07/14 23:32:27 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