summaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2013-06-24 04:21:19 +0000
committerriastradh <riastradh@NetBSD.org>2013-06-24 04:21:19 +0000
commitadfdcceb8aad478bc3c5692fb3aff045c0c8ef37 (patch)
treeee62fd1d002750ee339715e953885019cf401475 /lib/libc/string
parent8fcb059d64019ef3a03b90cb11f6c6d47aeeb6b9 (diff)
Replace consttime_bcmp/explicit_bzero by consttime_memequal/explicit_memset.
consttime_memequal is the same as the old consttime_bcmp. explicit_memset is to memset as explicit_bzero was to bcmp. Passes amd64 release and i386/ALL, but I'm sure I missed some spots, so please let me know.
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/Makefile.inc8
-rw-r--r--lib/libc/string/consttime_memequal.3 (renamed from lib/libc/string/consttime_bcmp.3)22
-rw-r--r--lib/libc/string/explicit_memset.3 (renamed from lib/libc/string/explicit_bzero.3)26
-rw-r--r--lib/libc/string/memcmp.36
-rw-r--r--lib/libc/string/memset.36
5 files changed, 35 insertions, 33 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index eecb6520f60..e88301b0612 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
-# $NetBSD: Makefile.inc,v 1.77 2013/06/24 01:12:08 riastradh Exp $
+# $NetBSD: Makefile.inc,v 1.78 2013/06/24 04:21:20 riastradh Exp $
# string sources
.PATH: ${ARCHDIR}/string ${.CURDIR}/string
@@ -19,7 +19,7 @@ SRCS+= bcmp.c bcopy.c bzero.c ffs.c memchr.c memcmp.c memset.c
SRCS+= strcat.c strcmp.c strcpy.c strcspn.c strlen.c
SRCS+= strncat.c strncmp.c strncpy.c strpbrk.c strsep.c
SRCS+= strspn.c strstr.c swab.c
-SRCS+= explicit_bzero.c consttime_bcmp.c
+SRCS+= explicit_memset.c consttime_memequal.c
SRCS+= memccpy.c memcpy.c memmem.c memmove.c
SRCS+= strchr.c strrchr.c
@@ -39,8 +39,8 @@ SRCS+= _strlcat.c _strlcpy.c _strerror_r.c
.include "${ARCHDIR}/string/Makefile.inc"
-MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 consttime_bcmp.3 \
- explicit_bzero.3 ffs.3 index.3 \
+MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 consttime_memequal.3 \
+ explicit_memset.3 ffs.3 index.3 \
memccpy.3 memchr.3 memcmp.3 memcpy.3 memmem.3 memmove.3 memset.3 \
popcount.3 \
rindex.3 strcasecmp.3 strcat.3 strchr.3 strcmp.3 strcoll.3 \
diff --git a/lib/libc/string/consttime_bcmp.3 b/lib/libc/string/consttime_memequal.3
index 1a4579dae45..2f71503b777 100644
--- a/lib/libc/string/consttime_bcmp.3
+++ b/lib/libc/string/consttime_memequal.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: consttime_bcmp.3,v 1.1 2013/06/23 16:44:06 riastradh Exp $
+.\" $NetBSD: consttime_memequal.3,v 1.1 2013/06/24 04:21:20 riastradh Exp $
.\"
.\" Copyright (c) 2013 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -28,20 +28,20 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 23, 2013
-.Dt CONSTTIME_BCMP 3
+.Dt CONSTTIME_MEMEQUAL 3
.Os
.Sh NAME
-.Nm consttime_bcmp
+.Nm consttime_memequal
.Nd compare byte strings for equality without timing leaks
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In string.h
.Ft int
-.Fn consttime_bcmp "void *b1" "void *b2" "size_t len"
+.Fn consttime_memequal "void *b1" "void *b2" "size_t len"
.Sh DESCRIPTION
The
-.Fn consttime_bcmp
+.Fn consttime_memequal
function compares
.Fa len
bytes of memory at
@@ -52,7 +52,7 @@ for equality, returning zero if they are identical and nonzero
otherwise.
.Pp
The time taken by
-.Fn consttime_bcmp
+.Fn consttime_memequal
depends on
.Fa len ,
but not on the data at
@@ -60,29 +60,29 @@ but not on the data at
or
.Fa b2 .
Thus,
-.Fn consttime_bcmp
+.Fn consttime_memequal
is appropriate for comparing cryptographic secrets, hashes, message
authentication codes, etc., without leaking information about them
through a timing side channel.
In crypto literature,
-.Fn consttime_bcmp
+.Fn consttime_memequal
is said to take
.Sq constant time ,
meaning time that does not vary depending on the data it processes.
.Pp
Note that unlike
.Xr memcmp 3 ,
-.Fn consttime_bcmp
+.Fn consttime_memequal
does not return a lexicographic ordering on the data at
.Fa b1
and
.Fa b2 ;
it tells only whether they are equal.
.Sh SEE ALSO
-.Xr explicit_bzero 3 ,
+.Xr explicit_memset 3 ,
.Xr memcmp 3
.Sh HISTORY
The
-.Fn consttime_bcmp
+.Fn consttime_memequal
function appeared in
.Nx 7.0 .
diff --git a/lib/libc/string/explicit_bzero.3 b/lib/libc/string/explicit_memset.3
index 12af1504a71..722c9475643 100644
--- a/lib/libc/string/explicit_bzero.3
+++ b/lib/libc/string/explicit_memset.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: explicit_bzero.3,v 1.1 2013/06/23 16:44:06 riastradh Exp $
+.\" $NetBSD: explicit_memset.3,v 1.1 2013/06/24 04:21:20 riastradh Exp $
.\"
.\" Copyright (c) 2013 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -28,26 +28,28 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 23, 2013
-.Dt EXPLICIT_BZERO 3
+.Dt EXPLICIT_MEMSET 3
.Os
.Sh NAME
-.Nm explicit_bzero
-.Nd guarantee zeroing a buffer in memory
+.Nm explicit_memset
+.Nd guarantee writing a byte to a byte string
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In string.h
.Ft void
-.Fn explicit_bzero "void *ptr" "size_t len"
+.Fn explicit_memset "void *b" "int c" "size_t len"
.Sh DESCRIPTION
The
-.Fn explicit_bzero
+.Fn explicit_memset
function writes
.Fa len
-zero bytes to the memory pointed to by
-.Fa ptr .
+bytes of value
+.Fa c
+(converted to an unsigned char) to the string
+.Fa b .
It is guaranteed not to be optimized away by the compiler even if
-.Fa ptr
+.Fa b
is no longer used and is about to be freed or go out of scope.
.Sh EXAMPLES
Create a buffer on the stack for a secret key, use it, and then zero it
@@ -62,14 +64,14 @@ f(void)
do_crypto_stuff(key, sizeof(key));
\&...
- explicit_bzero(key, sizeof(key));
+ explicit_memset(key, 0, sizeof(key));
}
.Ed
.Sh SEE ALSO
-.Xr consttime_bcmp 3 ,
+.Xr consttime_memequal 3 ,
.Xr memset 3
.Sh HISTORY
The
-.Fn explicit_bzero
+.Fn explicit_memset
function appeared in
.Nx 7.0 .
diff --git a/lib/libc/string/memcmp.3 b/lib/libc/string/memcmp.3
index 78e92105e30..fec697f7224 100644
--- a/lib/libc/string/memcmp.3
+++ b/lib/libc/string/memcmp.3
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)memcmp.3 8.1 (Berkeley) 6/4/93
-.\" $NetBSD: memcmp.3,v 1.10 2013/06/23 16:44:06 riastradh Exp $
+.\" $NetBSD: memcmp.3,v 1.11 2013/06/24 04:21:20 riastradh Exp $
.\"
.Dd June 23, 2013
.Dt MEMCMP 3
@@ -74,11 +74,11 @@ to compare cryptographic secrets, because the time it takes varies
depending on how many bytes are the same, and thus leaks information
about the two strings by a timing side channel.
To compare secrets, hashes, message authentication codes, etc., use
-.Xr consttime_bcmp 3
+.Xr consttime_memequal 3
instead.
.Sh SEE ALSO
.Xr bcmp 3 ,
-.Xr consttime_bcmp 3 ,
+.Xr consttime_memequal 3 ,
.Xr strcasecmp 3 ,
.Xr strcmp 3 ,
.Xr strcoll 3 ,
diff --git a/lib/libc/string/memset.3 b/lib/libc/string/memset.3
index 777b167e804..bc51985b354 100644
--- a/lib/libc/string/memset.3
+++ b/lib/libc/string/memset.3
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)memset.3 8.1 (Berkeley) 6/4/93
-.\" $NetBSD: memset.3,v 1.10 2013/06/23 16:44:06 riastradh Exp $
+.\" $NetBSD: memset.3,v 1.11 2013/06/24 04:21:20 riastradh Exp $
.\"
.Dd June 23, 2013
.Dt MEMSET 3
@@ -67,10 +67,10 @@ if it can prove that the string will not be used by the program again,
for example if it is allocated on the stack and about to out of scope.
If you want to guarantee that zeros are written to memory, for example
to sanitize a buffer holding a cryptographic secret, use
-.Xr explicit_bzero .
+.Xr explicit_memset .
.Sh SEE ALSO
.Xr bzero 3 ,
-.Xr explicit_bzero 3 ,
+.Xr explicit_memset 3 ,
.Xr swab 3
.Sh STANDARDS
The