From b022d9547307fbceeac6ec2faa6ad85e69251dce Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 22 Oct 2010 22:13:11 +0000 Subject: Move sc_akeyctx and sc_ivctx initialization to the g_eli_mkey_propagate() function which eliminates code duplication and will ensure proper order of operation. --- sys/geom/eli/g_eli_key.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'sys/geom/eli/g_eli_key.c') diff --git a/sys/geom/eli/g_eli_key.c b/sys/geom/eli/g_eli_key.c index bb060e4..37b2ad3 100644 --- a/sys/geom/eli/g_eli_key.c +++ b/sys/geom/eli/g_eli_key.c @@ -264,5 +264,30 @@ g_eli_mkey_propagate(struct g_eli_softc *sc, const unsigned char *mkey) /* Generate all encryption keys. */ g_eli_ekeys_generate(sc); } + + if (sc->sc_flags & G_ELI_FLAG_AUTH) { + /* + * Precalculate SHA256 for HMAC key generation. + * This is expensive operation and we can do it only once now or + * for every access to sector, so now will be much better. + */ + SHA256_Init(&sc->sc_akeyctx); + SHA256_Update(&sc->sc_akeyctx, sc->sc_akey, + sizeof(sc->sc_akey)); + } + /* + * Precalculate SHA256 for IV generation. + * This is expensive operation and we can do it only once now or for + * every access to sector, so now will be much better. + */ + switch (sc->sc_ealgo) { + case CRYPTO_AES_XTS: + break; + default: + SHA256_Init(&sc->sc_ivctx); + SHA256_Update(&sc->sc_ivctx, sc->sc_ivkey, + sizeof(sc->sc_ivkey)); + break; + } } #endif -- cgit v1.1