diff options
| author | Legrandin <gooksankoo@hoiptorrow.mailexpire.com> | 2011-09-20 19:41:33 +0200 |
|---|---|---|
| committer | Legrandin <gooksankoo@hoiptorrow.mailexpire.com> | 2011-09-20 19:41:33 +0200 |
| commit | 01f280d0e262a98af5a0b2c3d2a785e1d0879778 (patch) | |
| tree | a0a97c8dc5cdf6f345ce0cef7123c40e3c48e9d4 /lib/Crypto/Hash | |
| parent | 2662ac5c94f00532ddfcd538c7090133e47fad34 (diff) | |
| parent | 86c4cf4ea66e926267f53348d22698774a7939a5 (diff) | |
| download | pycrypto-01f280d0e262a98af5a0b2c3d2a785e1d0879778.tar.gz | |
Merged with upstream.
Diffstat (limited to 'lib/Crypto/Hash')
| -rw-r--r-- | lib/Crypto/Hash/HMAC.py | 8 | ||||
| -rw-r--r-- | lib/Crypto/Hash/SHA.py | 1 | ||||
| -rw-r--r-- | lib/Crypto/Hash/SHA224.py | 51 | ||||
| -rw-r--r-- | lib/Crypto/Hash/SHA384.py | 52 | ||||
| -rw-r--r-- | lib/Crypto/Hash/SHA512.py | 52 |
5 files changed, 163 insertions, 1 deletions
diff --git a/lib/Crypto/Hash/HMAC.py b/lib/Crypto/Hash/HMAC.py index 4daff2f..96e0afc 100644 --- a/lib/Crypto/Hash/HMAC.py +++ b/lib/Crypto/Hash/HMAC.py @@ -76,7 +76,13 @@ class HMAC: except AttributeError: self.digest_size = len(self.outer.digest()) - blocksize = 64 + try: + # The block size is 128 bytes for SHA384 and SHA512 and 64 bytes + # for the others hash function + blocksize = digestmod.block_size + except AttributeError: + blocksize = 64 + ipad = 0x36 opad = 0x5C diff --git a/lib/Crypto/Hash/SHA.py b/lib/Crypto/Hash/SHA.py index c806f09..b7a8041 100644 --- a/lib/Crypto/Hash/SHA.py +++ b/lib/Crypto/Hash/SHA.py @@ -52,3 +52,4 @@ except ImportError: hashFactory = sha digest_size = 20 +block_size = 64 diff --git a/lib/Crypto/Hash/SHA224.py b/lib/Crypto/Hash/SHA224.py new file mode 100644 index 0000000..ca0bbf7 --- /dev/null +++ b/lib/Crypto/Hash/SHA224.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# +# =================================================================== +# The contents of this file are dedicated to the public domain. To +# the extent that dedication to the public domain is not available, +# everyone is granted a worldwide, perpetual, royalty-free, +# non-exclusive license to exercise all rights associated with the +# contents of this file for any purpose whatsoever. +# No rights are reserved. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# =================================================================== + +# Just use the SHA module from the Python standard library + +__revision__ = "$Id$" + +__all__ = ['new', 'digest_size'] + +from Crypto.Util.wrapper import Wrapper + +# The OID for SHA-224 is: +# +# id-sha224 OBJECT IDENTIFIER ::= { +# joint-iso-itu-t(2) +# country(16) us(840) organization(1) gov(101) csor(3) +# nistalgorithm(4) hashalgs(2) 4 +# } +oid = '\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04' + +def new(data=""): + obj = Wrapper(hashFactory, data) + obj.oid = oid + obj.new = globals()['new'] + if not hasattr(obj, 'digest_size'): + obj.digest_size = digest_size + return obj + +# TOFIX: This code will not work for python<2.5 +import hashlib +hashFactory = hashlib.sha224 + +digest_size = 28 +block_size = 64 diff --git a/lib/Crypto/Hash/SHA384.py b/lib/Crypto/Hash/SHA384.py new file mode 100644 index 0000000..88e8e4a --- /dev/null +++ b/lib/Crypto/Hash/SHA384.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# +# =================================================================== +# The contents of this file are dedicated to the public domain. To +# the extent that dedication to the public domain is not available, +# everyone is granted a worldwide, perpetual, royalty-free, +# non-exclusive license to exercise all rights associated with the +# contents of this file for any purpose whatsoever. +# No rights are reserved. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# =================================================================== + +# Just use the SHA module from the Python standard library + +__revision__ = "$Id$" + +__all__ = ['new', 'digest_size'] + +from Crypto.Util.wrapper import Wrapper + +# The OID for SHA-384 is: +# +# id-sha384 OBJECT IDENTIFIER ::= { +# joint-iso-itu-t(2) +# country(16) us(840) organization(1) gov(101) csor(3) +# nistalgorithm(4) hashalgs(2) 2 +# } +oid = '\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02' + +def new(data=""): + obj = Wrapper(hashFactory, data) + obj.oid = oid + obj.new = globals()['new'] + if not hasattr(obj, 'digest_size'): + obj.digest_size = digest_size + return obj + +# TOFIX: This code will not work for python<2.5 +import hashlib +hashFactory = hashlib.sha384 + +digest_size = 48 +block_size = 128 + diff --git a/lib/Crypto/Hash/SHA512.py b/lib/Crypto/Hash/SHA512.py new file mode 100644 index 0000000..e95349f --- /dev/null +++ b/lib/Crypto/Hash/SHA512.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# +# =================================================================== +# The contents of this file are dedicated to the public domain. To +# the extent that dedication to the public domain is not available, +# everyone is granted a worldwide, perpetual, royalty-free, +# non-exclusive license to exercise all rights associated with the +# contents of this file for any purpose whatsoever. +# No rights are reserved. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# =================================================================== + +# Just use the SHA module from the Python standard library + +__revision__ = "$Id$" + +__all__ = ['new', 'digest_size'] + +from Crypto.Util.wrapper import Wrapper + +# The OID for SHA-512 is: +# +# id-sha512 OBJECT IDENTIFIER ::= { +# joint-iso-itu-t(2) +# country(16) us(840) organization(1) gov(101) csor(3) +# nistalgorithm(4) hashalgs(2) 3 +# } +oid = '\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03' + +def new(data=""): + obj = Wrapper(hashFactory, data) + obj.oid = oid + obj.new = globals()['new'] + if not hasattr(obj, 'digest_size'): + obj.digest_size = digest_size + return obj + +# TOFIX: This code will not work for python<2.5 +import hashlib +hashFactory = hashlib.sha512 + +digest_size = 64 +block_size = 128 + |
