#NEWLINE# def testSignVerify( self ) : #NEWLINE# #INDENT# h = SHA . new ( ) #NEWLINE# h . update ( b ( 'blah blah blah' ) ) #NEWLINE# rng = Random . new ( ) . read #NEWLINE# key = MyKey ( RSA . generate ( 1024 , rng ) ) #NEWLINE# global mgfcalls #NEWLINE# def newMGF( seed , maskLen ) : #NEWLINE# #INDENT# global mgfcalls #NEWLINE# mgfcalls += 1 #NEWLINE# return ( bchr ( 0 ) * maskLen ) #NEWLINE# #UNINDENT# for hashmod in ( MD2 , MD5 , SHA , SHA224 , SHA256 , SHA384 , RIPEMD ) : #NEWLINE# #INDENT# h = hashmod . new ( ) #NEWLINE# h . update ( b ( 'blah blah blah' ) ) #NEWLINE# key . asked = 0 #NEWLINE# signer = PKCS . new ( key ) #NEWLINE# s = signer . sign ( h ) #NEWLINE# self . failUnless ( signer . verify ( h , s ) ) #NEWLINE# self . assertEqual ( key . asked , h . digest_size ) #NEWLINE# #UNINDENT# h = SHA . new ( ) #NEWLINE# h . update ( b ( 'blah blah blah' ) ) #NEWLINE# for sLen in ( 0 , 3 , 21 ) : #NEWLINE# #INDENT# key . asked = 0 #NEWLINE# signer = PKCS . new ( key , saltLen = sLen ) #NEWLINE# s = signer . sign ( h ) #NEWLINE# self . assertEqual ( key . asked , sLen ) #NEWLINE# self . failUnless ( signer . verify ( h , s ) ) #NEWLINE# #UNINDENT# mgfcalls = 0 #NEWLINE# signer = PKCS . new ( key , newMGF ) #NEWLINE# s = signer . sign ( h ) #NEWLINE# self . assertEqual ( mgfcalls , 1 ) #NEWLINE# self . failUnless ( signer . verify ( h , s ) ) #NEWLINE# key . asked = 0 #NEWLINE# mgfcalls = 0 #NEWLINE# signer = PKCS . new ( key , newMGF , 0 ) #NEWLINE# s = signer . sign ( h ) #NEWLINE# self . assertEqual ( key . asked , 0 ) #NEWLINE# self . assertEqual ( mgfcalls , 1 ) #NEWLINE# self . failUnless ( signer . verify ( h , s ) )