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.
It seems in my case IV was supposed to be generated using AES-256 in ECB mode.

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


where E is AES-256 ECB, SN is sector number of disk data, extended to 16B (padded with zeros) and KEY is 32B long encryption key (HMAC = SHA-256).