本文整理汇总了Python中cryptography.hazmat.primitives.kdf.scrypt._MEM_LIMIT属性的典型用法代码示例。如果您正苦于以下问题:Python scrypt._MEM_LIMIT属性的具体用法?Python scrypt._MEM_LIMIT怎么用?Python scrypt._MEM_LIMIT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cryptography.hazmat.primitives.kdf.scrypt
的用法示例。
在下文中一共展示了scrypt._MEM_LIMIT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: derive_scrypt
# 需要导入模块: from cryptography.hazmat.primitives.kdf import scrypt [as 别名]
# 或者: from cryptography.hazmat.primitives.kdf.scrypt import _MEM_LIMIT [as 别名]
def derive_scrypt(self, key_material, salt, length, n, r, p):
buf = self._ffi.new("unsigned char[]", length)
res = self._lib.EVP_PBE_scrypt(
key_material, len(key_material), salt, len(salt), n, r, p,
scrypt._MEM_LIMIT, buf, length
)
self.openssl_assert(res == 1)
return self._ffi.buffer(buf)[:]
示例2: derive_scrypt
# 需要导入模块: from cryptography.hazmat.primitives.kdf import scrypt [as 别名]
# 或者: from cryptography.hazmat.primitives.kdf.scrypt import _MEM_LIMIT [as 别名]
def derive_scrypt(self, key_material, salt, length, n, r, p):
buf = self._ffi.new("unsigned char[]", length)
key_material_ptr = self._ffi.from_buffer(key_material)
res = self._lib.EVP_PBE_scrypt(
key_material_ptr, len(key_material), salt, len(salt), n, r, p,
scrypt._MEM_LIMIT, buf, length
)
if res != 1:
errors = self._consume_errors()
if not self._lib.CRYPTOGRAPHY_OPENSSL_LESS_THAN_111:
# This error is only added to the stack in 1.1.1+
self.openssl_assert(
errors[0]._lib_reason_match(
self._lib.ERR_LIB_EVP,
self._lib.ERR_R_MALLOC_FAILURE
) or
errors[0]._lib_reason_match(
self._lib.ERR_LIB_EVP,
self._lib.EVP_R_MEMORY_LIMIT_EXCEEDED
)
)
# memory required formula explained here:
# https://blog.filippo.io/the-scrypt-parameters/
min_memory = 128 * n * r // (1024**2)
raise MemoryError(
"Not enough memory to derive key. These parameters require"
" {} MB of memory.".format(min_memory)
)
return self._ffi.buffer(buf)[:]