uint64_t keyslot_sectors, sector;
int i;
- keyslot_sectors = div_round_up(keyLen * LUKS_STRIPES, SECTOR_SIZE);
+ keyslot_sectors = div_round_up(AF_split_size(keyLen, LUKS_STRIPES), SECTOR_SIZE);
sector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
for (i = 0; i < LUKS_NUMKEYS; i++) {
return 1;
}
- secs_per_stripes = div_round_up(phdr->keyBytes * phdr->keyblock[keyIndex].stripes, SECTOR_SIZE);
+ secs_per_stripes = div_round_up(AF_split_size(phdr->keyBytes, phdr->keyblock[keyIndex].stripes), SECTOR_SIZE);
if (phdr->payloadOffset < (phdr->keyblock[keyIndex].keyMaterialOffset + secs_per_stripes)) {
log_dbg("Invalid keyslot size %u (offset %u, stripes %u) in "
/* LUKS header starts at offset 0, first keyslot on LUKS_ALIGN_KEYSLOTS */
assert(sizeof(struct luks_phdr) <= LUKS_ALIGN_KEYSLOTS);
+ /* Stripes count cannot be changed without additional code fixes yet */
+ assert(LUKS_STRIPES == 4000);
+
if (repair && !require_luks_device)
return -EINVAL;
struct crypt_device *ctx)
{
unsigned int i=0;
- unsigned int blocksPerStripeSet = div_round_up(vk->keylength*stripes,SECTOR_SIZE);
+ unsigned int blocksPerStripeSet = div_round_up(AF_split_size(vk->keylength, stripes),SECTOR_SIZE);
int r;
uuid_t partitionUuid;
int currentSector;
{
struct volume_key *derived_key;
char *AfKey = NULL;
- unsigned int AFEKSize;
+ size_t AFEKSize;
uint64_t PBKDF2_temp;
int r;
return -EINVAL;
}
- if(hdr->keyblock[keyIndex].stripes < LUKS_STRIPES) {
+ /* LUKS keyslot has always at least 4000 stripes accoding to specification */
+ if(hdr->keyblock[keyIndex].stripes < 4000) {
log_err(ctx, _("Key slot %d material includes too few stripes. Header manipulation?\n"),
keyIndex);
return -EINVAL;
* AF splitting, the masterkey stored in vk->key is split to AfKey
*/
assert(vk->keylength == hdr->keyBytes);
- AFEKSize = hdr->keyblock[keyIndex].stripes*vk->keylength;
+ AFEKSize = AF_split_size(vk->keylength, hdr->keyblock[keyIndex].stripes);
AfKey = crypt_safe_alloc(AFEKSize);
if (!AfKey) {
r = -ENOMEM;
return -ENOMEM;
assert(vk->keylength == hdr->keyBytes);
- AFEKSize = hdr->keyblock[keyIndex].stripes*vk->keylength;
+ AFEKSize = AF_split_size(vk->keylength, hdr->keyblock[keyIndex].stripes);
AfKey = crypt_safe_alloc(AFEKSize);
if (!AfKey)
return -ENOMEM;
struct crypt_device *ctx)
{
struct device *device = crypt_metadata_device(ctx);
- unsigned int startOffset, endOffset, stripesLen;
+ unsigned int startOffset, endOffset;
int r;
r = LUKS_read_phdr(hdr, 1, 0, ctx);
/* secure deletion of key material */
startOffset = hdr->keyblock[keyIndex].keyMaterialOffset;
- stripesLen = hdr->keyBytes * hdr->keyblock[keyIndex].stripes;
- endOffset = startOffset + div_round_up(stripesLen, SECTOR_SIZE);
+ endOffset = startOffset + div_round_up(AF_split_size(hdr->keyBytes, hdr->keyblock[keyIndex].stripes), SECTOR_SIZE);
r = crypt_wipe(device, startOffset * SECTOR_SIZE,
(endOffset - startOffset) * SECTOR_SIZE,