From ccdc933edc0c4f1f6c848a9262e46d12766bd6e9 Mon Sep 17 00:00:00 2001 From: tuxxy Date: Tue, 17 Apr 2018 23:33:06 -0600 Subject: [PATCH] Add _tmp_bn_mont_ctx context manager --- src/cryptography/hazmat/backends/openssl/backend.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index 85e13b57266f..d1982053d149 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -1461,6 +1461,17 @@ def _tmp_bn_ctx(self): finally: self._lib.BN_CTX_end(bn_ctx) + @contextmanager + def _tmp_bn_mont_ctx(self, modulus): + bn_mont_ctx = self._lib.BN_MONT_CTX_new() + self.openssl_assert(bn_mont_ctx != self._ffi.NULL) + bn_mont_ctx = self._ffi.gc(bn_mont_ctx, self._lib.BN_MONT_CTX_free) + + with self._tmp_bn_ctx() as bn_ctx: + res = self._lib.BN_MONT_CTX_set(bn_mont_ctx, modulus, bn_ctx) + self.openssl_assert(res == 1) + yield bn_mont_ctx + def _ec_key_determine_group_get_func(self, ctx): """ Given an EC_KEY determine the group and what function is required to