diff options
| author | riastradh <riastradh@NetBSD.org> | 2013-06-24 04:21:19 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2013-06-24 04:21:19 +0000 |
| commit | adfdcceb8aad478bc3c5692fb3aff045c0c8ef37 (patch) | |
| tree | ee62fd1d002750ee339715e953885019cf401475 /sys | |
| parent | 8fcb059d64019ef3a03b90cb11f6c6d47aeeb6b9 (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 'sys')
| -rw-r--r-- | sys/dev/cgd_crypto.c | 12 | ||||
| -rw-r--r-- | sys/kern/kern_rndsink.c | 10 | ||||
| -rw-r--r-- | sys/kern/subr_cprng.c | 12 | ||||
| -rw-r--r-- | sys/lib/libkern/Makefile.libkern | 4 | ||||
| -rw-r--r-- | sys/lib/libkern/arc4random.c | 6 | ||||
| -rw-r--r-- | sys/lib/libkern/libkern.h | 6 | ||||
| -rw-r--r-- | sys/netipsec/key.c | 10 | ||||
| -rw-r--r-- | sys/netipsec/xform_ah.c | 6 | ||||
| -rw-r--r-- | sys/netipsec/xform_esp.c | 7 | ||||
| -rw-r--r-- | sys/opencrypto/cryptosoft.c | 14 |
10 files changed, 45 insertions, 42 deletions
diff --git a/sys/dev/cgd_crypto.c b/sys/dev/cgd_crypto.c index 340dd036d17..1f51ef31b82 100644 --- a/sys/dev/cgd_crypto.c +++ b/sys/dev/cgd_crypto.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgd_crypto.c,v 1.11 2012/12/05 02:23:20 christos Exp $ */ +/* $NetBSD: cgd_crypto.c,v 1.12 2013/06/24 04:21:20 riastradh Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.11 2012/12/05 02:23:20 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cgd_crypto.c,v 1.12 2013/06/24 04:21:20 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -210,7 +210,7 @@ cgd_cipher_aes_destroy(void *data) { struct aes_privdata *apd = data; - explicit_bzero(apd, sizeof(*apd)); + explicit_memset(apd, 0, sizeof(*apd)); free(apd, M_DEVBUF); } @@ -296,7 +296,7 @@ cgd_cipher_3des_init(size_t keylen, const void *key, size_t *blocksize) error |= des_key_sched(block + 1, cp->cp_key2); error |= des_key_sched(block + 2, cp->cp_key3); if (error) { - explicit_bzero(cp, sizeof(*cp)); + explicit_memset(cp, 0, sizeof(*cp)); free(cp, M_DEVBUF); return NULL; } @@ -308,7 +308,7 @@ cgd_cipher_3des_destroy(void *data) { struct c3des_privdata *cp = data; - explicit_bzero(cp, sizeof(*cp)); + explicit_memset(cp, 0, sizeof(*cp)); free(cp, M_DEVBUF); } @@ -393,7 +393,7 @@ cgd_cipher_bf_destroy(void *data) { struct bf_privdata *bp = data; - explicit_bzero(bp, sizeof(*bp)); + explicit_memset(bp, 0, sizeof(*bp)); free(bp, M_DEVBUF); } diff --git a/sys/kern/kern_rndsink.c b/sys/kern/kern_rndsink.c index 43ba3c97c39..5ddf010b752 100644 --- a/sys/kern/kern_rndsink.c +++ b/sys/kern/kern_rndsink.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rndsink.c,v 1.1 2013/06/23 02:35:24 riastradh Exp $ */ +/* $NetBSD: kern_rndsink.c,v 1.2 2013/06/24 04:21:20 riastradh Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.1 2013/06/23 02:35:24 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_rndsink.c,v 1.2 2013/06/24 04:21:20 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -156,7 +156,7 @@ rndsinks_distribute(void) uint8_t buffer[RNDSINK_MAX_BYTES]; struct rndsink *rndsink; - explicit_bzero(buffer, sizeof(buffer)); /* paranoia */ + explicit_memset(buffer, 0, sizeof(buffer)); /* paranoia */ mutex_spin_enter(&rndsinks_lock); while ((rndsink = TAILQ_FIRST(&rndsinks)) != NULL) { @@ -178,7 +178,7 @@ rndsinks_distribute(void) (*rndsink->rsink_callback)(rndsink->rsink_arg, buffer, rndsink->rsink_bytes); - explicit_bzero(buffer, rndsink->rsink_bytes); + explicit_memset(buffer, 0, rndsink->rsink_bytes); mutex_spin_enter(&rndsinks_lock); @@ -199,7 +199,7 @@ rndsinks_distribute(void) } mutex_spin_exit(&rndsinks_lock); - explicit_bzero(buffer, sizeof(buffer)); /* paranoia */ + explicit_memset(buffer, 0, sizeof(buffer)); /* paranoia */ } static void diff --git a/sys/kern/subr_cprng.c b/sys/kern/subr_cprng.c index 1e48dc8803c..2727e325fab 100644 --- a/sys/kern/subr_cprng.c +++ b/sys/kern/subr_cprng.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_cprng.c,v 1.19 2013/06/24 00:56:21 riastradh Exp $ */ +/* $NetBSD: subr_cprng.c,v 1.20 2013/06/24 04:21:20 riastradh Exp $ */ /*- * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.19 2013/06/24 00:56:21 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_cprng.c,v 1.20 2013/06/24 04:21:20 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -132,7 +132,7 @@ cprng_strong_create(const char *name, int ipl, int flags) /* XXX Fix nist_ctr_drbg API so this can't happen. */ panic("cprng %s: NIST CTR_DRBG instantiation failed", cprng->cs_name); - explicit_bzero(seed, sizeof(seed)); + explicit_memset(seed, 0, sizeof(seed)); if (!cprng->cs_ready && !ISSET(flags, CPRNG_INIT_ANY)) printf("cprng %s: creating with partial entropy\n", @@ -160,7 +160,7 @@ cprng_strong_destroy(struct cprng_strong *cprng) cv_destroy(&cprng->cs_cv); mutex_destroy(&cprng->cs_lock); - explicit_bzero(cprng, sizeof(*cprng)); /* paranoia */ + explicit_memset(cprng, 0, sizeof(*cprng)); /* paranoia */ kmem_free(cprng, sizeof(*cprng)); } @@ -366,7 +366,7 @@ cprng_strong_reseed(struct cprng_strong *cprng) const bool full_entropy = rndsink_request(cprng->cs_rndsink, seed, sizeof(seed)); cprng_strong_reseed_from(cprng, seed, sizeof(seed), full_entropy); - explicit_bzero(seed, sizeof(seed)); + explicit_memset(seed, 0, sizeof(seed)); } /* @@ -446,7 +446,7 @@ cprng_strong_rngtest(struct cprng_strong *cprng) rndsink_schedule(cprng->cs_rndsink); } - explicit_bzero(rt, sizeof(*rt)); /* paranoia */ + explicit_memset(rt, 0, sizeof(*rt)); /* paranoia */ kmem_intr_free(rt, sizeof(*rt)); } #endif diff --git a/sys/lib/libkern/Makefile.libkern b/sys/lib/libkern/Makefile.libkern index 675331f8057..3d355a6ad22 100644 --- a/sys/lib/libkern/Makefile.libkern +++ b/sys/lib/libkern/Makefile.libkern @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.libkern,v 1.23 2013/03/17 00:47:13 christos Exp $ +# $NetBSD: Makefile.libkern,v 1.24 2013/06/24 04:21:20 riastradh Exp $ # # Variable definitions for libkern. @@ -96,7 +96,7 @@ SRCS+= xlat_mbr_fstype.c SRCS+= heapsort.c ptree.c rb.c # for crypto -SRCS+= explicit_bzero.c consttime_bcmp.c +SRCS+= explicit_memset.c consttime_memequal.c # Files to clean up CLEANFILES+= lib${LIB}.o lib${LIB}.po diff --git a/sys/lib/libkern/arc4random.c b/sys/lib/libkern/arc4random.c index 2b7eb85f609..fc820d00b8f 100644 --- a/sys/lib/libkern/arc4random.c +++ b/sys/lib/libkern/arc4random.c @@ -1,4 +1,4 @@ -/* $NetBSD: arc4random.c,v 1.34 2013/06/23 02:38:22 riastradh Exp $ */ +/* $NetBSD: arc4random.c,v 1.35 2013/06/24 04:21:20 riastradh Exp $ */ /*- * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc. @@ -145,7 +145,7 @@ arc4_randrekey(void) const bool full_entropy = rndsink_request(arc4_rndsink, seed, sizeof(seed)); arc4_randrekey_from(seed, full_entropy); - explicit_bzero(seed, sizeof(seed)); + explicit_memset(seed, 0, sizeof(seed)); } /* @@ -171,7 +171,7 @@ arc4_randrekey_from(const uint8_t seed[ARC4_KEYBYTES], bool full_entropy) } arc4_i = arc4_j; - explicit_bzero(key, sizeof(key)); + explicit_memset(key, 0, sizeof(key)); /* * Throw away the first N words of output, as suggested in the diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index 63312119e08..767ced5199a 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.106 2012/08/30 12:16:49 drochner Exp $ */ +/* $NetBSD: libkern.h,v 1.107 2013/06/24 04:21:20 riastradh Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -346,6 +346,6 @@ unsigned int popcountll(unsigned long long) __constfunc; unsigned int popcount32(uint32_t) __constfunc; unsigned int popcount64(uint64_t) __constfunc; -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); #endif /* !_LIB_LIBKERN_LIBKERN_H_ */ diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 6ec2c1c9a77..22eac80669f 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.81 2013/06/05 19:01:26 christos Exp $ */ +/* $NetBSD: key.c,v 1.82 2013/06/24 04:21:20 riastradh Exp $ */ /* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ /* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.81 2013/06/05 19:01:26 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.82 2013/06/24 04:21:20 riastradh Exp $"); /* * This code is referd to RFC 2367 @@ -3030,9 +3030,11 @@ key_delsav(struct secasvar *sav) sav->tdb_xform = NULL; } else { if (sav->key_auth != NULL) - explicit_bzero(_KEYBUF(sav->key_auth), _KEYLEN(sav->key_auth)); + explicit_memset(_KEYBUF(sav->key_auth), 0, + _KEYLEN(sav->key_auth)); if (sav->key_enc != NULL) - explicit_bzero(_KEYBUF(sav->key_enc), _KEYLEN(sav->key_enc)); + explicit_memset(_KEYBUF(sav->key_enc), 0, + _KEYLEN(sav->key_enc)); } if (sav->key_auth != NULL) { KFREE(sav->key_auth); diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c index 9865c496ad1..1cb22c9c31d 100644 --- a/sys/netipsec/xform_ah.c +++ b/sys/netipsec/xform_ah.c @@ -1,4 +1,4 @@ -/* $NetBSD: xform_ah.c,v 1.39 2013/06/04 22:47:37 christos Exp $ */ +/* $NetBSD: xform_ah.c,v 1.40 2013/06/24 04:21:20 riastradh Exp $ */ /* $FreeBSD: src/sys/netipsec/xform_ah.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */ /* $OpenBSD: ip_ah.c,v 1.63 2001/06/26 06:18:58 angelos Exp $ */ /* @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.39 2013/06/04 22:47:37 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.40 2013/06/24 04:21:20 riastradh Exp $"); #include "opt_inet.h" #ifdef __FreeBSD__ @@ -910,7 +910,7 @@ ah_input_cb(struct cryptop *crp) ptr = (char *) (tc + 1); /* Verify authenticator. */ - if (consttime_bcmp(ptr + skip + rplen, calc, authsize)) { + if (consttime_memequal(ptr + skip + rplen, calc, authsize)) { u_int8_t *pppp = ptr + skip+rplen; DPRINTF(("ah_input: authentication hash mismatch " \ "over %d bytes " \ diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c index db2ae76a34f..b6d97fd321c 100644 --- a/sys/netipsec/xform_esp.c +++ b/sys/netipsec/xform_esp.c @@ -1,4 +1,4 @@ -/* $NetBSD: xform_esp.c,v 1.42 2013/06/04 22:47:37 christos Exp $ */ +/* $NetBSD: xform_esp.c,v 1.43 2013/06/24 04:21:20 riastradh Exp $ */ /* $FreeBSD: src/sys/netipsec/xform_esp.c,v 1.2.2.1 2003/01/24 05:11:36 sam Exp $ */ /* $OpenBSD: ip_esp.c,v 1.69 2001/06/26 06:18:59 angelos Exp $ */ @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.42 2013/06/04 22:47:37 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.43 2013/06/24 04:21:20 riastradh Exp $"); #include "opt_inet.h" #ifdef __FreeBSD__ @@ -593,7 +593,8 @@ esp_input_cb(struct cryptop *crp) ptr = (tc + 1); /* Verify authenticator */ - if (consttime_bcmp(ptr, aalg, esph->authsize) != 0) { + if (consttime_memequal(ptr, aalg, esph->authsize) + != 0) { DPRINTF(("esp_input_cb: " "authentication hash mismatch for packet in SA %s/%08lx\n", ipsec_address(&saidx->dst), diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 623fa2d827b..7cfd7e4b9f5 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.41 2013/02/02 21:38:24 christos Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.42 2013/06/24 04:21:20 riastradh Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.41 2013/02/02 21:38:24 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.42 2013/06/24 04:21:20 riastradh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1090,11 +1090,11 @@ swcr_freesession(void *arg, u_int64_t tid) axf = swd->sw_axf; if (swd->sw_ictx) { - explicit_bzero(swd->sw_ictx, axf->ctxsize); + explicit_memset(swd->sw_ictx, 0, axf->ctxsize); free(swd->sw_ictx, M_CRYPTO_DATA); } if (swd->sw_octx) { - explicit_bzero(swd->sw_octx, axf->ctxsize); + explicit_memset(swd->sw_octx, 0, axf->ctxsize); free(swd->sw_octx, M_CRYPTO_DATA); } break; @@ -1104,11 +1104,11 @@ swcr_freesession(void *arg, u_int64_t tid) axf = swd->sw_axf; if (swd->sw_ictx) { - explicit_bzero(swd->sw_ictx, axf->ctxsize); + explicit_memset(swd->sw_ictx, 0, axf->ctxsize); free(swd->sw_ictx, M_CRYPTO_DATA); } if (swd->sw_octx) { - explicit_bzero(swd->sw_octx, swd->sw_klen); + explicit_memset(swd->sw_octx, 0, swd->sw_klen); free(swd->sw_octx, M_CRYPTO_DATA); } break; @@ -1122,7 +1122,7 @@ swcr_freesession(void *arg, u_int64_t tid) axf = swd->sw_axf; if (swd->sw_ictx) { - explicit_bzero(swd->sw_ictx, axf->ctxsize); + explicit_memset(swd->sw_ictx, 0, axf->ctxsize); free(swd->sw_ictx, M_CRYPTO_DATA); } break; |
