diff options
author | phk <phk@FreeBSD.org> | 2003-04-28 06:38:31 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2003-04-28 06:38:31 +0000 |
commit | 1b6624b99947fc439495bb677aefb00a9b89872f (patch) | |
tree | 38bb00c7b7eb5b6fb68e5e36f14f20a69ce6d866 /sys/geom/bde | |
parent | 1adaf3d22c4a4b1e533a92a11802d2e7bd855616 (diff) | |
download | FreeBSD-src-1b6624b99947fc439495bb677aefb00a9b89872f.zip FreeBSD-src-1b6624b99947fc439495bb677aefb00a9b89872f.tar.gz |
Rename g_bde_get_sector() to g_bde_get_keysector() and pick up the
offset from the work packet.
Diffstat (limited to 'sys/geom/bde')
-rw-r--r-- | sys/geom/bde/g_bde_crypt.c | 35 | ||||
-rw-r--r-- | sys/geom/bde/g_bde_work.c | 12 |
2 files changed, 42 insertions, 5 deletions
diff --git a/sys/geom/bde/g_bde_crypt.c b/sys/geom/bde/g_bde_crypt.c index f4ffa12..d657fd4 100644 --- a/sys/geom/bde/g_bde_crypt.c +++ b/sys/geom/bde/g_bde_crypt.c @@ -53,6 +53,8 @@ #include <geom/bde/g_bde.h> +#define MD5_KEY + /* * Derive kkey from mkey + sector offset. * @@ -128,8 +130,30 @@ g_bde_crypt_read(struct g_bde_work *wp) g_bde_kkey(sc, &ki, DIR_DECRYPT, wp->offset + o); AES_decrypt(&ci, &ki, d, skey, sizeof skey); d = (u_char *)wp->data + o; +#ifdef MD5_KEY + { + MD5_CTX ct; + u_char rkey[16]; + int i; + + MD5Init(&ct); + MD5Update(&ct, d, sc->sectorsize); + MD5Final(rkey, &ct); + if (bcmp(rkey, skey, 16) != 0) { +#if 0 + printf("MD5_KEY failed at %jd (t=%d)\n", + (intmax_t)(wp->offset + o), time_second); +#endif + for (i = 0; i < sc->sectorsize; i++) + d[i] = 'A' + i % 26; + sprintf(d, "MD5_KEY failed at %jd (t=%d)", + (intmax_t)(wp->offset + o), time_second); + } + } +#else AES_makekey(&ki, DIR_DECRYPT, G_BDE_SKEYBITS, skey); AES_decrypt(&ci, &ki, d, d, sc->sectorsize); +#endif } bzero(skey, sizeof skey); bzero(&ci, sizeof ci); @@ -161,9 +185,20 @@ g_bde_crypt_write(struct g_bde_work *wp) s = (u_char *)wp->data + o; d = (u_char *)wp->sp->data + o; +#ifdef MD5_KEY + { + MD5_CTX ct; + + MD5Init(&ct); + MD5Update(&ct, s, sc->sectorsize); + MD5Final(skey, &ct); + bcopy(s, d, sc->sectorsize); + } +#else arc4rand(&skey, sizeof skey, 0); AES_makekey(&ki, DIR_ENCRYPT, G_BDE_SKEYBITS, skey); AES_encrypt(&ci, &ki, s, d, sc->sectorsize); +#endif d = (u_char *)wp->ksp->data + wp->ko + n * G_BDE_SKEYLEN; g_bde_kkey(sc, &ki, DIR_ENCRYPT, wp->offset + o); diff --git a/sys/geom/bde/g_bde_work.c b/sys/geom/bde/g_bde_work.c index da5b24b..c2fc237 100644 --- a/sys/geom/bde/g_bde_work.c +++ b/sys/geom/bde/g_bde_work.c @@ -77,7 +77,7 @@ static void g_bde_delete_sector(struct g_bde_softc *wp, struct g_bde_sector *sp); static struct g_bde_sector * g_bde_new_sector(struct g_bde_work *wp, u_int len); static void g_bde_release_keysector(struct g_bde_work *wp); -static struct g_bde_sector *g_bde_get_sector(struct g_bde_work *wp, off_t offset); +static struct g_bde_sector *g_bde_get_keysector(struct g_bde_work *wp); static int g_bde_start_read(struct g_bde_sector *sp); static void g_bde_purge_sector(struct g_bde_softc *sc, int fraction); @@ -195,12 +195,14 @@ g_bde_purge_one_sector(struct g_bde_softc *sc, struct g_bde_sector *sp) } static struct g_bde_sector * -g_bde_get_sector(struct g_bde_work *wp, off_t offset) +g_bde_get_keysector(struct g_bde_work *wp) { struct g_bde_sector *sp; struct g_bde_softc *sc; + off_t offset; - g_trace(G_T_TOPOLOGY, "g_bde_get_sector(%p, %jd)", wp, (intmax_t)offset); + offset = wp->kso; + g_trace(G_T_TOPOLOGY, "g_bde_get_keysector(%p, %jd)", wp, (intmax_t)offset); sc = wp->softc; if (malloc_last_fail() < g_bde_ncache) @@ -329,10 +331,10 @@ g_bde_read_keysector(struct g_bde_softc *sc, struct g_bde_work *wp) struct g_bde_sector *sp; g_trace(G_T_TOPOLOGY, "g_bde_read_keysector(%p)", wp); - sp = g_bde_get_sector(wp, wp->kso); + sp = g_bde_get_keysector(wp); if (sp == NULL) { g_bde_purge_sector(sc, -1); - sp = g_bde_get_sector(wp, wp->kso); + sp = g_bde_get_keysector(wp); } if (sp == NULL) return (sp); |