*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
{
int i;
uint64_t current_sector;
+ uint32_t sectors_per_stripes_set;
+
if (!keylength)
return -1;
- uint32_t sectors_per_stripes_set = DIV_ROUND_UP(keylength*LUKS_STRIPES, SECTOR_SIZE);
+ sectors_per_stripes_set = DIV_ROUND_UP(keylength*LUKS_STRIPES, SECTOR_SIZE);
printf("sectors_per_stripes %" PRIu32 "\n", sectors_per_stripes_set);
current_sector = DIV_ROUND_UP_MODULO(DIV_ROUND_UP(LUKS_PHDR_SIZE_B, SECTOR_SIZE),
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
struct dm_task *dmt;
struct dm_info dmi;
uint64_t start, length;
- char *target_type, *rcipher, *key, *params;
+ char *target_type, *key, *params;
void *next = NULL;
int r = -EINVAL;
if (!target_type || strcmp(target_type, "crypt") != 0)
goto out;
- rcipher = strsep(¶ms, " ");
+ (void)strsep(¶ms, " "); /* rcipher */
key = strsep(¶ms, " ");
if (buffer_size <= strlen(key))
}
// Decode key from its hex representation
-static int crypt_decode_key(char *key, char *hex, unsigned int size)
+static int crypt_decode_key(char *key, const char *hex, unsigned int size)
{
char buffer[3];
char *endp;
return 0;
}
-static void cmdLineLog(int level, char *msg)
+static void cmdLineLog(int level, const char *msg)
{
strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
global_lines++;
static void new_log(int level, const char *msg, void *usrptr)
{
- cmdLineLog(level, (char*)msg);
+ cmdLineLog(level, msg);
}
-static void reset_log()
+static void reset_log(void)
{
memset(global_log, 0, sizeof(global_log));
global_lines = 0;
return 0;
}
-void check_ok(int status, int line, const char *func)
+static void check_ok(int status, int line, const char *func)
{
char buf[256];
}
}
-void check_ko(int status, int line, const char *func)
+static void check_ko(int status, int line, const char *func)
{
char buf[256];
printf(" => errno %d, errmsg: %s\n", status, buf);
}
-void check_equal(int line, const char *func)
+static void check_equal(int line, const char *func)
{
printf("FAIL line %d [%s]: expected equal values differs.\n", line, func);
_cleanup();
exit(-1);
}
-void xlog(const char *msg, const char *tst, const char *func, int line, const char *txt)
+static void xlog(const char *msg, const char *tst, const char *func, int line, const char *txt)
{
if (_verbose) {
if (txt)
printf(" [%s,%s:%d] %s\n", msg, func, line, tst);
}
}
+
+/* crypt_device context must be "cd" to parse error properly here */
#define OK_(x) do { xlog("(success)", #x, __FUNCTION__, __LINE__, NULL); \
check_ok((x), __LINE__, __FUNCTION__); \
} while(0)
#define RUN_(x, y) do { printf("%s: %s\n", #x, (y)); x(); } while (0)
-// NEW API tests
-
static void AddDevicePlain(void)
{
- struct crypt_device *cd, *cd2;
+ struct crypt_device *cd;
struct crypt_params_plain params = {
.hash = "sha1",
.skip = 0,
int fd;
char key[128], key2[128], path[128];
- char *passphrase = PASSPHRASE;
+ const char *passphrase = PASSPHRASE;
// hashed hex version of PASSPHRASE
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t size, r_size;
OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
OK_(strcmp(cipher_mode,crypt_get_cipher_mode(cd)));
OK_(strcmp(cipher,crypt_get_cipher(cd)));
- EQ_(key_size, crypt_get_volume_key_size(cd));
+ EQ_((int)key_size, crypt_get_volume_key_size(cd));
EQ_(params.skip, crypt_get_iv_offset(cd));
EQ_(params.offset, crypt_get_data_offset(cd));
params.skip = 0;
OK_(crypt_init(&cd,DEVICE_1));
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
- FAIL_(crypt_init_by_name_and_header(&cd2, CDEVICE_1, H_DEVICE),"can't init plain device by header device");
- OK_(crypt_init_by_name(&cd2,CDEVICE_1));
- OK_(crypt_deactivate(cd,CDEVICE_1));
crypt_free(cd);
- crypt_free(cd2);
+
+ FAIL_(crypt_init_by_name_and_header(&cd, CDEVICE_1, H_DEVICE),"can't init plain device by header device");
+ OK_(crypt_init_by_name(&cd, CDEVICE_1));
+ OK_(strcmp(cipher_mode,crypt_get_cipher_mode(cd)));
+ OK_(strcmp(cipher,crypt_get_cipher(cd)));
+ EQ_((int)key_size, crypt_get_volume_key_size(cd));
+ EQ_(params.skip, crypt_get_iv_offset(cd));
+ EQ_(params.offset, crypt_get_data_offset(cd));
+ OK_(crypt_deactivate(cd, CDEVICE_1));
+ crypt_free(cd);
OK_(crypt_init(&cd,DEVICE_1));
OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
OK_(memcmp(key, key2, key_size));
OK_(strcmp(cipher, crypt_get_cipher(cd)));
OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
- EQ_(key_size, crypt_get_volume_key_size(cd));
+ EQ_((int)key_size, crypt_get_volume_key_size(cd));
EQ_(0, crypt_get_data_offset(cd));
OK_(crypt_deactivate(cd, CDEVICE_1));
};
size_t key_size = 256 / 8;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
- char *passphrase = PASSPHRASE;
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
+ const char *passphrase = PASSPHRASE;
+ char buf1[256] = {0}, buf2[256] = {0};
OK_(crypt_init(&cd, DEVICE_1));
crypt_set_log_callback(cd, &new_log, NULL);
EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1));
+ // Check error reporting.
+ // This must fail and create error message
+ crypt_deactivate(cd, CDEVICE_1);
+
+ // Here context must be the same
+ crypt_get_error(buf1, sizeof(buf1));
+ crypt_last_error(cd, buf2, sizeof(buf2));
+ OK_(!*buf1);
+ OK_(!*buf2);
+ OK_(strcmp(buf1, buf2));
+
+ crypt_get_error(buf1, sizeof(buf1));
+ crypt_last_error(cd, buf2, sizeof(buf2));
+ OK_(*buf1);
+ OK_(*buf2);
+
crypt_free(cd);
}
OK_(strcmp("aes", crypt_get_cipher(cd)));
OK_(strcmp("cbc-essiv:sha256", crypt_get_cipher_mode(cd)));
OK_(strcmp(DEVICE_1_UUID, crypt_get_uuid(cd)));
- EQ_(key_size, crypt_get_volume_key_size(cd));
+ EQ_((int)key_size, crypt_get_volume_key_size(cd));
EQ_(1032, crypt_get_data_offset(cd));
EQ_(0, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key, &key_size, KEY1, strlen(KEY1)));
};
char key[128], key2[128];
- char *passphrase = "blabla";
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *passphrase = "blabla";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t r_payload_offset, r_header_size, r_size_1;
crypt_decode_key(key, mk_hex, key_size);
OK_(memcmp(key, key2, key_size));
OK_(strcmp(cipher, crypt_get_cipher(cd)));
OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
- EQ_(key_size, crypt_get_volume_key_size(cd));
+ EQ_((int)key_size, crypt_get_volume_key_size(cd));
EQ_(4096, crypt_get_data_offset(cd));
OK_(strcmp(DEVICE_2, crypt_get_device_name(cd)));
};
char key[128], key2[128], cmd[256];
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t r_payload_offset;
crypt_decode_key(key, mk_hex, key_size);
};
char key[128], cmd[256];
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t r_payload_offset, r_header_size;
crypt_decode_key(key, mk_hex, key_size);
};
char key[128];
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t r_payload_offset;
crypt_decode_key(key, mk_hex, key_size);
};
char key[128];
- char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
+ const char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
size_t key_size = strlen(mk_hex) / 2;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
uint64_t r_payload_offset, r_header_size, r_size;
crypt_decode_key(key, mk_hex, key_size);
};
size_t key_size;
- char *mk_hex, *keystr, key[256];
+ const char *mk_hex, *keystr;
+ char key[256];
OK_(crypt_init(&cd, DEVICE_1));
OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, ¶ms));
struct crypt_params_luks1 params = {0};
char key[128] = "";
size_t key_size = 128;
- char *cipher = "aes";
- char *cipher_mode = "cbc-essiv:sha256";
+ const char *cipher = "aes";
+ const char *cipher_mode = "cbc-essiv:sha256";
int ret;
OK_(crypt_init(&cd, DEVICE_2));