@@ -359,118 +359,227 @@ def test_seal_with_test_vector_6(self):
359359 b'\x13 \xc7 \xf3 \xdd \x8c K\n >^Q\xf1 Q\xeb \x0f '
360360 b'\xfa \xe7 \xc4 =\x01 \x0f \xdb ' ), encData )
361361
362- if m2cryptoLoaded :
363- def test_seal_with_test_vector_1_openssl (self ):
364- key = bytearray (b'\x00 ' * 16 )
365- aesCCM = openssl_aesccm .new (key )
362+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
363+ def test_seal_with_test_vector_1_openssl (self ):
364+ key = bytearray (b'\x00 ' * 16 )
365+ aesCCM = openssl_aesccm .new (key )
366+
367+ nonce = bytearray (b'\x00 ' * 12 )
368+
369+ plaintext = bytearray (b'' )
370+ self .assertEqual (len (plaintext ), 0 )
371+
372+ encData = aesCCM .seal (nonce , plaintext , bytearray (0 ))
373+ self .assertEqual (bytearray (b'\xb9 \xf6 P\xfb <9\xbb \x1b \xee \x0e )\x1d 3'
374+ b'\xf6 \xae (' ), encData )
375+
376+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
377+ def test_seal_with_test_vector_2_openssl (self ):
378+ key = bytearray (b'\x00 ' * 16 )
379+ aesCCM = openssl_aesccm .new (key )
380+
381+ nonce = bytearray (b'\x00 ' * 12 )
382+
383+ plaintext = bytearray (b'\x00 ' * 16 )
384+ self .assertEqual (len (plaintext ), 16 )
385+
386+ encData = aesCCM .seal (nonce , plaintext , bytearray (0 ))
387+
388+ self .assertEqual (bytearray (b'n\xc7 _\xb2 \xe2 \xb4 \x87 F\x1e \xdd \xcb \xb8 '
389+ b'\x97 \x11 \x92 \xba MO\xa3 \xaf \x0b \xf6 \xd3 E'
390+ b'Aq0o\xfa \xdd \x9a \xfd ' ), encData )
391+
392+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
393+ def test_seal_with_test_vector_3_openssl (self ):
394+ key = bytearray (b'\xfe \xff \xe9 \x92 \x86 \x65 \x73 \x1c '
395+ b'\x6d \x6a \x8f \x94 \x67 \x30 \x83 \x08 ' )
396+ aesCCM = openssl_aesccm .new (key )
397+
398+ nonce = bytearray (b'\xca \xfe \xba \xbe \xfa \xce \xdb \xad \xde \xca \xf8 \x88 ' )
399+
400+ plaintext = bytearray (b'\xd9 \x31 \x32 \x25 \xf8 \x84 \x06 \xe5 '
401+ b'\xa5 \x59 \x09 \xc5 \xaf \xf5 \x26 \x9a '
402+ b'\x86 \xa7 \xa9 \x53 \x15 \x34 \xf7 \xda '
403+ b'\x2e \x4c \x30 \x3d \x8a \x31 \x8a \x72 '
404+ b'\x1c \x3c \x0c \x95 \x95 \x68 \x09 \x53 '
405+ b'\x2f \xcf \x0e \x24 \x49 \xa6 \xb5 \x25 '
406+ b'\xb1 \x6a \xed \xf5 \xaa \x0d \xe6 \x57 '
407+ b'\xba \x63 \x7b \x39 \x1a \xaf \xd2 \x55 ' )
408+
409+ self .assertEqual (len (plaintext ), 4 * 16 )
410+
411+ encData = aesCCM .seal (nonce , plaintext , bytearray (0 ))
412+
413+ self .assertEqual (bytearray (b"\x08 \x93 \xe9 K\x91 H\x80 \x1a \xf0 \xf7 4&"
414+ b"\xab \xb0 \x0e <\xa4 \x9b \xf0 \x9d y\xa2 "
415+ b"\x01 \' \xa7 \xeb \x19 &\xfa \x89 \x05 7\x87 "
416+ b"\xff \x02 \xd0 }q\x81 ;\x88 [\x85 \xe7 \xf9 "
417+ b"lN\xed \xf4 \xdb \x12 j\x04 Q\xce \x13 \xbd A"
418+ b"\xba \x01 \x8d \x1b \xa7 \xfc \xec e\x99 Dg\xa7 "
419+ b"{\x8b &B\xde \x91 ,\x01 ." ), encData )
420+
421+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
422+ def test_seal_with_test_vector_4_openssl (self ):
423+ key = bytearray (b'\xfe \xff \xe9 \x92 \x86 \x65 \x73 \x1c ' +
424+ b'\x6d \x6a \x8f \x94 \x67 \x30 \x83 \x08 ' )
425+ aesCCM = openssl_aesccm .new (key )
366426
367- nonce = bytearray (b'\x00 ' * 12 )
427+ nonce = bytearray (b'\xca \xfe \xba \xbe \xfa \xce \xdb \xad \xde \xca \xf8 \x88 ' )
428+
429+ plaintext = bytearray (b'\xd9 \x31 \x32 \x25 \xf8 \x84 \x06 \xe5 '
430+ b'\xa5 \x59 \x09 \xc5 \xaf \xf5 \x26 \x9a '
431+ b'\x86 \xa7 \xa9 \x53 \x15 \x34 \xf7 \xda '
432+ b'\x2e \x4c \x30 \x3d \x8a \x31 \x8a \x72 '
433+ b'\x1c \x3c \x0c \x95 \x95 \x68 \x09 \x53 '
434+ b'\x2f \xcf \x0e \x24 \x49 \xa6 \xb5 \x25 '
435+ b'\xb1 \x6a \xed \xf5 \xaa \x0d \xe6 \x57 '
436+ b'\xba \x63 \x7b \x39 ' )
437+
438+ data = bytearray (b'\xfe \xed \xfa \xce \xde \xad \xbe \xef '
439+ b'\xfe \xed \xfa \xce \xde \xad \xbe \xef '
440+ b'\xab \xad \xda \xd2 ' )
441+
442+ encData = aesCCM .seal (nonce , plaintext , data )
443+
444+ self .assertEqual (bytearray (b'\x08 \x93 \xe9 K\x91 H\x80 \x1a \xf0 \xf7 4&\xab '
445+ b'\xb0 \x0e <\xa4 \x9b \xf0 \x9d y\xa2 \x01 \' \xa7 '
446+ b'\xeb \x19 &\xfa \x89 \x05 7\x87 \xff \x02 \xd0 }q'
447+ b'\x81 ;\x88 [\x85 \xe7 \xf9 lN\xed \xf4 \xdb '
448+ b'\x12 j\x04 Q\xce \x13 \xbd A\xba \x02 8\xc3 &'
449+ b'\xb4 {4\xf7 \x8f e\x9e u'
450+ b'\x10 \x96 \xcd "' ), encData )
451+
452+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
453+ def test_seal_with_test_vector_5_openssl (self ):
454+ key = bytearray (32 )
455+
456+ aesCCM = openssl_aesccm .new (key )
457+
458+ nonce = bytearray (12 )
459+ plaintext = bytearray (0 )
460+ data = bytearray (0 )
461+
462+ encData = aesCCM .seal (nonce , plaintext , data )
463+
464+ self .assertEqual (bytearray (b'\xa8 \x90 &^C\xa2 hU\xf2 i'
465+ b'\xb9 ?\xf4 \xdd \xde \xf6 ' ), encData )
466+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
467+ def test_seal_with_test_vector_6_openssl (self ):
468+ key = bytearray (32 )
469+
470+ aesCCM = openssl_aesccm .new (key )
471+
472+ nonce = bytearray (12 )
473+ plaintext = bytearray (16 )
474+ data = bytearray (0 )
475+
476+ encData = aesCCM .seal (nonce , plaintext , data )
477+
478+ self .assertEqual (bytearray (b'\xc1 \x94 @D\xc8 \xe7 \xaa \x95 \xd2 \xde \x95 '
479+ b'\x13 \xc7 \xf3 \xdd \x8c K\n >^Q\xf1 Q\xeb \x0f '
480+ b'\xfa \xe7 \xc4 =\x01 \x0f \xdb ' ), encData )
481+
482+
483+ class TestAESCCMIdentical (unittest .TestCase ):
484+ @classmethod
485+ def setUpClass (self ):
486+ self .plaintext = bytearray (b'\x6b \xc1 \xbe \xe2 \x2e \x40 \x9f '
487+ b'\x96 \xe9 \x3d \x7e \x11 \x73 \x93 '
488+ b'\x17 \x2a \xae \x2d \x8a \x57 \x1e '
489+ b'\x03 \xac \x9c \x9e \xb7 \x6f \xac '
490+ b'\x45 \xaf \x8e \x51 \x30 \xc8 \x1c '
491+ b'\x46 \xa3 \x5c \xe4 \x11 \xe5 \xfb '
492+ b'\xc1 \x19 \x1a \x0a \x52 \xef \xf6 '
493+ b'\x9f \x24 \x45 \xdf \x4f \x9b \x17 '
494+ b'\xad \x2b \x41 \x7b \xe6 \x6c \x37 \x10 ' )
368495
369- plaintext = bytearray (b'' )
370- self .assertEqual (len (plaintext ), 0 )
496+ self .ciphertext = bytearray (b'\xba ce\x8c G\x8c \x19 i\xbc \x93 C\xf2 w\xd6 ?'
497+ b'\x8c \x8c \x11 \xd3 \x99 r\x95 Za\x17 \x10 F'
498+ b'\xb7 5\x17 \x01 \x14 \xab \x0b \x12 \x03 KElyBoJ'
499+ b'\xda \xaa \xc0 \xa9 \' \xb3 \xd5 \x12 \xa2 \x1f F,'
500+ b'\x8e \x04 \xf5 {\xf8 \xfd N\xfe \xe2 \xe9 x\xfe 1'
501+ b'\x17 5\xa6 \xc4 \\ Q3\x80 \xf4 \xca R\x8c ' )
371502
372- encData = aesCCM .seal (nonce , plaintext , bytearray (0 ))
373- self .assertEqual (bytearray (b'\xb9 \xf6 P\xfb <9\xbb \x1b \xee \x0e )\x1d 3'
374- b'\xf6 \xae (' ), encData )
503+ self .ciphertext_8 = bytearray (b'\xba ce\x8c G\x8c \x19 i\xbc \x93 C\xf2 w'
504+ b'\xd6 ?\x8c \x8c \x11 \xd3 \x99 r\x95 Za'
505+ b'\x17 \x10 F\xb7 5\x17 \x01 \x14 \xab \x0b '
506+ b'\x12 \x03 KElyBoJ\xda \xaa \xc0 \xa9 \' \xb3 '
507+ b'\xd5 \x12 \xa2 \x1f F,\x8e \x04 \xf5 {\xf8 '
508+ b'\xfd N\xfe \xe2 \x1f \xae \xeb \xcb :\xb2 /\xd0 ' )
375509
376- def test_seal_with_test_vector_2_openssl (self ):
377- key = bytearray (b'\x00 ' * 16 )
378- aesCCM = openssl_aesccm .new (key )
510+ self .key = bytearray (b'\xfe \xff \xe9 \x92 \x86 \x65 \x73 \x1c '
511+ b'\x6d \x6a \x8f \x94 \x67 \x30 \x83 \x08 ' )
379512
380- nonce = bytearray (b'\x00 ' * 12 )
513+ self . nonce = bytearray (b'\xca \xfe \xba \xbe \xfa \xce \xdb \xad \xde \xca \xf8 \x88 ' )
381514
382- plaintext = bytearray (b'\x00 ' * 16 )
383- self .assertEqual (len (plaintext ), 16 )
515+ self .data = bytearray (b'\xfe \xed \xfa \xce \xde \xad \xbe \xef '
516+ b'\xfe \xed \xfa \xce \xde \xad \xbe \xef '
517+ b'\xab \xad \xda \xd2 ' )
384518
385- encData = aesCCM . seal ( nonce , plaintext , bytearray ( 0 ))
519+ def test_seal_identical_messages_python ( self ):
386520
387- self .assertEqual (bytearray (b'n\xc7 _\xb2 \xe2 \xb4 \x87 F\x1e \xdd \xcb \xb8 '
388- b'\x97 \x11 \x92 \xba MO\xa3 \xaf \x0b \xf6 \xd3 E'
389- b'Aq0o\xfa \xdd \x9a \xfd ' ), encData )
521+ aesCCM = AESCCM (self .key , "python" , Rijndael (self .key , 16 ).encrypt )
390522
391- def test_seal_with_test_vector_3_openssl (self ):
392- key = bytearray (b'\xfe \xff \xe9 \x92 \x86 \x65 \x73 \x1c '
393- b'\x6d \x6a \x8f \x94 \x67 \x30 \x83 \x08 ' )
394- aesCCM = openssl_aesccm .new (key )
523+ for _ in range (2 ):
524+ encData = aesCCM .seal (self .nonce , self .plaintext , self .data )
525+ self .assertEqual (self .ciphertext , encData )
395526
396- nonce = bytearray ( b' \xca \xfe \xba \xbe \xfa \xce \xdb \xad \xde \xca \xf8 \x88 ' )
527+ def test_open_identical_messages_python ( self ):
397528
398- plaintext = bytearray (b'\xd9 \x31 \x32 \x25 \xf8 \x84 \x06 \xe5 '
399- b'\xa5 \x59 \x09 \xc5 \xaf \xf5 \x26 \x9a '
400- b'\x86 \xa7 \xa9 \x53 \x15 \x34 \xf7 \xda '
401- b'\x2e \x4c \x30 \x3d \x8a \x31 \x8a \x72 '
402- b'\x1c \x3c \x0c \x95 \x95 \x68 \x09 \x53 '
403- b'\x2f \xcf \x0e \x24 \x49 \xa6 \xb5 \x25 '
404- b'\xb1 \x6a \xed \xf5 \xaa \x0d \xe6 \x57 '
405- b'\xba \x63 \x7b \x39 \x1a \xaf \xd2 \x55 ' )
529+ aesCCM = AESCCM (self .key , "python" , Rijndael (self .key , 16 ).encrypt )
406530
407- self .assertEqual (len (plaintext ), 4 * 16 )
531+ for _ in range (2 ):
532+ decData = aesCCM .open (self .nonce , self .ciphertext , self .data )
533+ self .assertEqual (self .plaintext , decData )
408534
409- encData = aesCCM . seal ( nonce , plaintext , bytearray ( 0 ))
535+ def test_seal_identical_messages_8_python ( self ):
410536
411- self .assertEqual (bytearray (b"\x08 \x93 \xe9 K\x91 H\x80 \x1a \xf0 \xf7 4&"
412- b"\xab \xb0 \x0e <\xa4 \x9b \xf0 \x9d y\xa2 "
413- b"\x01 \' \xa7 \xeb \x19 &\xfa \x89 \x05 7\x87 "
414- b"\xff \x02 \xd0 }q\x81 ;\x88 [\x85 \xe7 \xf9 "
415- b"lN\xed \xf4 \xdb \x12 j\x04 Q\xce \x13 \xbd A"
416- b"\xba \x01 \x8d \x1b \xa7 \xfc \xec e\x99 Dg\xa7 "
417- b"{\x8b &B\xde \x91 ,\x01 ." ), encData )
537+ aesCCM = AESCCM (self .key , "python" , Rijndael (self .key , 16 ).encrypt , 8 )
418538
419- def test_seal_with_test_vector_4_openssl (self ):
420- key = bytearray (b'\xfe \xff \xe9 \x92 \x86 \x65 \x73 \x1c ' +
421- b'\x6d \x6a \x8f \x94 \x67 \x30 \x83 \x08 ' )
422- aesCCM = openssl_aesccm .new (key )
539+ for _ in range (2 ):
540+ encData = aesCCM .seal (self .nonce , self .plaintext , self .data )
541+ self .assertEqual (self .ciphertext_8 , encData )
423542
424- nonce = bytearray ( b' \xca \xfe \xba \xbe \xfa \xce \xdb \xad \xde \xca \xf8 \x88 ' )
543+ def test_open_identical_messages_8_python ( self ):
425544
426- plaintext = bytearray (b'\xd9 \x31 \x32 \x25 \xf8 \x84 \x06 \xe5 '
427- b'\xa5 \x59 \x09 \xc5 \xaf \xf5 \x26 \x9a '
428- b'\x86 \xa7 \xa9 \x53 \x15 \x34 \xf7 \xda '
429- b'\x2e \x4c \x30 \x3d \x8a \x31 \x8a \x72 '
430- b'\x1c \x3c \x0c \x95 \x95 \x68 \x09 \x53 '
431- b'\x2f \xcf \x0e \x24 \x49 \xa6 \xb5 \x25 '
432- b'\xb1 \x6a \xed \xf5 \xaa \x0d \xe6 \x57 '
433- b'\xba \x63 \x7b \x39 ' )
545+ aesCCM = AESCCM (self .key , "python" , Rijndael (self .key , 16 ).encrypt , 8 )
434546
435- data = bytearray ( b' \xfe \xed \xfa \xce \xde \xad \xbe \xef '
436- b' \xfe \xed \xfa \xce \xde \xad \xbe \xef '
437- b' \xab \xad \xda \xd2 ' )
547+ for _ in range ( 2 ):
548+ decData = aesCCM . open ( self . nonce , self . ciphertext_8 , self . data )
549+ self . assertEqual ( self . plaintext , decData )
438550
439- encData = aesCCM .seal (nonce , plaintext , data )
551+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
552+ def test_seal_identical_messages_openssl (self ):
440553
441- self .assertEqual (bytearray (b'\x08 \x93 \xe9 K\x91 H\x80 \x1a \xf0 \xf7 4&\xab '
442- b'\xb0 \x0e <\xa4 \x9b \xf0 \x9d y\xa2 \x01 \' \xa7 '
443- b'\xeb \x19 &\xfa \x89 \x05 7\x87 \xff \x02 \xd0 }q'
444- b'\x81 ;\x88 [\x85 \xe7 \xf9 lN\xed \xf4 \xdb '
445- b'\x12 j\x04 Q\xce \x13 \xbd A\xba \x02 8\xc3 &'
446- b'\xb4 {4\xf7 \x8f e\x9e u'
447- b'\x10 \x96 \xcd "' ), encData )
554+ aesCCM = openssl_aesccm .new (self .key )
448555
449- def test_seal_with_test_vector_5_openssl (self ):
450- key = bytearray (32 )
556+ for _ in range (2 ):
557+ encData = aesCCM .seal (self .nonce , self .plaintext , self .data )
558+ self .assertEqual (self .ciphertext , encData )
451559
452- aesCCM = openssl_aesccm .new (key )
560+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
561+ def test_open_identical_messages_openssl (self ):
453562
454- nonce = bytearray (12 )
455- plaintext = bytearray (0 )
456- data = bytearray (0 )
563+ aesCCM = openssl_aesccm .new (self .key )
457564
458- encData = aesCCM .seal (nonce , plaintext , data )
565+ for _ in range (2 ):
566+ decData = aesCCM .open (self .nonce , self .ciphertext , self .data )
567+ self .assertEqual (self .plaintext , decData )
459568
460- self . assertEqual ( bytearray ( b' \xa8 \x90 &^C \xa2 hU \xf2 i'
461- b' \xb9 ? \xf4 \xdd \xde \xf6 ' ), encData )
569+ @ unittest . skipUnless ( m2cryptoLoaded , "requires M2Crypto" )
570+ def test_seal_identical_messages_8_openssl ( self ):
462571
463- def test_seal_with_test_vector_6_openssl (self ):
464- key = bytearray (32 )
572+ aesCCM = openssl_aesccm .new (self .key , 8 )
465573
466- aesCCM = openssl_aesccm .new (key )
574+ for _ in range (2 ):
575+ encData = aesCCM .seal (self .nonce , self .plaintext , self .data )
576+ self .assertEqual (self .ciphertext_8 , encData )
467577
468- nonce = bytearray (12 )
469- plaintext = bytearray (16 )
470- data = bytearray (0 )
578+ @unittest .skipUnless (m2cryptoLoaded , "requires M2Crypto" )
579+ def test_open_identical_messages_8_openssl (self ):
471580
472- encData = aesCCM . seal ( nonce , plaintext , data )
581+ aesCCM = openssl_aesccm . new ( self . key , 8 )
473582
474- self . assertEqual ( bytearray ( b' \xc1 \x94 @D \xc8 \xe7 \xaa \x95 \xd2 \xde \x95 '
475- b' \x13 \xc7 \xf3 \xdd \x8c K \n >^Q \xf1 Q \xeb \x0f '
476- b' \xfa \xe7 \xc4 = \x01 \x0f \xdb ' ), encData )
583+ for _ in range ( 2 ):
584+ decData = aesCCM . open ( self . nonce , self . ciphertext_8 , self . data )
585+ self . assertEqual ( self . plaintext , decData )
0 commit comments