本文整理汇总了Python中Crypto.Hash.SHA384属性的典型用法代码示例。如果您正苦于以下问题:Python Hash.SHA384属性的具体用法?Python Hash.SHA384怎么用?Python Hash.SHA384使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Crypto.Hash
的用法示例。
在下文中一共展示了Hash.SHA384属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [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)
示例2: get_hash_module
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [as 别名]
def get_hash_module(hash_name):
if hash_name == "SHA-512":
hash_module = SHA512
elif hash_name == "SHA-512/224":
hash_module = SHA512.new(truncate="224")
elif hash_name == "SHA-512/256":
hash_module = SHA512.new(truncate="256")
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
示例3: runTest
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [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)
示例4: get_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [as 别名]
def get_tests(config={}):
from Crypto.Hash import SHA384
from common import make_hash_tests
return make_hash_tests(SHA384, "SHA384", test_data,
digest_size=48,
oid='\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02')
示例5: get_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [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)
示例6: get_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [as 别名]
def get_tests(config={}):
from Crypto.Hash import SHA384
from .common import make_hash_tests
return make_hash_tests(SHA384, "SHA384", test_data,
digest_size=48,
oid='2.16.840.1.101.3.4.2.2')
示例7: test3
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [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)
示例8: add_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [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)
示例9: add_tests
# 需要导入模块: from Crypto import Hash [as 别名]
# 或者: from Crypto.Hash import SHA384 [as 别名]
def add_tests(self, filename):
comps = "Crypto.SelfTest.Signature.test_vectors.wycheproof".split(".")
with open(pycryptodome_filename(comps, filename), "rt") as file_in:
tv_tree = json.load(file_in)
class TestVector(object):
pass
self.tv = []
for group in tv_tree['testGroups']:
key = RSA.import_key(group['keyPem'])
hash_name = group['sha']
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)
assert group['type'] == "RSASigVer"
for test in group['tests']:
tv = TestVector()
tv.id = test['tcId']
tv.comment = test['comment']
for attr in 'msg', 'sig':
setattr(tv, attr, unhexlify(test[attr]))
tv.key = key
tv.hash_module = hash_module
tv.valid = test['result'] != "invalid"
tv.warning = test['result'] == "acceptable"
self.tv.append(tv)