Deleted Added
full compact
g_bde.h (105464) g_bde.h (105512)
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 *
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 *
35 * $FreeBSD: head/sys/geom/bde/g_bde.h 105464 2002-10-19 17:02:17Z phk $
35 * $FreeBSD: head/sys/geom/bde/g_bde.h 105512 2002-10-20 11:09:58Z phk $
36 */
37
38/* These are quite, but not entirely unlike constants. */
39#define G_BDE_MKEYLEN (2048/8)
40#define G_BDE_SKEYBITS 128
41#define G_BDE_SKEYLEN (G_BDE_SKEYBITS/8)
42#define G_BDE_KKEYBITS 128
43#define G_BDE_KKEYLEN (G_BDE_KKEYBITS/8)
44#define G_BDE_MAXKEYS 4
45#define G_BDE_LOCKSIZE 384
46
47/* This just needs to be "large enough" */
48#define G_BDE_KEYBYTES 304
49
50struct g_bde_work;
51struct g_bde_softc;
52
53struct g_bde_sector {
54 struct g_bde_work *owner;
55 struct g_bde_softc *softc;
56 off_t offset;
57 u_int size;
58 u_int ref;
59 void *data;
60 TAILQ_ENTRY(g_bde_sector) list;
61 u_char valid;
62 u_char malloc;
63 enum {JUNK, IO, VALID} state;
64 int error;
65};
66
67struct g_bde_work {
68 struct mtx mutex;
69 off_t offset;
70 off_t length;
71 void *data;
72 struct bio *bp;
73 struct g_bde_softc *softc;
74 off_t so;
75 off_t kso;
76 u_int ko;
77 struct g_bde_sector *sp;
78 struct g_bde_sector *ksp;
79 TAILQ_ENTRY(g_bde_work) list;
80 enum {SETUP, WAIT, FINISH} state;
81 int error;
82};
83
84struct g_bde_key {
85 uint64_t sector0;
86 /* Physical byte offset of first byte used */
87 uint64_t sectorN;
88 /* Physical byte offset of first byte not used */
89 uint64_t keyoffset;
90 uint64_t lsector[G_BDE_MAXKEYS];
91 /* Physical offsets */
92 uint32_t sectorsize;
93 uint32_t flags;
36 */
37
38/* These are quite, but not entirely unlike constants. */
39#define G_BDE_MKEYLEN (2048/8)
40#define G_BDE_SKEYBITS 128
41#define G_BDE_SKEYLEN (G_BDE_SKEYBITS/8)
42#define G_BDE_KKEYBITS 128
43#define G_BDE_KKEYLEN (G_BDE_KKEYBITS/8)
44#define G_BDE_MAXKEYS 4
45#define G_BDE_LOCKSIZE 384
46
47/* This just needs to be "large enough" */
48#define G_BDE_KEYBYTES 304
49
50struct g_bde_work;
51struct g_bde_softc;
52
53struct g_bde_sector {
54 struct g_bde_work *owner;
55 struct g_bde_softc *softc;
56 off_t offset;
57 u_int size;
58 u_int ref;
59 void *data;
60 TAILQ_ENTRY(g_bde_sector) list;
61 u_char valid;
62 u_char malloc;
63 enum {JUNK, IO, VALID} state;
64 int error;
65};
66
67struct g_bde_work {
68 struct mtx mutex;
69 off_t offset;
70 off_t length;
71 void *data;
72 struct bio *bp;
73 struct g_bde_softc *softc;
74 off_t so;
75 off_t kso;
76 u_int ko;
77 struct g_bde_sector *sp;
78 struct g_bde_sector *ksp;
79 TAILQ_ENTRY(g_bde_work) list;
80 enum {SETUP, WAIT, FINISH} state;
81 int error;
82};
83
84struct g_bde_key {
85 uint64_t sector0;
86 /* Physical byte offset of first byte used */
87 uint64_t sectorN;
88 /* Physical byte offset of first byte not used */
89 uint64_t keyoffset;
90 uint64_t lsector[G_BDE_MAXKEYS];
91 /* Physical offsets */
92 uint32_t sectorsize;
93 uint32_t flags;
94 /* 1 = lockfile in sector 0 */
94 uint8_t hash[16];
95 uint8_t spare[48];
96 uint8_t key[G_BDE_MKEYLEN];
97 /* Non-stored help-fields */
98 uint64_t zone_width; /* On-disk width of zone */
99 uint64_t zone_cont; /* Payload width of zone */
100 uint64_t media_width; /* Non-magic width of zone */
101 u_int keys_per_sector;
102};
103
104struct g_bde_softc {
105 off_t mediasize;
106 u_int sectorsize;
107 uint64_t zone_cont;
108 struct g_geom *geom;
109 struct g_consumer *consumer;
110 TAILQ_HEAD(, g_bde_sector) freelist;
111 TAILQ_HEAD(, g_bde_work) worklist;
112 struct mtx worklist_mutex;
113 struct proc *thread;
114 struct g_bde_key key;
115 u_char arc4_sbox[256];
116 u_char arc4_i, arc4_j;
117 int dead;
118 u_int nwork;
119 u_int nsect;
120 u_int ncache;
121};
122
123/* g_bde_crypt.c */
124void g_bde_crypt_delete(struct g_bde_work *wp);
125void g_bde_crypt_read(struct g_bde_work *wp);
126void g_bde_crypt_write(struct g_bde_work *wp);
127
128/* g_bde_key.c */
129void g_bde_zap_key(struct g_bde_softc *sc);
130int g_bde_get_key(struct g_bde_softc *sc, void *ptr, int len);
131int g_bde_init_keybytes(struct g_bde_softc *sc, char *passp, int len);
132
133/* g_bde_lock .c */
134void g_bde_encode_lock(struct g_bde_key *gl, u_char *ptr);
135void g_bde_decode_lock(struct g_bde_key *gl, u_char *ptr);
136u_char g_bde_arc4(struct g_bde_softc *sc);
137void g_bde_arc4_seq(struct g_bde_softc *sc, void *ptr, u_int len);
95 uint8_t hash[16];
96 uint8_t spare[48];
97 uint8_t key[G_BDE_MKEYLEN];
98 /* Non-stored help-fields */
99 uint64_t zone_width; /* On-disk width of zone */
100 uint64_t zone_cont; /* Payload width of zone */
101 uint64_t media_width; /* Non-magic width of zone */
102 u_int keys_per_sector;
103};
104
105struct g_bde_softc {
106 off_t mediasize;
107 u_int sectorsize;
108 uint64_t zone_cont;
109 struct g_geom *geom;
110 struct g_consumer *consumer;
111 TAILQ_HEAD(, g_bde_sector) freelist;
112 TAILQ_HEAD(, g_bde_work) worklist;
113 struct mtx worklist_mutex;
114 struct proc *thread;
115 struct g_bde_key key;
116 u_char arc4_sbox[256];
117 u_char arc4_i, arc4_j;
118 int dead;
119 u_int nwork;
120 u_int nsect;
121 u_int ncache;
122};
123
124/* g_bde_crypt.c */
125void g_bde_crypt_delete(struct g_bde_work *wp);
126void g_bde_crypt_read(struct g_bde_work *wp);
127void g_bde_crypt_write(struct g_bde_work *wp);
128
129/* g_bde_key.c */
130void g_bde_zap_key(struct g_bde_softc *sc);
131int g_bde_get_key(struct g_bde_softc *sc, void *ptr, int len);
132int g_bde_init_keybytes(struct g_bde_softc *sc, char *passp, int len);
133
134/* g_bde_lock .c */
135void g_bde_encode_lock(struct g_bde_key *gl, u_char *ptr);
136void g_bde_decode_lock(struct g_bde_key *gl, u_char *ptr);
137u_char g_bde_arc4(struct g_bde_softc *sc);
138void g_bde_arc4_seq(struct g_bde_softc *sc, void *ptr, u_int len);
138void g_bde_arc4_seed(struct g_bde_softc *sc, void *ptr, u_int len);
139void g_bde_arc4_seed(struct g_bde_softc *sc, const void *ptr, u_int len);
139int g_bde_keyloc_encrypt(struct g_bde_softc *sc, void *input, void *output);
140int g_bde_keyloc_decrypt(struct g_bde_softc *sc, void *input, void *output);
141int g_bde_decrypt_lock(struct g_bde_softc *sc, u_char *sbox, u_char *meta, off_t mediasize, u_int sectorsize, u_int *nkey);
142
143/* g_bde_math .c */
144uint64_t g_bde_max_sector(struct g_bde_key *lp);
145void g_bde_map_sector(struct g_bde_key *lp, uint64_t isector, uint64_t *osector, uint64_t *ksector, u_int *koffset);
146
147/* g_bde_work.c */
148void g_bde_start1(struct bio *bp);
149void g_bde_worker(void *arg);
150
140int g_bde_keyloc_encrypt(struct g_bde_softc *sc, void *input, void *output);
141int g_bde_keyloc_decrypt(struct g_bde_softc *sc, void *input, void *output);
142int g_bde_decrypt_lock(struct g_bde_softc *sc, u_char *sbox, u_char *meta, off_t mediasize, u_int sectorsize, u_int *nkey);
143
144/* g_bde_math .c */
145uint64_t g_bde_max_sector(struct g_bde_key *lp);
146void g_bde_map_sector(struct g_bde_key *lp, uint64_t isector, uint64_t *osector, uint64_t *ksector, u_int *koffset);
147
148/* g_bde_work.c */
149void g_bde_start1(struct bio *bp);
150void g_bde_worker(void *arg);
151