File: byte_starts.3

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (24 lines) | stat: -rw-r--r-- 889 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.TH byte_starts 3
.SH NAME
byte_starts \- find out if a buffer starts with a string
.SH SYNTAX
.B #include <libowfat/byte.h>

int \fBbyte_starts\fP(const char *\fIbuf\fR,size_t \fIbuflen\fR,const char *\fIstr\fR);
.SH DESCRIPTION
\fIbyte_starts\fR returns 1 if the \fIbuflen\fR>=strlen(\fIstr\fR) and the first
strlen(\fIstr\fR) bytes of \fIbuf\fR match the contents of \fIstr\fR, or
0 otherwise.

This function is meant to be used in protocol parsing and with a string
constant for \fIstr\fR and will use gcc/clang macro trickery to reduce to a call to
\fImemcmp\fR then.

\fIbyte_starts\fR compares as few bytes as possible. An attacker observing
the execution timing can thus learn where the first mismatch happened.

Use \fIbyte_equal_notimingattack\fR to compare keys, passphrases, cookies or
hashes instead.

.SH "SEE ALSO"
byte_equal(3), byte_equal_notimingattack(3), byte_start(3)