Lines Matching defs:pkt

30 static ossl_inline void packet_forward(PACKET *pkt, size_t len)
32 pkt->curr += len;
33 pkt->remaining -= len;
39 static ossl_inline size_t PACKET_remaining(const PACKET *pkt)
41 return pkt->remaining;
50 static ossl_inline const unsigned char *PACKET_end(const PACKET *pkt)
52 return pkt->curr + pkt->remaining;
59 static ossl_inline const unsigned char *PACKET_data(const PACKET *pkt)
61 return pkt->curr;
69 __owur static ossl_inline int PACKET_buf_init(PACKET *pkt,
77 pkt->curr = buf;
78 pkt->remaining = len;
83 static ossl_inline void PACKET_null_init(PACKET *pkt)
85 pkt->curr = NULL;
86 pkt->remaining = 0;
94 __owur static ossl_inline int PACKET_equal(const PACKET *pkt, const void *ptr,
97 if (PACKET_remaining(pkt) != num)
99 return CRYPTO_memcmp(pkt->curr, ptr, num) == 0;
103 * Peek ahead and initialize |subpkt| with the next |len| bytes read from |pkt|.
105 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
107 __owur static ossl_inline int PACKET_peek_sub_packet(const PACKET *pkt,
110 if (PACKET_remaining(pkt) < len)
113 return PACKET_buf_init(subpkt, pkt->curr, len);
117 * Initialize |subpkt| with the next |len| bytes read from |pkt|. Data is not
119 * original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
121 __owur static ossl_inline int PACKET_get_sub_packet(PACKET *pkt,
124 if (!PACKET_peek_sub_packet(pkt, subpkt, len))
127 packet_forward(pkt, len);
133 * Peek ahead at 2 bytes in network order from |pkt| and store the value in
136 __owur static ossl_inline int PACKET_peek_net_2(const PACKET *pkt,
139 if (PACKET_remaining(pkt) < 2)
142 *data = ((unsigned int)(*pkt->curr)) << 8;
143 *data |= *(pkt->curr + 1);
149 /* Get 2 bytes in network order from |pkt| and store the value in |*data| */
150 __owur static ossl_inline int PACKET_get_net_2(PACKET *pkt, unsigned int *data)
152 if (!PACKET_peek_net_2(pkt, data))
155 packet_forward(pkt, 2);
161 __owur static ossl_inline int PACKET_get_net_2_len(PACKET *pkt, size_t *data)
164 int ret = PACKET_get_net_2(pkt, &i);
173 * Peek ahead at 3 bytes in network order from |pkt| and store the value in
176 __owur static ossl_inline int PACKET_peek_net_3(const PACKET *pkt,
179 if (PACKET_remaining(pkt) < 3)
182 *data = ((unsigned long)(*pkt->curr)) << 16;
183 *data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
184 *data |= *(pkt->curr + 2);
190 /* Get 3 bytes in network order from |pkt| and store the value in |*data| */
191 __owur static ossl_inline int PACKET_get_net_3(PACKET *pkt, unsigned long *data)
193 if (!PACKET_peek_net_3(pkt, data))
196 packet_forward(pkt, 3);
202 __owur static ossl_inline int PACKET_get_net_3_len(PACKET *pkt, size_t *data)
205 int ret = PACKET_get_net_3(pkt, &i);
214 * Peek ahead at 4 bytes in network order from |pkt| and store the value in
217 __owur static ossl_inline int PACKET_peek_net_4(const PACKET *pkt,
220 if (PACKET_remaining(pkt) < 4)
223 *data = ((unsigned long)(*pkt->curr)) << 24;
224 *data |= ((unsigned long)(*(pkt->curr + 1))) << 16;
225 *data |= ((unsigned long)(*(pkt->curr + 2))) << 8;
226 *data |= *(pkt->curr + 3);
232 * Peek ahead at 8 bytes in network order from |pkt| and store the value in
235 __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt,
238 if (PACKET_remaining(pkt) < 8)
241 *data = ((uint64_t)(*pkt->curr)) << 56;
242 *data |= ((uint64_t)(*(pkt->curr + 1))) << 48;
243 *data |= ((uint64_t)(*(pkt->curr + 2))) << 40;
244 *data |= ((uint64_t)(*(pkt->curr + 3))) << 32;
245 *data |= ((uint64_t)(*(pkt->curr + 4))) << 24;
246 *data |= ((uint64_t)(*(pkt->curr + 5))) << 16;
247 *data |= ((uint64_t)(*(pkt->curr + 6))) << 8;
248 *data |= *(pkt->curr + 7);
254 /* Get 4 bytes in network order from |pkt| and store the value in |*data| */
255 __owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
257 if (!PACKET_peek_net_4(pkt, data))
260 packet_forward(pkt, 4);
266 __owur static ossl_inline int PACKET_get_net_4_len(PACKET *pkt, size_t *data)
269 int ret = PACKET_get_net_4(pkt, &i);
277 /* Get 8 bytes in network order from |pkt| and store the value in |*data| */
278 __owur static ossl_inline int PACKET_get_net_8(PACKET *pkt, uint64_t *data)
280 if (!PACKET_peek_net_8(pkt, data))
283 packet_forward(pkt, 8);
288 /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
289 __owur static ossl_inline int PACKET_peek_1(const PACKET *pkt,
292 if (!PACKET_remaining(pkt))
295 *data = *pkt->curr;
300 /* Get 1 byte from |pkt| and store the value in |*data| */
301 __owur static ossl_inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
303 if (!PACKET_peek_1(pkt, data))
306 packet_forward(pkt, 1);
312 __owur static ossl_inline int PACKET_get_1_len(PACKET *pkt, size_t *data)
315 int ret = PACKET_get_1(pkt, &i);
324 * Peek ahead at 4 bytes in reverse network order from |pkt| and store the value
327 __owur static ossl_inline int PACKET_peek_4(const PACKET *pkt,
330 if (PACKET_remaining(pkt) < 4)
333 *data = *pkt->curr;
334 *data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
335 *data |= ((unsigned long)(*(pkt->curr + 2))) << 16;
336 *data |= ((unsigned long)(*(pkt->curr + 3))) << 24;
343 * Get 4 bytes in reverse network order from |pkt| and store the value in
346 __owur static ossl_inline int PACKET_get_4(PACKET *pkt, unsigned long *data)
348 if (!PACKET_peek_4(pkt, data))
351 packet_forward(pkt, 4);
357 * Peek ahead at |len| bytes from the |pkt| and store a pointer to them in
358 * |*data|. This just points at the underlying buffer that |pkt| is using. The
362 __owur static ossl_inline int PACKET_peek_bytes(const PACKET *pkt,
366 if (PACKET_remaining(pkt) < len)
369 *data = pkt->curr;
375 * Read |len| bytes from the |pkt| and store a pointer to them in |*data|. This
376 * just points at the underlying buffer that |pkt| is using. The caller should
380 __owur static ossl_inline int PACKET_get_bytes(PACKET *pkt,
384 if (!PACKET_peek_bytes(pkt, data, len))
387 packet_forward(pkt, len);
392 /* Peek ahead at |len| bytes from |pkt| and copy them to |data| */
393 __owur static ossl_inline int PACKET_peek_copy_bytes(const PACKET *pkt,
397 if (PACKET_remaining(pkt) < len)
400 memcpy(data, pkt->curr, len);
406 * Read |len| bytes from |pkt| and copy them to |data|.
409 __owur static ossl_inline int PACKET_copy_bytes(PACKET *pkt,
412 if (!PACKET_peek_copy_bytes(pkt, data, len))
415 packet_forward(pkt, len);
427 __owur static ossl_inline int PACKET_copy_all(const PACKET *pkt,
431 if (PACKET_remaining(pkt) > dest_len) {
435 *len = pkt->remaining;
436 memcpy(dest, pkt->curr, pkt->remaining);
441 * Copy |pkt| bytes to a newly allocated buffer and store a pointer to the
449 __owur static ossl_inline int PACKET_memdup(const PACKET *pkt,
458 length = PACKET_remaining(pkt);
463 *data = OPENSSL_memdup(pkt->curr, length);
472 * Read a C string from |pkt| and copy to a newly allocated, NUL-terminated
475 * If the data in |pkt| does not contain a NUL-byte, the entire data is
481 __owur static ossl_inline int PACKET_strndup(const PACKET *pkt, char **data)
485 /* This will succeed on an empty packet, unless pkt->curr == NULL. */
486 *data = OPENSSL_strndup((const char *)pkt->curr, PACKET_remaining(pkt));
490 /* Returns 1 if |pkt| contains at least one 0-byte, 0 otherwise. */
491 static ossl_inline int PACKET_contains_zero_byte(const PACKET *pkt)
493 return memchr(pkt->curr, 0, pkt->remaining) != NULL;
497 __owur static ossl_inline int PACKET_forward(PACKET *pkt, size_t len)
499 if (PACKET_remaining(pkt) < len)
502 packet_forward(pkt, len);
509 * the contents in |subpkt|. |pkt| can equal |subpkt|.
511 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
512 * Upon failure, the original |pkt| and |subpkt| are not modified.
514 __owur static ossl_inline int PACKET_get_length_prefixed_1(PACKET *pkt,
519 PACKET tmp = *pkt;
525 *pkt = tmp;
534 * leftover bytes in |pkt|.
536 __owur static ossl_inline int PACKET_as_length_prefixed_1(PACKET *pkt,
541 PACKET tmp = *pkt;
548 *pkt = tmp;
557 * the contents in |subpkt|. |pkt| can equal |subpkt|.
559 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
560 * Upon failure, the original |pkt| and |subpkt| are not modified.
562 __owur static ossl_inline int PACKET_get_length_prefixed_2(PACKET *pkt,
567 PACKET tmp = *pkt;
574 *pkt = tmp;
583 * leftover bytes in |pkt|.
585 __owur static ossl_inline int PACKET_as_length_prefixed_2(PACKET *pkt,
590 PACKET tmp = *pkt;
598 *pkt = tmp;
607 * the contents in |subpkt|. |pkt| can equal |subpkt|.
609 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
610 * Upon failure, the original |pkt| and |subpkt| are not modified.
612 __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
617 PACKET tmp = *pkt;
623 *pkt = tmp;
701 int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes);
707 int WPACKET_init(WPACKET *pkt, BUF_MEM *buf);
714 int WPACKET_init_null(WPACKET *pkt, size_t lenbytes);
720 int WPACKET_init_null_der(WPACKET *pkt);
727 int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len,
735 int WPACKET_init_der(WPACKET *pkt, unsigned char *buf, size_t len);
740 int WPACKET_set_flags(WPACKET *pkt, unsigned int flags);
748 int WPACKET_close(WPACKET *pkt);
754 int WPACKET_finish(WPACKET *pkt);
763 int WPACKET_fill_lengths(WPACKET *pkt);
770 int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes);
776 #define WPACKET_start_sub_packet_u8(pkt) \
777 WPACKET_start_sub_packet_len__((pkt), 1)
778 #define WPACKET_start_sub_packet_u16(pkt) \
779 WPACKET_start_sub_packet_len__((pkt), 2)
780 #define WPACKET_start_sub_packet_u24(pkt) \
781 WPACKET_start_sub_packet_len__((pkt), 3)
782 #define WPACKET_start_sub_packet_u32(pkt) \
783 WPACKET_start_sub_packet_len__((pkt), 4)
789 int WPACKET_start_sub_packet(WPACKET *pkt);
799 int WPACKET_allocate_bytes(WPACKET *pkt, size_t len,
808 int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
815 #define WPACKET_sub_allocate_bytes_u8(pkt, len, bytes) \
816 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 1)
817 #define WPACKET_sub_allocate_bytes_u16(pkt, len, bytes) \
818 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 2)
819 #define WPACKET_sub_allocate_bytes_u24(pkt, len, bytes) \
820 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 3)
821 #define WPACKET_sub_allocate_bytes_u32(pkt, len, bytes) \
822 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 4)
836 * if (!WPACKET_sub_reserve_bytes_u16(&pkt, EVP_PKEY_get_size(pkey), &sigbytes1)
838 * || !WPACKET_sub_allocate_bytes_u16(&pkt, siglen, &sigbytes2)
842 int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes);
847 int WPACKET_sub_reserve_bytes__(WPACKET *pkt, size_t len,
853 #define WPACKET_sub_reserve_bytes_u8(pkt, len, bytes) \
854 WPACKET_reserve_bytes__((pkt), (len), (bytes), 1)
855 #define WPACKET_sub_reserve_bytes_u16(pkt, len, bytes) \
856 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 2)
857 #define WPACKET_sub_reserve_bytes_u24(pkt, len, bytes) \
858 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 3)
859 #define WPACKET_sub_reserve_bytes_u32(pkt, len, bytes) \
860 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 4)
869 int WPACKET_put_bytes__(WPACKET *pkt, uint64_t val, size_t bytes);
875 #define WPACKET_put_bytes_u8(pkt, val) \
876 WPACKET_put_bytes__((pkt), (val), 1)
877 #define WPACKET_put_bytes_u16(pkt, val) \
878 WPACKET_put_bytes__((pkt), (val), 2)
879 #define WPACKET_put_bytes_u24(pkt, val) \
880 WPACKET_put_bytes__((pkt), (val), 3)
881 #define WPACKET_put_bytes_u32(pkt, val) \
882 WPACKET_put_bytes__((pkt), (val), 4)
883 #define WPACKET_put_bytes_u64(pkt, val) \
884 WPACKET_put_bytes__((pkt), (val), 8)
887 int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);
890 int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len);
893 int WPACKET_memset(WPACKET *pkt, int ch, size_t len);
900 int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,
904 #define WPACKET_sub_memcpy_u8(pkt, src, len) \
905 WPACKET_sub_memcpy__((pkt), (src), (len), 1)
906 #define WPACKET_sub_memcpy_u16(pkt, src, len) \
907 WPACKET_sub_memcpy__((pkt), (src), (len), 2)
908 #define WPACKET_sub_memcpy_u24(pkt, src, len) \
909 WPACKET_sub_memcpy__((pkt), (src), (len), 3)
910 #define WPACKET_sub_memcpy_u32(pkt, src, len) \
911 WPACKET_sub_memcpy__((pkt), (src), (len), 4)
917 int WPACKET_get_total_written(WPACKET *pkt, size_t *written);
923 int WPACKET_get_length(WPACKET *pkt, size_t *len);
929 unsigned char *WPACKET_get_curr(WPACKET *pkt);
932 int WPACKET_is_null_buf(WPACKET *pkt);
935 void WPACKET_cleanup(WPACKET *pkt);