# calculate ESS IV initialization vector for aes- bc essiv encryption

I want to do block level encrypton on my ext4 image file system with aes-cbc-essiv

How can I find/calculate the the ESSIV needed for encryption?

Essentially: Let $\text{SN}$ by the current sector number encoded as a 128-bit integer. Let $K$ be the key used for encryption. Let $\operatorname{hash}(\cdot)$ be a hash function, which is specified in the cipher name.
Now the $\text{IV}$ is computed as $\operatorname{IV}(\text{SN})=E_{\operatorname{hash}(K)}(\text{SN})$.