Lines Matching refs:pkt
29 static ossl_inline void packet_forward(PACKET *pkt, size_t len)
31 pkt->curr += len;
32 pkt->remaining -= len;
38 static ossl_inline size_t PACKET_remaining(const PACKET *pkt)
40 return pkt->remaining;
49 static ossl_inline const unsigned char *PACKET_end(const PACKET *pkt)
51 return pkt->curr + pkt->remaining;
58 static ossl_inline const unsigned char *PACKET_data(const PACKET *pkt)
60 return pkt->curr;
68 __owur static ossl_inline int PACKET_buf_init(PACKET *pkt,
76 pkt->curr = buf;
77 pkt->remaining = len;
82 static ossl_inline void PACKET_null_init(PACKET *pkt)
84 pkt->curr = NULL;
85 pkt->remaining = 0;
93 __owur static ossl_inline int PACKET_equal(const PACKET *pkt, const void *ptr,
96 if (PACKET_remaining(pkt) != num)
98 return CRYPTO_memcmp(pkt->curr, ptr, num) == 0;
102 * Peek ahead and initialize |subpkt| with the next |len| bytes read from |pkt|.
104 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
106 __owur static ossl_inline int PACKET_peek_sub_packet(const PACKET *pkt,
109 if (PACKET_remaining(pkt) < len)
112 return PACKET_buf_init(subpkt, pkt->curr, len);
116 * Initialize |subpkt| with the next |len| bytes read from |pkt|. Data is not
118 * original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
120 __owur static ossl_inline int PACKET_get_sub_packet(PACKET *pkt,
123 if (!PACKET_peek_sub_packet(pkt, subpkt, len))
126 packet_forward(pkt, len);
132 * Peek ahead at 2 bytes in network order from |pkt| and store the value in
135 __owur static ossl_inline int PACKET_peek_net_2(const PACKET *pkt,
138 if (PACKET_remaining(pkt) < 2)
141 *data = ((unsigned int)(*pkt->curr)) << 8;
142 *data |= *(pkt->curr + 1);
148 /* Get 2 bytes in network order from |pkt| and store the value in |*data| */
149 __owur static ossl_inline int PACKET_get_net_2(PACKET *pkt, unsigned int *data)
151 if (!PACKET_peek_net_2(pkt, data))
154 packet_forward(pkt, 2);
160 __owur static ossl_inline int PACKET_get_net_2_len(PACKET *pkt, size_t *data)
163 int ret = PACKET_get_net_2(pkt, &i);
172 * Peek ahead at 3 bytes in network order from |pkt| and store the value in
175 __owur static ossl_inline int PACKET_peek_net_3(const PACKET *pkt,
178 if (PACKET_remaining(pkt) < 3)
181 *data = ((unsigned long)(*pkt->curr)) << 16;
182 *data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
183 *data |= *(pkt->curr + 2);
189 /* Get 3 bytes in network order from |pkt| and store the value in |*data| */
190 __owur static ossl_inline int PACKET_get_net_3(PACKET *pkt, unsigned long *data)
192 if (!PACKET_peek_net_3(pkt, data))
195 packet_forward(pkt, 3);
201 __owur static ossl_inline int PACKET_get_net_3_len(PACKET *pkt, size_t *data)
204 int ret = PACKET_get_net_3(pkt, &i);
213 * Peek ahead at 4 bytes in network order from |pkt| and store the value in
216 __owur static ossl_inline int PACKET_peek_net_4(const PACKET *pkt,
219 if (PACKET_remaining(pkt) < 4)
222 *data = ((unsigned long)(*pkt->curr)) << 24;
223 *data |= ((unsigned long)(*(pkt->curr + 1))) << 16;
224 *data |= ((unsigned long)(*(pkt->curr + 2))) << 8;
225 *data |= *(pkt->curr + 3);
231 * Peek ahead at 8 bytes in network order from |pkt| and store the value in
234 __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt,
237 if (PACKET_remaining(pkt) < 8)
240 *data = ((uint64_t)(*pkt->curr)) << 56;
241 *data |= ((uint64_t)(*(pkt->curr + 1))) << 48;
242 *data |= ((uint64_t)(*(pkt->curr + 2))) << 40;
243 *data |= ((uint64_t)(*(pkt->curr + 3))) << 32;
244 *data |= ((uint64_t)(*(pkt->curr + 4))) << 24;
245 *data |= ((uint64_t)(*(pkt->curr + 5))) << 16;
246 *data |= ((uint64_t)(*(pkt->curr + 6))) << 8;
247 *data |= *(pkt->curr + 7);
253 /* Get 4 bytes in network order from |pkt| and store the value in |*data| */
254 __owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
256 if (!PACKET_peek_net_4(pkt, data))
259 packet_forward(pkt, 4);
265 __owur static ossl_inline int PACKET_get_net_4_len(PACKET *pkt, size_t *data)
268 int ret = PACKET_get_net_4(pkt, &i);
276 /* Get 8 bytes in network order from |pkt| and store the value in |*data| */
277 __owur static ossl_inline int PACKET_get_net_8(PACKET *pkt, uint64_t *data)
279 if (!PACKET_peek_net_8(pkt, data))
282 packet_forward(pkt, 8);
287 /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
288 __owur static ossl_inline int PACKET_peek_1(const PACKET *pkt,
291 if (!PACKET_remaining(pkt))
294 *data = *pkt->curr;
299 /* Get 1 byte from |pkt| and store the value in |*data| */
300 __owur static ossl_inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
302 if (!PACKET_peek_1(pkt, data))
305 packet_forward(pkt, 1);
311 __owur static ossl_inline int PACKET_get_1_len(PACKET *pkt, size_t *data)
314 int ret = PACKET_get_1(pkt, &i);
323 * Peek ahead at 4 bytes in reverse network order from |pkt| and store the value
326 __owur static ossl_inline int PACKET_peek_4(const PACKET *pkt,
329 if (PACKET_remaining(pkt) < 4)
332 *data = *pkt->curr;
333 *data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
334 *data |= ((unsigned long)(*(pkt->curr + 2))) << 16;
335 *data |= ((unsigned long)(*(pkt->curr + 3))) << 24;
342 * Get 4 bytes in reverse network order from |pkt| and store the value in
345 __owur static ossl_inline int PACKET_get_4(PACKET *pkt, unsigned long *data)
347 if (!PACKET_peek_4(pkt, data))
350 packet_forward(pkt, 4);
356 * Peek ahead at |len| bytes from the |pkt| and store a pointer to them in
357 * |*data|. This just points at the underlying buffer that |pkt| is using. The
361 __owur static ossl_inline int PACKET_peek_bytes(const PACKET *pkt,
365 if (PACKET_remaining(pkt) < len)
368 *data = pkt->curr;
374 * Read |len| bytes from the |pkt| and store a pointer to them in |*data|. This
375 * just points at the underlying buffer that |pkt| is using. The caller should
379 __owur static ossl_inline int PACKET_get_bytes(PACKET *pkt,
383 if (!PACKET_peek_bytes(pkt, data, len))
386 packet_forward(pkt, len);
391 /* Peek ahead at |len| bytes from |pkt| and copy them to |data| */
392 __owur static ossl_inline int PACKET_peek_copy_bytes(const PACKET *pkt,
396 if (PACKET_remaining(pkt) < len)
399 memcpy(data, pkt->curr, len);
405 * Read |len| bytes from |pkt| and copy them to |data|.
408 __owur static ossl_inline int PACKET_copy_bytes(PACKET *pkt,
411 if (!PACKET_peek_copy_bytes(pkt, data, len))
414 packet_forward(pkt, len);
426 __owur static ossl_inline int PACKET_copy_all(const PACKET *pkt,
430 if (PACKET_remaining(pkt) > dest_len) {
434 *len = pkt->remaining;
435 memcpy(dest, pkt->curr, pkt->remaining);
440 * Copy |pkt| bytes to a newly allocated buffer and store a pointer to the
448 __owur static ossl_inline int PACKET_memdup(const PACKET *pkt,
457 length = PACKET_remaining(pkt);
462 *data = OPENSSL_memdup(pkt->curr, length);
471 * Read a C string from |pkt| and copy to a newly allocated, NUL-terminated
474 * If the data in |pkt| does not contain a NUL-byte, the entire data is
480 __owur static ossl_inline int PACKET_strndup(const PACKET *pkt, char **data)
484 /* This will succeed on an empty packet, unless pkt->curr == NULL. */
485 *data = OPENSSL_strndup((const char *)pkt->curr, PACKET_remaining(pkt));
489 /* Returns 1 if |pkt| contains at least one 0-byte, 0 otherwise. */
490 static ossl_inline int PACKET_contains_zero_byte(const PACKET *pkt)
492 return memchr(pkt->curr, 0, pkt->remaining) != NULL;
496 __owur static ossl_inline int PACKET_forward(PACKET *pkt, size_t len)
498 if (PACKET_remaining(pkt) < len)
501 packet_forward(pkt, len);
508 * the contents in |subpkt|. |pkt| can equal |subpkt|.
510 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
511 * Upon failure, the original |pkt| and |subpkt| are not modified.
513 __owur static ossl_inline int PACKET_get_length_prefixed_1(PACKET *pkt,
518 PACKET tmp = *pkt;
524 *pkt = tmp;
533 * leftover bytes in |pkt|.
535 __owur static ossl_inline int PACKET_as_length_prefixed_1(PACKET *pkt,
540 PACKET tmp = *pkt;
547 *pkt = tmp;
556 * the contents in |subpkt|. |pkt| can equal |subpkt|.
558 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
559 * Upon failure, the original |pkt| and |subpkt| are not modified.
561 __owur static ossl_inline int PACKET_get_length_prefixed_2(PACKET *pkt,
566 PACKET tmp = *pkt;
573 *pkt = tmp;
582 * leftover bytes in |pkt|.
584 __owur static ossl_inline int PACKET_as_length_prefixed_2(PACKET *pkt,
589 PACKET tmp = *pkt;
597 *pkt = tmp;
606 * the contents in |subpkt|. |pkt| can equal |subpkt|.
608 * the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
609 * Upon failure, the original |pkt| and |subpkt| are not modified.
611 __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
616 PACKET tmp = *pkt;
622 *pkt = tmp;
697 int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes);
703 int WPACKET_init(WPACKET *pkt, BUF_MEM *buf);
710 int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len,
715 int WPACKET_set_flags(WPACKET *pkt, unsigned int flags);
723 int WPACKET_close(WPACKET *pkt);
729 int WPACKET_finish(WPACKET *pkt);
738 int WPACKET_fill_lengths(WPACKET *pkt);
745 int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes);
751 #define WPACKET_start_sub_packet_u8(pkt) \
752 WPACKET_start_sub_packet_len__((pkt), 1)
753 #define WPACKET_start_sub_packet_u16(pkt) \
754 WPACKET_start_sub_packet_len__((pkt), 2)
755 #define WPACKET_start_sub_packet_u24(pkt) \
756 WPACKET_start_sub_packet_len__((pkt), 3)
757 #define WPACKET_start_sub_packet_u32(pkt) \
758 WPACKET_start_sub_packet_len__((pkt), 4)
764 int WPACKET_start_sub_packet(WPACKET *pkt);
774 int WPACKET_allocate_bytes(WPACKET *pkt, size_t len,
783 int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
790 #define WPACKET_sub_allocate_bytes_u8(pkt, len, bytes) \
791 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 1)
792 #define WPACKET_sub_allocate_bytes_u16(pkt, len, bytes) \
793 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 2)
794 #define WPACKET_sub_allocate_bytes_u24(pkt, len, bytes) \
795 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 3)
796 #define WPACKET_sub_allocate_bytes_u32(pkt, len, bytes) \
797 WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 4)
811 * if (!WPACKET_sub_reserve_bytes_u16(&pkt, EVP_PKEY_size(pkey), &sigbytes1)
813 * || !WPACKET_sub_allocate_bytes_u16(&pkt, siglen, &sigbytes2)
817 int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes);
822 int WPACKET_sub_reserve_bytes__(WPACKET *pkt, size_t len,
828 #define WPACKET_sub_reserve_bytes_u8(pkt, len, bytes) \
829 WPACKET_reserve_bytes__((pkt), (len), (bytes), 1)
830 #define WPACKET_sub_reserve_bytes_u16(pkt, len, bytes) \
831 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 2)
832 #define WPACKET_sub_reserve_bytes_u24(pkt, len, bytes) \
833 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 3)
834 #define WPACKET_sub_reserve_bytes_u32(pkt, len, bytes) \
835 WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 4)
844 int WPACKET_put_bytes__(WPACKET *pkt, uint64_t val, size_t bytes);
850 #define WPACKET_put_bytes_u8(pkt, val) \
851 WPACKET_put_bytes__((pkt), (val), 1)
852 #define WPACKET_put_bytes_u16(pkt, val) \
853 WPACKET_put_bytes__((pkt), (val), 2)
854 #define WPACKET_put_bytes_u24(pkt, val) \
855 WPACKET_put_bytes__((pkt), (val), 3)
856 #define WPACKET_put_bytes_u32(pkt, val) \
857 WPACKET_put_bytes__((pkt), (val), 4)
858 #define WPACKET_put_bytes_u64(pkt, val) \
859 WPACKET_put_bytes__((pkt), (val), 8)
862 int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);
865 int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len);
868 int WPACKET_memset(WPACKET *pkt, int ch, size_t len);
875 int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,
879 #define WPACKET_sub_memcpy_u8(pkt, src, len) \
880 WPACKET_sub_memcpy__((pkt), (src), (len), 1)
881 #define WPACKET_sub_memcpy_u16(pkt, src, len) \
882 WPACKET_sub_memcpy__((pkt), (src), (len), 2)
883 #define WPACKET_sub_memcpy_u24(pkt, src, len) \
884 WPACKET_sub_memcpy__((pkt), (src), (len), 3)
885 #define WPACKET_sub_memcpy_u32(pkt, src, len) \
886 WPACKET_sub_memcpy__((pkt), (src), (len), 4)
892 int WPACKET_get_total_written(WPACKET *pkt, size_t *written);
898 int WPACKET_get_length(WPACKET *pkt, size_t *len);
904 unsigned char *WPACKET_get_curr(WPACKET *pkt);
907 void WPACKET_cleanup(WPACKET *pkt);