Exemple #1
0
 def _load_backend_mixin(mixin_cls, name, dryrun):
     from passlib.utils import as_bool
     if not as_bool(os.environ.get("PASSLIB_BUILTIN_BCRYPT")):
         log.debug("bcrypt 'builtin' backend not enabled via $PASSLIB_BUILTIN_BCRYPT")
         return False
     global _builtin_bcrypt
     from passlib.crypto._blowfish import raw_bcrypt as _builtin_bcrypt
     return mixin_cls._finalize_backend_mixin(name, dryrun)
Exemple #2
0
 def _load_backend_mixin(mixin_cls, name, dryrun):
     from passlib.utils import as_bool
     if not as_bool(os.environ.get("PASSLIB_BUILTIN_BCRYPT")):
         log.debug("bcrypt 'builtin' backend not enabled via $PASSLIB_BUILTIN_BCRYPT")
         return False
     global _builtin_bcrypt
     from passlib.crypto._blowfish import raw_bcrypt as _builtin_bcrypt
     return mixin_cls._finalize_backend_mixin(name, dryrun)
Exemple #3
0
    'shake_128',
    'shake_256',
}


def _set_mock_fips_mode(enable=True):
    """
    UT helper which monkeypatches lookup_hash() internals to replicate FIPS mode.
    """
    global mock_fips_mode
    mock_fips_mode = enable
    lookup_hash.clear_cache()


# helper for UTs
if as_bool(os.environ.get("PASSLIB_MOCK_FIPS_MODE")):
    _set_mock_fips_mode()

#=============================================================================
# hmac utils
#=============================================================================

#: translation tables used by compile_hmac()
_TRANS_5C = join_byte_values((x ^ 0x5C) for x in irange(256))
_TRANS_36 = join_byte_values((x ^ 0x36) for x in irange(256))


def compile_hmac(digest, key, multipart=False):
    """
    This function returns an efficient HMAC function, hardcoded with a specific digest & key.
    It can be used via ``hmac = compile_hmac(digest, key)``.