OPENSSL_LOAD_U16_LE(3ossl)
π OPENSSL_LOAD_U16_LE β read & write unsigned 16, 32 and 64-bit ints in a specific byte order
okay so bestie, this is from the OpenSSL family of manual pages β the 3ossl crew π β and it's genuinely one of those "tiny but life-changing" ones, no cap.
β¨ 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 β literally the whole friend group π
for reading and writing unsigned 16, 32 and 64-bit integers in a specific byte order. That's the vibe check and they all pass.
π 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);
like, look at them all lined up π«Ά so organized, so iconic.
π¦ DESCRIPTION π¦
So these functions read and write 16, 32 and 64 bit unsigned integers in a specified byte order. Simple concept, huge slay. π
The "_be" functions use big-endian byte order, while the "_le" functions use little-endian byte order. That's it, that's the whole personality trait. π
They're implemented directly in the header file, and declared static. And when the compiler supports inline functions, they're also declared inline. So they're living rent-free in your translation unit, main character energy. β¨
An optimising compiler will often convert these to just one or two machine instructions: a load or store with a possible byte swap. Lowkey kind of obsessed β all that wrapper code and it just evaporates into a mov and maybe a bswap. Gorgeous. π₯
The "load" functions write the decoded integer value at the address pointed to by val, which must be a valid (possibly suitably aligned) address of an object of the appropriate type. π So like β give it a real uint16_t, not some random chaos pointer, iykyk.
The "store" functions write the encoding of val at the address pointed to by out. π
For convenience, these functions return the updated input or output pointer, making it easy to continue reading or writing more data at the next memory location. That's the "and then what?" pointer β you can just chain them down your buffer like a little conga line. πβ¨
β οΈ No bounds checks are performed, the caller is responsible for making sure that the input or output buffers are sufficiently large for the requested read or write. Not me reading past the end of a buffer π β bestie, you are the bounds check. Be the bounds check. This is genuinely your problem, not the library's. π
πΈ RETURN VALUES πΈ
All these functions return the next memory address following the last byte written or read. Every single one. Consistent queens. π
π HISTORY π
These functions were added in OpenSSL 3.5. Fresh off the press, new-ish but already thriving. β
π 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 π«Ά go forth and byte-swap responsibly. mwah. π
this has been 3.5.6, dated 2026-04-07, signing off from the OPENSSL_LOAD_U16_LE(3ossl) corner of the OpenSSL docs β stay aligned, stay endian-aware πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms