diff options
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 4dd544cf..31ffe0d1 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -61,34 +61,48 @@ class Backend(object): self.activate_osrandom_engine() def deactivate_osrandom_engine(self): + # obtains a new structural reference e = self._lib.ENGINE_get_default_RAND() if e != self._ffi.NULL: + # this obtains the name of the engine but does not obtain a + # structural or functional reference name = self._lib.ENGINE_get_name(e) assert name != self._ffi.NULL if name == self._lib.Cryptography_osrandom_engine_name: + # removes the engine provided from the list of available RAND + # engines. self._lib.ENGINE_unregister_RAND(e) # this resets the RNG to use the new engine self._lib.RAND_cleanup() + # decrement the structural reference from get_default_RAND res = self._lib.ENGINE_finish(e) assert res == 1 def activate_osrandom_engine(self): + # obtains a new structural reference current_rand = self._lib.ENGINE_get_default_RAND() if current_rand != self._ffi.NULL: + # this obtains the name of the engine but does not obtain a + # structural or functional reference name = self._lib.ENGINE_get_name(current_rand) assert name != self._ffi.NULL if name != self._lib.Cryptography_osrandom_engine_name: self._activate_osrandom_engine() + # decrement the structural reference from get_default_RAND res = self._lib.ENGINE_finish(current_rand) assert res == 1 else: self._activate_osrandom_engine() def _activate_osrandom_engine(self): + # Fetches an engine by id and returns it. This creates a structural + # reference. e = self._lib.ENGINE_by_id(self._lib.Cryptography_osrandom_engine_id) assert e != self._ffi.NULL + # Initialize the engine for use. This adds a functional reference. res = self._lib.ENGINE_init(e) assert res == 1 + # Set the engine as the default RAND provider. res = self._lib.ENGINE_set_default_RAND(e) assert res == 1 # decrement the structural ref incremented by ENGINE_by_id @@ -97,7 +111,7 @@ class Backend(object): # decrement the functional ref incremented by ENGINE_init res = self._lib.ENGINE_finish(e) assert res == 1 - # this resets the RNG to use the new engine + # Reset the RNG to use the new engine self._lib.RAND_cleanup() def openssl_version_text(self): |