PR/39525: Joachim Schueth, Frederik Sausmikat: cgd inadvertently encrypts blkno eight times to generate IVdiff -r1.27 -r1.28 src/sbin/cgdconfig/cgdconfig.8
(christos)
--- 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: | |||
87 | Configure all the devices listed in the cgd configuration file. | 87 | Configure all the devices listed in the cgd configuration file. | |
88 | .It Fl f Ar configfile | 88 | .It Fl f Ar configfile | |
89 | Specify the configuration file explicitly, rather than using the default | 89 | Specify the configuration file explicitly, rather than using the default | |
90 | configuration file | 90 | configuration file | |
91 | .Pa /etc/cgd/cgd.conf . | 91 | .Pa /etc/cgd/cgd.conf . | |
92 | .It Fl G | 92 | .It Fl G | |
93 | Generate a new paramsfile (to stdout) using the values from | 93 | Generate a new paramsfile (to stdout) using the values from | |
94 | .Ar paramsfile | 94 | .Ar paramsfile | |
95 | which will generate the same key. | 95 | which will generate the same key. | |
96 | This may need to prompt for multiple passphrases. | 96 | This may need to prompt for multiple passphrases. | |
97 | .It Fl g | 97 | .It Fl g | |
98 | Generate a paramsfile (to stdout). | 98 | Generate a paramsfile (to stdout). | |
99 | .It Fl i Ar ivmeth | 99 | .It Fl i Ar ivmeth | |
100 | Specify the IV method (default: encblkno). | 100 | Specify the IV method (default: encblkno1). | |
101 | .It Fl k Ar kgmeth | 101 | .It Fl k Ar kgmeth | |
102 | Specify the key generation method (default: pkcs5_pbkdf2/sha1). | 102 | Specify the key generation method (default: pkcs5_pbkdf2/sha1). | |
103 | .It Fl o Ar outfile | 103 | .It Fl o Ar outfile | |
104 | When generating a | 104 | When generating a | |
105 | .Ar paramsfile , | 105 | .Ar paramsfile , | |
106 | store it in | 106 | store it in | |
107 | .Ar outfile . | 107 | .Ar outfile . | |
108 | .It Fl p | 108 | .It Fl p | |
109 | Read all passphrases from stdin rather than | 109 | Read all passphrases from stdin rather than | |
110 | .Pa /dev/tty . | 110 | .Pa /dev/tty . | |
111 | Passphrases are separated by newlines. | 111 | Passphrases are separated by newlines. | |
112 | Users of this flag must be able to predict the order in which passphrases | 112 | Users of this flag must be able to predict the order in which passphrases | |
113 | are prompted. | 113 | are 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 | |||
306 | The salt. | 306 | The salt. | |
307 | Only used for pkcs5_pbkdf2/sha1 and pkcs5_pbkdf2. | 307 | Only 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/ | |
312 | configuration directory, used to store paramsfiles. | 312 | configuration directory, used to store paramsfiles. | |
313 | .It Pa /etc/cgd/cgd.conf | 313 | .It Pa /etc/cgd/cgd.conf | |
314 | cgd configuration file. | 314 | cgd configuration file. | |
315 | .El | 315 | .El | |
316 | .Sh EXAMPLES | 316 | .Sh EXAMPLES | |
317 | To set up and configure a cgd that uses AES with a 192 bit key | 317 | To set up and configure a cgd that uses AES with a 192 bit key | |
318 | in CBC mode with the IV Method | 318 | in 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 | |
327 | When using verification methods, the first time that we configure the | 327 | When using verification methods, the first time that we configure the | |
328 | disk the verification method will fail. | 328 | disk the verification method will fail. | |
329 | We overcome this by supplying | 329 | We overcome this by supplying | |
330 | .Fl V Ar re-enter | 330 | .Fl V Ar re-enter | |
331 | when we configure the first time to set up the disk. | 331 | when we configure the first time to set up the disk. | |
332 | Here is the | 332 | Here 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 | |
353 | To configure a cgd that uses Blowfish with a 200 bit key that it | 353 | To configure a cgd that uses Blowfish with a 200 bit key that it | |
354 | reads from stdin: | 354 | reads 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 | |
359 | An example parameters file which uses PKCS#5 PBKDF2: | 359 | An 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 | |
372 | An example parameters file which stores its key locally: | 372 | An 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 | |
382 | An example | 382 | An 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 | # |
--- 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 | |||
147 | int | 147 | int | |
148 | params_filldefaults(struct params *p) | 148 | params_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 | |||
178 | int | 178 | int | |
179 | params_verify(const struct params *p) | 179 | params_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 | |||
210 | struct params * | 221 | struct params * | |
211 | params_algorithm(string_t *in) | 222 | params_algorithm(string_t *in) | |
212 | { | 223 | { | |
213 | struct params *p = params_new(); | 224 | struct params *p = params_new(); | |
214 | 225 |
--- 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
--- 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 | |||
489 | static 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 */ | |
490 | static int | 500 | static int | |
491 | cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l) | 501 | cgd_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 |
--- 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 | |||
59 | struct cryptdata { | 59 | struct 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 | |||
66 | struct cgd_softc { | 71 | struct 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 */ |