# AES-256 CTR with ESSIV, is this correct?

I am having some problems encrypting disk using AES-256 in CTR mode, with ESSIV iv generation (I am aware of couple of flaws, although this mode is enough for now). What I have here is:

S = SHA256(K), result 32 bytes
K = original key, 32 bytes
SN = sector number, 16 bytes
E = AES-256 CTR
IV2 = generated iv, 16 bytes


What I am doing with it:

IV2 = E(data=SN, key=S, iv=SN)
decrypted_data = E(data=encrypted_data, key=K, iv=IV2)


In couple of sources (e.g. here: https://is.muni.cz/th/vesfr/final.pdf) I got that for ESSIV generation I should use the exact same block cipher as for main de/encryption. However, I am getting wrong results. Is this the correct approach?

Thanks.

• I will perform some tests tomorrow, but it seems that ESSIV generation encryption was supposed to be performed in ECB mode. – wtdmn Jun 14 '20 at 20:47

ESSIV_IV = E(data=SN, key=HMAC(KEY))