byte_starts(3)
π byte_starts(3) π
okay so bestie, welcome to section 3 of the Library Functions Manual β yes we're in the Library Functions Manual, the section for library calls, and today's main character is byte_starts. she's small, she's fast, and she's about to tell you whether your buffer starts with a string. let's go π«Ά
β¨ NAME β¨
byte_starts β find out if a buffer starts with a string π
πΈ SYNTAX πΈ
#include <libowfat/byte.h>
int byte_starts(const char *buf,size_t buflen,const char *str);
π¦ DESCRIPTION π¦
okay so here's the tea. byte_starts returns 1 if buflen>=strlen(str) and the first strlen(str) bytes of buf match the contents of str. otherwise? it returns 0. that's it, that's the whole vibe. β¨
this function is meant to be used in protocol parsing and with a string constant for str β and when you do that, she'll use gcc/clang macro trickery to reduce down to a call to memcmp then. literally so iconic of her. π₯
now for the serious bit, bestie, because I love you and I need you to be safe:
byte_starts compares as few bytes as possible. An attacker observing the execution timing can thus learn where the first mismatch happened. π
that's a timing side channel, no cap. she stops the second she finds a mismatch, which is fast and cute for parsing, but it leaks info if someone's watching the clock.
so if you're comparing keys, passphrases, cookies or hashes? use byte_equal_notimingattack instead. periodt. π
π SEE ALSO π
anyway that's the page π this was byte_starts from the Library Functions Manual, section 3, and the footer's just her name again because she doesn't need a whole version-and-date moment β she's timeless like that. mwah, stay safe, compare your secrets with the notimingattack one, bye bestie ππ¦πΈ
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms