]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/string/timingsafe_bcmp.3
MFV r362254: file 5.39.
[FreeBSD/FreeBSD.git] / lib / libc / string / timingsafe_bcmp.3
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 .Nm timingsafe_memcmp
24 .Nd timing-safe byte sequence comparisons
25 .Sh SYNOPSIS
26 .In string.h
27 .Ft int
28 .Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len"
29 .Ft int
30 .Fn timingsafe_memcmp "const void *b1" "const void *b2" "size_t len"
31 .Sh DESCRIPTION
32 The
33 .Fn timingsafe_bcmp
34 and
35 .Fn timingsafe_memcmp
36 functions lexicographically compare the first
37 .Fa len
38 bytes (each interpreted as an
39 .Vt unsigned char )
40 pointed to by
41 .Fa b1
42 and
43 .Fa b2 .
44 .Pp
45 Additionally, their running times are independent of the byte sequences compared,
46 making them safe to use for comparing secret values such as cryptographic MACs.
47 In contrast,
48 .Xr bcmp 3
49 and
50 .Xr memcmp 3
51 may short-circuit after finding the first differing byte.
52 .Sh RETURN VALUES
53 The
54 .Fn timingsafe_bcmp
55 function returns 0 or not zero if the byte sequence pointed to by
56 .Fa b1
57 compares equal to or not equal to (respectively)
58 the byte sequence pointed to by
59 .Fa b2 .
60 .Pp
61 The
62 .Fn timingsafe_memcmp
63 function returns a negative value, 0, or positive value if the byte sequence
64 pointed to by
65 .Fa b1
66 compares less than, equal to, or greater than (respectively)
67 the byte sequence pointed to by
68 .Fa b2 .
69 .Sh SEE ALSO
70 .Xr bcmp 3 ,
71 .Xr memcmp 3
72 .Sh STANDARDS
73 The
74 .Fn timingsafe_bcmp
75 and
76 .Fn timingsafe_memcmp
77 functions are
78 .Fx
79 extensions.
80 .Sh HISTORY
81 The
82 .Fn timingsafe_bcmp
83 function first appeared in
84 .Ox 4.9 .
85 .Pp
86 The
87 .Fn timingsafe_memcmp
88 function first appeared in
89 .Ox 5.6 .
90 .Pp
91 Both functions first appeared in
92 .Fx 12.0 .