#include "luks.h"
#include "internal.h"
-#define div_round_up(a,b) ({ \
- typeof(a) __a = (a); \
- typeof(b) __b = (b); \
- (__a - 1) / __b + 1; \
-})
-
-static inline int round_up_modulo(int x, int m) {
- return div_round_up(x, m) * m;
-}
-
static const char *cleaner_name=NULL;
static uint64_t cleaner_size = 0;
static int devfd=-1;
static int setup_mapping(const char *cipher, const char *name,
- int bsize, struct volume_key *vk,
+ unsigned int bsize, struct volume_key *vk,
unsigned int sector, size_t srcLength,
int mode, struct crypt_device *ctx)
{
struct crypt_dm_active_device dmd = {
.target = DM_CRYPT,
.uuid = NULL,
- .size = round_up_modulo(srcLength, bsize) / SECTOR_SIZE,
+ .size = size_round_up(srcLength, bsize) / SECTOR_SIZE,
.flags = CRYPT_ACTIVATE_PRIVATE,
.data_device = device,
.u.crypt = {
#include "pbkdf.h"
#include "internal.h"
-#define div_round_up(a,b) ({ \
- typeof(a) __a = (a); \
- typeof(b) __b = (b); \
- (__a - 1) / __b + 1; \
-})
-
-static inline int round_up_modulo(int x, int m) {
- return div_round_up(x, m) * m;
-}
-
-/* Get size of struct luks_phrd with all keyslots material space */
-static uint64_t LUKS_device_sectors(size_t keyLen)
+/* Get size of struct luks_phdr with all keyslots material space */
+static size_t LUKS_device_sectors(size_t keyLen)
{
- uint64_t keyslot_sectors, sector;
+ size_t keyslot_sectors, sector;
int i;
keyslot_sectors = AF_split_sectors(keyLen, LUKS_STRIPES);
sector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
for (i = 0; i < LUKS_NUMKEYS; i++) {
- sector = round_up_modulo(sector, LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
+ sector = size_round_up(sector, LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
sector += keyslot_sectors;
}
struct crypt_device *ctx)
{
unsigned int i=0;
- unsigned int blocksPerStripeSet = AF_split_sectors(vk->keylength, stripes);
+ size_t blocksPerStripeSet, currentSector;
int r;
uuid_t partitionUuid;
- int currentSector;
char luksMagic[] = LUKS_MAGIC;
/* For separate metadata device allow zero alignment */
}
currentSector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
+ blocksPerStripeSet = AF_split_sectors(vk->keylength, stripes);
for(i = 0; i < LUKS_NUMKEYS; ++i) {
header->keyblock[i].active = LUKS_KEY_DISABLED;
header->keyblock[i].keyMaterialOffset = currentSector;
header->keyblock[i].stripes = stripes;
- currentSector = round_up_modulo(currentSector + blocksPerStripeSet,
+ currentSector = size_round_up(currentSector + blocksPerStripeSet,
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
}
header->payloadOffset = alignPayload;
} else {
/* alignOffset - offset from natural device alignment provided by topology info */
- currentSector = round_up_modulo(currentSector, alignPayload);
+ currentSector = size_round_up(currentSector, alignPayload);
header->payloadOffset = currentSector + alignOffset;
}