lib/utils_crypt: optimize seek to keyfile-offset
Avoid using unbuffered reads when "seeking" to a keyfile offset. This is
abysmally slow when the key is hidden at the end of a large device.
Instead, try to actually call lseek, falling back on reading in chunks
of BUFSIZ bytes until the desired offset is reached.
Command line:
cryptsetup luksOpen /dev/vdc1 home \
--keyfile /dev/vdd --keyfile-size 4096 --keyfile-offset
123456789
Before:
real 0m25.589s
user 0m7.030s
sys 0m18.479s
After:
real 0m4.464s
user 0m4.253s
sys 0m0.157s