summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/timingsafe_bcmp.3
diff options
context:
space:
mode:
authormatthew <>2014-06-13 02:12:17 +0000
committermatthew <>2014-06-13 02:12:17 +0000
commitcc594d5ff9b7bb08404d34d62287ee1dfd6b8332 (patch)
tree228054f338d1a5a8d53b4b58798bd55801ab2ce2 /src/lib/libc/string/timingsafe_bcmp.3
parent5a1fd238ffb5612e4dd1965f694b7f04ab0d5ecb (diff)
downloadopenbsd-cc594d5ff9b7bb08404d34d62287ee1dfd6b8332.tar.gz
openbsd-cc594d5ff9b7bb08404d34d62287ee1dfd6b8332.tar.bz2
openbsd-cc594d5ff9b7bb08404d34d62287ee1dfd6b8332.zip
Add timingsafe_memcmp().
ok deraadt, jmc, tedu
Diffstat (limited to 'src/lib/libc/string/timingsafe_bcmp.3')
-rw-r--r--src/lib/libc/string/timingsafe_bcmp.392
1 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/libc/string/timingsafe_bcmp.3 b/src/lib/libc/string/timingsafe_bcmp.3
new file mode 100644
index 0000000000..0886731ce7
--- /dev/null
+++ b/src/lib/libc/string/timingsafe_bcmp.3
@@ -0,0 +1,92 @@
1.\" $OpenBSD: timingsafe_bcmp.3,v 1.1 2014/06/13 02:12:17 matthew 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.Dd $Mdocdate: June 13 2014 $
17.Dt TIMINGSAFE_BCMP 3
18.Os
19.Sh NAME
20.Nm timingsafe_bcmp ,
21.Nm timingsafe_memcmp
22.Nd timing-safe byte sequence comparisons
23.Sh SYNOPSIS
24.In string.h
25.Ft int
26.Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len"
27.Ft int
28.Fn timingsafe_memcmp "const void *b1" "const void *b2" "size_t len"
29.Sh DESCRIPTION
30The
31.Fn timingsafe_bcmp
32and
33.Fn timingsafe_memcmp
34functions lexicographically compare the first
35.Fa len
36bytes (each interpreted as an
37.Vt unsigned char )
38pointed to by
39.Fa b1
40and
41.Fa b2 .
42.Pp
43Additionally, their running times are independent of the byte sequences compared,
44making them safe to use for comparing secret values such as cryptographic MACs.
45In contrast,
46.Xr bcmp 3
47and
48.Xr memcmp 3
49may short-circuit after finding the first differing byte.
50.Sh RETURN VALUES
51The
52.Fn timingsafe_bcmp
53function returns 0 or 1 if the byte sequence pointed to by
54.Fa b1
55compares equal to or not equal to (respectively)
56the byte sequence pointed to by
57.Fa b2 .
58.Pp
59The
60.Fn timingsafe_memcmp
61function returns \-1, 0, or 1 if the byte sequence pointed to by
62.Fa b1
63compares less than, equal to, or greater than (respectively)
64the byte sequence pointed to by
65.Fa b2 .
66.Pp
67Note that these return values are compatible with, but stricter than,
68the ones specified for
69.Xr bcmp 3
70and
71.Xr memcmp 3 .
72.Sh SEE ALSO
73.Xr bcmp 3 ,
74.Xr memcmp 3
75.Sh STANDARDS
76The
77.Fn timingsafe_bcmp
78and
79.Fn timingsafe_memcmp
80functions are
81.Ox
82extensions.
83.Sh HISTORY
84The
85.Fn timingsafe_bcmp
86function first appeared in
87.Ox 4.9 .
88.Pp
89The
90.Fn timingsafe_memcmp
91function first appeared in
92.Ox 5.6 .