本文整理汇总了Python中Crypto.Hash.SHA512属性的典型用法代码示例。如果您正苦于以下问题:Python Hash.SHA512属性的具体用法?Python Hash.SHA512怎么用?Python Hash.SHA512使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Crypto.Hash
的用法示例。
在下文中一共展示了Hash.SHA512属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tests_SHA512
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_tests_SHA512():
test_vectors = load_tests(("Crypto", "SelfTest", "Hash", "test_vectors", "SHA2"),
"SHA512ShortMsg.rsp",
"KAT SHA-512",
{ "len" : lambda x: int(x) } )
test_data = test_data_512_other[:]
for tv in test_vectors:
try:
if tv.startswith('['):
continue
except AttributeError:
pass
if tv.len == 0:
tv.msg = b""
test_data.append((hexlify(tv.md), tv.msg, tv.desc))
tests = make_hash_tests(SHA512, "SHA512", test_data,
digest_size=64,
oid="2.16.840.1.101.3.4.2.3")
return tests
示例2: get_tests_SHA512_224
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_tests_SHA512_224():
test_vectors = load_tests(("Crypto", "SelfTest", "Hash", "test_vectors", "SHA2"),
"SHA512_224ShortMsg.rsp",
"KAT SHA-512/224",
{ "len" : lambda x: int(x) } )
test_data = []
for tv in test_vectors:
try:
if tv.startswith('['):
continue
except AttributeError:
pass
if tv.len == 0:
tv.msg = b""
test_data.append((hexlify(tv.md), tv.msg, tv.desc))
tests = make_hash_tests(SHA512, "SHA512/224", test_data,
digest_size=28,
oid="2.16.840.1.101.3.4.2.5",
extra_params={ "truncate" : "224" })
return tests
示例3: get_tests_SHA512_256
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_tests_SHA512_256():
test_vectors = load_tests(("Crypto", "SelfTest", "Hash", "test_vectors", "SHA2"),
"SHA512_256ShortMsg.rsp",
"KAT SHA-512/256",
{ "len" : lambda x: int(x) } )
test_data = []
for tv in test_vectors:
try:
if tv.startswith('['):
continue
except AttributeError:
pass
if tv.len == 0:
tv.msg = b""
test_data.append((hexlify(tv.md), tv.msg, tv.desc))
tests = make_hash_tests(SHA512, "SHA512/256", test_data,
digest_size=32,
oid="2.16.840.1.101.3.4.2.6",
extra_params={ "truncate" : "256" })
return tests
示例4: runTest
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def runTest(self):
key = RSA.generate(1024)
signer = pkcs1_15.new(key)
hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
"SHA224", "SHA256", "SHA384", "SHA512",
"SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")
for name in hash_names:
hashed = load_hash_by_name(name).new(b"Test")
signer.sign(hashed)
from Crypto.Hash import BLAKE2b, BLAKE2s
for hash_size in (20, 32, 48, 64):
hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b"Test")
signer.sign(hashed_b)
for hash_size in (16, 20, 28, 32):
hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b"Test")
signer.sign(hashed_s)
示例5: runTest
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def runTest(self):
key = RSA.generate(1280)
signer = pss.new(key)
hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
"SHA224", "SHA256", "SHA384", "SHA512",
"SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")
for name in hash_names:
hashed = load_hash_by_name(name).new(b("Test"))
signer.sign(hashed)
from Crypto.Hash import BLAKE2b, BLAKE2s
for hash_size in (20, 32, 48, 64):
hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b("Test"))
signer.sign(hashed_b)
for hash_size in (16, 20, 28, 32):
hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b("Test"))
signer.sign(hashed_s)
示例6: get_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_tests(config={}):
from Crypto.Hash import SHA512
from common import make_hash_tests
return make_hash_tests(SHA512, "SHA512", test_data,
digest_size=64,
oid="\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03")
示例7: get_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_tests(config={}):
global test_data
from Crypto.Hash import HMAC, MD5, SHA as SHA1, SHA256
from common import make_mac_tests
hashmods = dict(MD5=MD5, SHA1=SHA1, SHA256=SHA256, default=None)
try:
from Crypto.Hash import SHA224, SHA384, SHA512
hashmods.update(dict(SHA224=SHA224, SHA384=SHA384, SHA512=SHA512))
test_data += hashlib_test_data
except ImportError:
import sys
sys.stderr.write("SelfTest: warning: not testing HMAC-SHA224/384/512 (not available)\n")
return make_mac_tests(HMAC, "HMAC", test_data, hashmods)
示例8: test3
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def test3(self):
# Verify that hmac_hash_module works like prf
password = b("xxx")
salt = b("yyy")
for hashmod in (MD5, SHA1, SHA224, SHA256, SHA384, SHA512):
pr1 = PBKDF2(password, salt, 16, 100,
prf=lambda p, s: HMAC.new(p,s,hashmod).digest())
pr2 = PBKDF2(password, salt, 16, 100, hmac_hash_module=hashmod)
self.assertEqual(pr1, pr2)
示例9: add_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def add_tests(self, filename):
comps = "Crypto.SelfTest.Protocol.test_vectors.wycheproof".split(".")
with open(pycryptodome_filename(comps, filename), "rt") as file_in:
tv_tree = json.load(file_in)
algo_name = tv_tree['algorithm']
if algo_name == "HKDF-SHA-1":
hash_module = SHA1
elif algo_name == "HKDF-SHA-256":
hash_module = SHA256
elif algo_name == "HKDF-SHA-384":
hash_module = SHA384
elif algo_name == "HKDF-SHA-512":
hash_module = SHA512
else:
raise ValueError("Unknown algorithm " + algo_name)
for group in tv_tree['testGroups']:
from collections import namedtuple
TestVector = namedtuple('TestVector', 'id comment ikm salt info size okm hash_module valid warning filename')
for test in group['tests']:
tv = TestVector(
test['tcId'],
test['comment'],
unhexlify(test['ikm']),
unhexlify(test['salt']),
unhexlify(test['info']),
int(test['size']),
unhexlify(test['okm']),
hash_module,
test['result'] != "invalid",
test['result'] == "acceptable",
filename
)
self.tv.append(tv)
示例10: get_hash_module
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA512 [as 别名]
def get_hash_module(hash_name):
if hash_name == "SHA-512":
hash_module = SHA512
elif hash_name == "SHA-384":
hash_module = SHA384
elif hash_name == "SHA-256":
hash_module = SHA256
elif hash_name == "SHA-224":
hash_module = SHA224
elif hash_name == "SHA-1":
hash_module = SHA1
else:
raise ValueError("Unknown hash algorithm: " + hash_name)
return hash_module