"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/api-test.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

api-test.c  (cryptsetup-2.3.6.tar.xz):api-test.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 34 skipping to change at line 34
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <inttypes.h> #include <inttypes.h>
#include <sys/types.h> #include <sys/types.h>
#include "api_test.h" #include "api_test.h"
#include "luks.h" #include "luks1/luks.h"
#include "libcryptsetup.h" #include "libcryptsetup.h"
#define DMDIR "/dev/mapper/" #define DMDIR "/dev/mapper/"
#define DEVICE_1_UUID "28632274-8c8a-493f-835b-da802e1c576b" #define DEVICE_1_UUID "28632274-8c8a-493f-835b-da802e1c576b"
#define DEVICE_EMPTY_name "crypt_zero" #define DEVICE_EMPTY_name "crypt_zero"
#define DEVICE_EMPTY DMDIR DEVICE_EMPTY_name #define DEVICE_EMPTY DMDIR DEVICE_EMPTY_name
#define DEVICE_ERROR_name "crypt_error" #define DEVICE_ERROR_name "crypt_error"
#define DEVICE_ERROR DMDIR DEVICE_ERROR_name #define DEVICE_ERROR DMDIR DEVICE_ERROR_name
skipping to change at line 113 skipping to change at line 113
uint32_t sectors_per_stripes_set; uint32_t sectors_per_stripes_set;
if (!keylength) { if (!keylength) {
if (r_header_size) if (r_header_size)
*r_header_size = 0; *r_header_size = 0;
if (r_payload_offset) if (r_payload_offset)
*r_payload_offset = 0; *r_payload_offset = 0;
return -1; return -1;
} }
sectors_per_stripes_set = DIV_ROUND_UP(keylength*LUKS_STRIPES, SECTOR_SIZ sectors_per_stripes_set = DIV_ROUND_UP(keylength*LUKS_STRIPES, TST_SECTOR
E); _SIZE);
current_sector = DIV_ROUND_UP_MODULO(DIV_ROUND_UP(LUKS_PHDR_SIZE_B, SECTO current_sector = DIV_ROUND_UP_MODULO(DIV_ROUND_UP(LUKS_PHDR_SIZE_B, TST_S
R_SIZE), ECTOR_SIZE),
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE); LUKS_ALIGN_KEYSLOTS / TST_SECTOR_SIZE);
for (i=0; i < (LUKS_NUMKEYS - 1); i++) for (i=0; i < (LUKS_NUMKEYS - 1); i++)
current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per _stripes_set, current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per _stripes_set,
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE); LUKS_ALIGN_KEYSLOTS / TST_SECTOR_SIZE);
if (r_header_size) if (r_header_size)
*r_header_size = current_sector + sectors_per_stripes_set; *r_header_size = current_sector + sectors_per_stripes_set;
current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per_stripes _set, current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per_stripes _set,
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE); LUKS_ALIGN_KEYSLOTS / TST_SECTOR_SIZE);
if (r_payload_offset) { if (r_payload_offset) {
if (metadata_device) if (metadata_device)
*r_payload_offset = alignpayload_sec; *r_payload_offset = alignpayload_sec;
else else
*r_payload_offset = DIV_ROUND_UP_MODULO(current_sector, a lignpayload_sec) *r_payload_offset = DIV_ROUND_UP_MODULO(current_sector, a lignpayload_sec)
+ alignoffset_sec; + alignoffset_sec;
} }
return 0; return 0;
skipping to change at line 242 skipping to change at line 242
free(DEVICE_2); free(DEVICE_2);
free(DEVICE_3); free(DEVICE_3);
} }
static int _setup(void) static int _setup(void)
{ {
int fd, ro = 0; int fd, ro = 0;
char cmd[128]; char cmd[128];
test_loop_file = strdup(THE_LFILE_TEMPLATE); test_loop_file = strdup(THE_LFILE_TEMPLATE);
if (!test_loop_file)
return 1;
if ((fd=mkstemp(test_loop_file)) == -1) { if ((fd=mkstemp(test_loop_file)) == -1) {
printf("cannot create temporary file with template %s\n", test_lo op_file); printf("cannot create temporary file with template %s\n", test_lo op_file);
return 1; return 1;
} }
close(fd); close(fd);
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/n ull", snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/n ull",
test_loop_file, SECTOR_SIZE, TST_LOOP_FILE_SIZE); test_loop_file, TST_SECTOR_SIZE, TST_LOOP_FILE_SIZE);
if (_system(cmd, 1)) if (_system(cmd, 1))
return 1; return 1;
fd = loop_attach(&THE_LOOP_DEV, test_loop_file, 0, 0, &ro); fd = loop_attach(&THE_LOOP_DEV, test_loop_file, 0, 0, &ro);
close(fd); close(fd);
tmp_file_1 = strdup(THE_LFILE_TEMPLATE); tmp_file_1 = strdup(THE_LFILE_TEMPLATE);
if (!tmp_file_1)
return 1;
if ((fd=mkstemp(tmp_file_1)) == -1) { if ((fd=mkstemp(tmp_file_1)) == -1) {
printf("cannot create temporary file with template %s\n", tmp_fil e_1); printf("cannot create temporary file with template %s\n", tmp_fil e_1);
return 1; return 1;
} }
close(fd); close(fd);
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/n ull", snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d 2>/dev/n ull",
tmp_file_1, SECTOR_SIZE, 10); tmp_file_1, TST_SECTOR_SIZE, 10);
if (_system(cmd, 1)) if (_system(cmd, 1))
return 1; return 1;
_system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"", 1); _system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"", 1);
_system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"", 1); _system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"", 1);
_system(" [ ! -e " IMAGE1 " ] && xz -dk " IMAGE1 ".xz", 1); _system(" [ ! -e " IMAGE1 " ] && xz -dk " IMAGE1 ".xz", 1);
fd = loop_attach(&DEVICE_1, IMAGE1, 0, 0, &ro); fd = loop_attach(&DEVICE_1, IMAGE1, 0, 0, &ro);
close(fd); close(fd);
skipping to change at line 295 skipping to change at line 301
_system(" [ ! -e " EVL_HEADER_4 " ] && xz -dk " EVL_HEADER_4 ".xz", 1); _system(" [ ! -e " EVL_HEADER_4 " ] && xz -dk " EVL_HEADER_4 ".xz", 1);
/* two keyslots with same offset (overlapping keyslots) */ /* two keyslots with same offset (overlapping keyslots) */
_system(" [ ! -e " EVL_HEADER_5 " ] && xz -dk " EVL_HEADER_5 ".xz", 1); _system(" [ ! -e " EVL_HEADER_5 " ] && xz -dk " EVL_HEADER_5 ".xz", 1);
/* valid header: payloadOffset=4096, key_size=32, /* valid header: payloadOffset=4096, key_size=32,
* volume_key = bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a 6de7a1a */ * volume_key = bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a 6de7a1a */
_system(" [ ! -e " VALID_HEADER " ] && xz -dk " VALID_HEADER ".xz", 1); _system(" [ ! -e " VALID_HEADER " ] && xz -dk " VALID_HEADER ".xz", 1);
/* Prepare tcrypt images */ /* Prepare tcrypt images */
_system("tar xJf tcrypt-images.tar.xz 2>/dev/null", 1); _system("tar xJf tcrypt-images.tar.xz 2>/dev/null", 1);
_system("modprobe dm-crypt", 0); _system("modprobe dm-crypt >/dev/null 2>&1", 0);
_system("modprobe dm-verity", 0); _system("modprobe dm-verity >/dev/null 2>&1", 0);
_fips_mode = fips_mode(); _fips_mode = fips_mode();
if (_debug) if (_debug)
printf("FIPS MODE: %d\n", _fips_mode); printf("FIPS MODE: %d\n", _fips_mode);
/* Use default log callback */ /* Use default log callback */
crypt_set_log_callback(NULL, &global_log_callback, NULL); crypt_set_log_callback(NULL, &global_log_callback, NULL);
return 0; return 0;
} }
skipping to change at line 368 skipping to change at line 374
FAIL_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0), "cannot v erify key with plain"); FAIL_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0), "cannot v erify key with plain");
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// test boundaries in offset parameter // test boundaries in offset parameter
t_device_size(DEVICE_1,&size); t_device_size(DEVICE_1,&size);
params.hash = NULL; params.hash = NULL;
// zero sectors length // zero sectors length
params.offset = size >> SECTOR_SHIFT; params.offset = size >> TST_SECTOR_SHIFT;
OK_(crypt_init(&cd, DEVICE_1)); OK_(crypt_init(&cd, DEVICE_1));
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
EQ_(crypt_get_data_offset(cd),params.offset); EQ_(crypt_get_data_offset(cd),params.offset);
// device size is 0 sectors // device size is 0 sectors
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0), "invalid device size (0 blocks)"); FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0), "invalid device size (0 blocks)");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
// data part of crypt device is of 1 sector size // data part of crypt device is of 1 sector size
params.offset = (size >> SECTOR_SHIFT) - 1; params.offset = (size >> TST_SECTOR_SHIFT) - 1;
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init(&cd, DEVICE_1)); OK_(crypt_init(&cd, DEVICE_1));
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphras e, strlen(passphrase), 0)); OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphras e, strlen(passphrase), 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1); snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
if (t_device_size(path, &r_size) >= 0) if (t_device_size(path, &r_size) >= 0)
EQ_(r_size>>SECTOR_SHIFT, 1); EQ_(r_size >> TST_SECTOR_SHIFT, 1);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// size > device_size // size > device_size
params.offset = 0; params.offset = 0;
params.size = (size >> SECTOR_SHIFT) + 1; params.size = (size >> TST_SECTOR_SHIFT) + 1;
crypt_init(&cd, DEVICE_1); crypt_init(&cd, DEVICE_1);
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small"); FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// offset == device_size (autodetect size) // offset == device_size (autodetect size)
params.offset = (size >> SECTOR_SHIFT); params.offset = (size >> TST_SECTOR_SHIFT);
params.size = 0; params.size = 0;
crypt_init(&cd, DEVICE_1); crypt_init(&cd, DEVICE_1);
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small"); FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// offset == device_size (user defined size) // offset == device_size (user defined size)
params.offset = (size >> SECTOR_SHIFT); params.offset = (size >> TST_SECTOR_SHIFT);
params.size = 123; params.size = 123;
crypt_init(&cd, DEVICE_1); crypt_init(&cd, DEVICE_1);
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small"); FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Device too small");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// offset+size > device_size // offset+size > device_size
params.offset = 42; params.offset = 42;
params.size = (size >> SECTOR_SHIFT) - params.offset + 1; params.size = (size >> TST_SECTOR_SHIFT) - params.offset + 1;
crypt_init(&cd, DEVICE_1); crypt_init(&cd, DEVICE_1);
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Offset and size are beyond device real size"); FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphr ase, strlen(passphrase), 0),"Offset and size are beyond device real size");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// offset+size == device_size // offset+size == device_size
params.offset = 42; params.offset = 42;
params.size = (size >> SECTOR_SHIFT) - params.offset; params.size = (size >> TST_SECTOR_SHIFT) - params.offset;
crypt_init(&cd, DEVICE_1); crypt_init(&cd, DEVICE_1);
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params)); OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_si ze, &params));
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphras e, strlen(passphrase), 0)); OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphras e, strlen(passphrase), 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
if (!t_device_size(path, &r_size)) if (!t_device_size(path, &r_size))
EQ_((r_size >> SECTOR_SHIFT),params.size); EQ_((r_size >> TST_SECTOR_SHIFT),params.size);
OK_(crypt_deactivate(cd,CDEVICE_1)); OK_(crypt_deactivate(cd,CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.hash = "sha1"; params.hash = "sha1";
params.offset = 0; params.offset = 0;
params.size = 0; params.size = 0;
params.skip = 0; params.skip = 0;
// Now use hashed password // Now use hashed password
OK_(crypt_init(&cd, DEVICE_1)); OK_(crypt_init(&cd, DEVICE_1));
skipping to change at line 490 skipping to change at line 496
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init(&cd,DEVICE_1)); OK_(crypt_init(&cd,DEVICE_1));
OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams)); OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams));
params.size = 0; params.size = 0;
params.offset = 0; params.offset = 0;
// crypt_set_data_device // crypt_set_data_device
FAIL_(crypt_set_data_device(cd,H_DEVICE),"can't set data device for plain device"); FAIL_(crypt_set_data_device(cd,H_DEVICE),"can't set data device for plain device");
NULL_(crypt_get_metadata_device_name(cd)); NULL_(crypt_get_metadata_device_name(cd));
FAIL_(crypt_header_is_detached(cd), "plain has no header");
// crypt_get_type // crypt_get_type
OK_(strcmp(crypt_get_type(cd),CRYPT_PLAIN)); OK_(strcmp(crypt_get_type(cd),CRYPT_PLAIN));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
// crypt_resize() // crypt_resize()
OK_(crypt_resize(cd,CDEVICE_1,size>>SECTOR_SHIFT)); // same size OK_(crypt_resize(cd, CDEVICE_1, size >> TST_SECTOR_SHIFT)); // same size
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size, size); EQ_(r_size, size);
// size overlaps // size overlaps
FAIL_(crypt_resize(cd, CDEVICE_1, (uint64_t)-1),"Backing device is too sm all"); FAIL_(crypt_resize(cd, CDEVICE_1, (uint64_t)-1),"Backing device is too sm all");
FAIL_(crypt_resize(cd, CDEVICE_1, (size>>SECTOR_SHIFT)+1),"crypt device o verlaps backing device"); FAIL_(crypt_resize(cd, CDEVICE_1, (size >> TST_SECTOR_SHIFT) + 1),"crypt device overlaps backing device");
// resize ok // resize ok
OK_(crypt_resize(cd,CDEVICE_1, 123)); OK_(crypt_resize(cd,CDEVICE_1, 123));
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, 123); EQ_(r_size >> TST_SECTOR_SHIFT, 123);
OK_(crypt_resize(cd,CDEVICE_1,0)); // full size (autodetect) OK_(crypt_resize(cd,CDEVICE_1,0)); // full size (autodetect)
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size, size); EQ_(r_size, size);
OK_(crypt_deactivate(cd,CDEVICE_1)); OK_(crypt_deactivate(cd,CDEVICE_1));
EQ_(crypt_status(cd,CDEVICE_1),CRYPT_INACTIVE); EQ_(crypt_status(cd,CDEVICE_1),CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// offset tests // offset tests
OK_(crypt_init(&cd,DEVICE_1)); OK_(crypt_init(&cd,DEVICE_1));
params.offset = 42; params.offset = 42;
params.size = (size>>SECTOR_SHIFT) - params.offset - 10; params.size = (size >> TST_SECTOR_SHIFT) - params.offset - 10;
OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams)); OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams));
OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0)); OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0));
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, params.size); EQ_(r_size >> TST_SECTOR_SHIFT, params.size);
// resize to fill remaining capacity // resize to fill remaining capacity
OK_(crypt_resize(cd,CDEVICE_1,params.size + 10)); OK_(crypt_resize(cd,CDEVICE_1,params.size + 10));
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, params.size + 10); EQ_(r_size >> TST_SECTOR_SHIFT, params.size + 10);
// 1 sector beyond real size // 1 sector beyond real size
FAIL_(crypt_resize(cd,CDEVICE_1,params.size + 11), "new device size overl aps backing device"); // with respect to offset FAIL_(crypt_resize(cd,CDEVICE_1,params.size + 11), "new device size overl aps backing device"); // with respect to offset
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, params.size + 10); EQ_(r_size >> TST_SECTOR_SHIFT, params.size + 10);
GE_(crypt_status(cd,CDEVICE_1),CRYPT_ACTIVE); GE_(crypt_status(cd,CDEVICE_1),CRYPT_ACTIVE);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
NOTFAIL_(fd, "Bad loop device."); NOTFAIL_(fd, "Bad loop device.");
close(fd); close(fd);
// resize to minimal size // resize to minimal size
OK_(crypt_resize(cd,CDEVICE_1, 1)); // minimal device size OK_(crypt_resize(cd,CDEVICE_1, 1)); // minimal device size
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, 1); EQ_(r_size >> TST_SECTOR_SHIFT, 1);
// use size of backing device (autodetect with respect to offset) // use size of backing device (autodetect with respect to offset)
OK_(crypt_resize(cd,CDEVICE_1,0)); OK_(crypt_resize(cd,CDEVICE_1,0));
if (!t_device_size(path,&r_size)) if (!t_device_size(path,&r_size))
EQ_(r_size>>SECTOR_SHIFT, (size >> SECTOR_SHIFT)- 42); EQ_(r_size >> TST_SECTOR_SHIFT, (size >> TST_SECTOR_SHIFT)- 42);
OK_(crypt_deactivate(cd,CDEVICE_1)); OK_(crypt_deactivate(cd,CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.size = 0; params.size = 0;
params.offset = 0; params.offset = 0;
OK_(crypt_init(&cd,DEVICE_1)); OK_(crypt_init(&cd,DEVICE_1));
OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams)); OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,&pa rams));
OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0)); OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0));
// suspend/resume tests // suspend/resume tests
skipping to change at line 880 skipping to change at line 887
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Enc rypted area too small"); FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Enc rypted area too small");
CRYPT_FREE(cd); CRYPT_FREE(cd);
// 1 sector for encrypted area // 1 sector for encrypted area
OK_(crypt_init(&cd, DMDIR L_DEVICE_1S)); OK_(crypt_init(&cd, DMDIR L_DEVICE_1S));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
EQ_(crypt_get_data_offset(cd), params.data_alignment); EQ_(crypt_get_data_offset(cd), params.data_alignment);
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(t_device_size(DMDIR CDEVICE_1, &r_size_1)); OK_(t_device_size(DMDIR CDEVICE_1, &r_size_1));
EQ_(r_size_1, SECTOR_SIZE); EQ_(r_size_1, TST_SECTOR_SIZE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
// restrict format only to empty context // restrict format only to empty context
FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_s ize, &params), "Context is already formatted"); FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_s ize, &params), "Context is already formatted");
FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_s ize, NULL), "Context is already formatted"); FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_s ize, NULL), "Context is already formatted");
// change data device to wrong one // change data device to wrong one
OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_0S)); OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_0S));
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice too small"); FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice too small");
OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_1S)); OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_1S));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
skipping to change at line 924 skipping to change at line 931
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.data_alignment = OFFSET_1M; params.data_alignment = OFFSET_1M;
params.data_device = NULL; params.data_device = NULL;
// test uuid mismatch and _init_by_name_and_header // test uuid mismatch and _init_by_name_and_header
OK_(crypt_init(&cd, DMDIR L_DEVICE_1S)); OK_(crypt_init(&cd, DMDIR L_DEVICE_1S));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
EQ_(0, crypt_header_is_detached(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.data_alignment = 0; params.data_alignment = 0;
params.data_device = DEVICE_2; params.data_device = DEVICE_2;
OK_(crypt_init(&cd, DMDIR H_DEVICE)); OK_(crypt_init(&cd, DMDIR H_DEVICE));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// there we've got uuid mismatch // there we've got uuid mismatch
OK_(crypt_init_by_name_and_header(&cd, CDEVICE_1, DMDIR H_DEVICE)); OK_(crypt_init_by_name_and_header(&cd, CDEVICE_1, DMDIR H_DEVICE));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
NULL_(crypt_get_type(cd)); NULL_(crypt_get_type(cd));
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice is active"); FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice is active");
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0), "Dev ice is active"); FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0), "Dev ice is active");
EQ_(crypt_status(cd, CDEVICE_2), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_2), CRYPT_INACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
FAIL_(crypt_header_is_detached(cd), "no header for mismatched device");
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.data_device = NULL; params.data_device = NULL;
OK_(crypt_init(&cd, DEVICE_2)); OK_(crypt_init(&cd, DEVICE_2));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
// even with no keyslots defined it can be activated by volume key // even with no keyslots defined it can be activated by volume key
OK_(crypt_volume_key_verify(cd, key, key_size)); OK_(crypt_volume_key_verify(cd, key, key_size));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0));
skipping to change at line 1026 skipping to change at line 1035
OK_(strcmp(cipher, crypt_get_cipher(cd))); OK_(strcmp(cipher, crypt_get_cipher(cd)));
OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd))); OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
EQ_((int)key_size, crypt_get_volume_key_size(cd)); EQ_((int)key_size, crypt_get_volume_key_size(cd));
EQ_(OFFSET_2M, crypt_get_data_offset(cd)); EQ_(OFFSET_2M, crypt_get_data_offset(cd));
OK_(strcmp(DEVICE_2, crypt_get_device_name(cd))); OK_(strcmp(DEVICE_2, crypt_get_device_name(cd)));
reset_log(); reset_log();
OK_(crypt_dump(cd)); OK_(crypt_dump(cd));
OK_(!(global_lines != 0)); OK_(!(global_lines != 0));
reset_log(); reset_log();
FAIL_(crypt_dump_json(cd, NULL, 0), "LUKS1 not supported");
FAIL_(crypt_set_uuid(cd, "blah"), "wrong UUID format"); FAIL_(crypt_set_uuid(cd, "blah"), "wrong UUID format");
OK_(crypt_set_uuid(cd, DEVICE_TEST_UUID)); OK_(crypt_set_uuid(cd, DEVICE_TEST_UUID));
OK_(strcmp(DEVICE_TEST_UUID, crypt_get_uuid(cd))); OK_(strcmp(DEVICE_TEST_UUID, crypt_get_uuid(cd)));
FAIL_(crypt_deactivate(cd, CDEVICE_2), "not active"); FAIL_(crypt_deactivate(cd, CDEVICE_2), "not active");
CRYPT_FREE(cd); CRYPT_FREE(cd);
// No benchmark PBKDF2 // No benchmark PBKDF2
pbkdf.flags = CRYPT_PBKDF_NO_BENCHMARK; pbkdf.flags = CRYPT_PBKDF_NO_BENCHMARK;
skipping to change at line 1245 skipping to change at line 1255
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init(&cd, DMDIR H_DEVICE)); OK_(crypt_init(&cd, DMDIR H_DEVICE));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK)); OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(!crypt_get_metadata_device_name(cd)); OK_(!crypt_get_metadata_device_name(cd));
EQ_(strcmp(DMDIR H_DEVICE, crypt_get_metadata_device_name(cd)), 0); EQ_(strcmp(DMDIR H_DEVICE, crypt_get_metadata_device_name(cd)), 0);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
EQ_(1, crypt_header_is_detached(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// repeat with init with two devices // repeat with init with two devices
OK_(crypt_init_data_device(&cd, DMDIR H_DEVICE, DMDIR L_DEVICE_OK)); OK_(crypt_init_data_device(&cd, DMDIR H_DEVICE, DMDIR L_DEVICE_OK));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init_data_device(&cd, DMDIR H_DEVICE, DMDIR L_DEVICE_OK)); OK_(crypt_init_data_device(&cd, DMDIR H_DEVICE, DMDIR L_DEVICE_OK));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
OK_(!crypt_get_metadata_device_name(cd)); OK_(!crypt_get_metadata_device_name(cd));
EQ_(strcmp(DMDIR H_DEVICE, crypt_get_metadata_device_name(cd)), 0); EQ_(strcmp(DMDIR H_DEVICE, crypt_get_metadata_device_name(cd)), 0);
EQ_(1, crypt_header_is_detached(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// bad header: device too small (payloadOffset > device_size) // bad header: device too small (payloadOffset > device_size)
OK_(crypt_init(&cd, DMDIR H_DEVICE_WRONG)); OK_(crypt_init(&cd, DMDIR H_DEVICE_WRONG));
FAIL_(crypt_load(cd, CRYPT_LUKS1, NULL), "Device too small"); FAIL_(crypt_load(cd, CRYPT_LUKS1, NULL), "Device too small");
NULL_(crypt_get_type(cd)); NULL_(crypt_get_type(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// 0 secs for encrypted data area // 0 secs for encrypted data area
params.data_alignment = 2048; params.data_alignment = 2048;
params.data_device = NULL; params.data_device = NULL;
OK_(crypt_init(&cd, DMDIR L_DEVICE_0S)); OK_(crypt_init(&cd, DMDIR L_DEVICE_0S));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
FAIL_(crypt_set_metadata_size(cd, 0x004000, 0x004000), "Wrong context typ e"); FAIL_(crypt_set_metadata_size(cd, 0x004000, 0x004000), "Wrong context typ e");
OK_(crypt_get_metadata_size(cd, &mdata_size, &keyslots_size)); OK_(crypt_get_metadata_size(cd, &mdata_size, &keyslots_size));
EQ_(mdata_size, LUKS_ALIGN_KEYSLOTS); EQ_(mdata_size, LUKS_ALIGN_KEYSLOTS);
EQ_(keyslots_size, r_header_size * SECTOR_SIZE - mdata_size); EQ_(keyslots_size, r_header_size * TST_SECTOR_SIZE - mdata_size);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// load should be ok // load should be ok
OK_(crypt_init(&cd, DMDIR L_DEVICE_0S)); OK_(crypt_init(&cd, DMDIR L_DEVICE_0S));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice too small"); FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Dev ice too small");
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE); EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
CRYPT_FREE(cd); CRYPT_FREE(cd);
// damaged header // damaged header
OK_(_system("dd if=/dev/zero of=" DMDIR L_DEVICE_OK " bs=512 count=8 2>/d ev/null", 1)); OK_(_system("dd if=/dev/zero of=" DMDIR L_DEVICE_OK " bs=512 count=8 2>/d ev/null", 1));
skipping to change at line 1345 skipping to change at line 1357
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// restore header from backup // restore header from backup
OK_(crypt_init(&cd, DMDIR L_DEVICE_OK)); OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
OK_(crypt_header_restore(cd, CRYPT_LUKS1, BACKUP_FILE)); OK_(crypt_header_restore(cd, CRYPT_LUKS1, BACKUP_FILE));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
EQ_(0, crypt_header_is_detached(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
// exercise luksOpen using backup header in file // exercise luksOpen using backup header in file
OK_(crypt_init(&cd, BACKUP_FILE)); OK_(crypt_init(&cd, BACKUP_FILE));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK)); OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK));
EQ_(crypt_activate_by_passphrase(cd, CDEVICE_1, 0, passphrase, strlen(pas sphrase), 0), 0); EQ_(crypt_activate_by_passphrase(cd, CDEVICE_1, 0, passphrase, strlen(pas sphrase), 0), 0);
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
EQ_(1, crypt_header_is_detached(cd));
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init(&cd, BACKUP_FILE)); OK_(crypt_init(&cd, BACKUP_FILE));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL)); OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK)); OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK));
EQ_(crypt_activate_by_passphrase(cd, CDEVICE_1, 7, passphrase, strlen(pas sphrase), 0), 7); EQ_(crypt_activate_by_passphrase(cd, CDEVICE_1, 7, passphrase, strlen(pas sphrase), 0), 7);
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
skipping to change at line 1417 skipping to change at line 1431
OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000)); OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
OK_(create_dmdevice_over_loop(L_DEVICE_0S, 1000)); OK_(create_dmdevice_over_loop(L_DEVICE_0S, 1000));
OK_(create_dmdevice_over_loop(L_DEVICE_WRONG, r_payload_offset + 1000)); OK_(create_dmdevice_over_loop(L_DEVICE_WRONG, r_payload_offset + 1000));
// test header and encrypted payload all in one device // test header and encrypted payload all in one device
OK_(crypt_init(&cd, DMDIR L_DEVICE_OK)); OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
OK_(crypt_resize(cd, CDEVICE_1, 42)); OK_(crypt_resize(cd, CDEVICE_1, 42));
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(42, r_size >> SECTOR_SHIFT); EQ_(42, r_size >> TST_SECTOR_SHIFT);
// autodetect encrypted device area size // autodetect encrypted device area size
OK_(crypt_resize(cd, CDEVICE_1, 0)); OK_(crypt_resize(cd, CDEVICE_1, 0));
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(1000, r_size >> SECTOR_SHIFT); EQ_(1000, r_size >> TST_SECTOR_SHIFT);
FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small"); FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small");
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(1000, r_size >> SECTOR_SHIFT); EQ_(1000, r_size >> TST_SECTOR_SHIFT);
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
params.data_alignment = 0; params.data_alignment = 0;
params.data_device = DMDIR L_DEVICE_0S; params.data_device = DMDIR L_DEVICE_0S;
// test case for external header // test case for external header
OK_(crypt_init(&cd, DMDIR H_DEVICE)); OK_(crypt_init(&cd, DMDIR H_DEVICE));
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params)); OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_siz e, &params));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
OK_(crypt_resize(cd, CDEVICE_1, 666)); OK_(crypt_resize(cd, CDEVICE_1, 666));
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(666, r_size >> SECTOR_SHIFT); EQ_(666, r_size >> TST_SECTOR_SHIFT);
// autodetect encrypted device size // autodetect encrypted device size
OK_(crypt_resize(cd, CDEVICE_1, 0)); OK_(crypt_resize(cd, CDEVICE_1, 0));
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(1000, r_size >> SECTOR_SHIFT); EQ_(1000, r_size >> TST_SECTOR_SHIFT);
FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small"); FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small");
if (!t_device_size(DMDIR CDEVICE_1, &r_size)) if (!t_device_size(DMDIR CDEVICE_1, &r_size))
EQ_(1000, r_size >> SECTOR_SHIFT); EQ_(1000, r_size >> TST_SECTOR_SHIFT);
GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE); GE_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1)); OK_(crypt_deactivate(cd, CDEVICE_1));
CRYPT_FREE(cd); CRYPT_FREE(cd);
OK_(crypt_init(&cd, DMDIR L_DEVICE_OK)); OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
OK_(crypt_load(cd, NULL, NULL)); OK_(crypt_load(cd, NULL, NULL));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0)); OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
/* do not allow resize of other device */ /* do not allow resize of other device */
OK_(crypt_init(&cd2, DMDIR L_DEVICE_WRONG)); OK_(crypt_init(&cd2, DMDIR L_DEVICE_WRONG));
skipping to change at line 1733 skipping to change at line 1747
struct crypt_params_tcrypt params = { struct crypt_params_tcrypt params = {
.passphrase = passphrase, .passphrase = passphrase,
.passphrase_size = strlen(passphrase), .passphrase_size = strlen(passphrase),
.keyfiles = keyfiles, .keyfiles = keyfiles,
.keyfiles_count = 2, .keyfiles_count = 2,
}; };
double enc_mbr = 0, dec_mbr = 0; double enc_mbr = 0, dec_mbr = 0;
const char *tcrypt_dev = "tcrypt-images/tck_5-sha512-xts-aes"; const char *tcrypt_dev = "tcrypt-images/tck_5-sha512-xts-aes";
const char *tcrypt_dev2 = "tcrypt-images/tc_5-sha512-xts-serpent-twofish- aes"; const char *tcrypt_dev2 = "tcrypt-images/tc_5-sha512-xts-serpent-twofish- aes";
size_t key_size = 64; size_t key_size = 64;
char key[key_size], key_def[key_size]; char key[64], key_def[64];
const char *key_hex = const char *key_hex =
"98dee64abe44bbf41d171c1f7b3e8eacda6d6b01f459097459a167f8c2872a96 " "98dee64abe44bbf41d171c1f7b3e8eacda6d6b01f459097459a167f8c2872a96 "
"3979531d1cdc18af62757cf22286f16f8583d848524f128d7594ac2082668c73 "; "3979531d1cdc18af62757cf22286f16f8583d848524f128d7594ac2082668c73 ";
int r; int r;
crypt_decode_key(key_def, key_hex, strlen(key_hex) / 2); crypt_decode_key(key_def, key_hex, strlen(key_hex) / 2);
// First ensure we can use af_alg skcipher interface // First ensure we can use af_alg skcipher interface
r = crypt_benchmark(NULL, "aes", "xts", 512, 16, 1024, &enc_mbr, &dec_mbr ); r = crypt_benchmark(NULL, "aes", "xts", 512, 16, 1024, &enc_mbr, &dec_mbr );
if (r == -ENOTSUP || r == -ENOENT) { if (r == -ENOTSUP || r == -ENOENT) {
 End of changes. 44 change blocks. 
39 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)