1 #include "internal/quic_vlint.h"
2 #include "internal/e_os.h"
4 void ossl_quic_vlint_encode_n(uint8_t *buf, uint64_t v, int n)
9 buf[0] = (uint8_t)(0x40 | ((v >> 8) & 0x3F));
12 buf[0] = (uint8_t)(0x80 | ((v >> 24) & 0x3F));
13 buf[1] = (uint8_t)(v >> 16);
14 buf[2] = (uint8_t)(v >> 8);
17 buf[0] = (uint8_t)(0xC0 | ((v >> 56) & 0x3F));
18 buf[1] = (uint8_t)(v >> 48);
19 buf[2] = (uint8_t)(v >> 40);
20 buf[3] = (uint8_t)(v >> 32);
21 buf[4] = (uint8_t)(v >> 24);
22 buf[5] = (uint8_t)(v >> 16);
23 buf[6] = (uint8_t)(v >> 8);
28 void ossl_quic_vlint_encode(uint8_t *buf, uint64_t v)
30 ossl_quic_vlint_encode_n(buf, v, ossl_quic_vlint_encode_len(v));
33 uint64_t ossl_quic_vlint_decode_unchecked(const unsigned char *buf)
35 uint8_t first_byte = buf[0];
36 size_t sz = ossl_quic_vlint_decode_len(first_byte);
39 return first_byte & 0x3F;
42 return ((uint64_t)(first_byte & 0x3F) << 8)
46 return ((uint64_t)(first_byte & 0x3F) << 24)
47 | ((uint64_t)buf[1] << 16)
48 | ((uint64_t)buf[2] << 8)
51 return ((uint64_t)(first_byte & 0x3F) << 56)
52 | ((uint64_t)buf[1] << 48)
53 | ((uint64_t)buf[2] << 40)
54 | ((uint64_t)buf[3] << 32)
55 | ((uint64_t)buf[4] << 24)
56 | ((uint64_t)buf[5] << 16)
57 | ((uint64_t)buf[6] << 8)
61 int ossl_quic_vlint_decode(const unsigned char *buf, size_t buf_len, uint64_t *v)
69 dec_len = ossl_quic_vlint_decode_len(buf[0]);
70 if (buf_len < dec_len)
73 x = ossl_quic_vlint_decode_unchecked(buf);