sys/geom/eli/g_eli.c
/*
 * Here we generate IV. It is unique for every sector.
 */
Here we generate IV. It is unique for every sector.
Here we generate IV . It is unique for every sector .
void
g_eli_crypto_ivgen(struct g_eli_softc *sc, off_t offset, u_char *iv,
    size_t size)
{
	uint8_t off[8];
	if ((sc->sc_flags & G_ELI_FLAG_NATIVE_BYTE_ORDER) != 0)
		bcopy(&offset, off, sizeof(off));
	else
		le64enc(off, (uint64_t)offset);
	switch (sc->sc_ealgo) {
	case CRYPTO_AES_XTS:
		bcopy(off, iv, sizeof(off));
		bzero(iv + sizeof(off), size - sizeof(off));
		break;
	default:
	    {
		u_char hash[SHA256_DIGEST_LENGTH];
		SHA256_CTX ctx;
		bcopy(&sc->sc_ivctx, &ctx, sizeof(ctx));
		SHA256_Update(&ctx, off, sizeof(off));
		SHA256_Final(hash, &ctx);
		bcopy(hash, iv, MIN(sizeof(hash), size));
		break;
	    }
	}
}
void g_eli_crypto_ivgen ( struct g_eli_softc * sc , off_t offset , u_char * iv , size_t size ) { uint8_t off [ 8 ] ; if ( ( sc -> sc_flags & G_ELI_FLAG_NATIVE_BYTE_ORDER ) != 0 ) bcopy ( & offset , off , sizeof ( off ) ) ; else le64enc ( off , ( uint64_t ) offset ) ; switch ( sc -> sc_ealgo ) { case CRYPTO_AES_XTS : bcopy ( off , iv , sizeof ( off ) ) ; bzero ( iv + sizeof ( off ) , size - sizeof ( off ) ) ; break ; default : { u_char hash [ SHA256_DIGEST_LENGTH ] ; SHA256_CTX ctx ; bcopy ( & sc -> sc_ivctx , & ctx , sizeof ( ctx ) ) ; SHA256_Update ( & ctx , off , sizeof ( off ) ) ; SHA256_Final ( hash , & ctx ) ; bcopy ( hash , iv , MIN ( sizeof ( hash ) , size ) ) ; break ; } } }
Here we generate IV.
Here we generate IV .
/* Copy precalculated SHA256 context for IV-Key. */