OPENSSL_LOAD_U16_LE(3ossl)
π OPENSSL_LOAD_U16_LE β the byte-order bestie you didn't know you needed
okay so bestie, this is a page from the 3ossl manual, and it's genuinely one of the cutest little header files in all of OpenSSL. twelve lil functions. all about reading and writing unsigned ints in the byte order you actually want. no cap, it's giving "small but mighty." π
β¨ NAME β¨
OPENSSL_load_u16_le, OPENSSL_load_u16_be, OPENSSL_load_u32_le, OPENSSL_load_u32_be, OPENSSL_load_u64_le, OPENSSL_load_u64_be, OPENSSL_store_u16_le, OPENSSL_store_u16_be, OPENSSL_store_u32_le, OPENSSL_store_u32_be, OPENSSL_store_u64_le, OPENSSL_store_u64_be β read and write unsigned 16, 32 and 64-bit integers in a specific byte order π
πΈ SYNOPSIS πΈ
#include <openssl/byteorder.h>
static ossl_inline unsigned char *OPENSSL_store_u16_le(
unsigned char *out, uint16_t val);
static ossl_inline unsigned char *OPENSSL_store_u16_be(
unsigned char *out, uint16_t val);
static ossl_inline unsigned char *OPENSSL_store_u32_le(
unsigned char *out, uint32_t val);
static ossl_inline unsigned char *OPENSSL_store_u32_be(
unsigned char *out, uint32_t val);
static ossl_inline unsigned char *OPENSSL_store_u64_le(
unsigned char *out, uint64_t val);
static ossl_inline unsigned char *OPENSSL_store_u64_be(
unsigned char *out, uint64_t val);
static ossl_inline const unsigned char *OPENSSL_load_u16_le(
uint16_t *val, const unsigned char *in);
static ossl_inline const unsigned char *OPENSSL_load_u16_be(
uint16_t *val, const unsigned char *in);
static ossl_inline const unsigned char *OPENSSL_load_u32_le(
uint32_t *val, const unsigned char *in);
static ossl_inline const unsigned char *OPENSSL_load_u32_be(
uint32_t *val, const unsigned char *in);
static ossl_inline const unsigned char *OPENSSL_load_u64_le(
uint64_t *val, const unsigned char *in);
static ossl_inline const unsigned char *OPENSSL_load_u64_be(
uint64_t *val, const unsigned char *in);
π¦ DESCRIPTION π¦
so here's the tea β β these functions read and write 16, 32 and 64 bit unsigned integers in whichever byte order you specify. simple as that, and honestly? iconic.
the _be girlies use big-endian byte order. the _le girlies use little-endian byte order. pick your fighter. π₯
the way they pull this off is lowkey adorable: they're implemented directly in the header file itself, and they're declared static. and when your compiler supports inline functions, they're declared inline too. so an optimising compiler will often smush these all the way down to just one or two machine instructions β a load or store with a possible byte swap. one or two instructions!! she's efficient, she's minimal, she ate. π₯
now, the deets on how the two families work:
- the "load" functions write the decoded integer value at the address pointed to by
val. that address must be a valid address of an object of the appropriate type β possibly suitably aligned, bestie, don't play with that. β¨ - the "store" functions write the encoding of
valat the address pointed to byout.
and for convenience?? (and this part is so thoughtful of them π«Ά) these functions return the updated input or output pointer, which makes it super easy to keep reading or writing more data at the next memory location. chaining! we love chaining!
β οΈ no bounds checks are performed. none. zero. the caller is responsible for making sure the input or output buffers are sufficiently large for the requested read or write. this is a you problem, not a her problem. please check your buffer sizes, i'm begging π
π RETURN VALUES π
all of these functions return the next memory address following the last byte written or read. every single one. consistent queen. π
β HISTORY β
these functions were added in OpenSSL 3.5. she's new here, be nice. π
π COPYRIGHT π
Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie! πΈ this was version 3.5.0, dated 2026-09-25, and the page itself answers to the name OPENSSL_LOAD_U16_LE(3ossl) β say it with me now. mwah π π¦ β¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms