Module Name:    src
Committed By:   drochner
Date:           Mon May 23 15:22:57 UTC 2011

Modified Files:
        src/sys/opencrypto: cryptodev.c

Log Message:
If symmetric encryption is done from userland crypto(4) and no IV
is specified, the kernel gets one from the random generator. Make sure it
is copied out to the user, otherwise the result is quite useless.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/opencrypto/cryptodev.c

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

Modified files:

Index: src/sys/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.60 src/sys/opencrypto/cryptodev.c:1.61
--- src/sys/opencrypto/cryptodev.c:1.60	Mon May 23 13:53:59 2011
+++ src/sys/opencrypto/cryptodev.c	Mon May 23 15:22:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.60 2011/05/23 13:53:59 drochner Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.61 2011/05/23 15:22:57 drochner Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $	*/
 /*	$OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $	*/
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.60 2011/05/23 13:53:59 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.61 2011/05/23 15:22:57 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -594,7 +594,8 @@
 		if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
 			crde->crd_skip = 0;
 		} else {
-			crde->crd_flags |= CRD_F_IV_PRESENT;
+			if (!(crde->crd_flags & CRD_F_ENCRYPT))
+				crde->crd_flags |= CRD_F_IV_PRESENT;
 			crde->crd_skip = cse->txform->ivsize;
 			crde->crd_len -= cse->txform->ivsize;
 		}
@@ -1290,7 +1291,8 @@
 			if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
 				crde->crd_skip = 0;
 			} else {
-				crde->crd_flags |= CRD_F_IV_PRESENT;
+				if (!(crde->crd_flags & CRD_F_ENCRYPT))
+					crde->crd_flags |= CRD_F_IV_PRESENT;
 				crde->crd_skip = cse->txform->ivsize;
 				crde->crd_len -= cse->txform->ivsize;
 			}

Reply via email to