Fri Sep 12 16:51:55 2008 UTC ()
PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV


(christos)
diff -r1.27 -r1.28 src/sbin/cgdconfig/cgdconfig.8
diff -r1.23 -r1.24 src/sbin/cgdconfig/params.c
diff -r1.10 -r1.11 src/share/man/man4/cgd.4
diff -r1.52 -r1.53 src/sys/dev/cgd.c
diff -r1.11 -r1.12 src/sys/dev/cgdvar.h

cvs diff -r1.27 -r1.28 src/sbin/cgdconfig/cgdconfig.8 (expand / switch to unified diff)

--- src/sbin/cgdconfig/cgdconfig.8 2008/05/13 09:31:06 1.27
+++ src/sbin/cgdconfig/cgdconfig.8 2008/09/12 16:51:55 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: cgdconfig.8,v 1.27 2008/05/13 09:31:06 wiz Exp $ 1.\" $NetBSD: cgdconfig.8,v 1.28 2008/09/12 16:51:55 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 2002, The NetBSD Foundation, Inc. 3.\" Copyright (c) 2002, The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Roland C. Dowdeswell. 7.\" by Roland C. Dowdeswell.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd May 10, 2008 30.Dd September 12, 2008
31.Dt CGDCONFIG 8 31.Dt CGDCONFIG 8
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm cgdconfig 34.Nm cgdconfig
35.Nd configuration utility for the cryptographic disk driver 35.Nd configuration utility for the cryptographic disk driver
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Nm 37.Nm
38.Op Fl npv 38.Op Fl npv
39.Op Fl V Ar vmeth 39.Op Fl V Ar vmeth
40.Ar cgd dev 40.Ar cgd dev
41.Op Ar paramsfile 41.Op Ar paramsfile
42.Nm 42.Nm
43.Fl C 43.Fl C
@@ -87,27 +87,27 @@ The options are as follows: @@ -87,27 +87,27 @@ The options are as follows:
87Configure all the devices listed in the cgd configuration file. 87Configure all the devices listed in the cgd configuration file.
88.It Fl f Ar configfile 88.It Fl f Ar configfile
89Specify the configuration file explicitly, rather than using the default 89Specify the configuration file explicitly, rather than using the default
90configuration file 90configuration file
91.Pa /etc/cgd/cgd.conf . 91.Pa /etc/cgd/cgd.conf .
92.It Fl G 92.It Fl G
93Generate a new paramsfile (to stdout) using the values from 93Generate a new paramsfile (to stdout) using the values from
94.Ar paramsfile 94.Ar paramsfile
95which will generate the same key. 95which will generate the same key.
96This may need to prompt for multiple passphrases. 96This may need to prompt for multiple passphrases.
97.It Fl g 97.It Fl g
98Generate a paramsfile (to stdout). 98Generate a paramsfile (to stdout).
99.It Fl i Ar ivmeth 99.It Fl i Ar ivmeth
100Specify the IV method (default: encblkno). 100Specify the IV method (default: encblkno1).
101.It Fl k Ar kgmeth 101.It Fl k Ar kgmeth
102Specify the key generation method (default: pkcs5_pbkdf2/sha1). 102Specify the key generation method (default: pkcs5_pbkdf2/sha1).
103.It Fl o Ar outfile 103.It Fl o Ar outfile
104When generating a 104When generating a
105.Ar paramsfile , 105.Ar paramsfile ,
106store it in 106store it in
107.Ar outfile . 107.Ar outfile .
108.It Fl p 108.It Fl p
109Read all passphrases from stdin rather than 109Read all passphrases from stdin rather than
110.Pa /dev/tty . 110.Pa /dev/tty .
111Passphrases are separated by newlines. 111Passphrases are separated by newlines.
112Users of this flag must be able to predict the order in which passphrases 112Users of this flag must be able to predict the order in which passphrases
113are prompted. 113are prompted.
@@ -306,27 +306,27 @@ Only used for pkcs5_pbkdf2/sha1 and pkcs @@ -306,27 +306,27 @@ Only used for pkcs5_pbkdf2/sha1 and pkcs
306The salt. 306The salt.
307Only used for pkcs5_pbkdf2/sha1 and pkcs5_pbkdf2. 307Only used for pkcs5_pbkdf2/sha1 and pkcs5_pbkdf2.
308.El 308.El
309.Sh FILES 309.Sh FILES
310.Bl -tag -width indentxxxxxxxxxxxxxxxxxx -compact 310.Bl -tag -width indentxxxxxxxxxxxxxxxxxx -compact
311.It Pa /etc/cgd/ 311.It Pa /etc/cgd/
312configuration directory, used to store paramsfiles. 312configuration directory, used to store paramsfiles.
313.It Pa /etc/cgd/cgd.conf 313.It Pa /etc/cgd/cgd.conf
314cgd configuration file. 314cgd configuration file.
315.El 315.El
316.Sh EXAMPLES 316.Sh EXAMPLES
317To set up and configure a cgd that uses AES with a 192 bit key 317To set up and configure a cgd that uses AES with a 192 bit key
318in CBC mode with the IV Method 318in CBC mode with the IV Method
319.Sq encblkno 319.Sq encblkno1
320(encrypted block number): 320(encrypted block number):
321.Bd -literal 321.Bd -literal
322 # cgdconfig -g -o /etc/cgd/wd0e aes-cbc 192 322 # cgdconfig -g -o /etc/cgd/wd0e aes-cbc 192
323 # cgdconfig cgd0 /dev/wd0e 323 # cgdconfig cgd0 /dev/wd0e
324 /dev/wd0e's passphrase: 324 /dev/wd0e's passphrase:
325.Ed 325.Ed
326.Pp 326.Pp
327When using verification methods, the first time that we configure the 327When using verification methods, the first time that we configure the
328disk the verification method will fail. 328disk the verification method will fail.
329We overcome this by supplying 329We overcome this by supplying
330.Fl V Ar re-enter 330.Fl V Ar re-enter
331when we configure the first time to set up the disk. 331when we configure the first time to set up the disk.
332Here is the 332Here is the
@@ -349,40 +349,40 @@ parameters file: @@ -349,40 +349,40 @@ parameters file:
349 old file's passphrase: 349 old file's passphrase:
350 new file's passphrase: 350 new file's passphrase:
351.Ed 351.Ed
352.Pp 352.Pp
353To configure a cgd that uses Blowfish with a 200 bit key that it 353To configure a cgd that uses Blowfish with a 200 bit key that it
354reads from stdin: 354reads from stdin:
355.Bd -literal 355.Bd -literal
356 # cgdconfig -s cgd0 /dev/sd0h blowfish-cbc 200 356 # cgdconfig -s cgd0 /dev/sd0h blowfish-cbc 200
357.Ed 357.Ed
358.Pp 358.Pp
359An example parameters file which uses PKCS#5 PBKDF2: 359An example parameters file which uses PKCS#5 PBKDF2:
360.Bd -literal 360.Bd -literal
361 algorithm aes-cbc; 361 algorithm aes-cbc;
362 iv-method encblkno; 362 iv-method encblkno1;
363 keylength 128; 363 keylength 128;
364 verify_method none; 364 verify_method none;
365 keygen pkcs5_pbkdf2/sha1 { 365 keygen pkcs5_pbkdf2/sha1 {
366 iterations 39361; 366 iterations 39361;
367 salt AAAAgMoHiYonye6Kog \\ 367 salt AAAAgMoHiYonye6Kog \\
368 dYJAobCHE=; 368 dYJAobCHE=;
369 }; 369 };
370.Ed 370.Ed
371.Pp 371.Pp
372An example parameters file which stores its key locally: 372An example parameters file which stores its key locally:
373.Bd -literal 373.Bd -literal
374 algorithm aes-cbc; 374 algorithm aes-cbc;
375 iv-method encblkno; 375 iv-method encblkno1;
376 keylength 256; 376 keylength 256;
377 verify_method none; 377 verify_method none;
378 keygen storedkey key AAABAK3QO6d7xzLfrXTdsgg4 \\ 378 keygen storedkey key AAABAK3QO6d7xzLfrXTdsgg4 \\
379 ly2TdxkFqOkYYcbyUKu/f60L; 379 ly2TdxkFqOkYYcbyUKu/f60L;
380.Ed 380.Ed
381.Pp 381.Pp
382An example 382An example
383.Pa /etc/cgd/cgd.conf : 383.Pa /etc/cgd/cgd.conf :
384.Bd -literal 384.Bd -literal
385 # 385 #
386 # /etc/cgd/cgd.conf 386 # /etc/cgd/cgd.conf
387 # Configuration file for cryptographic disk devices 387 # Configuration file for cryptographic disk devices
388 # 388 #

cvs diff -r1.23 -r1.24 src/sbin/cgdconfig/params.c (expand / switch to unified diff)

--- src/sbin/cgdconfig/params.c 2008/05/11 03:15:21 1.23
+++ src/sbin/cgdconfig/params.c 2008/09/12 16:51:55 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: params.c,v 1.23 2008/05/11 03:15:21 elric Exp $ */ 1/* $NetBSD: params.c,v 1.24 2008/09/12 16:51:55 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell. 8 * by Roland C. Dowdeswell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: params.c,v 1.23 2008/05/11 03:15:21 elric Exp $"); 34__RCSID("$NetBSD: params.c,v 1.24 2008/09/12 16:51:55 christos Exp $");
35#endif 35#endif
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38 38
39#include <err.h> 39#include <err.h>
40#include <errno.h> 40#include <errno.h>
41#include <stdio.h> 41#include <stdio.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44#include <util.h> 44#include <util.h>
45 45
46#include "params.h" 46#include "params.h"
47#include "pkcs5_pbkdf2.h" 47#include "pkcs5_pbkdf2.h"
@@ -142,73 +142,84 @@ params_combine(struct params *p1, struct @@ -142,73 +142,84 @@ params_combine(struct params *p1, struct
142 */ 142 */
143 free(p2); 143 free(p2);
144 return p; 144 return p;
145} 145}
146 146
147int 147int
148params_filldefaults(struct params *p) 148params_filldefaults(struct params *p)
149{ 149{
150 size_t i; 150 size_t i;
151 151
152 if (p->verify_method == VERIFY_UNKNOWN) 152 if (p->verify_method == VERIFY_UNKNOWN)
153 p->verify_method = VERIFY_NONE; 153 p->verify_method = VERIFY_NONE;
154 if (!p->ivmeth) 154 if (!p->ivmeth)
155 p->ivmeth = string_fromcharstar("encblkno"); 155 p->ivmeth = string_fromcharstar("encblkno1");
156 if (p->keylen == (size_t)-1) { 156 if (p->keylen == (size_t)-1) {
157 i = crypt_defaults_lookup(string_tocharstar(p->algorithm)); 157 i = crypt_defaults_lookup(string_tocharstar(p->algorithm));
158 if (i != (size_t)-1) { 158 if (i != (size_t)-1) {
159 p->keylen = crypto_defaults[i].keylen; 159 p->keylen = crypto_defaults[i].keylen;
160 } else { 160 } else {
161 warnx("could not determine key length for unknown " 161 warnx("could not determine key length for unknown "
162 "algorithm \"%s\"", 162 "algorithm \"%s\"",
163 string_tocharstar(p->algorithm)); 163 string_tocharstar(p->algorithm));
164 return -1; 164 return -1;
165 } 165 }
166 } 166 }
167 return 0; 167 return 0;
168} 168}
169 169
170/* 170/*
171 * params_verify traverses the parameters and all of the keygen methods 171 * params_verify traverses the parameters and all of the keygen methods
172 * looking for inconsistencies. It outputs warnings on non-fatal errors 172 * looking for inconsistencies. It outputs warnings on non-fatal errors
173 * such as unknown encryption methods, but returns failure on fatal 173 * such as unknown encryption methods, but returns failure on fatal
174 * conditions such as a PKCS5_PBKDF2 keygen without a salt. It is intended 174 * conditions such as a PKCS5_PBKDF2 keygen without a salt. It is intended
175 * to run before key generation. 175 * to run before key generation.
176 */ 176 */
177 177
178int 178int
179params_verify(const struct params *p) 179params_verify(const struct params *p)
180{ 180{
 181 static const char *encblkno[] = {
 182 "encblkno", "encblkno1", "encblkno8"
 183 };
 184 static size_t i;
 185 const char *meth;
181 186
182 if (!p->algorithm) { 187 if (!p->algorithm) {
183 warnx("unspecified algorithm"); 188 warnx("unspecified algorithm");
184 return 0; 189 return 0;
185 } 190 }
186 /* 191 /*
187 * we only warn for the encryption method so that it is possible 192 * we only warn for the encryption method so that it is possible
188 * to use an older cgdconfig(8) with a new kernel that supports 193 * to use an older cgdconfig(8) with a new kernel that supports
189 * additional crypto algorithms. 194 * additional crypto algorithms.
190 */ 195 */
191 if (crypt_defaults_lookup(string_tocharstar(p->algorithm)) == -1) 196 if (crypt_defaults_lookup(string_tocharstar(p->algorithm)) == -1)
192 warnx("unknown algorithm \"%s\"(warning)", 197 warnx("unknown algorithm \"%s\"(warning)",
193 string_tocharstar(p->algorithm)); 198 string_tocharstar(p->algorithm));
194 /* same rationale with IV methods. */ 199 /* same rationale with IV methods. */
195 if (!p->ivmeth) { 200 if (!p->ivmeth) {
196 warnx("unspecified IV method"); 201 warnx("unspecified IV method");
197 return 0; 202 return 0;
198 } 203 }
199 if (strcmp("encblkno", string_tocharstar(p->ivmeth))) 204
200 warnx("unknown IV method \"%s\" (warning)", 205 meth = string_tocharstar(p->ivmeth);
201 string_tocharstar(p->ivmeth)); 206 for (i = 0; i < __arraycount(encblkno); i++)
 207 if (strcmp(encblkno[i], meth) == 0)
 208 break;
 209
 210 if (i == __arraycount(encblkno))
 211 warnx("unknown IV method \"%s\" (warning)", meth);
 212
202 if (p->keylen == (size_t)-1) { 213 if (p->keylen == (size_t)-1) {
203 warnx("unspecified key length"); 214 warnx("unspecified key length");
204 return 0; 215 return 0;
205 } 216 }
206 217
207 return keygen_verify(p->keygen); 218 return keygen_verify(p->keygen);
208} 219}
209 220
210struct params * 221struct params *
211params_algorithm(string_t *in) 222params_algorithm(string_t *in)
212{ 223{
213 struct params *p = params_new(); 224 struct params *p = params_new();
214 225

cvs diff -r1.10 -r1.11 src/share/man/man4/cgd.4 (expand / switch to unified diff)

--- src/share/man/man4/cgd.4 2008/04/30 13:10:53 1.10
+++ src/share/man/man4/cgd.4 2008/09/12 16:51:55 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: cgd.4,v 1.10 2008/04/30 13:10:53 martin Exp $ 1.\" $NetBSD: cgd.4,v 1.11 2008/09/12 16:51:55 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Roland C. Dowdeswell. 7.\" by Roland C. Dowdeswell.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd March 11, 2006 30.Dd September 12, 2008
31.Dt CGD 4 31.Dt CGD 4
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm cgd 34.Nm cgd
35.Nd cryptographic disk driver 35.Nd cryptographic disk driver
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.Cd "pseudo-device cgd" Op Ar count 37.Cd "pseudo-device cgd" Op Ar count
38.Sh DESCRIPTION 38.Sh DESCRIPTION
39The 39The
40.Nm 40.Nm
41driver provides the capability of encrypting blocks on their way 41driver provides the capability of encrypting blocks on their way
42to and from a disk or partition. 42to and from a disk or partition.
43.Pp 43.Pp
@@ -66,34 +66,49 @@ Triple DES in CBC mode. @@ -66,34 +66,49 @@ Triple DES in CBC mode.
66Triple DES uses a 64 bit blocksize and is 66Triple DES uses a 64 bit blocksize and is
67performed in EDE3 mode with a 168 bit key. 67performed in EDE3 mode with a 168 bit key.
68The key passed to the kernel 68The key passed to the kernel
69is 192 bits but the parity bits are ignored. 69is 192 bits but the parity bits are ignored.
70.It blowfish-cbc 70.It blowfish-cbc
71Blowfish in CBC mode. 71Blowfish in CBC mode.
72Blowfish uses a 64 bit blocksize and can accept keys between 40 and 72Blowfish uses a 64 bit blocksize and can accept keys between 40 and
73448 bits in multiples of 8. 73448 bits in multiples of 8.
74It is strongly encouraged that keys be at least 128 bits long. 74It is strongly encouraged that keys be at least 128 bits long.
75There are no performance advantages of using shorter keys. 75There are no performance advantages of using shorter keys.
76The default key length is 128 bits. 76The default key length is 128 bits.
77.El 77.El
78.Ss IV Methods 78.Ss IV Methods
79Currently, the only IV Method supported is 79Currently, the following IV Methods are supported:
80.Ar encblkno 80.Bl -tag -width encblkno1
81(Encrypted Block Number). 81.It encblkno1
82This method encrypts the block number of the 82This method encrypts the block number of the physical disk block once with
83physical disk block with the cipher and key provided and uses that as the 83the cipher and key provided and uses the result as the IV for CBC mode.
84IV for CBC mode. 84This method should ensure that each block has a different IV and that the IV
85This method should ensure that each block has a different 85is reasonably unpredictable.
86IV and that the IV is reasonably unpredictable. 86This is the default method used by
 87.Xr cgdconfig 8
 88when configuring new
 89.Nm Ns 's .
 90.It encblkno8
 91This is the original IV method used by
 92.Nm
 93and provided for backward compatibility. It repeatedly encrypts the block
 94number of the physical disk block eight times and uses the result as the IV
 95for CBC mode.
 96This method should ensure that each block has a different IV and that the IV
 97is reasonably unpredictable.
 98The eightfold encryption was not intended and causes a notable
 99performance loss with little (if any) increase in security over a
 100single encryption.
 101.El
87.Ss IOCTLS 102.Ss IOCTLS
88A 103A
89.Nm 104.Nm
90responds to all of the standard disk 105responds to all of the standard disk
91.Xr ioctl 2 106.Xr ioctl 2
92calls defined in 107calls defined in
93.Xr sd 4 , 108.Xr sd 4 ,
94and also defines the following: 109and also defines the following:
95.Bl -tag -width CGDIOCSET 110.Bl -tag -width CGDIOCSET
96.It CGDIOCSET 111.It CGDIOCSET
97configure the 112configure the
98.Nm . 113.Nm .
99This 114This

cvs diff -r1.52 -r1.53 src/sys/dev/cgd.c (expand / switch to unified diff)

--- src/sys/dev/cgd.c 2008/04/28 20:23:46 1.52
+++ src/sys/dev/cgd.c 2008/09/12 16:51:55 1.53
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cgd.c,v 1.52 2008/04/28 20:23:46 martin Exp $ */ 1/* $NetBSD: cgd.c,v 1.53 2008/09/12 16:51:55 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell. 8 * by Roland C. Dowdeswell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.52 2008/04/28 20:23:46 martin Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.53 2008/09/12 16:51:55 christos Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/errno.h> 39#include <sys/errno.h>
40#include <sys/buf.h> 40#include <sys/buf.h>
41#include <sys/bufq.h> 41#include <sys/bufq.h>
42#include <sys/malloc.h> 42#include <sys/malloc.h>
43#include <sys/pool.h> 43#include <sys/pool.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/device.h> 45#include <sys/device.h>
46#include <sys/disk.h> 46#include <sys/disk.h>
@@ -476,80 +476,102 @@ cgddump(dev_t dev, daddr_t blkno, void * @@ -476,80 +476,102 @@ cgddump(dev_t dev, daddr_t blkno, void *
476 476
477 DPRINTF_FOLLOW(("cgddump(%d, %" PRId64 ", %p, %lu)\n", dev, blkno, va, 477 DPRINTF_FOLLOW(("cgddump(%d, %" PRId64 ", %p, %lu)\n", dev, blkno, va,
478 (unsigned long)size)); 478 (unsigned long)size));
479 GETCGD_SOFTC(cs, dev); 479 GETCGD_SOFTC(cs, dev);
480 return dk_dump(di, &cs->sc_dksc, dev, blkno, va, size); 480 return dk_dump(di, &cs->sc_dksc, dev, blkno, va, size);
481} 481}
482 482
483/* 483/*
484 * XXXrcd: 484 * XXXrcd:
485 * for now we hardcode the maximum key length. 485 * for now we hardcode the maximum key length.
486 */ 486 */
487#define MAX_KEYSIZE 1024 487#define MAX_KEYSIZE 1024
488 488
 489static const struct {
 490 const char *n;
 491 int v;
 492 int d;
 493} encblkno[] = {
 494 { "encblkno", CGD_CIPHER_CBC_ENCBLKNO8, 1 },
 495 { "encblkno8", CGD_CIPHER_CBC_ENCBLKNO8, 1 },
 496 { "encblkno1", CGD_CIPHER_CBC_ENCBLKNO1, 8 },
 497};
 498
489/* ARGSUSED */ 499/* ARGSUSED */
490static int 500static int
491cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l) 501cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
492{ 502{
493 struct cgd_ioctl *ci = data; 503 struct cgd_ioctl *ci = data;
494 struct vnode *vp; 504 struct vnode *vp;
495 int ret; 505 int ret;
 506 size_t i;
496 size_t keybytes; /* key length in bytes */ 507 size_t keybytes; /* key length in bytes */
497 const char *cp; 508 const char *cp;
498 char *inbuf; 509 char *inbuf;
499 510
500 cp = ci->ci_disk; 511 cp = ci->ci_disk;
501 if ((ret = dk_lookup(cp, l, &vp, UIO_USERSPACE)) != 0) 512 if ((ret = dk_lookup(cp, l, &vp, UIO_USERSPACE)) != 0)
502 return ret; 513 return ret;
503 514
504 inbuf = malloc(MAX_KEYSIZE, M_TEMP, M_WAITOK); 515 inbuf = malloc(MAX_KEYSIZE, M_TEMP, M_WAITOK);
505 516
506 if ((ret = cgdinit(cs, cp, vp, l)) != 0) 517 if ((ret = cgdinit(cs, cp, vp, l)) != 0)
507 goto bail; 518 goto bail;
508 519
509 (void)memset(inbuf, 0, MAX_KEYSIZE); 520 (void)memset(inbuf, 0, MAX_KEYSIZE);
510 ret = copyinstr(ci->ci_alg, inbuf, 256, NULL); 521 ret = copyinstr(ci->ci_alg, inbuf, 256, NULL);
511 if (ret) 522 if (ret)
512 goto bail; 523 goto bail;
513 cs->sc_cfuncs = cryptfuncs_find(inbuf); 524 cs->sc_cfuncs = cryptfuncs_find(inbuf);
514 if (!cs->sc_cfuncs) { 525 if (!cs->sc_cfuncs) {
515 ret = EINVAL; 526 ret = EINVAL;
516 goto bail; 527 goto bail;
517 } 528 }
518 529
519 /* right now we only support encblkno, so hard-code it */ 
520 (void)memset(inbuf, 0, MAX_KEYSIZE); 530 (void)memset(inbuf, 0, MAX_KEYSIZE);
521 ret = copyinstr(ci->ci_ivmethod, inbuf, MAX_KEYSIZE, NULL); 531 ret = copyinstr(ci->ci_ivmethod, inbuf, MAX_KEYSIZE, NULL);
522 if (ret) 532 if (ret)
523 goto bail; 533 goto bail;
524 if (strcmp("encblkno", inbuf)) { 534
 535 for (i = 0; i < __arraycount(encblkno); i++)
 536 if (strcmp(encblkno[i].n, inbuf) == 0)
 537 break;
 538
 539 if (i == __arraycount(encblkno)) {
525 ret = EINVAL; 540 ret = EINVAL;
526 goto bail; 541 goto bail;
527 } 542 }
528 543
529 keybytes = ci->ci_keylen / 8 + 1; 544 keybytes = ci->ci_keylen / 8 + 1;
530 if (keybytes > MAX_KEYSIZE) { 545 if (keybytes > MAX_KEYSIZE) {
531 ret = EINVAL; 546 ret = EINVAL;
532 goto bail; 547 goto bail;
533 } 548 }
 549
534 (void)memset(inbuf, 0, MAX_KEYSIZE); 550 (void)memset(inbuf, 0, MAX_KEYSIZE);
535 ret = copyin(ci->ci_key, inbuf, keybytes); 551 ret = copyin(ci->ci_key, inbuf, keybytes);
536 if (ret) 552 if (ret)
537 goto bail; 553 goto bail;
538 554
539 cs->sc_cdata.cf_blocksize = ci->ci_blocksize; 555 cs->sc_cdata.cf_blocksize = ci->ci_blocksize;
540 cs->sc_cdata.cf_mode = CGD_CIPHER_CBC_ENCBLKNO; 556 cs->sc_cdata.cf_mode = encblkno[i].v;
541 cs->sc_cdata.cf_priv = cs->sc_cfuncs->cf_init(ci->ci_keylen, inbuf, 557 cs->sc_cdata.cf_priv = cs->sc_cfuncs->cf_init(ci->ci_keylen, inbuf,
542 &cs->sc_cdata.cf_blocksize); 558 &cs->sc_cdata.cf_blocksize);
 559 /*
 560 * The blocksize is supposed to be in bytes. Unfortunately originally
 561 * it was expressed in bits. For compatibility we maintain encblkno
 562 * and encblkno8.
 563 */
 564 cs->sc_cdata.cf_blocksize /= encblkno[i].d;
543 (void)memset(inbuf, 0, MAX_KEYSIZE); 565 (void)memset(inbuf, 0, MAX_KEYSIZE);
544 if (!cs->sc_cdata.cf_priv) { 566 if (!cs->sc_cdata.cf_priv) {
545 printf("cgd: unable to initialize cipher\n"); 567 printf("cgd: unable to initialize cipher\n");
546 ret = EINVAL; /* XXX is this the right error? */ 568 ret = EINVAL; /* XXX is this the right error? */
547 goto bail; 569 goto bail;
548 } 570 }
549 free(inbuf, M_TEMP); 571 free(inbuf, M_TEMP);
550 572
551 bufq_alloc(&cs->sc_dksc.sc_bufq, "fcfs", 0); 573 bufq_alloc(&cs->sc_dksc.sc_bufq, "fcfs", 0);
552 574
553 cs->sc_data = malloc(MAXPHYS, M_DEVBUF, M_WAITOK); 575 cs->sc_data = malloc(MAXPHYS, M_DEVBUF, M_WAITOK);
554 cs->sc_data_used = 0; 576 cs->sc_data_used = 0;
555 577

cvs diff -r1.11 -r1.12 src/sys/dev/cgdvar.h (expand / switch to unified diff)

--- src/sys/dev/cgdvar.h 2008/04/28 20:23:46 1.11
+++ src/sys/dev/cgdvar.h 2008/09/12 16:51:55 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cgdvar.h,v 1.11 2008/04/28 20:23:46 martin Exp $ */ 1/* $NetBSD: cgdvar.h,v 1.12 2008/09/12 16:51:55 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell. 8 * by Roland C. Dowdeswell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -49,27 +49,32 @@ struct cgd_ioctl { @@ -49,27 +49,32 @@ struct cgd_ioctl {
49 49
50#ifdef _KERNEL 50#ifdef _KERNEL
51 51
52#include <dev/cgd_crypto.h> 52#include <dev/cgd_crypto.h>
53 53
54/* This cryptdata structure is here rather than cgd_crypto.h, since 54/* This cryptdata structure is here rather than cgd_crypto.h, since
55 * it stores local state which will not be generalised beyond the 55 * it stores local state which will not be generalised beyond the
56 * cgd driver. 56 * cgd driver.
57 */ 57 */
58 58
59struct cryptdata { 59struct cryptdata {
60 size_t cf_blocksize; /* block size (in bytes) */ 60 size_t cf_blocksize; /* block size (in bytes) */
61 int cf_mode; /* Cipher Mode and IV Gen method */ 61 int cf_mode; /* Cipher Mode and IV Gen method */
62#define CGD_CIPHER_CBC_ENCBLKNO 1 /* CBC Mode w/ Enc Block Number */ 62#define CGD_CIPHER_CBC_ENCBLKNO8 1 /* CBC Mode w/ Enc Block Number
 63 * 8 passes (compat only)
 64 */
 65#define CGD_CIPHER_CBC_ENCBLKNO1 2 /* CBC Mode w/ Enc Block Number
 66 * 1 pass (default)
 67 */
63 void *cf_priv; /* enc alg private data */ 68 void *cf_priv; /* enc alg private data */
64}; 69};
65 70
66struct cgd_softc { 71struct cgd_softc {
67 struct dk_softc sc_dksc; /* generic disk interface */ 72 struct dk_softc sc_dksc; /* generic disk interface */
68 struct cryptinfo *sc_crypt; /* the alg/key/etc */ 73 struct cryptinfo *sc_crypt; /* the alg/key/etc */
69 struct vnode *sc_tvn; /* target device's vnode */ 74 struct vnode *sc_tvn; /* target device's vnode */
70 dev_t sc_tdev; /* target device */ 75 dev_t sc_tdev; /* target device */
71 char *sc_tpath; /* target device's path */ 76 char *sc_tpath; /* target device's path */
72 void * sc_data; /* emergency buffer */ 77 void * sc_data; /* emergency buffer */
73 int sc_data_used; /* Really lame, we'll change */ 78 int sc_data_used; /* Really lame, we'll change */
74 size_t sc_tpathlen; /* length of prior string */ 79 size_t sc_tpathlen; /* length of prior string */
75 struct cryptdata sc_cdata; /* crypto data */ 80 struct cryptdata sc_cdata; /* crypto data */