Deleted Added
full compact
g_eli_integrity.c (214116) g_eli_integrity.c (214118)
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_integrity.c 214116 2010-10-20 20:01:45Z pjd $");
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_integrity.c 214118 2010-10-20 20:50:55Z pjd $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

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

124/*
125 * The function is called after we read and decrypt data.
126 *
127 * g_eli_start -> g_eli_auth_read -> g_io_request -> g_eli_read_done -> g_eli_auth_run -> G_ELI_AUTH_READ_DONE -> g_io_deliver
128 */
129static int
130g_eli_auth_read_done(struct cryptop *crp)
131{
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

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

124/*
125 * The function is called after we read and decrypt data.
126 *
127 * g_eli_start -> g_eli_auth_read -> g_io_request -> g_eli_read_done -> g_eli_auth_run -> G_ELI_AUTH_READ_DONE -> g_io_deliver
128 */
129static int
130g_eli_auth_read_done(struct cryptop *crp)
131{
132 struct g_eli_softc *sc;
132 struct bio *bp;
133
134 if (crp->crp_etype == EAGAIN) {
135 if (g_eli_crypto_rerun(crp) == 0)
136 return (0);
137 }
138 bp = (struct bio *)crp->crp_opaque;
139 bp->bio_inbed++;

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

147 if (bp->bio_error == 0)
148 bp->bio_error = crp->crp_etype;
149 }
150 /*
151 * Do we have all sectors already?
152 */
153 if (bp->bio_inbed < bp->bio_children)
154 return (0);
133 struct bio *bp;
134
135 if (crp->crp_etype == EAGAIN) {
136 if (g_eli_crypto_rerun(crp) == 0)
137 return (0);
138 }
139 bp = (struct bio *)crp->crp_opaque;
140 bp->bio_inbed++;

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

148 if (bp->bio_error == 0)
149 bp->bio_error = crp->crp_etype;
150 }
151 /*
152 * Do we have all sectors already?
153 */
154 if (bp->bio_inbed < bp->bio_children)
155 return (0);
156 sc = bp->bio_to->geom->softc;
155 if (bp->bio_error == 0) {
157 if (bp->bio_error == 0) {
156 struct g_eli_softc *sc;
157 u_int i, lsec, nsec, data_secsize, decr_secsize, encr_secsize;
158 u_char *srcdata, *dstdata, *auth;
159 off_t coroff, corsize;
160
161 /*
162 * Verify data integrity based on calculated and read HMACs.
163 */
158 u_int i, lsec, nsec, data_secsize, decr_secsize, encr_secsize;
159 u_char *srcdata, *dstdata, *auth;
160 off_t coroff, corsize;
161
162 /*
163 * Verify data integrity based on calculated and read HMACs.
164 */
164 sc = bp->bio_to->geom->softc;
165 /* Sectorsize of decrypted provider eg. 4096. */
166 decr_secsize = bp->bio_to->sectorsize;
167 /* The real sectorsize of encrypted provider, eg. 512. */
168 encr_secsize = LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize;
169 /* Number of data bytes in one encrypted sector, eg. 480. */
170 data_secsize = sc->sc_data_per_sector;
171 /* Number of sectors from decrypted provider, eg. 2. */
172 nsec = bp->bio_length / decr_secsize;

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

235 bp->bio_error);
236 }
237 bp->bio_completed = 0;
238 }
239 /*
240 * Read is finished, send it up.
241 */
242 g_io_deliver(bp, bp->bio_error);
165 /* Sectorsize of decrypted provider eg. 4096. */
166 decr_secsize = bp->bio_to->sectorsize;
167 /* The real sectorsize of encrypted provider, eg. 512. */
168 encr_secsize = LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize;
169 /* Number of data bytes in one encrypted sector, eg. 480. */
170 data_secsize = sc->sc_data_per_sector;
171 /* Number of sectors from decrypted provider, eg. 2. */
172 nsec = bp->bio_length / decr_secsize;

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

235 bp->bio_error);
236 }
237 bp->bio_completed = 0;
238 }
239 /*
240 * Read is finished, send it up.
241 */
242 g_io_deliver(bp, bp->bio_error);
243 atomic_subtract_int(&sc->sc_inflight, 1);
243 return (0);
244}
245
246/*
247 * The function is called after data encryption.
248 *
249 * g_eli_start -> g_eli_auth_run -> G_ELI_AUTH_WRITE_DONE -> g_io_request -> g_eli_write_done -> g_io_deliver
250 */

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

271 if (bp->bio_error == 0)
272 bp->bio_error = crp->crp_etype;
273 }
274 /*
275 * All sectors are already encrypted?
276 */
277 if (bp->bio_inbed < bp->bio_children)
278 return (0);
244 return (0);
245}
246
247/*
248 * The function is called after data encryption.
249 *
250 * g_eli_start -> g_eli_auth_run -> G_ELI_AUTH_WRITE_DONE -> g_io_request -> g_eli_write_done -> g_io_deliver
251 */

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

272 if (bp->bio_error == 0)
273 bp->bio_error = crp->crp_etype;
274 }
275 /*
276 * All sectors are already encrypted?
277 */
278 if (bp->bio_inbed < bp->bio_children)
279 return (0);
280 sc = bp->bio_to->geom->softc;
279 if (bp->bio_error != 0) {
280 G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
281 bp->bio_error);
282 free(bp->bio_driver2, M_ELI);
283 bp->bio_driver2 = NULL;
284 cbp = bp->bio_driver1;
285 bp->bio_driver1 = NULL;
286 g_destroy_bio(cbp);
287 g_io_deliver(bp, bp->bio_error);
281 if (bp->bio_error != 0) {
282 G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
283 bp->bio_error);
284 free(bp->bio_driver2, M_ELI);
285 bp->bio_driver2 = NULL;
286 cbp = bp->bio_driver1;
287 bp->bio_driver1 = NULL;
288 g_destroy_bio(cbp);
289 g_io_deliver(bp, bp->bio_error);
290 atomic_subtract_int(&sc->sc_inflight, 1);
288 return (0);
289 }
291 return (0);
292 }
290 sc = bp->bio_to->geom->softc;
291 cp = LIST_FIRST(&sc->sc_geom->consumer);
292 cbp = bp->bio_driver1;
293 bp->bio_driver1 = NULL;
294 cbp->bio_to = cp->provider;
295 cbp->bio_done = g_eli_write_done;
296
297 /* Number of sectors from decrypted provider, eg. 1. */
298 nsec = bp->bio_length / bp->bio_to->sectorsize;

--- 240 unchanged lines hidden ---
293 cp = LIST_FIRST(&sc->sc_geom->consumer);
294 cbp = bp->bio_driver1;
295 bp->bio_driver1 = NULL;
296 cbp->bio_to = cp->provider;
297 cbp->bio_done = g_eli_write_done;
298
299 /* Number of sectors from decrypted provider, eg. 1. */
300 nsec = bp->bio_length / bp->bio_to->sectorsize;

--- 240 unchanged lines hidden ---