Skip to content

Commit

Permalink
Add _tmp_bn_mont_ctx context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxxy committed Apr 18, 2018
1 parent 7d52269 commit ccdc933
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cryptography/hazmat/backends/openssl/backend.py
Expand Up @@ -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
Expand Down

0 comments on commit ccdc933

Please sign in to comment.