diff --git a/python/pycryptsetup-test.py b/python/pycryptsetup-test.py index ccc9342e..a9cc3b9f 100755 --- a/python/pycryptsetup-test.py +++ b/python/pycryptsetup-test.py @@ -70,7 +70,7 @@ r = c.isLuks() print("isLuks :", r) c.askyes(message = "Is there anybody out there?") c.log(priority = pycryptsetup.CRYPT_LOG_ERROR, message = "Nobody there...\n") -c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512) +c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512, hashMode = "sha256") print("isLuks :", c.isLuks()) print("luksUUID:", c.luksUUID()) print("addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2)) diff --git a/python/pycryptsetup.c b/python/pycryptsetup.c index 9753c672..426af25a 100644 --- a/python/pycryptsetup.c +++ b/python/pycryptsetup.c @@ -366,22 +366,26 @@ static PyObject *CryptSetup_Info(CryptSetupObject* self, PyObject *args, PyObjec static char CryptSetup_luksFormat_HELP[] = "Format device to enable LUKS\n\n\ - luksFormat(cipher = 'aes', cipherMode = 'cbc-essiv:sha256', keysize = 256)\n\n\ + luksFormat(cipher = 'aes', cipherMode = 'cbc-essiv:sha256', keysize = 256, hashMode = 'sha256')\n\n\ cipher - cipher specification, e.g. aes, serpent\n\ cipherMode - cipher mode specification, e.g. cbc-essiv:sha256, xts-plain64\n\ - keysize - key size in bits"; + keysize - key size in bits\n\ + hashMode - hash specification, e.g. sha256"; static PyObject *CryptSetup_luksFormat(CryptSetupObject* self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"cipher", "cipherMode", "keysize", NULL}; - char *cipher_mode = NULL, *cipher = NULL; + static const char *kwlist[] = {"cipher", "cipherMode", "keysize", "hashMode", NULL}; + char *cipher_mode = NULL, *cipher = NULL, *hashMode = NULL; int keysize = 256; PyObject *keysize_object = NULL; + struct crypt_params_luks1 params = {}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzO", CONST_CAST(char**)kwlist, - &cipher, &cipher_mode, &keysize_object)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOz", CONST_CAST(char**)kwlist, + &cipher, &cipher_mode, &keysize_object, + &hashMode)) return NULL; + params.hash = hashMode; if (!keysize_object || keysize_object == Py_None) { /* use default value */ } else if (!PyInt_Check(keysize_object)) { @@ -399,7 +403,7 @@ static PyObject *CryptSetup_luksFormat(CryptSetupObject* self, PyObject *args, P // FIXME use #defined defaults return PyObjectResult(crypt_format(self->device, CRYPT_LUKS1, cipher ?: "aes", cipher_mode ?: "cbc-essiv:sha256", - NULL, NULL, keysize / 8, NULL)); + NULL, NULL, keysize / 8, ¶ms)); } static char