diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:27:53 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:27:53 +0000 |
| commit | 808413da28df9fb93e1f304e6016b15e660f54c8 (patch) | |
| tree | f3ecb4f928716223c9563ee34e044ab84549debb /include/internal/packet.h | |
| parent | 8e12a5c4eb3507846b507d0afe87d115af41df40 (diff) | |
Diffstat (limited to 'include/internal/packet.h')
| -rw-r--r-- | include/internal/packet.h | 105 |
1 files changed, 49 insertions, 56 deletions
diff --git a/include/internal/packet.h b/include/internal/packet.h index 6fcd345ce28d..e5de4d43283f 100644 --- a/include/internal/packet.h +++ b/include/internal/packet.h @@ -8,16 +8,16 @@ */ #ifndef OSSL_INTERNAL_PACKET_H -# define OSSL_INTERNAL_PACKET_H -# pragma once +#define OSSL_INTERNAL_PACKET_H +#pragma once -# include <string.h> -# include <openssl/bn.h> -# include <openssl/buffer.h> -# include <openssl/crypto.h> -# include <openssl/e_os2.h> +#include <string.h> +#include <openssl/bn.h> +#include <openssl/buffer.h> +#include <openssl/crypto.h> +#include <openssl/e_os2.h> -# include "internal/numbers.h" +#include "internal/numbers.h" typedef struct { /* Pointer to where we are currently reading from */ @@ -67,8 +67,8 @@ static ossl_inline const unsigned char *PACKET_data(const PACKET *pkt) * is being used. */ __owur static ossl_inline int PACKET_buf_init(PACKET *pkt, - const unsigned char *buf, - size_t len) + const unsigned char *buf, + size_t len) { /* Sanity check for negative values. */ if (len > (size_t)(SIZE_MAX / 2)) @@ -92,7 +92,7 @@ static ossl_inline void PACKET_null_init(PACKET *pkt) * If lengths are equal, performs the comparison in constant time. */ __owur static ossl_inline int PACKET_equal(const PACKET *pkt, const void *ptr, - size_t num) + size_t num) { if (PACKET_remaining(pkt) != num) return 0; @@ -105,7 +105,7 @@ __owur static ossl_inline int PACKET_equal(const PACKET *pkt, const void *ptr, * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|. */ __owur static ossl_inline int PACKET_peek_sub_packet(const PACKET *pkt, - PACKET *subpkt, size_t len) + PACKET *subpkt, size_t len) { if (PACKET_remaining(pkt) < len) return 0; @@ -119,7 +119,7 @@ __owur static ossl_inline int PACKET_peek_sub_packet(const PACKET *pkt, * original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|. */ __owur static ossl_inline int PACKET_get_sub_packet(PACKET *pkt, - PACKET *subpkt, size_t len) + PACKET *subpkt, size_t len) { if (!PACKET_peek_sub_packet(pkt, subpkt, len)) return 0; @@ -134,7 +134,7 @@ __owur static ossl_inline int PACKET_get_sub_packet(PACKET *pkt, * |*data| */ __owur static ossl_inline int PACKET_peek_net_2(const PACKET *pkt, - unsigned int *data) + unsigned int *data) { if (PACKET_remaining(pkt) < 2) return 0; @@ -174,7 +174,7 @@ __owur static ossl_inline int PACKET_get_net_2_len(PACKET *pkt, size_t *data) * |*data| */ __owur static ossl_inline int PACKET_peek_net_3(const PACKET *pkt, - unsigned long *data) + unsigned long *data) { if (PACKET_remaining(pkt) < 3) return 0; @@ -215,7 +215,7 @@ __owur static ossl_inline int PACKET_get_net_3_len(PACKET *pkt, size_t *data) * |*data| */ __owur static ossl_inline int PACKET_peek_net_4(const PACKET *pkt, - unsigned long *data) + unsigned long *data) { if (PACKET_remaining(pkt) < 4) return 0; @@ -233,7 +233,7 @@ __owur static ossl_inline int PACKET_peek_net_4(const PACKET *pkt, * |*data| */ __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt, - uint64_t *data) + uint64_t *data) { if (PACKET_remaining(pkt) < 8) return 0; @@ -287,7 +287,7 @@ __owur static ossl_inline int PACKET_get_net_8(PACKET *pkt, uint64_t *data) /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */ __owur static ossl_inline int PACKET_peek_1(const PACKET *pkt, - unsigned int *data) + unsigned int *data) { if (!PACKET_remaining(pkt)) return 0; @@ -325,7 +325,7 @@ __owur static ossl_inline int PACKET_get_1_len(PACKET *pkt, size_t *data) * in |*data| */ __owur static ossl_inline int PACKET_peek_4(const PACKET *pkt, - unsigned long *data) + unsigned long *data) { if (PACKET_remaining(pkt) < 4) return 0; @@ -360,8 +360,8 @@ __owur static ossl_inline int PACKET_get_4(PACKET *pkt, unsigned long *data) * underlying buffer gets freed */ __owur static ossl_inline int PACKET_peek_bytes(const PACKET *pkt, - const unsigned char **data, - size_t len) + const unsigned char **data, + size_t len) { if (PACKET_remaining(pkt) < len) return 0; @@ -378,8 +378,8 @@ __owur static ossl_inline int PACKET_peek_bytes(const PACKET *pkt, * freed */ __owur static ossl_inline int PACKET_get_bytes(PACKET *pkt, - const unsigned char **data, - size_t len) + const unsigned char **data, + size_t len) { if (!PACKET_peek_bytes(pkt, data, len)) return 0; @@ -391,8 +391,8 @@ __owur static ossl_inline int PACKET_get_bytes(PACKET *pkt, /* Peek ahead at |len| bytes from |pkt| and copy them to |data| */ __owur static ossl_inline int PACKET_peek_copy_bytes(const PACKET *pkt, - unsigned char *data, - size_t len) + unsigned char *data, + size_t len) { if (PACKET_remaining(pkt) < len) return 0; @@ -407,7 +407,7 @@ __owur static ossl_inline int PACKET_peek_copy_bytes(const PACKET *pkt, * The caller is responsible for ensuring that |data| can hold |len| bytes. */ __owur static ossl_inline int PACKET_copy_bytes(PACKET *pkt, - unsigned char *data, size_t len) + unsigned char *data, size_t len) { if (!PACKET_peek_copy_bytes(pkt, data, len)) return 0; @@ -425,8 +425,8 @@ __owur static ossl_inline int PACKET_copy_bytes(PACKET *pkt, * done with a given PACKET). */ __owur static ossl_inline int PACKET_copy_all(const PACKET *pkt, - unsigned char *dest, - size_t dest_len, size_t *len) + unsigned char *dest, + size_t dest_len, size_t *len) { if (PACKET_remaining(pkt) > dest_len) { *len = 0; @@ -447,7 +447,7 @@ __owur static ossl_inline int PACKET_copy_all(const PACKET *pkt, * done with a given PACKET). */ __owur static ossl_inline int PACKET_memdup(const PACKET *pkt, - unsigned char **data, size_t *len) + unsigned char **data, size_t *len) { size_t length; @@ -512,13 +512,12 @@ __owur static ossl_inline int PACKET_forward(PACKET *pkt, size_t len) * Upon failure, the original |pkt| and |subpkt| are not modified. */ __owur static ossl_inline int PACKET_get_length_prefixed_1(PACKET *pkt, - PACKET *subpkt) + PACKET *subpkt) { unsigned int length; const unsigned char *data; PACKET tmp = *pkt; - if (!PACKET_get_1(&tmp, &length) || - !PACKET_get_bytes(&tmp, &data, (size_t)length)) { + if (!PACKET_get_1(&tmp, &length) || !PACKET_get_bytes(&tmp, &data, (size_t)length)) { return 0; } @@ -534,14 +533,12 @@ __owur static ossl_inline int PACKET_get_length_prefixed_1(PACKET *pkt, * leftover bytes in |pkt|. */ __owur static ossl_inline int PACKET_as_length_prefixed_1(PACKET *pkt, - PACKET *subpkt) + PACKET *subpkt) { unsigned int length; const unsigned char *data; PACKET tmp = *pkt; - if (!PACKET_get_1(&tmp, &length) || - !PACKET_get_bytes(&tmp, &data, (size_t)length) || - PACKET_remaining(&tmp) != 0) { + if (!PACKET_get_1(&tmp, &length) || !PACKET_get_bytes(&tmp, &data, (size_t)length) || PACKET_remaining(&tmp) != 0) { return 0; } @@ -560,14 +557,13 @@ __owur static ossl_inline int PACKET_as_length_prefixed_1(PACKET *pkt, * Upon failure, the original |pkt| and |subpkt| are not modified. */ __owur static ossl_inline int PACKET_get_length_prefixed_2(PACKET *pkt, - PACKET *subpkt) + PACKET *subpkt) { unsigned int length; const unsigned char *data; PACKET tmp = *pkt; - if (!PACKET_get_net_2(&tmp, &length) || - !PACKET_get_bytes(&tmp, &data, (size_t)length)) { + if (!PACKET_get_net_2(&tmp, &length) || !PACKET_get_bytes(&tmp, &data, (size_t)length)) { return 0; } @@ -583,15 +579,13 @@ __owur static ossl_inline int PACKET_get_length_prefixed_2(PACKET *pkt, * leftover bytes in |pkt|. */ __owur static ossl_inline int PACKET_as_length_prefixed_2(PACKET *pkt, - PACKET *subpkt) + PACKET *subpkt) { unsigned int length; const unsigned char *data; PACKET tmp = *pkt; - if (!PACKET_get_net_2(&tmp, &length) || - !PACKET_get_bytes(&tmp, &data, (size_t)length) || - PACKET_remaining(&tmp) != 0) { + if (!PACKET_get_net_2(&tmp, &length) || !PACKET_get_bytes(&tmp, &data, (size_t)length) || PACKET_remaining(&tmp) != 0) { return 0; } @@ -610,13 +604,12 @@ __owur static ossl_inline int PACKET_as_length_prefixed_2(PACKET *pkt, * Upon failure, the original |pkt| and |subpkt| are not modified. */ __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt, - PACKET *subpkt) + PACKET *subpkt) { unsigned long length; const unsigned char *data; PACKET tmp = *pkt; - if (!PACKET_get_net_3(&tmp, &length) || - !PACKET_get_bytes(&tmp, &data, (size_t)length)) { + if (!PACKET_get_net_3(&tmp, &length) || !PACKET_get_bytes(&tmp, &data, (size_t)length)) { return 0; } @@ -680,19 +673,19 @@ struct wpacket_st { /* Flags */ /* Default */ -#define WPACKET_FLAGS_NONE 0 +#define WPACKET_FLAGS_NONE 0 /* Error on WPACKET_close() if no data written to the WPACKET */ -#define WPACKET_FLAGS_NON_ZERO_LENGTH 1 +#define WPACKET_FLAGS_NON_ZERO_LENGTH 1 /* * Abandon all changes on WPACKET_close() if no data written to the WPACKET, * i.e. this does not write out a zero packet length */ -#define WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH 2 +#define WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH 2 /* QUIC variable-length integer length prefix */ -#define WPACKET_FLAGS_QUIC_VLINT 4 +#define WPACKET_FLAGS_QUIC_VLINT 4 /* * Initialise a WPACKET with the buffer in |buf|. The buffer must exist @@ -727,7 +720,7 @@ int WPACKET_init_null_der(WPACKET *pkt); * occur if you attempt to write beyond the end of the buffer */ int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len, - size_t lenbytes); + size_t lenbytes); /* * Same as WPACKET_init_static_len except lenbytes is always 0, and we set the @@ -799,7 +792,7 @@ int WPACKET_start_sub_packet(WPACKET *pkt); * change its location. */ int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, - unsigned char **allocbytes); + unsigned char **allocbytes); /* * The same as WPACKET_allocate_bytes() except additionally a new sub-packet is @@ -808,7 +801,7 @@ int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, * directly. Use the convenience macros below instead. */ int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len, - unsigned char **allocbytes, size_t lenbytes); + unsigned char **allocbytes, size_t lenbytes); /* * Convenience macros for calling WPACKET_sub_allocate_bytes with different @@ -847,7 +840,7 @@ int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes); * The "reserve_bytes" equivalent of WPACKET_sub_allocate_bytes__() */ int WPACKET_sub_reserve_bytes__(WPACKET *pkt, size_t len, - unsigned char **allocbytes, size_t lenbytes); + unsigned char **allocbytes, size_t lenbytes); /* * Convenience macros for WPACKET_sub_reserve_bytes with different lengths @@ -900,7 +893,7 @@ int WPACKET_memset(WPACKET *pkt, int ch, size_t len); * directly. Use the convenience macros below instead. */ int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len, - size_t lenbytes); + size_t lenbytes); /* Convenience macros for calling WPACKET_sub_memcpy with different lengths */ #define WPACKET_sub_memcpy_u8(pkt, src, len) \ @@ -936,4 +929,4 @@ int WPACKET_is_null_buf(WPACKET *pkt); /* Release resources in a WPACKET if a failure has occurred. */ void WPACKET_cleanup(WPACKET *pkt); -#endif /* OSSL_INTERNAL_PACKET_H */ +#endif /* OSSL_INTERNAL_PACKET_H */ |
