2 * Python bindings to libcryptsetup
4 * Copyright (C) 2009-2014, Red Hat, Inc. All rights reserved.
5 * Written by Martin Sivak
7 * This file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this file; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <structmember.h>
26 #include "libcryptsetup.h"
28 /* Python API use char* where const char* should be used... */
29 #define CONST_CAST(x) (x)(uintptr_t)
31 #if PY_MAJOR_VERSION < 3
33 #define MOD_SUCCESS_VAL(val)
34 #define MOD_INIT(name) void init##name(void)
35 #define MOD_DEF(ob, name, doc, methods) \
36 ob = Py_InitModule3(name, methods, doc);
38 #define PyInt_AsLong PyLong_AsLong
39 #define PyInt_Check PyLong_Check
40 #define MOD_ERROR_VAL NULL
41 #define MOD_SUCCESS_VAL(val) val
42 #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
43 #define MOD_DEF(ob, name, doc, methods) \
44 static struct PyModuleDef moduledef = { \
45 PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
46 ob = PyModule_Create(&moduledef);
49 MOD_INIT(pycryptsetup);
54 /* Type-specific fields go here. */
55 struct crypt_device *device;
59 PyObject *yesDialogCB;
60 PyObject *cmdLineLogCB;
61 PyObject *passwordDialogCB;
64 static int yesDialog(const char *msg, void *this)
66 CryptSetupObject *self = this;
67 PyObject *result, *arglist;
70 if (self->yesDialogCB){
71 arglist = Py_BuildValue("(s)", msg);
75 result = PyEval_CallObject(self->yesDialogCB, arglist);
81 if (!PyArg_Parse(result, "i", &r))
91 static int passwordDialog(const char *msg, char *buf, size_t length, void *this)
93 CryptSetupObject *self = this;
94 PyObject *result, *arglist;
98 if(self->passwordDialogCB){
99 arglist = Py_BuildValue("(s)", msg);
103 result = PyEval_CallObject(self->passwordDialogCB, arglist);
109 if (!PyArg_Parse(result, "z", &res)) {
114 strncpy(buf, res, length - 1);
126 static void cmdLineLog(int cls, const char *msg, void *this)
128 CryptSetupObject *self = this;
129 PyObject *result, *arglist;
131 if(self->cmdLineLogCB) {
132 arglist = Py_BuildValue("(is)", cls, msg);
136 result = PyEval_CallObject(self->cmdLineLogCB, arglist);
142 static void CryptSetup_dealloc(CryptSetupObject* self)
144 /* free the callbacks */
145 Py_XDECREF(self->yesDialogCB);
146 Py_XDECREF(self->cmdLineLogCB);
147 Py_XDECREF(self->passwordDialogCB);
149 free(self->activated_as);
151 crypt_free(self->device);
154 Py_TYPE(self)->tp_free((PyObject*)self);
157 static PyObject *CryptSetup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
159 CryptSetupObject *self = (CryptSetupObject *)type->tp_alloc(type, 0);
162 self->yesDialogCB = NULL;
163 self->passwordDialogCB = NULL;
164 self->cmdLineLogCB = NULL;
165 self->activated_as = NULL;
168 return (PyObject *)self;
171 static PyObject *PyObjectResult(int is)
173 PyObject *result = Py_BuildValue("i", is);
176 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
183 "CryptSetup object\n\n\
184 constructor takes one to five arguments:\n\
185 __init__(device, name, yesDialog, passwordDialog, logFunc)\n\n\
186 yesDialog - python function with func(text) signature, \n\
187 which asks the user question text and returns 1\n\
188 of the answer was positive or 0 if not\n\
189 logFunc - python function with func(level, text) signature to log stuff somewhere";
191 static int CryptSetup_init(CryptSetupObject* self, PyObject *args, PyObject *kwds)
193 static const char *kwlist[] = {"device", "name", "yesDialog", "passwordDialog", "logFunc", NULL};
194 PyObject *yesDialogCB = NULL,
195 *passwordDialogCB = NULL,
196 *cmdLineLogCB = NULL,
198 char *device = NULL, *deviceName = NULL;
201 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOOO", CONST_CAST(char**)kwlist, &device, &deviceName,
202 &yesDialogCB, &passwordDialogCB, &cmdLineLogCB))
206 if (crypt_init(&(self->device), device)) {
207 PyErr_SetString(PyExc_IOError, "Device cannot be opened");
210 /* Try to load header form device */
211 r = crypt_load(self->device, NULL, NULL);
212 if (r && r != -EINVAL) {
213 PyErr_SetString(PyExc_RuntimeError, "Cannot initialize device context");
216 } else if (deviceName) {
217 if (crypt_init_by_name(&(self->device), deviceName)) {
218 PyErr_SetString(PyExc_IOError, "Device cannot be opened");
221 /* Context is initialized automatically from active device */
223 PyErr_SetString(PyExc_RuntimeError, "Either device file or luks name has to be specified");
228 self->activated_as = strdup(deviceName);
231 tmp = self->yesDialogCB;
232 Py_INCREF(yesDialogCB);
233 self->yesDialogCB = yesDialogCB;
235 crypt_set_confirm_callback(self->device, yesDialog, self);
238 if (passwordDialogCB) {
239 tmp = self->passwordDialogCB;
240 Py_INCREF(passwordDialogCB);
241 self->passwordDialogCB = passwordDialogCB;
243 crypt_set_password_callback(self->device, passwordDialog, self);
247 tmp = self->cmdLineLogCB;
248 Py_INCREF(cmdLineLogCB);
249 self->cmdLineLogCB = cmdLineLogCB;
251 crypt_set_log_callback(self->device, cmdLineLog, self);
258 CryptSetup_activate_HELP[] =
259 "Activate LUKS device\n\n\
262 static PyObject *CryptSetup_activate(CryptSetupObject* self, PyObject *args, PyObject *kwds)
264 static const char *kwlist[] = {"name", "passphrase", NULL};
265 char *name = NULL, *passphrase = NULL;
268 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s", CONST_CAST(char**)kwlist, &name, &passphrase))
271 // FIXME: allow keyfile and \0 in passphrase
272 is = crypt_activate_by_passphrase(self->device, name, CRYPT_ANY_SLOT,
273 passphrase, passphrase ? strlen(passphrase) : 0, 0);
276 free(self->activated_as);
277 self->activated_as = strdup(name);
280 return PyObjectResult(is);
284 CryptSetup_deactivate_HELP[] =
285 "Dectivate LUKS device\n\n\
288 static PyObject *CryptSetup_deactivate(CryptSetupObject* self, PyObject *args, PyObject *kwds)
290 int is = crypt_deactivate(self->device, self->activated_as);
293 free(self->activated_as);
294 self->activated_as = NULL;
297 return PyObjectResult(is);
301 CryptSetup_askyes_HELP[] =
302 "Asks a question using the configured dialog CB\n\n\
303 int askyes(message)";
305 static PyObject *CryptSetup_askyes(CryptSetupObject* self, PyObject *args, PyObject *kwds)
307 static const char *kwlist[] = {"message", NULL};
308 PyObject *message = NULL, *result, *arglist;
310 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", CONST_CAST(char**)kwlist, &message))
315 arglist = Py_BuildValue("(O)", message);
317 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for internal call");
321 result = PyEval_CallObject(self->yesDialogCB, arglist);
329 CryptSetup_log_HELP[] =
330 "Logs a string using the configured log CB\n\n\
331 log(int level, message)";
333 static PyObject *CryptSetup_log(CryptSetupObject* self, PyObject *args, PyObject *kwds)
335 static const char *kwlist[] = {"priority", "message", NULL};
336 PyObject *message = NULL, *priority = NULL, *result, *arglist;
338 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", CONST_CAST(char**)kwlist, &message, &priority))
344 arglist = Py_BuildValue("(OO)", message, priority);
346 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for internal call");
350 result = PyEval_CallObject(self->cmdLineLogCB, arglist);
359 CryptSetup_luksUUID_HELP[] =
360 "Get UUID of the LUKS device\n\n\
363 static PyObject *CryptSetup_luksUUID(CryptSetupObject* self, PyObject *args, PyObject *kwds)
367 result = Py_BuildValue("s", crypt_get_uuid(self->device));
369 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
375 CryptSetup_isLuks_HELP[] =
376 "Is the device LUKS?\n\n\
379 static PyObject *CryptSetup_isLuks(CryptSetupObject* self, PyObject *args, PyObject *kwds)
381 return PyObjectResult(crypt_load(self->device, CRYPT_LUKS1, NULL));
385 CryptSetup_Info_HELP[] =
386 "Returns dictionary with info about opened device\nKeys:\n\
387 dir\n name\n uuid\n cipher\n cipher_mode\n keysize\n device\n\
388 offset\n size\n skip\n mode\n";
390 static PyObject *CryptSetup_Info(CryptSetupObject* self, PyObject *args, PyObject *kwds)
394 result = Py_BuildValue("{s:s,s:s,s:z,s:s,s:s,s:s,s:i,s:K}",
395 "dir", crypt_get_dir(),
396 "device", crypt_get_device_name(self->device),
397 "name", self->activated_as,
398 "uuid", crypt_get_uuid(self->device),
399 "cipher", crypt_get_cipher(self->device),
400 "cipher_mode", crypt_get_cipher_mode(self->device),
401 "keysize", crypt_get_volume_key_size(self->device) * 8,
403 //"mode", (co.flags & CRYPT_FLAG_READONLY) ? "readonly" : "read/write",
404 "offset", crypt_get_data_offset(self->device)
408 PyErr_SetString(PyExc_RuntimeError, "Error during constructing values for return value");
414 CryptSetup_luksFormat_HELP[] =
415 "Format device to enable LUKS\n\n\
416 luksFormat(cipher = 'aes', cipherMode = 'cbc-essiv:sha256', keysize = 256)\n\n\
417 cipher - cipher specification, e.g. aes, serpent\n\
418 cipherMode - cipher mode specification, e.g. cbc-essiv:sha256, xts-plain64\n\
419 keysize - key size in bits";
421 static PyObject *CryptSetup_luksFormat(CryptSetupObject* self, PyObject *args, PyObject *kwds)
423 static const char *kwlist[] = {"cipher", "cipherMode", "keysize", NULL};
424 char *cipher_mode = NULL, *cipher = NULL;
426 PyObject *keysize_object = NULL;
428 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzO", CONST_CAST(char**)kwlist,
429 &cipher, &cipher_mode, &keysize_object))
432 if (!keysize_object || keysize_object == Py_None) {
433 /* use default value */
434 } else if (!PyInt_Check(keysize_object)) {
435 PyErr_SetString(PyExc_TypeError, "keysize must be an integer");
437 } else if (PyInt_AsLong(keysize_object) % 8) {
438 PyErr_SetString(PyExc_TypeError, "keysize must have integer value dividable by 8");
440 } else if (PyInt_AsLong(keysize_object) <= 0) {
441 PyErr_SetString(PyExc_TypeError, "keysize must be positive number bigger than 0");
444 keysize = PyInt_AsLong(keysize_object);
446 // FIXME use #defined defaults
447 return PyObjectResult(crypt_format(self->device, CRYPT_LUKS1,
448 cipher ?: "aes", cipher_mode ?: "cbc-essiv:sha256",
449 NULL, NULL, keysize / 8, NULL));
453 CryptSetup_addKeyByPassphrase_HELP[] =
454 "Initialize keyslot using passphrase\n\n\
455 addKeyByPassphrase(passphrase, newPassphrase, slot)\n\n\
456 passphrase - string or none to ask the user\n\
457 newPassphrase - passphrase to add\n\
458 slot - which slot to use (optional)";
460 static PyObject *CryptSetup_addKeyByPassphrase(CryptSetupObject* self, PyObject *args, PyObject *kwds)
462 static const char *kwlist[] = {"passphrase", "newPassphrase", "slot", NULL};
463 char *passphrase = NULL, *newpassphrase = NULL;
464 size_t passphrase_len = 0, newpassphrase_len = 0;
465 int slot = CRYPT_ANY_SLOT;
467 if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|i", CONST_CAST(char**)kwlist, &passphrase, &newpassphrase, &slot))
471 passphrase_len = strlen(passphrase);
474 newpassphrase_len = strlen(newpassphrase);
476 return PyObjectResult(crypt_keyslot_add_by_passphrase(self->device, slot,
477 passphrase, passphrase_len,
478 newpassphrase, newpassphrase_len));
482 CryptSetup_addKeyByVolumeKey_HELP[] =
483 "Initialize keyslot using cached volume key\n\n\
484 addKeyByVolumeKey(passphrase, newPassphrase, slot)\n\n\
485 newPassphrase - passphrase to add\n\
486 slot - which slot to use (optional)";
488 static PyObject *CryptSetup_addKeyByVolumeKey(CryptSetupObject* self, PyObject *args, PyObject *kwds)
490 static const char *kwlist[] = {"newPassphrase", "slot", NULL};
491 char *newpassphrase = NULL;
492 size_t newpassphrase_len = 0;
493 int slot = CRYPT_ANY_SLOT;
495 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", CONST_CAST(char**)kwlist, &newpassphrase, &slot))
499 newpassphrase_len = strlen(newpassphrase);
501 return PyObjectResult(crypt_keyslot_add_by_volume_key(self->device, slot,
502 NULL, 0, newpassphrase, newpassphrase_len));
506 CryptSetup_removePassphrase_HELP[] =
507 "Destroy keyslot using passphrase\n\n\
508 removePassphrase(passphrase)\n\n\
509 passphrase - string or none to ask the user";
511 static PyObject *CryptSetup_removePassphrase(CryptSetupObject* self, PyObject *args, PyObject *kwds)
513 static const char *kwlist[] = {"passphrase", NULL};
514 char *passphrase = NULL;
515 size_t passphrase_len = 0;
518 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", CONST_CAST(char**)kwlist, &passphrase))
522 passphrase_len = strlen(passphrase);
524 is = crypt_activate_by_passphrase(self->device, NULL, CRYPT_ANY_SLOT,
525 passphrase, passphrase_len, 0);
527 return PyObjectResult(is);
529 return PyObjectResult(crypt_keyslot_destroy(self->device, is));
533 CryptSetup_killSlot_HELP[] =
534 "Destroy keyslot\n\n\
536 slot - the slot to remove";
538 static PyObject *CryptSetup_killSlot(CryptSetupObject* self, PyObject *args, PyObject *kwds)
540 static const char *kwlist[] = {"slot", NULL};
541 int slot = CRYPT_ANY_SLOT;
543 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", CONST_CAST(char**)kwlist, &slot))
546 switch (crypt_keyslot_status(self->device, slot)) {
547 case CRYPT_SLOT_ACTIVE:
548 return PyObjectResult(crypt_keyslot_destroy(self->device, slot));
549 case CRYPT_SLOT_ACTIVE_LAST:
550 PyErr_SetString(PyExc_ValueError, "Last slot, removing it would render the device unusable");
552 case CRYPT_SLOT_INACTIVE:
553 PyErr_SetString(PyExc_ValueError, "Inactive slot");
555 case CRYPT_SLOT_INVALID:
556 PyErr_SetString(PyExc_ValueError, "Invalid slot");
564 CryptSetup_Status_HELP[] =
565 "Status of LUKS device\n\n\
568 static PyObject *CryptSetup_Status(CryptSetupObject* self, PyObject *args, PyObject *kwds)
570 if (!self->activated_as){
571 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
575 return PyObjectResult(crypt_status(self->device, self->activated_as));
579 CryptSetup_Resume_HELP[] =
580 "Resume LUKS device\n\n\
581 luksOpen(passphrase)\n\n\
582 passphrase - string or none to ask the user";
584 static PyObject *CryptSetup_Resume(CryptSetupObject* self, PyObject *args, PyObject *kwds)
586 static const char *kwlist[] = {"passphrase", NULL};
587 char* passphrase = NULL;
588 size_t passphrase_len = 0;
590 if (!self->activated_as){
591 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
595 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s", CONST_CAST(char**)kwlist, &passphrase))
599 passphrase_len = strlen(passphrase);
601 return PyObjectResult(crypt_resume_by_passphrase(self->device, self->activated_as,
602 CRYPT_ANY_SLOT, passphrase, passphrase_len));
606 CryptSetup_Suspend_HELP[] =
607 "Suspend LUKS device\n\n\
610 static PyObject *CryptSetup_Suspend(CryptSetupObject* self, PyObject *args, PyObject *kwds)
612 if (!self->activated_as){
613 PyErr_SetString(PyExc_IOError, "Device has not been activated yet.");
617 return PyObjectResult(crypt_suspend(self->device, self->activated_as));
621 CryptSetup_debugLevel_HELP[] =
622 "Set debug level\n\n\
623 debugLevel(level)\n\n\
624 level - debug level";
626 static PyObject *CryptSetup_debugLevel(CryptSetupObject* self, PyObject *args, PyObject *kwds)
628 static const char *kwlist[] = {"level", NULL};
631 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", CONST_CAST(char**)kwlist, &level))
634 crypt_set_debug_level(level);
640 CryptSetup_iterationTime_HELP[] =
641 "Set iteration time\n\n\
642 iterationTime(time_ms)\n\n\
643 time_ms - time in miliseconds";
645 static PyObject *CryptSetup_iterationTime(CryptSetupObject* self, PyObject *args, PyObject *kwds)
647 static const char *kwlist[] = {"time_ms", NULL};
648 uint64_t time_ms = 0;
650 if (!PyArg_ParseTupleAndKeywords(args, kwds, "K", CONST_CAST(char**)kwlist, &time_ms))
653 crypt_set_iteration_time(self->device, time_ms);
658 static PyMemberDef CryptSetup_members[] = {
659 {CONST_CAST(char*)"yesDialogCB", T_OBJECT_EX, offsetof(CryptSetupObject, yesDialogCB), 0, CONST_CAST(char*)"confirmation dialog callback"},
660 {CONST_CAST(char*)"cmdLineLogCB", T_OBJECT_EX, offsetof(CryptSetupObject, cmdLineLogCB), 0, CONST_CAST(char*)"logging callback"},
661 {CONST_CAST(char*)"passwordDialogCB", T_OBJECT_EX, offsetof(CryptSetupObject, passwordDialogCB), 0, CONST_CAST(char*)"password dialog callback"},
665 static PyMethodDef CryptSetup_methods[] = {
666 /* self-test methods */
667 {"log", (PyCFunction)CryptSetup_log, METH_VARARGS|METH_KEYWORDS, CryptSetup_askyes_HELP},
668 {"askyes", (PyCFunction)CryptSetup_askyes, METH_VARARGS|METH_KEYWORDS, CryptSetup_log_HELP},
670 /* activation and deactivation */
671 {"deactivate", (PyCFunction)CryptSetup_deactivate, METH_NOARGS, CryptSetup_deactivate_HELP},
672 {"activate", (PyCFunction)CryptSetup_activate, METH_VARARGS|METH_KEYWORDS, CryptSetup_activate_HELP},
674 /* cryptsetup info entrypoints */
675 {"luksUUID", (PyCFunction)CryptSetup_luksUUID, METH_NOARGS, CryptSetup_luksUUID_HELP},
676 {"isLuks", (PyCFunction)CryptSetup_isLuks, METH_NOARGS, CryptSetup_isLuks_HELP},
677 {"info", (PyCFunction)CryptSetup_Info, METH_NOARGS, CryptSetup_Info_HELP},
678 {"status", (PyCFunction)CryptSetup_Status, METH_NOARGS, CryptSetup_Status_HELP},
680 /* cryptsetup mgmt entrypoints */
681 {"luksFormat", (PyCFunction)CryptSetup_luksFormat, METH_VARARGS|METH_KEYWORDS, CryptSetup_luksFormat_HELP},
682 {"addKeyByPassphrase", (PyCFunction)CryptSetup_addKeyByPassphrase, METH_VARARGS|METH_KEYWORDS, CryptSetup_addKeyByPassphrase_HELP},
683 {"addKeyByVolumeKey", (PyCFunction)CryptSetup_addKeyByVolumeKey, METH_VARARGS|METH_KEYWORDS, CryptSetup_addKeyByVolumeKey_HELP},
684 {"removePassphrase", (PyCFunction)CryptSetup_removePassphrase, METH_VARARGS|METH_KEYWORDS, CryptSetup_removePassphrase_HELP},
685 {"killSlot", (PyCFunction)CryptSetup_killSlot, METH_VARARGS|METH_KEYWORDS, CryptSetup_killSlot_HELP},
688 {"resume", (PyCFunction)CryptSetup_Resume, METH_VARARGS|METH_KEYWORDS, CryptSetup_Resume_HELP},
689 {"suspend", (PyCFunction)CryptSetup_Suspend, METH_NOARGS, CryptSetup_Suspend_HELP},
692 {"debugLevel", (PyCFunction)CryptSetup_debugLevel, METH_VARARGS|METH_KEYWORDS, CryptSetup_debugLevel_HELP},
693 {"iterationTime", (PyCFunction)CryptSetup_iterationTime, METH_VARARGS|METH_KEYWORDS, CryptSetup_iterationTime_HELP},
695 {NULL} /* Sentinel */
698 static PyTypeObject CryptSetupType = {
699 PyVarObject_HEAD_INIT(NULL, 0)
700 "pycryptsetup.CryptSetup", /*tp_name*/
701 sizeof(CryptSetupObject), /*tp_basicsize*/
703 (destructor)CryptSetup_dealloc, /*tp_dealloc*/
710 0, /*tp_as_sequence*/
718 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
719 CryptSetup_HELP, /* tp_doc */
722 0, /* tp_richcompare */
723 0, /* tp_weaklistoffset */
726 CryptSetup_methods, /* tp_methods */
727 CryptSetup_members, /* tp_members */
731 0, /* tp_descr_get */
732 0, /* tp_descr_set */
733 0, /* tp_dictoffset */
734 (initproc)CryptSetup_init, /* tp_init */
736 CryptSetup_new, /* tp_new */
739 static PyMethodDef pycryptsetup_methods[] = {
740 {NULL} /* Sentinel */
743 MOD_INIT(pycryptsetup)
747 if (PyType_Ready(&CryptSetupType) < 0)
748 return MOD_ERROR_VAL;
750 MOD_DEF(m, "pycryptsetup", "CryptSetup pythonized API.", pycryptsetup_methods);
751 Py_INCREF(&CryptSetupType);
753 PyModule_AddObject(m, "CryptSetup", (PyObject *)&CryptSetupType);
755 /* debug constants */
756 PyModule_AddIntConstant(m, "CRYPT_DEBUG_ALL", CRYPT_DEBUG_ALL);
757 PyModule_AddIntConstant(m, "CRYPT_DEBUG_NONE", CRYPT_DEBUG_NONE);
760 PyModule_AddIntConstant(m, "CRYPT_LOG_NORMAL", CRYPT_LOG_NORMAL);
761 PyModule_AddIntConstant(m, "CRYPT_LOG_ERROR", CRYPT_LOG_ERROR);
762 PyModule_AddIntConstant(m, "CRYPT_LOG_VERBOSE", CRYPT_LOG_VERBOSE);
763 PyModule_AddIntConstant(m, "CRYPT_LOG_DEBUG", CRYPT_LOG_DEBUG);
765 /* status constants */
766 PyModule_AddIntConstant(m, "CRYPT_INVALID", CRYPT_INVALID);
767 PyModule_AddIntConstant(m, "CRYPT_INACTIVE", CRYPT_INACTIVE);
768 PyModule_AddIntConstant(m, "CRYPT_ACTIVE", CRYPT_ACTIVE);
769 PyModule_AddIntConstant(m, "CRYPT_BUSY", CRYPT_BUSY);
771 return MOD_SUCCESS_VAL(m);