Lines Matching +full:512 +full:- +full:bytes
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2005-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
58 * 512 bytes and a power of two number.
60 * Let's store HMAC in sector. This is a must. This leaves us 480 bytes for
61 * data. We can't use that directly (ie. we can't create provider with 480 bytes
62 * sector size). We need another sector from where we take only 32 bytes of data
66 * Now, let's assume, we want to create provider with 4096 bytes sector.
67 * To output 4096 bytes of authenticated data we need 8x480 plus 1x256, so we
68 * need nine 512-bytes sectors at the input to get one 4096-bytes sector at the
69 * output. That's better. With 4096 bytes sector we can use 89% of size of the
77 …* da0: +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+-…
80 …* +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+-…
81 …* |512 bytes| |512 bytes| |512 bytes| |512 bytes| |512 bytes| |512 bytes| |512 bytes| |512 by…
82 …* +---------+ +---------+ +---------+ +---------+ +---------+ +---------+ +---------+ +------…
83 … +----------+
84 * da0.eli: +----+----+----+----+----+----+----+----+----+
86 * +----+----+----+----+----+----+----+----+----+
87 * | 4096 bytes |
88 * +--------------------------------------------+
98 …* g_eli_start -> g_eli_auth_read -> g_io_request -> g_eli_read_done -> g_eli_auth_run -> g_eli_aut…
100 …* g_eli_start -> g_eli_auth_run -> g_eli_auth_write_done -> g_io_request -> g_eli_write_done -> g_…
107 * IV doesn't change HMAC, when we use encrypt-then-authenticate method.
115 bcopy(&sc->sc_akeyctx, &ctx, sizeof(ctx)); in g_eli_auth_keygen()
123 …* g_eli_start -> g_eli_auth_read -> g_io_request -> g_eli_read_done -> g_eli_auth_run -> G_ELI_AUT…
131 if (crp->crp_etype == EAGAIN) { in g_eli_auth_read_done()
135 bp = (struct bio *)crp->crp_opaque; in g_eli_auth_read_done()
136 bp->bio_inbed++; in g_eli_auth_read_done()
137 sc = bp->bio_to->geom->softc; in g_eli_auth_read_done()
138 if (crp->crp_etype == 0) { in g_eli_auth_read_done()
139 bp->bio_completed += crp->crp_payload_length; in g_eli_auth_read_done()
141 bp->bio_inbed, bp->bio_children, crp->crp_payload_length, (intmax_t)bp->bio_completed); in g_eli_auth_read_done()
147 decr_secsize = bp->bio_to->sectorsize; in g_eli_auth_read_done()
148 /* The real sectorsize of encrypted provider, eg. 512. */ in g_eli_auth_read_done()
150 LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize; in g_eli_auth_read_done()
152 nsec = bp->bio_length / decr_secsize; in g_eli_auth_read_done()
154 nsec = (nsec * sc->sc_bytes_per_sector) / encr_secsize; in g_eli_auth_read_done()
156 rel_sec = ((crp->crp_buf.cb_buf + crp->crp_payload_start) - in g_eli_auth_read_done()
157 (char *)bp->bio_driver2) / encr_secsize; in g_eli_auth_read_done()
159 errorp = (int *)((char *)bp->bio_driver2 + encr_secsize * nsec + in g_eli_auth_read_done()
161 *errorp = crp->crp_etype; in g_eli_auth_read_done()
164 bp->bio_inbed, bp->bio_children, crp->crp_etype); in g_eli_auth_read_done()
165 if (bp->bio_error == 0 || bp->bio_error == EINTEGRITY) in g_eli_auth_read_done()
166 bp->bio_error = crp->crp_etype == EBADMSG ? in g_eli_auth_read_done()
167 EINTEGRITY : crp->crp_etype; in g_eli_auth_read_done()
169 if (crp->crp_cipher_key != NULL) in g_eli_auth_read_done()
170 g_eli_key_drop(sc, __DECONST(void *, crp->crp_cipher_key)); in g_eli_auth_read_done()
175 if (bp->bio_inbed < bp->bio_children) in g_eli_auth_read_done()
178 if (bp->bio_error == 0) { in g_eli_auth_read_done()
183 decr_secsize = bp->bio_to->sectorsize; in g_eli_auth_read_done()
184 /* The real sectorsize of encrypted provider, eg. 512. */ in g_eli_auth_read_done()
185 encr_secsize = LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize; in g_eli_auth_read_done()
186 /* Number of data bytes in one encrypted sector, eg. 480. */ in g_eli_auth_read_done()
187 data_secsize = sc->sc_data_per_sector; in g_eli_auth_read_done()
189 nsec = bp->bio_length / decr_secsize; in g_eli_auth_read_done()
191 nsec = (nsec * sc->sc_bytes_per_sector) / encr_secsize; in g_eli_auth_read_done()
193 lsec = sc->sc_bytes_per_sector / encr_secsize; in g_eli_auth_read_done()
195 srcdata = bp->bio_driver2; in g_eli_auth_read_done()
196 dstdata = bp->bio_data; in g_eli_auth_read_done()
199 data_secsize = sc->sc_data_per_sector; in g_eli_auth_read_done()
202 bcopy(srcdata + sc->sc_alen, dstdata, data_secsize); in g_eli_auth_read_done()
206 } else if (bp->bio_error == EINTEGRITY) { in g_eli_auth_read_done()
212 decr_secsize = bp->bio_to->sectorsize; in g_eli_auth_read_done()
213 /* The real sectorsize of encrypted provider, eg. 512. */ in g_eli_auth_read_done()
214 encr_secsize = LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize; in g_eli_auth_read_done()
215 /* Number of data bytes in one encrypted sector, eg. 480. */ in g_eli_auth_read_done()
216 data_secsize = sc->sc_data_per_sector; in g_eli_auth_read_done()
218 nsec = bp->bio_length / decr_secsize; in g_eli_auth_read_done()
220 nsec = (nsec * sc->sc_bytes_per_sector) / encr_secsize; in g_eli_auth_read_done()
222 lsec = sc->sc_bytes_per_sector / encr_secsize; in g_eli_auth_read_done()
224 errorp = (int *)((char *)bp->bio_driver2 + encr_secsize * nsec); in g_eli_auth_read_done()
225 coroff = -1; in g_eli_auth_read_done()
227 dstoff = bp->bio_offset; in g_eli_auth_read_done()
230 data_secsize = sc->sc_data_per_sector; in g_eli_auth_read_done()
233 if (errorp[i - 1] == EBADMSG) { in g_eli_auth_read_done()
239 if (coroff == -1) in g_eli_auth_read_done()
247 if (coroff != -1) { in g_eli_auth_read_done()
249 "bytes of data at offset %jd.", in g_eli_auth_read_done()
250 sc->sc_name, (intmax_t)corsize, in g_eli_auth_read_done()
252 coroff = -1; in g_eli_auth_read_done()
259 if (coroff != -1) { in g_eli_auth_read_done()
261 "bytes of data at offset %jd.", in g_eli_auth_read_done()
262 sc->sc_name, (intmax_t)corsize, (intmax_t)coroff); in g_eli_auth_read_done()
266 if (bp->bio_error != 0) { in g_eli_auth_read_done()
267 if (bp->bio_error != EINTEGRITY) { in g_eli_auth_read_done()
270 bp->bio_error); in g_eli_auth_read_done()
272 bp->bio_completed = 0; in g_eli_auth_read_done()
277 g_io_deliver(bp, bp->bio_error); in g_eli_auth_read_done()
278 atomic_subtract_int(&sc->sc_inflight, 1); in g_eli_auth_read_done()
285 …* g_eli_start -> g_eli_auth_run -> G_ELI_AUTH_WRITE_DONE -> g_io_request -> g_eli_write_done -> g_…
295 if (crp->crp_etype == EAGAIN) { in g_eli_auth_write_done()
299 bp = (struct bio *)crp->crp_opaque; in g_eli_auth_write_done()
300 bp->bio_inbed++; in g_eli_auth_write_done()
301 if (crp->crp_etype == 0) { in g_eli_auth_write_done()
303 bp->bio_inbed, bp->bio_children); in g_eli_auth_write_done()
306 bp->bio_inbed, bp->bio_children, crp->crp_etype); in g_eli_auth_write_done()
307 if (bp->bio_error == 0) in g_eli_auth_write_done()
308 bp->bio_error = crp->crp_etype; in g_eli_auth_write_done()
310 sc = bp->bio_to->geom->softc; in g_eli_auth_write_done()
311 if (crp->crp_cipher_key != NULL) in g_eli_auth_write_done()
312 g_eli_key_drop(sc, __DECONST(void *, crp->crp_cipher_key)); in g_eli_auth_write_done()
317 if (bp->bio_inbed < bp->bio_children) in g_eli_auth_write_done()
319 if (bp->bio_error != 0) { in g_eli_auth_write_done()
321 bp->bio_error); in g_eli_auth_write_done()
323 cbp = bp->bio_driver1; in g_eli_auth_write_done()
324 bp->bio_driver1 = NULL; in g_eli_auth_write_done()
326 g_io_deliver(bp, bp->bio_error); in g_eli_auth_write_done()
327 atomic_subtract_int(&sc->sc_inflight, 1); in g_eli_auth_write_done()
330 cp = LIST_FIRST(&sc->sc_geom->consumer); in g_eli_auth_write_done()
331 cbp = bp->bio_driver1; in g_eli_auth_write_done()
332 bp->bio_driver1 = NULL; in g_eli_auth_write_done()
333 cbp->bio_to = cp->provider; in g_eli_auth_write_done()
334 cbp->bio_done = g_eli_write_done; in g_eli_auth_write_done()
337 nsec = bp->bio_length / bp->bio_to->sectorsize; in g_eli_auth_write_done()
339 nsec = (nsec * sc->sc_bytes_per_sector) / cp->provider->sectorsize; in g_eli_auth_write_done()
341 cbp->bio_length = cp->provider->sectorsize * nsec; in g_eli_auth_write_done()
342 cbp->bio_offset = (bp->bio_offset / bp->bio_to->sectorsize) * sc->sc_bytes_per_sector; in g_eli_auth_write_done()
343 cbp->bio_data = bp->bio_driver2; in g_eli_auth_write_done()
350 if (cbp->bio_length > maxphys) { in g_eli_auth_write_done()
352 cbp2->bio_length = cbp->bio_length - maxphys; in g_eli_auth_write_done()
353 cbp2->bio_data = cbp->bio_data + maxphys; in g_eli_auth_write_done()
354 cbp2->bio_offset = cbp->bio_offset + maxphys; in g_eli_auth_write_done()
355 cbp2->bio_to = cp->provider; in g_eli_auth_write_done()
356 cbp2->bio_done = g_eli_write_done; in g_eli_auth_write_done()
357 cbp->bio_length = maxphys; in g_eli_auth_write_done()
363 bp->bio_inbed = 0; in g_eli_auth_write_done()
364 bp->bio_children = (cbp2 != NULL ? 2 : 1); in g_eli_auth_write_done()
381 G_ELI_SETWORKER(bp->bio_pflags, 0); in g_eli_auth_read()
383 cp = LIST_FIRST(&sc->sc_geom->consumer); in g_eli_auth_read()
384 cbp = bp->bio_driver1; in g_eli_auth_read()
385 bp->bio_driver1 = NULL; in g_eli_auth_read()
386 cbp->bio_to = cp->provider; in g_eli_auth_read()
387 cbp->bio_done = g_eli_read_done; in g_eli_auth_read()
390 nsec = bp->bio_length / bp->bio_to->sectorsize; in g_eli_auth_read()
392 nsec = (nsec * sc->sc_bytes_per_sector) / cp->provider->sectorsize; in g_eli_auth_read()
394 cbp->bio_length = cp->provider->sectorsize * nsec; in g_eli_auth_read()
395 size = cbp->bio_length; in g_eli_auth_read()
398 cbp->bio_offset = (bp->bio_offset / bp->bio_to->sectorsize) * sc->sc_bytes_per_sector; in g_eli_auth_read()
402 bp->bio_error = ENOMEM; in g_eli_auth_read()
403 g_io_deliver(bp, bp->bio_error); in g_eli_auth_read()
404 atomic_subtract_int(&sc->sc_inflight, 1); in g_eli_auth_read()
407 cbp->bio_data = bp->bio_driver2; in g_eli_auth_read()
410 memset((char *)bp->bio_driver2 + cbp->bio_length, 0, in g_eli_auth_read()
418 if (cbp->bio_length > maxphys) { in g_eli_auth_read()
420 cbp2->bio_length = cbp->bio_length - maxphys; in g_eli_auth_read()
421 cbp2->bio_data = cbp->bio_data + maxphys; in g_eli_auth_read()
422 cbp2->bio_offset = cbp->bio_offset + maxphys; in g_eli_auth_read()
423 cbp2->bio_to = cp->provider; in g_eli_auth_read()
424 cbp2->bio_done = g_eli_read_done; in g_eli_auth_read()
425 cbp->bio_length = maxphys; in g_eli_auth_read()
443 …* g_eli_start -> g_eli_auth_read -> g_io_request -> g_eli_read_done -> G_ELI_AUTH_RUN -> g_eli_aut…
445 …* g_eli_start -> G_ELI_AUTH_RUN -> g_eli_auth_write_done -> g_io_request -> g_eli_write_done -> g_…
461 G_ELI_SETWORKER(bp->bio_pflags, wr->w_number); in g_eli_auth_run()
462 sc = wr->w_softc; in g_eli_auth_run()
464 decr_secsize = bp->bio_to->sectorsize; in g_eli_auth_run()
465 /* The real sectorsize of encrypted provider, eg. 512. */ in g_eli_auth_run()
466 encr_secsize = LIST_FIRST(&sc->sc_geom->consumer)->provider->sectorsize; in g_eli_auth_run()
467 /* Number of data bytes in one encrypted sector, eg. 480. */ in g_eli_auth_run()
468 data_secsize = sc->sc_data_per_sector; in g_eli_auth_run()
470 nsec = bp->bio_length / decr_secsize; in g_eli_auth_run()
472 nsec = (nsec * sc->sc_bytes_per_sector) / encr_secsize; in g_eli_auth_run()
474 lsec = sc->sc_bytes_per_sector / encr_secsize; in g_eli_auth_run()
476 dstoff = (bp->bio_offset / bp->bio_to->sectorsize) * sc->sc_bytes_per_sector; in g_eli_auth_run()
478 plaindata = bp->bio_data; in g_eli_auth_run()
479 if (bp->bio_cmd == BIO_READ) { in g_eli_auth_run()
480 data = bp->bio_driver2; in g_eli_auth_run()
491 if (bp->bio_driver1 != NULL) { in g_eli_auth_run()
492 g_destroy_bio(bp->bio_driver1); in g_eli_auth_run()
493 bp->bio_driver1 = NULL; in g_eli_auth_run()
495 bp->bio_error = ENOMEM; in g_eli_auth_run()
496 g_io_deliver(bp, bp->bio_error); in g_eli_auth_run()
498 atomic_subtract_int(&sc->sc_inflight, 1); in g_eli_auth_run()
501 data = bp->bio_driver2; in g_eli_auth_run()
504 bp->bio_inbed = 0; in g_eli_auth_run()
505 bp->bio_children = nsec; in g_eli_auth_run()
515 crp = crypto_getreq(wr->w_sid, M_WAITOK); in g_eli_auth_run()
518 data_secsize = sc->sc_data_per_sector; in g_eli_auth_run()
525 if (bp->bio_cmd == BIO_WRITE) in g_eli_auth_run()
526 memset(data + sc->sc_alen + data_secsize, 0, in g_eli_auth_run()
527 encr_secsize - sc->sc_alen - data_secsize); in g_eli_auth_run()
528 } else if (data_secsize + sc->sc_alen != encr_secsize) { in g_eli_auth_run()
531 * per-sector data size is rounded down to ensure that in g_eli_auth_run()
534 * bytes. in g_eli_auth_run()
536 if (bp->bio_cmd == BIO_WRITE) in g_eli_auth_run()
537 memset(data + sc->sc_alen + data_secsize, 0, in g_eli_auth_run()
538 encr_secsize - sc->sc_alen - data_secsize); in g_eli_auth_run()
541 if (bp->bio_cmd == BIO_WRITE) { in g_eli_auth_run()
542 bcopy(plaindata, data + sc->sc_alen, data_secsize); in g_eli_auth_run()
546 crypto_use_buf(crp, data, sc->sc_alen + data_secsize); in g_eli_auth_run()
547 crp->crp_opaque = (void *)bp; in g_eli_auth_run()
549 crp->crp_flags = CRYPTO_F_CBIFSYNC; in g_eli_auth_run()
550 if (bp->bio_cmd == BIO_WRITE) { in g_eli_auth_run()
551 crp->crp_callback = g_eli_auth_write_done; in g_eli_auth_run()
552 crp->crp_op = CRYPTO_OP_ENCRYPT | in g_eli_auth_run()
555 crp->crp_callback = g_eli_auth_read_done; in g_eli_auth_run()
556 crp->crp_op = CRYPTO_OP_DECRYPT | in g_eli_auth_run()
560 crp->crp_digest_start = 0; in g_eli_auth_run()
561 crp->crp_payload_start = sc->sc_alen; in g_eli_auth_run()
562 crp->crp_payload_length = data_secsize; in g_eli_auth_run()
563 if ((sc->sc_flags & G_ELI_FLAG_FIRST_KEY) == 0) { in g_eli_auth_run()
564 crp->crp_cipher_key = g_eli_key_hold(sc, dstoff, in g_eli_auth_run()
567 if (g_eli_ivlen(sc->sc_ealgo) != 0) { in g_eli_auth_run()
568 crp->crp_flags |= CRYPTO_F_IV_SEPARATE; in g_eli_auth_run()
569 g_eli_crypto_ivgen(sc, dstoff, crp->crp_iv, in g_eli_auth_run()
570 sizeof(crp->crp_iv)); in g_eli_auth_run()
574 crp->crp_auth_key = authkey; in g_eli_auth_run()