FreeBSD/sys/geom/eli/g_eli_key.c
/*
 * When doing encryption only, copy IV key and encryption key.
 * When doing encryption and authentication, copy IV key, generate encryption
 * key and generate authentication key.
 */
When doing encryption only, copy IV key and encryption key.
When doing encryption and authentication, copy IV key, generate encryption
key and generate authentication key.
When doing encryption only copy IV key and encryption key . When doing encryption and authentication copy IV key generate encryption key and generate authentication key .
void
g_eli_mkey_propagate(struct g_eli_softc *sc, const unsigned char *mkey)
{
	bcopy(mkey, sc->sc_mkey, sizeof(sc->sc_mkey));
	bcopy(mkey, sc->sc_ivkey, sizeof(sc->sc_ivkey));
	mkey += sizeof(sc->sc_ivkey);
	if ((sc->sc_flags & G_ELI_FLAG_AUTH) != 0) {
		g_eli_crypto_hmac(mkey, G_ELI_MAXKEYLEN, "\x11", 1,
		    sc->sc_akey, 0);
	} else {
		arc4rand(sc->sc_akey, sizeof(sc->sc_akey), 0);
	}
	g_eli_key_init(sc);
	if ((sc->sc_flags & G_ELI_FLAG_AUTH) != 0) {
		SHA256_Init(&sc->sc_akeyctx);
		SHA256_Update(&sc->sc_akeyctx, sc->sc_akey,
		    sizeof(sc->sc_akey));
	}
	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;
	}
}
void g_eli_mkey_propagate ( struct g_eli_softc * sc , const unsigned char * mkey ) { bcopy ( mkey , sc -> sc_mkey , sizeof ( sc -> sc_mkey ) ) ; bcopy ( mkey , sc -> sc_ivkey , sizeof ( sc -> sc_ivkey ) ) ; mkey += sizeof ( sc -> sc_ivkey ) ; if ( ( sc -> sc_flags & G_ELI_FLAG_AUTH ) != 0 ) { g_eli_crypto_hmac ( mkey , G_ELI_MAXKEYLEN , " \x11 " , 1 , sc -> sc_akey , 0 ) ; } else { arc4rand ( sc -> sc_akey , sizeof ( sc -> sc_akey ) , 0 ) ; } g_eli_key_init ( sc ) ; if ( ( sc -> sc_flags & G_ELI_FLAG_AUTH ) != 0 ) { SHA256_Init ( & sc -> sc_akeyctx ) ; SHA256_Update ( & sc -> sc_akeyctx , sc -> sc_akey , sizeof ( sc -> sc_akey ) ) ; } 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 ; } }
When doing encryption only, copy IV key and encryption key.
When doing encryption only copy IV key and encryption key .
/* Remember the Master Key. */ /*
	 * The authentication key is: akey = HMAC_SHA512(Data-Key, 0x11)
	 */ /* Initialize encryption keys. */ /*
		 * 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.
		 */ /*
	 * 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.
	 */