Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(49019)

Delta Between Two Patch Sets: Lib/test/test_hashlib.py

Issue 16113: Add SHA-3 (Keccak) support
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/hashlib.py ('k') | Modules/hashlib.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # Test hashlib module 1 # Test hashlib module
2 # 2 #
3 # $Id$ 3 # $Id$
4 # 4 #
5 # Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) 5 # Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)
6 # Licensed to PSF under a Contributor Agreement. 6 # Licensed to PSF under a Contributor Agreement.
7 # 7 #
8 8
9 import array 9 import array
10 import hashlib 10 import hashlib
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 def check_blocksize_name(self, name, block_size=0, digest_size=0, 288 def check_blocksize_name(self, name, block_size=0, digest_size=0,
289 digest_length=None): 289 digest_length=None):
290 constructors = self.constructors_to_test[name] 290 constructors = self.constructors_to_test[name]
291 for hash_object_constructor in constructors: 291 for hash_object_constructor in constructors:
292 m = hash_object_constructor() 292 m = hash_object_constructor()
293 self.assertEqual(m.block_size, block_size) 293 self.assertEqual(m.block_size, block_size)
294 self.assertEqual(m.digest_size, digest_size) 294 self.assertEqual(m.digest_size, digest_size)
295 if digest_length: 295 if digest_length:
296 self.assertEqual(len(m.digest(digest_length)), 296 self.assertEqual(len(m.digest(digest_length)),
297 digest_size) 297 digest_length)
298 self.assertEqual(len(m.hexdigest(digest_length)), 298 self.assertEqual(len(m.hexdigest(digest_length)),
299 2*digest_size) 299 2*digest_length)
300 else: 300 else:
301 self.assertEqual(len(m.digest()), digest_size) 301 self.assertEqual(len(m.digest()), digest_size)
302 self.assertEqual(len(m.hexdigest()), 2*digest_size) 302 self.assertEqual(len(m.hexdigest()), 2*digest_size)
303 self.assertEqual(m.name, name) 303 self.assertEqual(m.name, name)
304 # split for sha3_512 / _sha3.sha3 object 304 # split for sha3_512 / _sha3.sha3 object
305 self.assertIn(name.split("_")[0], repr(m)) 305 self.assertIn(name.split("_")[0], repr(m))
306 306
307 def test_blocksize_name(self): 307 def test_blocksize_name(self):
308 self.check_blocksize_name('md5', 64, 16) 308 self.check_blocksize_name('md5', 64, 16)
309 self.check_blocksize_name('sha1', 64, 20) 309 self.check_blocksize_name('sha1', 64, 20)
310 self.check_blocksize_name('sha224', 64, 28) 310 self.check_blocksize_name('sha224', 64, 28)
311 self.check_blocksize_name('sha256', 64, 32) 311 self.check_blocksize_name('sha256', 64, 32)
312 self.check_blocksize_name('sha384', 128, 48) 312 self.check_blocksize_name('sha384', 128, 48)
313 self.check_blocksize_name('sha512', 128, 64) 313 self.check_blocksize_name('sha512', 128, 64)
314 #self.check_blocksize_name('sha3_224', 128, 64) 314 self.check_blocksize_name('sha3_224', 144, 28)
gregory.p.smith 2016/06/02 23:52:33 commented out?
315 #self.check_blocksize_name('sha3_256', 128, 64) 315 self.check_blocksize_name('sha3_256', 136, 32)
316 #self.check_blocksize_name('sha3_384', 128, 64) 316 self.check_blocksize_name('sha3_384', 104, 48)
317 #self.check_blocksize_name('sha3_512', 128, 64) 317 self.check_blocksize_name('sha3_512', 72, 64)
318 self.check_blocksize_name('shake_128', 168, 0, 32)
319 self.check_blocksize_name('shake_256', 136, 0, 64)
318 320
319 def test_case_md5_0(self): 321 def test_case_md5_0(self):
320 self.check('md5', b'', 'd41d8cd98f00b204e9800998ecf8427e') 322 self.check('md5', b'', 'd41d8cd98f00b204e9800998ecf8427e')
321 323
322 def test_case_md5_1(self): 324 def test_case_md5_1(self):
323 self.check('md5', b'abc', '900150983cd24fb0d6963f7d28e17f72') 325 self.check('md5', b'abc', '900150983cd24fb0d6963f7d28e17f72')
324 326
325 def test_case_md5_2(self): 327 def test_case_md5_2(self):
326 self.check('md5', 328 self.check('md5',
327 b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 789', 329 b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 789',
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 self._test_pbkdf2_hmac(py_hashlib.pbkdf2_hmac) 660 self._test_pbkdf2_hmac(py_hashlib.pbkdf2_hmac)
659 661
660 @unittest.skipUnless(hasattr(c_hashlib, 'pbkdf2_hmac'), 662 @unittest.skipUnless(hasattr(c_hashlib, 'pbkdf2_hmac'),
661 ' test requires OpenSSL > 1.0') 663 ' test requires OpenSSL > 1.0')
662 def test_pbkdf2_hmac_c(self): 664 def test_pbkdf2_hmac_c(self):
663 self._test_pbkdf2_hmac(c_hashlib.pbkdf2_hmac) 665 self._test_pbkdf2_hmac(c_hashlib.pbkdf2_hmac)
664 666
665 667
666 if __name__ == "__main__": 668 if __name__ == "__main__":
667 unittest.main() 669 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+