Skip to contentSkip to conversation

Atmel driver - XTS mode - Alignement issue

DISCUSSION levent demir 1 participant 1 message May 31, 2016 Crypto API

lore
Share & tools
lore
#0 lore raw

Hi all,

I am working on SAMA5D3 board with atmel-aes driver, I have a question about sg.

This board does not support XTS mode, however we want to add this functionality.

As a recall XTS mode :

For a 512 bytes block:

1) We encrypt the given IV with the second part of the key [ECB].
2) We compute the 32 tweaks value (with GF multiplication)
3) We Xor the plaintext with the tweaks (called XOR_1)
4) We encrypt the result with ECB and the first half of the key
5) Again we xor the result with tweaks (called XOR_2)

So if I want to add my own XTS mode I need to make all those operations.

I have seen in the code there is a alignement issue to handle, if source data is aligned
we can encrypt it directly. If source data is not aligned we call a function to copy into a buffer :

625 if (!src_aligned) {

626            sg_copy_to_buffer(src, sg_nents(src), dd->buf, len);
			    ...

Moreover we are working with dm-crypt.

My question is : is it possible to make the XOR operation directly on scatterlist if data is aligned ?
Or I am forced to use the sg_copy_to/from_buffer.

We have tested and here are the results :

1) The easy solution is to copy the src data into the buffer and to xor it with tweaks for XOR_1 and XOR_2
2) If we xor only the ciphertext [dst] (XOR_2) directly with the scatterlist and compute the src XOR_1 with the buffer, it is working.
3) If we xor direcly with the scatterlist for XOR_1 and XOR_2 we have an error at the mount step using dm-crypt :

[269132.780000] EXT4-fs (dm-0): ext4_check_descriptors: Block bitmap for
group 0 not in group
(block 16843203)!
[269132.790000] EXT4-fs (dm-0): group descriptors corrupted! 

If you can help me on this point.

Thanks.