Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Replace consttime_bcmp/explicit_bzero by consttime_memequal/...



details:   https://anonhg.NetBSD.org/src/rev/20ce880ac401
branches:  trunk
changeset: 787564:20ce880ac401
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jun 24 04:21:19 2013 +0000

description:
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:

 common/lib/libc/string/consttime_bcmp.c      |  19 ------
 common/lib/libc/string/consttime_memequal.c  |  19 ++++++
 common/lib/libc/string/explicit_bzero.c      |  22 -------
 common/lib/libc/string/explicit_memset.c     |  22 +++++++
 crypto/external/bsd/libsaslc/dist/src/dict.c |   6 +-
 crypto/external/bsd/openssh/dist/dns.c       |   6 +-
 distrib/sets/lists/comp/mi                   |  20 ++++--
 include/string.h                             |   6 +-
 lib/libc/string/Makefile.inc                 |   8 +-
 lib/libc/string/consttime_bcmp.3             |  88 ----------------------------
 lib/libc/string/consttime_memequal.3         |  88 ++++++++++++++++++++++++++++
 lib/libc/string/explicit_bzero.3             |  75 -----------------------
 lib/libc/string/explicit_memset.3            |  77 ++++++++++++++++++++++++
 lib/libc/string/memcmp.3                     |   6 +-
 lib/libc/string/memset.3                     |   6 +-
 lib/libcrypt/bcrypt.c                        |   6 +-
 lib/libcrypt/crypt-sha1.c                    |   6 +-
 lib/libcrypt/md5crypt.c                      |   6 +-
 share/man/man9/rndsink.9                     |   6 +-
 sys/dev/cgd_crypto.c                         |  12 +-
 sys/kern/kern_rndsink.c                      |  10 +-
 sys/kern/subr_cprng.c                        |  12 +-
 sys/lib/libkern/Makefile.libkern             |   4 +-
 sys/lib/libkern/arc4random.c                 |   6 +-
 sys/lib/libkern/libkern.h                    |   6 +-
 sys/netipsec/key.c                           |  10 +-
 sys/netipsec/xform_ah.c                      |   6 +-
 sys/netipsec/xform_esp.c                     |   7 +-
 sys/opencrypto/cryptosoft.c                  |  14 ++--
 29 files changed, 295 insertions(+), 284 deletions(-)

diffs (truncated from 1131 to 300 lines):

diff -r 5323e89ad8cf -r 20ce880ac401 common/lib/libc/string/consttime_bcmp.c
--- a/common/lib/libc/string/consttime_bcmp.c   Mon Jun 24 03:57:36 2013 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-/* $NetBSD: consttime_bcmp.c,v 1.1 2012/08/30 12:16:49 drochner Exp $ */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#define consttime_bcmp __consttime_bcmp
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-int
-consttime_bcmp(const void *b1, const void *b2, size_t len)
-{
-       const char *c1 = b1, *c2 = b2;
-       int res = 0;
-
-       while (len --)
-               res |= *c1++ ^ *c2++;
-       return res;
-}
diff -r 5323e89ad8cf -r 20ce880ac401 common/lib/libc/string/consttime_memequal.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/string/consttime_memequal.c       Mon Jun 24 04:21:19 2013 +0000
@@ -0,0 +1,19 @@
+/* $NetBSD: consttime_memequal.c,v 1.1 2013/06/24 04:21:19 riastradh Exp $ */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <string.h>
+#define consttime_memequal __consttime_memequal
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+int
+consttime_memequal(const void *b1, const void *b2, size_t len)
+{
+       const char *c1 = b1, *c2 = b2;
+       int res = 0;
+
+       while (len --)
+               res |= *c1++ ^ *c2++;
+       return res;
+}
diff -r 5323e89ad8cf -r 20ce880ac401 common/lib/libc/string/explicit_bzero.c
--- a/common/lib/libc/string/explicit_bzero.c   Mon Jun 24 03:57:36 2013 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-/* $NetBSD: explicit_bzero.c,v 1.1 2012/08/30 12:16:49 drochner Exp $ */
-
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <string.h>
-#define explicit_bzero __explicit_bzero
-#define explicit_memset_impl __explicit_memset_impl
-#else
-#include <lib/libkern/libkern.h>
-#endif
-
-/*
- * The use of a volatile pointer guarantees that the compiler
- * will not optimise the call away.
- */
-void *(* volatile explicit_memset_impl)(void *, int, size_t) = memset;
-
-void
-explicit_bzero(void *b, size_t len)
-{
-
-       (*explicit_memset_impl)(b, 0, len);
-}
diff -r 5323e89ad8cf -r 20ce880ac401 common/lib/libc/string/explicit_memset.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/string/explicit_memset.c  Mon Jun 24 04:21:19 2013 +0000
@@ -0,0 +1,22 @@
+/* $NetBSD: explicit_memset.c,v 1.1 2013/06/24 04:21:19 riastradh Exp $ */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <string.h>
+#define explicit_memset __explicit_memset
+#define explicit_memset_impl __explicit_memset_impl
+#else
+#include <lib/libkern/libkern.h>
+#endif
+
+/*
+ * The use of a volatile pointer guarantees that the compiler
+ * will not optimise the call away.
+ */
+void *(* volatile explicit_memset_impl)(void *, int, size_t) = memset;
+
+void
+explicit_memset(void *b, int c, size_t len)
+{
+
+       (*explicit_memset_impl)(b, c, len);
+}
diff -r 5323e89ad8cf -r 20ce880ac401 crypto/external/bsd/libsaslc/dist/src/dict.c
--- a/crypto/external/bsd/libsaslc/dist/src/dict.c      Mon Jun 24 03:57:36 2013 +0000
+++ b/crypto/external/bsd/libsaslc/dist/src/dict.c      Mon Jun 24 04:21:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dict.c,v 1.7 2013/05/10 16:39:25 christos Exp $ */
+/* $NetBSD: dict.c,v 1.8 2013/06/24 04:21:19 riastradh Exp $ */
 
 /* Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: dict.c,v 1.7 2013/05/10 16:39:25 christos Exp $");
+__RCSID("$NetBSD: dict.c,v 1.8 2013/06/24 04:21:19 riastradh Exp $");
 
 #include <sys/queue.h>
 
@@ -136,7 +136,7 @@
 
        free(node->key);
        /* zero value, it may contain sensitive data */
-       __explicit_bzero(node->value, node->value_len);
+       __explicit_memset(node->value, 0, node->value_len);
        free(node->value);
        LIST_REMOVE(node, nodes);
        free(node);
diff -r 5323e89ad8cf -r 20ce880ac401 crypto/external/bsd/openssh/dist/dns.c
--- a/crypto/external/bsd/openssh/dist/dns.c    Mon Jun 24 03:57:36 2013 +0000
+++ b/crypto/external/bsd/openssh/dist/dns.c    Mon Jun 24 04:21:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dns.c,v 1.5 2012/12/12 17:42:39 christos Exp $ */
+/*     $NetBSD: dns.c,v 1.6 2013/06/24 04:21:19 riastradh Exp $        */
 /* $OpenBSD: dns.c,v 1.28 2012/05/23 03:28:28 djm Exp $ */
 
 /*
@@ -27,7 +27,7 @@
  */
 
 #include "includes.h"
-__RCSID("$NetBSD: dns.c,v 1.5 2012/12/12 17:42:39 christos Exp $");
+__RCSID("$NetBSD: dns.c,v 1.6 2013/06/24 04:21:19 riastradh Exp $");
 #include <sys/types.h>
 #include <sys/socket.h>
 
@@ -278,7 +278,7 @@
                if (hostkey_algorithm == dnskey_algorithm &&
                    hostkey_digest_type == dnskey_digest_type) {
                        if (hostkey_digest_len == dnskey_digest_len &&
-                           __consttime_bcmp(hostkey_digest, dnskey_digest,
+                           __consttime_memequal(hostkey_digest, dnskey_digest,
                            hostkey_digest_len) == 0)
                                *flags |= DNS_VERIFY_MATCH;
                }
diff -r 5323e89ad8cf -r 20ce880ac401 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Mon Jun 24 03:57:36 2013 +0000
+++ b/distrib/sets/lists/comp/mi        Mon Jun 24 04:21:19 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1826 2013/06/24 01:12:08 riastradh Exp $
+#      $NetBSD: mi,v 1.1827 2013/06/24 04:21:19 riastradh Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5159,7 +5159,8 @@
 ./usr/share/man/cat3/conj.0                    comp-c-catman           complex,.cat
 ./usr/share/man/cat3/conjf.0                   comp-c-catman           complex,.cat
 ./usr/share/man/cat3/conjl.0                   comp-c-catman           complex,.cat
-./usr/share/man/cat3/consttime_bcmp.0          comp-c-catman           .cat
+./usr/share/man/cat3/consttime_bcmp.0          comp-obsolete           obsolete
+./usr/share/man/cat3/consttime_memcmp.0                comp-c-catman           .cat
 ./usr/share/man/cat3/copysign.0                        comp-c-catman           .cat
 ./usr/share/man/cat3/copysignf.0               comp-c-catman           .cat
 ./usr/share/man/cat3/copysignl.0               comp-c-catman           .cat
@@ -5558,7 +5559,8 @@
 ./usr/share/man/cat3/exp2.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/exp2f.0                   comp-c-catman           .cat
 ./usr/share/man/cat3/expf.0                    comp-c-catman           .cat
-./usr/share/man/cat3/explicit_bzero.0          comp-c-catman           .cat
+./usr/share/man/cat3/explicit_bzero.0          comp-obsolete           obsolete
+./usr/share/man/cat3/explicit_memset.0         comp-c-catman           .cat
 ./usr/share/man/cat3/expm1.0                   comp-c-catman           .cat
 ./usr/share/man/cat3/expm1f.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/extattr.0                 comp-obsolete           obsolete
@@ -11702,7 +11704,8 @@
 ./usr/share/man/html3/conj.html                        comp-c-htmlman          complex,html
 ./usr/share/man/html3/conjf.html               comp-c-htmlman          complex,html
 ./usr/share/man/html3/conjl.html               comp-c-htmlman          complex,html
-./usr/share/man/html3/consttime_bcmp.html      comp-c-htmlman          html
+./usr/share/man/html3/consttime_bcmp.html      comp-obsolete           obsolete
+./usr/share/man/html3/consttime_memequal.html  comp-c-htmlman          html
 ./usr/share/man/html3/copysign.html            comp-c-htmlman          html
 ./usr/share/man/html3/copysignf.html           comp-c-htmlman          html
 ./usr/share/man/html3/copysignl.html           comp-c-htmlman          html
@@ -12099,7 +12102,8 @@
 ./usr/share/man/html3/exp2.html                        comp-c-htmlman          html
 ./usr/share/man/html3/exp2f.html               comp-c-htmlman          html
 ./usr/share/man/html3/expf.html                        comp-c-htmlman          html
-./usr/share/man/html3/explicit_bzero.html      comp-c-htmlman          html
+./usr/share/man/html3/explicit_bzero.html      comp-obsolete           obsolete
+./usr/share/man/html3/explicit_memset.html     comp-c-htmlman          html
 ./usr/share/man/html3/expm1.html               comp-c-htmlman          html
 ./usr/share/man/html3/expm1f.html              comp-c-htmlman          html
 ./usr/share/man/html3/extattr.html             comp-obsolete           obsolete
@@ -18153,7 +18157,8 @@
 ./usr/share/man/man3/conj.3                    comp-c-man              complex,.man
 ./usr/share/man/man3/conjf.3                   comp-c-man              complex,.man
 ./usr/share/man/man3/conjl.3                   comp-c-man              complex,.man
-./usr/share/man/man3/consttime_bcmp.3          comp-c-man              .man
+./usr/share/man/man3/consttime_bcmp.3          comp-obsolete           obsolete
+./usr/share/man/man3/consttime_memequal.3      comp-c-man              .man
 ./usr/share/man/man3/copysign.3                        comp-c-man              .man
 ./usr/share/man/man3/copysignf.3               comp-c-man              .man
 ./usr/share/man/man3/copysignl.3               comp-c-man              .man
@@ -18552,7 +18557,8 @@
 ./usr/share/man/man3/exp2.3                    comp-c-man              .man
 ./usr/share/man/man3/exp2f.3                   comp-c-man              .man
 ./usr/share/man/man3/expf.3                    comp-c-man              .man
-./usr/share/man/man3/explicit_bzero.3          comp-c-man              .man
+./usr/share/man/man3/explicit_bzero.3          comp-obsolete           obsolete
+./usr/share/man/man3/explicit_memset.3         comp-c-man              .man
 ./usr/share/man/man3/expm1.3                   comp-c-man              .man
 ./usr/share/man/man3/expm1f.3                  comp-c-man              .man
 ./usr/share/man/man3/extattr.3                 comp-obsolete           obsolete
diff -r 5323e89ad8cf -r 20ce880ac401 include/string.h
--- a/include/string.h  Mon Jun 24 03:57:36 2013 +0000
+++ b/include/string.h  Mon Jun 24 04:21:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: string.h,v 1.43 2013/04/21 18:41:32 joerg Exp $        */
+/*     $NetBSD: string.h,v 1.44 2013/06/24 04:21:20 riastradh Exp $    */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -109,8 +109,8 @@
 char   *stresep(char **, const char *, int);
 char   *strndup(const char *, size_t);
 void   *memrchr(const void *, int, size_t);
-void   __explicit_bzero(void *, size_t);
-int    __consttime_bcmp(const void *, const void *, size_t);
+void   __explicit_memset(void *, int, size_t);
+int    __consttime_memequal(const void *, const void *, size_t);
 __END_DECLS
 #endif
 
diff -r 5323e89ad8cf -r 20ce880ac401 lib/libc/string/Makefile.inc
--- a/lib/libc/string/Makefile.inc      Mon Jun 24 03:57:36 2013 +0000
+++ b/lib/libc/string/Makefile.inc      Mon Jun 24 04:21:19 2013 +0000
@@ -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+= 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 @@
 
 .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 -r 5323e89ad8cf -r 20ce880ac401 lib/libc/string/consttime_bcmp.3
--- a/lib/libc/string/consttime_bcmp.3  Mon Jun 24 03:57:36 2013 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-.\"    $NetBSD: consttime_bcmp.3,v 1.1 2013/06/23 16:44:06 riastradh Exp $
-.\"
-.\" Copyright (c) 2013 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This documentation is derived from text contributed to The NetBSD
-.\" Foundation by Taylor R. Campbell.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN



Home | Main Index | Thread Index | Old Index