summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/bcmp.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/bcmp.3')
-rw-r--r--src/lib/libc/string/bcmp.344
1 files changed, 30 insertions, 14 deletions
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3
index 118c55c579..1660b4356b 100644
--- a/src/lib/libc/string/bcmp.3
+++ b/src/lib/libc/string/bcmp.3
@@ -11,11 +11,7 @@
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software 14.\" 3. Neither the name of the University nor the names of its contributors
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software 15.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission. 16.\" without specific prior written permission.
21.\" 17.\"
@@ -31,24 +27,25 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
33.\" 29.\"
34.\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 30.\" $OpenBSD: bcmp.3,v 1.9 2011/07/25 00:38:52 schwarze Exp $
35.\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $
36.\" 31.\"
37.Dd April 19, 1991 32.Dd $Mdocdate: July 25 2011 $
38.Dt BCMP 3 33.Dt BCMP 3
39.Os BSD 4.2 34.Os
40.Sh NAME 35.Sh NAME
41.Nm bcmp 36.Nm bcmp ,
37.Nm timingsafe_bcmp
42.Nd compare byte string 38.Nd compare byte string
43.Sh SYNOPSIS 39.Sh SYNOPSIS
44.Fd #include <string.h> 40.Fd #include <string.h>
45.Ft int 41.Ft int
46.Fn bcmp "const void *b1" "const void *b2" "size_t len" 42.Fn bcmp "const void *b1" "const void *b2" "size_t len"
43.Ft int
44.Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len"
47.Sh DESCRIPTION 45.Sh DESCRIPTION
48The 46The
49.Fn bcmp 47.Fn bcmp
50function 48function compares byte string
51compares byte string
52.Fa b1 49.Fa b1
53against byte string 50against byte string
54.Fa b2 , 51.Fa b2 ,
@@ -59,6 +56,20 @@ bytes long.
59Zero-length strings are always identical. 56Zero-length strings are always identical.
60.Pp 57.Pp
61The strings may overlap. 58The strings may overlap.
59.Pp
60The
61.Fn timingsafe_bcmp
62function has the same semantics as
63.Fn bcmp ,
64but its running time is independent of the contents of
65.Fa b1
66and
67.Fa b2 ,
68making it safe to use for comparing secret values such as cryptographic MACs.
69In contrast,
70.Fn bcmp
71returns after finding the first differing byte,
72making it vulnerable to timing attacks.
62.Sh SEE ALSO 73.Sh SEE ALSO
63.Xr memcmp 3 , 74.Xr memcmp 3 ,
64.Xr strcasecmp 3 , 75.Xr strcasecmp 3 ,
@@ -66,7 +77,12 @@ The strings may overlap.
66.Xr strcoll 3 , 77.Xr strcoll 3 ,
67.Xr strxfrm 3 78.Xr strxfrm 3
68.Sh HISTORY 79.Sh HISTORY
69A 80The
70.Fn bcmp 81.Fn bcmp
71function first appeared in 82function first appeared in
72.Bx 4.2 . 83.Bx 4.2 .
84.Pp
85The
86.Fn timingsafe_bcmp
87function first appeared in
88.Ox 4.9 .