Skip to content

Commit

Permalink
Merge ccdc933 into cd46145
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxxy committed Apr 18, 2018
2 parents cd46145 + ccdc933 commit 5d7d820
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/_cffi_src/openssl/bignum.py
Expand Up @@ -10,11 +10,17 @@

TYPES = """
typedef ... BN_CTX;
typedef ... BN_MONT_CTX;
typedef ... BIGNUM;
typedef int... BN_ULONG;
"""

FUNCTIONS = """
#define BN_FLG_CONSTTIME ...
void BN_set_flags(BIGNUM *, int);
int BN_get_flags(const BIGNUM *, int);
BIGNUM *BN_new(void);
void BN_free(BIGNUM *);
void BN_clear_free(BIGNUM *);
Expand All @@ -29,6 +35,10 @@
BIGNUM *BN_CTX_get(BN_CTX *);
void BN_CTX_end(BN_CTX *);
BN_MONT_CTX *BN_MONT_CTX_new(void);
int BN_MONT_CTX_set(BN_MONT_CTX *, BIGNUM *, BN_CTX *);
void BN_MONT_CTX_free(BN_MONT_CTX *);
BIGNUM *BN_copy(BIGNUM *, const BIGNUM *);
BIGNUM *BN_dup(const BIGNUM *);
Expand Down Expand Up @@ -63,6 +73,10 @@
int BN_exp(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
int BN_mod_exp(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
BN_CTX *);
int BN_mod_exp_mont(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
BN_CTX *, BN_MONT_CTX *);
int BN_mod_exp_mont_consttime(BIGNUM *, const BIGNUM *, const BIGNUM *,
const BIGNUM *, BN_CTX *, BN_MONT_CTX *);
int BN_gcd(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
BIGNUM *BN_mod_inverse(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
Expand Down
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 5d7d820

Please sign in to comment.