mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
Rename g_bde_get_sector() to g_bde_get_keysector() and pick up the
offset from the work packet.
This commit is contained in:
parent
11ca41a9bb
commit
306babd20c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=114153
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user