]> git.saurik.com Git - apple/libc.git/blame - string/FreeBSD/timingsafe_bcmp.3
Libc-1158.30.7.tar.gz
[apple/libc.git] / string / FreeBSD / timingsafe_bcmp.3
CommitLineData
fc5ea90f
A
1.\" $OpenBSD: timingsafe_bcmp.3,v 1.2 2014/06/21 20:22:15 tedu Exp $
2.\"
3.\" Copyright (c) 2014 Google Inc.
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.\" $FreeBSD$
18.Dd August 15, 2016
19.Dt TIMINGSAFE_BCMP 3
20.Os
21.Sh NAME
22.Nm timingsafe_bcmp
23.Nd timing-safe byte sequence comparisons
24.Sh SYNOPSIS
25.In string.h
26.Ft int
27.Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len"
28.Sh DESCRIPTION
29The
30.Fn timingsafe_bcmp
31function compares the first
32.Fa len
33bytes pointed to by
34.Fa b1
35and
36.Fa b2 .
37.Pp
38Additionally, the running time is independent of the byte sequences compared,
39making it safe to use for comparing secret values such as cryptographic MACs.
40In contrast,
41.Xr bcmp 3
42and
43.Xr memcmp 3
44may short-circuit after finding the first differing byte.
45.Sh RETURN VALUES
46The
47.Fn timingsafe_bcmp
48function returns 0 or not zero if the byte sequence pointed to by
49.Fa b1
50compares equal to or not equal to (respectively)
51the byte sequence pointed to by
52.Fa b2 .
53.Sh SEE ALSO
54.Xr bcmp 3
55.Sh STANDARDS
56The
57.Fn timingsafe_bcmp
58function is a non-standard extension.
59.Sh HISTORY
60The
61.Fn timingsafe_bcmp
62function first appeared in
63.Ox 4.9 ,
64.Fx 12.0 ,
65and macOS 10.12.1.