Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/eli/g_eli_integrity.c
Show First 20 Lines • Show All 443 Lines • ▼ Show 20 Lines | |||||
* 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 | * 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 | ||||
* BIO_WRITE: | * BIO_WRITE: | ||||
* g_eli_start -> G_ELI_AUTH_RUN -> g_eli_auth_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver | * g_eli_start -> G_ELI_AUTH_RUN -> g_eli_auth_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver | ||||
*/ | */ | ||||
void | void | ||||
g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp) | g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp) | ||||
{ | { | ||||
struct g_eli_softc *sc; | struct g_eli_softc *sc; | ||||
struct cryptopq crpq; | |||||
struct cryptop *crp; | struct cryptop *crp; | ||||
u_int i, lsec, nsec, data_secsize, decr_secsize, encr_secsize; | u_int i, lsec, nsec, data_secsize, decr_secsize, encr_secsize; | ||||
off_t dstoff; | off_t dstoff; | ||||
u_char *p, *data, *authkey, *plaindata; | u_char *p, *data, *authkey, *plaindata; | ||||
int error; | int error; | ||||
bool batch; | |||||
G_ELI_LOGREQ(3, bp, "%s", __func__); | G_ELI_LOGREQ(3, bp, "%s", __func__); | ||||
bp->bio_pflags = wr->w_number; | bp->bio_pflags = wr->w_number; | ||||
sc = wr->w_softc; | sc = wr->w_softc; | ||||
/* Sectorsize of decrypted provider eg. 4096. */ | /* Sectorsize of decrypted provider eg. 4096. */ | ||||
decr_secsize = bp->bio_to->sectorsize; | decr_secsize = bp->bio_to->sectorsize; | ||||
/* The real sectorsize of encrypted provider, eg. 512. */ | /* The real sectorsize of encrypted provider, eg. 512. */ | ||||
Show All 26 Lines | g_eli_auth_run(struct g_eli_worker *wr, struct bio *bp) | ||||
} | } | ||||
bp->bio_inbed = 0; | bp->bio_inbed = 0; | ||||
bp->bio_children = nsec; | bp->bio_children = nsec; | ||||
#if defined(__mips_n64) || defined(__mips_o64) | #if defined(__mips_n64) || defined(__mips_o64) | ||||
p = (char *)roundup((uintptr_t)p, sizeof(uintptr_t)); | p = (char *)roundup((uintptr_t)p, sizeof(uintptr_t)); | ||||
#endif | #endif | ||||
TAILQ_INIT(&crpq); | |||||
batch = atomic_load_int(&g_eli_batch) != 0; | |||||
for (i = 1; i <= nsec; i++, dstoff += encr_secsize) { | for (i = 1; i <= nsec; i++, dstoff += encr_secsize) { | ||||
crp = crypto_getreq(wr->w_sid, M_WAITOK); | crp = crypto_getreq(wr->w_sid, M_WAITOK); | ||||
authkey = (u_char *)p; p += G_ELI_AUTH_SECKEYLEN; | authkey = (u_char *)p; p += G_ELI_AUTH_SECKEYLEN; | ||||
data_secsize = sc->sc_data_per_sector; | data_secsize = sc->sc_data_per_sector; | ||||
if ((i % lsec) == 0) { | if ((i % lsec) == 0) { | ||||
data_secsize = decr_secsize % data_secsize; | data_secsize = decr_secsize % data_secsize; | ||||
/* | /* | ||||
Show All 9 Lines | if (bp->bio_cmd == BIO_WRITE) { | ||||
bcopy(plaindata, data + sc->sc_alen, data_secsize); | bcopy(plaindata, data + sc->sc_alen, data_secsize); | ||||
plaindata += data_secsize; | plaindata += data_secsize; | ||||
} | } | ||||
crypto_use_buf(crp, data, sc->sc_alen + data_secsize); | crypto_use_buf(crp, data, sc->sc_alen + data_secsize); | ||||
crp->crp_opaque = (void *)bp; | crp->crp_opaque = (void *)bp; | ||||
data += encr_secsize; | data += encr_secsize; | ||||
crp->crp_flags = CRYPTO_F_CBIFSYNC; | crp->crp_flags = CRYPTO_F_CBIFSYNC; | ||||
if (g_eli_batch) | |||||
crp->crp_flags |= CRYPTO_F_BATCH; | |||||
if (bp->bio_cmd == BIO_WRITE) { | if (bp->bio_cmd == BIO_WRITE) { | ||||
crp->crp_callback = g_eli_auth_write_done; | crp->crp_callback = g_eli_auth_write_done; | ||||
crp->crp_op = CRYPTO_OP_ENCRYPT | | crp->crp_op = CRYPTO_OP_ENCRYPT | | ||||
CRYPTO_OP_COMPUTE_DIGEST; | CRYPTO_OP_COMPUTE_DIGEST; | ||||
} else { | } else { | ||||
crp->crp_callback = g_eli_auth_read_done; | crp->crp_callback = g_eli_auth_read_done; | ||||
crp->crp_op = CRYPTO_OP_DECRYPT | | crp->crp_op = CRYPTO_OP_DECRYPT | | ||||
CRYPTO_OP_VERIFY_DIGEST; | CRYPTO_OP_VERIFY_DIGEST; | ||||
Show All 10 Lines | if (g_eli_ivlen(sc->sc_ealgo) != 0) { | ||||
crp->crp_flags |= CRYPTO_F_IV_SEPARATE; | crp->crp_flags |= CRYPTO_F_IV_SEPARATE; | ||||
g_eli_crypto_ivgen(sc, dstoff, crp->crp_iv, | g_eli_crypto_ivgen(sc, dstoff, crp->crp_iv, | ||||
sizeof(crp->crp_iv)); | sizeof(crp->crp_iv)); | ||||
} | } | ||||
g_eli_auth_keygen(sc, dstoff, authkey); | g_eli_auth_keygen(sc, dstoff, authkey); | ||||
crp->crp_auth_key = authkey; | crp->crp_auth_key = authkey; | ||||
if (batch) { | |||||
TAILQ_INSERT_TAIL(&crpq, crp, crp_next); | |||||
} else { | |||||
error = crypto_dispatch(crp); | error = crypto_dispatch(crp); | ||||
KASSERT(error == 0, ("crypto_dispatch() failed (error=%d)", | KASSERT(error == 0, | ||||
error)); | ("crypto_dispatch() failed (error=%d)", error)); | ||||
} | } | ||||
} | |||||
if (batch) | |||||
crypto_dispatch_batch(&crpq, 0); | |||||
} | } |