diff options
author | john <john@f711b948-2313-0410-aaa9-d29f33439f0b> | 2008-03-10 22:54:53 +0000 |
---|---|---|
committer | john <john@f711b948-2313-0410-aaa9-d29f33439f0b> | 2008-03-10 22:54:53 +0000 |
commit | 5540677e73de473caa55bc5eb680ad87f6fc7979 (patch) | |
tree | f6554428550adfbe03c841d8deaae2f2c4f3a185 /crypto_utils.py | |
parent | b12c6b643f13bef290afb74e6435a6553a709195 (diff) |
added lifecycle commands to CardOS
Passive Authentication for BAC MRTDs
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@254 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'crypto_utils.py')
-rw-r--r-- | crypto_utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crypto_utils.py b/crypto_utils.py index c655e1e..59f0fba 100644 --- a/crypto_utils.py +++ b/crypto_utils.py @@ -42,6 +42,26 @@ def cipher(do_encrypt, cipherspec, key, data, iv = None): del cipher return result + +def hash(hashspec, data): + """Do a cryptographic hash operation. + hashspec must be of the form "cipher\"""" + from Crypto.Hash import SHA, RIPEMD, MD2, MD4, MD5 + + if len(hashspec) != 3 and len(hashspec) != 6: + raise ValueError, 'hashspec must be one of SHA, RIPEMD, MD2, MD4, MD5' + + h_class = locals().get(hashspec.upper(), None) + if h_class is None: + raise ValueError, "Hash '%s' not known, must be one of %s" % (hashspec, ", ".join([e.lower() for e in dir() if e.isupper()])) + + hash = h_class.new() + hash.update(data) + result = hash.digest() + #m.hexdigest() + + del hash + return result def operation_on_string(string1, string2, op): if len(string1) != len(string2): |