Module Name:    src
Committed By:   drochner
Date:           Tue May 24 18:59:23 UTC 2011

Modified Files:
        src/sys/arch/x86/x86: via_padlock.c
        src/sys/opencrypto: cryptosoft.c cryptosoft_xform.c xform.c xform.h

Log Message:
move the "context size" struct member (which is a pure software
implementation thing) from the abstract xform descriptor to
the cryptosoft implementation part -- for sanity, and now clients
of opencrypto don't depend on headers of cipher implementations anymore


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/x86/x86/via_padlock.c
cvs rdiff -u -r1.34 -r1.35 src/sys/opencrypto/cryptosoft.c
cvs rdiff -u -r1.20 -r1.21 src/sys/opencrypto/cryptosoft_xform.c
cvs rdiff -u -r1.25 -r1.26 src/sys/opencrypto/xform.c
cvs rdiff -u -r1.16 -r1.17 src/sys/opencrypto/xform.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/via_padlock.c
diff -u src/sys/arch/x86/x86/via_padlock.c:1.14 src/sys/arch/x86/x86/via_padlock.c:1.15
--- src/sys/arch/x86/x86/via_padlock.c:1.14	Sat Feb 19 13:52:28 2011
+++ src/sys/arch/x86/x86/via_padlock.c	Tue May 24 18:59:21 2011
@@ -1,5 +1,5 @@
 /*	$OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $	*/
-/*	$NetBSD: via_padlock.c,v 1.14 2011/02/19 13:52:28 jmcneill Exp $ */
+/*	$NetBSD: via_padlock.c,v 1.15 2011/05/24 18:59:21 drochner Exp $ */
 
 /*-
  * Copyright (c) 2003 Jason Wright
@@ -20,7 +20,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.14 2011/02/19 13:52:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.15 2011/05/24 18:59:21 drochner Exp $");
 
 #ifdef _KERNEL_OPT
 # include "rnd.h"
@@ -313,14 +313,14 @@
 			}
 			ses->swd = swd;
 
-			swd->sw_ictx = malloc(axf->auth_hash->ctxsize,
+			swd->sw_ictx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if (swd->sw_ictx == NULL) {
 				via_padlock_crypto_freesession(sc, sesn);
 				return (ENOMEM);
 			}
 
-			swd->sw_octx = malloc(axf->auth_hash->ctxsize,
+			swd->sw_octx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if (swd->sw_octx == NULL) {
 				via_padlock_crypto_freesession(sc, sesn);
@@ -365,7 +365,7 @@
 {
 	struct via_padlock_softc *sc = arg;
 	struct swcr_data *swd;
-	const struct auth_hash *axf;
+	const struct swcr_auth_hash *axf;
 	int sesn;
 	uint32_t sid = ((uint32_t)tid) & 0xffffffff;
 
@@ -379,7 +379,7 @@
 
 	if (sc->sc_sessions[sesn].swd) {
 		swd = sc->sc_sessions[sesn].swd;
-		axf = swd->sw_axf->auth_hash;
+		axf = swd->sw_axf;
 
 		if (swd->sw_ictx) {
 			memset(swd->sw_ictx, 0, axf->ctxsize);

Index: src/sys/opencrypto/cryptosoft.c
diff -u src/sys/opencrypto/cryptosoft.c:1.34 src/sys/opencrypto/cryptosoft.c:1.35
--- src/sys/opencrypto/cryptosoft.c:1.34	Tue May 24 18:52:51 2011
+++ src/sys/opencrypto/cryptosoft.c	Tue May 24 18:59:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft.c,v 1.34 2011/05/24 18:52:51 drochner Exp $ */
+/*	$NetBSD: cryptosoft.c,v 1.35 2011/05/24 18:59:22 drochner 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.34 2011/05/24 18:52:51 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.35 2011/05/24 18:59:22 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -479,7 +479,7 @@
 
 	axf = sw->sw_axf;
 
-	memcpy(&ctx, sw->sw_ictx, axf->auth_hash->ctxsize);
+	memcpy(&ctx, sw->sw_ictx, axf->ctxsize);
 
 	switch (outtype) {
 	case CRYPTO_BUF_CONTIG:
@@ -519,7 +519,7 @@
 			return EINVAL;
 
 		axf->Final(aalg, &ctx);
-		memcpy(&ctx, sw->sw_octx, axf->auth_hash->ctxsize);
+		memcpy(&ctx, sw->sw_octx, axf->ctxsize);
 		axf->Update(&ctx, aalg, axf->auth_hash->hashsize);
 		axf->Final(aalg, &ctx);
 		break;
@@ -752,14 +752,14 @@
 			axf = &swcr_auth_hash_hmac_ripemd_160_96;
 			goto authcommon;	/* leave this for safety */
 		authcommon:
-			(*swd)->sw_ictx = malloc(axf->auth_hash->ctxsize,
+			(*swd)->sw_ictx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if ((*swd)->sw_ictx == NULL) {
 				swcr_freesession(NULL, i);
 				return ENOBUFS;
 			}
 
-			(*swd)->sw_octx = malloc(axf->auth_hash->ctxsize,
+			(*swd)->sw_octx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if ((*swd)->sw_octx == NULL) {
 				swcr_freesession(NULL, i);
@@ -796,7 +796,7 @@
 		case CRYPTO_SHA1_KPDK:
 			axf = &swcr_auth_hash_key_sha1;
 		auth2common:
-			(*swd)->sw_ictx = malloc(axf->auth_hash->ctxsize,
+			(*swd)->sw_ictx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if ((*swd)->sw_ictx == NULL) {
 				swcr_freesession(NULL, i);
@@ -827,7 +827,7 @@
 		case CRYPTO_SHA1:
 			axf = &swcr_auth_hash_sha1;
 		auth3common:
-			(*swd)->sw_ictx = malloc(axf->auth_hash->ctxsize,
+			(*swd)->sw_ictx = malloc(axf->ctxsize,
 			    M_CRYPTO_DATA, M_NOWAIT);
 			if ((*swd)->sw_ictx == NULL) {
 				swcr_freesession(NULL, i);
@@ -916,11 +916,11 @@
 			axf = swd->sw_axf;
 
 			if (swd->sw_ictx) {
-				memset(swd->sw_ictx, 0, axf->auth_hash->ctxsize);
+				memset(swd->sw_ictx, 0, axf->ctxsize);
 				free(swd->sw_ictx, M_CRYPTO_DATA);
 			}
 			if (swd->sw_octx) {
-				memset(swd->sw_octx, 0, axf->auth_hash->ctxsize);
+				memset(swd->sw_octx, 0, axf->ctxsize);
 				free(swd->sw_octx, M_CRYPTO_DATA);
 			}
 			break;
@@ -930,7 +930,7 @@
 			axf = swd->sw_axf;
 
 			if (swd->sw_ictx) {
-				memset(swd->sw_ictx, 0, axf->auth_hash->ctxsize);
+				memset(swd->sw_ictx, 0, axf->ctxsize);
 				free(swd->sw_ictx, M_CRYPTO_DATA);
 			}
 			if (swd->sw_octx) {

Index: src/sys/opencrypto/cryptosoft_xform.c
diff -u src/sys/opencrypto/cryptosoft_xform.c:1.20 src/sys/opencrypto/cryptosoft_xform.c:1.21
--- src/sys/opencrypto/cryptosoft_xform.c:1.20	Tue May 24 18:52:51 2011
+++ src/sys/opencrypto/cryptosoft_xform.c	Tue May 24 18:59:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptosoft_xform.c,v 1.20 2011/05/24 18:52:51 drochner Exp $ */
+/*	$NetBSD: cryptosoft_xform.c,v 1.21 2011/05/24 18:59:22 drochner Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $	*/
 
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.20 2011/05/24 18:52:51 drochner Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.21 2011/05/24 18:59:22 drochner Exp $");
 
 #include <crypto/blowfish/blowfish.h>
 #include <crypto/cast128/cast128.h>
@@ -54,9 +54,11 @@
 #include <sys/md5.h>
 #include <sys/rmd160.h>
 #include <sys/sha1.h>
+#include <sys/sha2.h>
 
 struct swcr_auth_hash {
 	const struct auth_hash *auth_hash;
+	int ctxsize;
 	void (*Init)(void *);
 	int  (*Update)(void *, const uint8_t *, uint16_t);
 	void (*Final)(uint8_t *, void *);
@@ -222,80 +224,80 @@
 
 /* Authentication instances */
 static const struct swcr_auth_hash swcr_auth_hash_null = {
-	&auth_hash_null,
+	&auth_hash_null, sizeof(int), /* NB: context isn't used */
 	null_init, null_update, null_final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_md5 = {
-	&auth_hash_hmac_md5,
+	&auth_hash_hmac_md5, sizeof(MD5_CTX),
 	(void (*) (void *)) MD5Init, MD5Update_int,
 	(void (*) (u_int8_t *, void *)) MD5Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha1 = {
-	&auth_hash_hmac_sha1,
+	&auth_hash_hmac_sha1, sizeof(SHA1_CTX),
 	SHA1Init_int, SHA1Update_int, SHA1Final_int
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_ripemd_160 = {
-	&auth_hash_hmac_ripemd_160,
+	&auth_hash_hmac_ripemd_160, sizeof(RMD160_CTX),
 	(void (*)(void *)) RMD160Init, RMD160Update_int,
 	(void (*)(u_int8_t *, void *)) RMD160Final
 };
 static const struct swcr_auth_hash swcr_auth_hash_hmac_md5_96 = {
-	&auth_hash_hmac_md5_96,
+	&auth_hash_hmac_md5_96, sizeof(MD5_CTX),
 	(void (*) (void *)) MD5Init, MD5Update_int,
 	(void (*) (u_int8_t *, void *)) MD5Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha1_96 = {
-	&auth_hash_hmac_sha1_96,
+	&auth_hash_hmac_sha1_96, sizeof(SHA1_CTX),
 	SHA1Init_int, SHA1Update_int, SHA1Final_int
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_ripemd_160_96 = {
-	&auth_hash_hmac_ripemd_160_96,
+	&auth_hash_hmac_ripemd_160_96, sizeof(RMD160_CTX),
 	(void (*)(void *)) RMD160Init, RMD160Update_int,
 	(void (*)(u_int8_t *, void *)) RMD160Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_key_md5 = {
-	&auth_hash_key_md5,
+	&auth_hash_key_md5, sizeof(MD5_CTX),
 	(void (*)(void *)) MD5Init, MD5Update_int,
 	(void (*)(u_int8_t *, void *)) MD5Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_key_sha1 = {
-	&auth_hash_key_sha1,
+	&auth_hash_key_sha1, sizeof(SHA1_CTX),
 	SHA1Init_int, SHA1Update_int, SHA1Final_int
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_md5 = {
-	&auth_hash_md5,
+	&auth_hash_md5, sizeof(MD5_CTX),
 	(void (*) (void *)) MD5Init, MD5Update_int,
 	(void (*) (u_int8_t *, void *)) MD5Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_sha1 = {
-	&auth_hash_sha1,
+	&auth_hash_sha1, sizeof(SHA1_CTX),
 	(void (*)(void *)) SHA1Init, SHA1Update_int,
 	(void (*)(u_int8_t *, void *)) SHA1Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_256 = {
-	&auth_hash_hmac_sha2_256,
+	&auth_hash_hmac_sha2_256, sizeof(SHA256_CTX),
 	(void (*)(void *)) SHA256_Init, SHA256Update_int,
 	(void (*)(u_int8_t *, void *)) SHA256_Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_384 = {
-	&auth_hash_hmac_sha2_384,
+	&auth_hash_hmac_sha2_384, sizeof(SHA384_CTX),
 	(void (*)(void *)) SHA384_Init, SHA384Update_int,
 	(void (*)(u_int8_t *, void *)) SHA384_Final
 };
 
 static const struct swcr_auth_hash swcr_auth_hash_hmac_sha2_512 = {
-	&auth_hash_hmac_sha2_384,
+	&auth_hash_hmac_sha2_512, sizeof(SHA512_CTX),
 	(void (*)(void *)) SHA512_Init, SHA512Update_int,
 	(void (*)(u_int8_t *, void *)) SHA512_Final
 };

Index: src/sys/opencrypto/xform.c
diff -u src/sys/opencrypto/xform.c:1.25 src/sys/opencrypto/xform.c:1.26
--- src/sys/opencrypto/xform.c:1.25	Mon May 23 13:51:10 2011
+++ src/sys/opencrypto/xform.c	Tue May 24 18:59:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xform.c,v 1.25 2011/05/23 13:51:10 drochner Exp $ */
+/*	$NetBSD: xform.c,v 1.26 2011/05/24 18:59:23 drochner Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $	*/
 
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.25 2011/05/23 13:51:10 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.26 2011/05/24 18:59:23 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -143,72 +143,72 @@
 /* Authentication instances */
 const struct auth_hash auth_hash_null = {
 	CRYPTO_NULL_HMAC, "NULL-HMAC",
-	0, 0, 12, 64, sizeof(int)		/* NB: context isn't used */
+	0, 0, 12, 64
 };
 
 const struct auth_hash auth_hash_hmac_md5 = {
 	CRYPTO_MD5_HMAC, "HMAC-MD5",
-	16, 16, 16, 64, sizeof(MD5_CTX)
+	16, 16, 16, 64
 };
 
 const struct auth_hash auth_hash_hmac_sha1 = {
 	CRYPTO_SHA1_HMAC, "HMAC-SHA1",
-	20, 20, 20, 64, sizeof(SHA1_CTX)
+	20, 20, 20, 64
 };
 
 const struct auth_hash auth_hash_hmac_ripemd_160 = {
 	CRYPTO_RIPEMD160_HMAC, "HMAC-RIPEMD-160",
-	20, 20, 20, 64, sizeof(RMD160_CTX)
+	20, 20, 20, 64
 };
 
 const struct auth_hash auth_hash_hmac_md5_96 = {
 	CRYPTO_MD5_HMAC_96, "HMAC-MD5-96",
-	16, 16, 12, 64, sizeof(MD5_CTX)
+	16, 16, 12, 64
 };
 
 const struct auth_hash auth_hash_hmac_sha1_96 = {
 	CRYPTO_SHA1_HMAC_96, "HMAC-SHA1-96",
-	20, 20, 12, 64, sizeof(SHA1_CTX)
+	20, 20, 12, 64
 };
 
 const struct auth_hash auth_hash_hmac_ripemd_160_96 = {
 	CRYPTO_RIPEMD160_HMAC_96, "HMAC-RIPEMD-160",
-	20, 20, 12, 64, sizeof(RMD160_CTX)
+	20, 20, 12, 64
 };
 
 const struct auth_hash auth_hash_key_md5 = {
 	CRYPTO_MD5_KPDK, "Keyed MD5",
-	0, 16, 16, 0, sizeof(MD5_CTX)
+	0, 16, 16, 0
 };
 
 const struct auth_hash auth_hash_key_sha1 = {
 	CRYPTO_SHA1_KPDK, "Keyed SHA1",
-	0, 20, 20, 0, sizeof(SHA1_CTX)
+	0, 20, 20, 0
 };
 
 const struct auth_hash auth_hash_md5 = {
 	CRYPTO_MD5, "MD5",
-	0, 16, 16, 0, sizeof(MD5_CTX)
+	0, 16, 16, 0
 };
 
 const struct auth_hash auth_hash_sha1 = {
 	CRYPTO_SHA1, "SHA1",
-	0, 20, 20, 0, sizeof(SHA1_CTX)
+	0, 20, 20, 0
 };
 
 const struct auth_hash auth_hash_hmac_sha2_256 = {
 	CRYPTO_SHA2_256_HMAC, "HMAC-SHA2",
-	32, 32, 16, 64, sizeof(SHA256_CTX)
+	32, 32, 16, 64
 };
 
 const struct auth_hash auth_hash_hmac_sha2_384 = {
 	CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384",
-	48, 48, 24, 128, sizeof(SHA384_CTX)
+	48, 48, 24, 128
 };
 
 const struct auth_hash auth_hash_hmac_sha2_512 = {
 	CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512",
-	64, 64, 32, 128, sizeof(SHA512_CTX)
+	64, 64, 32, 128
 };
 
 /* Compression instance */

Index: src/sys/opencrypto/xform.h
diff -u src/sys/opencrypto/xform.h:1.16 src/sys/opencrypto/xform.h:1.17
--- src/sys/opencrypto/xform.h:1.16	Mon May 23 13:51:10 2011
+++ src/sys/opencrypto/xform.h	Tue May 24 18:59:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xform.h,v 1.16 2011/05/23 13:51:10 drochner Exp $ */
+/*	$NetBSD: xform.h,v 1.17 2011/05/24 18:59:23 drochner Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/xform.h,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
 /*	$OpenBSD: xform.h,v 1.10 2002/04/22 23:10:09 deraadt Exp $	*/
 
@@ -26,11 +26,6 @@
 #ifndef _CRYPTO_XFORM_H_
 #define _CRYPTO_XFORM_H_
 
-#include <sys/md5.h>
-#include <sys/sha1.h>
-#include <sys/sha2.h>
-#include <sys/rmd160.h>
-
 /* Declarations */
 struct auth_hash {
 	int type;
@@ -39,7 +34,6 @@
 	u_int16_t hashsize;
 	u_int16_t authsize;
 	u_int16_t blocksize;
-	u_int16_t ctxsize;
 };
 
 /* Provide array-limit for clients (e.g., netipsec) */

Reply via email to