Deleted Added
full compact
g_bde.c (105551) g_bde.c (106407)
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9 * DARPA CHATS research program.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9 * DARPA CHATS research program.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The names of the authors may not be used to endorse or promote
20 * products derived from this software without specific prior written
21 * permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
35 * $FreeBSD: head/sys/geom/bde/g_bde.c 105551 2002-10-20 20:28:24Z phk $
32 * $FreeBSD: head/sys/geom/bde/g_bde.c 106407 2002-11-04 09:27:01Z phk $
36 *
37 */
38
39#include <sys/param.h>
40#include <sys/stdint.h>
41#include <sys/bio.h>
42#include <sys/lock.h>
43#include <sys/mutex.h>
44#include <sys/malloc.h>
33 *
34 */
35
36#include <sys/param.h>
37#include <sys/stdint.h>
38#include <sys/bio.h>
39#include <sys/lock.h>
40#include <sys/mutex.h>
41#include <sys/malloc.h>
45#include <geom/geom.h>
46#include <geom/bde/g_bde.h>
47#include <sys/systm.h>
48#include <sys/kernel.h>
49#include <sys/kthread.h>
50
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/kthread.h>
45
46#include <crypto/rijndael/rijndael.h>
47#include <crypto/sha2/sha2.h>
48#include <geom/geom.h>
49#include <geom/bde/g_bde.h>
51#define BDE_CLASS_NAME "BDE"
52
53static void
54g_bde_start(struct bio *bp)
55{
56 struct g_geom *gp;
57 struct g_consumer *cp;
58 struct g_bde_softc *sc;

--- 112 unchanged lines hidden (view full) ---

171 wakeup(sc);
172 error = g_access_rel(cp, -1, -1, -1);
173 KASSERT(error == 0, ("error on close"));
174 g_detach(cp);
175 g_destroy_consumer(cp);
176 g_topology_unlock();
177 while (sc->dead != 2 && !LIST_EMPTY(&pp->consumers))
178 tsleep(sc, PRIBIO, "g_bdedie", hz);
50#define BDE_CLASS_NAME "BDE"
51
52static void
53g_bde_start(struct bio *bp)
54{
55 struct g_geom *gp;
56 struct g_consumer *cp;
57 struct g_bde_softc *sc;

--- 112 unchanged lines hidden (view full) ---

170 wakeup(sc);
171 error = g_access_rel(cp, -1, -1, -1);
172 KASSERT(error == 0, ("error on close"));
173 g_detach(cp);
174 g_destroy_consumer(cp);
175 g_topology_unlock();
176 while (sc->dead != 2 && !LIST_EMPTY(&pp->consumers))
177 tsleep(sc, PRIBIO, "g_bdedie", hz);
178 g_waitidle();
179 g_topology_lock();
180 g_destroy_provider(pp);
181 mtx_destroy(&sc->worklist_mutex);
182 bzero(&sc->key, sizeof sc->key);
183 g_free(sc);
184 g_destroy_geom(gp);
185 return (0);
186 }

--- 16 unchanged lines hidden (view full) ---

203 error = g_access_rel(cp, 1, 1, 1);
204 if (error) {
205 g_detach(cp);
206 g_destroy_consumer(cp);
207 g_destroy_geom(gp);
208 return (error);
209 }
210 g_topology_unlock();
179 g_topology_lock();
180 g_destroy_provider(pp);
181 mtx_destroy(&sc->worklist_mutex);
182 bzero(&sc->key, sizeof sc->key);
183 g_free(sc);
184 g_destroy_geom(gp);
185 return (0);
186 }

--- 16 unchanged lines hidden (view full) ---

203 error = g_access_rel(cp, 1, 1, 1);
204 if (error) {
205 g_detach(cp);
206 g_destroy_consumer(cp);
207 g_destroy_geom(gp);
208 return (error);
209 }
210 g_topology_unlock();
211 g_waitidle();
211 while (1) {
212 sectorsize = cp->provider->sectorsize;
213 mediasize = cp->provider->mediasize;
214 sc = g_malloc(sizeof(struct g_bde_softc), M_WAITOK | M_ZERO);
215 gp->softc = sc;
216 sc->geom = gp;
217 sc->consumer = cp;
218
219 error = g_bde_decrypt_lock(sc, ga->ptr,
212 while (1) {
213 sectorsize = cp->provider->sectorsize;
214 mediasize = cp->provider->mediasize;
215 sc = g_malloc(sizeof(struct g_bde_softc), M_WAITOK | M_ZERO);
216 gp->softc = sc;
217 sc->geom = gp;
218 sc->consumer = cp;
219
220 error = g_bde_decrypt_lock(sc, ga->ptr,
220 (u_char *)ga->ptr + 256, mediasize, sectorsize, NULL);
221 bzero(sc->arc4_sbox, sizeof sc->arc4_sbox);
221 (u_char *)ga->ptr + (sizeof sc->sha2),
222 mediasize, sectorsize, NULL);
223 bzero(sc->sha2, sizeof sc->sha2);
222 if (error)
223 break;
224 kp = &sc->key;
225
226 /* Initialize helper-fields */
227 kp->keys_per_sector = kp->sectorsize / G_BDE_SKEYLEN;
228 kp->zone_cont = kp->keys_per_sector * kp->sectorsize;
229 kp->zone_width = kp->zone_cont + kp->sectorsize;

--- 47 unchanged lines hidden ---
224 if (error)
225 break;
226 kp = &sc->key;
227
228 /* Initialize helper-fields */
229 kp->keys_per_sector = kp->sectorsize / G_BDE_SKEYLEN;
230 kp->zone_cont = kp->keys_per_sector * kp->sectorsize;
231 kp->zone_width = kp->zone_cont + kp->sectorsize;

--- 47 unchanged lines hidden ---