diff options
-rw-r--r-- | SWIG/_evp.i | 13 | ||||
-rw-r--r-- | tests/test_evp.py | 5 |
2 files changed, 16 insertions, 2 deletions
diff --git a/SWIG/_evp.i b/SWIG/_evp.i index d04e806..9a3b67b 100644 --- a/SWIG/_evp.i +++ b/SWIG/_evp.i @@ -430,8 +430,17 @@ PyObject *cipher_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, const void *kbuf, *ibuf; Py_ssize_t klen, ilen; - if ((PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) - || (PyObject_AsReadBuffer(iv, &ibuf, &ilen) == -1)) + if (cipher == Py_None) + cipher = NULL; + + if (key == Py_None) + kbuf = NULL; + else if (PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) + return NULL; + + if (iv == Py_None) + ibuf = NULL; + else if (PyObject_AsReadBuffer(iv, &ibuf, &ilen) == -1) return NULL; if (!EVP_CipherInit(ctx, cipher, (unsigned char *)kbuf, diff --git a/tests/test_evp.py b/tests/test_evp.py index d133ed0..fff7127 100644 --- a/tests/test_evp.py +++ b/tests/test_evp.py @@ -517,6 +517,11 @@ class CipherTestCase(unittest.TestCase): unhexlify('5cd148eeaf680d4ff933aed83009cad4110162f53ef89fd44fad09611b0524d4'), unhexlify('')) + def test_cipher_init_reinit(self): + ctx = m2.cipher_ctx_new() + m2.cipher_init(ctx, m2.aes_128_cbc(), b'\x01' * (128//8), b'\x02' * (128//8), 1) + m2.cipher_init(ctx, m2.aes_128_cbc(), None, None, 1) + class PBKDF2TestCase(unittest.TestCase): def test_rfc3211_test_vectors(self): |