summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/bcmp.3
diff options
context:
space:
mode:
authormatthew <>2010-09-24 13:33:00 +0000
committermatthew <>2010-09-24 13:33:00 +0000
commitca3efbcfa52175f6883523a4782ce280dd592054 (patch)
treea85c16e95e9d9e32e4eb2a44cfd664f4e6320458 /src/lib/libc/string/bcmp.3
parenta94c2f0834fa88251427636d1ca7fb8d29c15712 (diff)
downloadopenbsd-ca3efbcfa52175f6883523a4782ce280dd592054.tar.gz
openbsd-ca3efbcfa52175f6883523a4782ce280dd592054.tar.bz2
openbsd-ca3efbcfa52175f6883523a4782ce280dd592054.zip
Add timingsafe_bcmp(3) to libc, mention that it's already in the
kernel in kern(9), and remove it from OpenSSH. ok deraadt@, djm@
Diffstat (limited to 'src/lib/libc/string/bcmp.3')
-rw-r--r--src/lib/libc/string/bcmp.328
1 files changed, 25 insertions, 3 deletions
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3
index 57e1a0fade..1a77750627 100644
--- a/src/lib/libc/string/bcmp.3
+++ b/src/lib/libc/string/bcmp.3
@@ -27,18 +27,21 @@
27.\" 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
28.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
29.\" 29.\"
30.\" $OpenBSD: bcmp.3,v 1.7 2007/05/31 19:19:32 jmc Exp $ 30.\" $OpenBSD: bcmp.3,v 1.8 2010/09/24 13:33:00 matthew Exp $
31.\" 31.\"
32.Dd $Mdocdate: May 31 2007 $ 32.Dd $Mdocdate: September 24 2010 $
33.Dt BCMP 3 33.Dt BCMP 3
34.Os 34.Os
35.Sh NAME 35.Sh NAME
36.Nm bcmp 36.Nm bcmp ,
37.Nm timingsafe_bcmp
37.Nd compare byte string 38.Nd compare byte string
38.Sh SYNOPSIS 39.Sh SYNOPSIS
39.Fd #include <string.h> 40.Fd #include <string.h>
40.Ft int 41.Ft int
41.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"
42.Sh DESCRIPTION 45.Sh DESCRIPTION
43The 46The
44.Fn bcmp 47.Fn bcmp
@@ -53,6 +56,20 @@ bytes long.
53Zero-length strings are always identical. 56Zero-length strings are always identical.
54.Pp 57.Pp
55The 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.
56.Sh SEE ALSO 73.Sh SEE ALSO
57.Xr memcmp 3 , 74.Xr memcmp 3 ,
58.Xr strcasecmp 3 , 75.Xr strcasecmp 3 ,
@@ -64,3 +81,8 @@ A
64.Fn bcmp 81.Fn bcmp
65function first appeared in 82function first appeared in
66.Bx 4.2 . 83.Bx 4.2 .
84.Pp
85The
86.Fn timingsafe_bcmp
87function first appeared in
88.Ox 4.9 .