<s> import public_private_key <EOL> import hashlib <EOL> from coro . ssh . util import packet , random <EOL> from Crypto . PublicKey import DSA <EOL> from Crypto . Util import number <EOL> class SSH_DSS ( public_private_key . SSH_Public_Private_Key ) : <EOL> supports_signature = <NUM_LIT:1> <EOL> supports_encryption = <NUM_LIT:0> <EOL> name = '<STR_LIT>' <EOL> private_key = ( <NUM_LIT:0> L , <NUM_LIT:0> L , <NUM_LIT:0> L , <NUM_LIT:0> L , <NUM_LIT:0> L ) <EOL> public_key = ( <NUM_LIT:0> L , <NUM_LIT:0> L , <NUM_LIT:0> L , <NUM_LIT:0> L ) <EOL> def set_public_key ( self , public_key ) : <EOL> dss , p , q , g , y = packet . unpack_payload ( DSS_PUBLIC_KEY_PAYLOAD , public_key ) <EOL> if dss != '<STR_LIT>' : <EOL> raise ValueError ( dss ) <EOL> self . public_key = ( p , q , g , y ) <EOL> set_public_key . __doc__ = public_private_key . SSH_Public_Private_Key . set_public_key . __doc__ <EOL> def set_private_key ( self , private_key ) : <EOL> dss , p , q , g , y , x = packet . unpack_payload ( DSS_PRIVATE_KEY_PAYLOAD , private_key ) <EOL> if dss != '<STR_LIT>' : <EOL> raise ValueError ( dss ) <EOL> self . private_key = ( p , q , g , y , x ) <EOL> set_private_key . __doc__ = public_private_key . SSH_Public_Private_Key . set_private_key . __doc__ <EOL> def get_public_key_blob ( self ) : <EOL> if self . public_key != ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) : <EOL> p , q , g , y = self . public_key <EOL> else : <EOL> p , q , g , y , x = self . private_key <EOL> return packet . pack_payload ( DSS_PUBLIC_KEY_PAYLOAD , <EOL> ( '<STR_LIT>' , <EOL> p , q , g , y ) ) <EOL> get_public_key_blob . __doc__ = public_private_key . SSH_Public_Private_Key . get_public_key_blob . __doc__ <EOL> def get_private_key_blob ( self ) : <EOL> p , q , g , y , x = self . private_key <EOL> return packet . pack_payload ( DSS_PRIVATE_KEY_PAYLOAD , <EOL> ( '<STR_LIT>' , <EOL> p , q , g , y , x ) ) <EOL> get_private_key_blob . __doc__ = public_private_key . SSH_Public_Private_Key . get_private_key_blob . __doc__ <EOL> def create ( self , size = <NUM_LIT> ) : <EOL> key = DSA . generate ( size ) <EOL> self . private_key = ( key . p , key . q , key . g , key . y , key . x ) <EOL> self . public_key = ( key . p , key . q , key . g , key . y ) <EOL> def sign ( self , message ) : <EOL> p , q , g , y , x = self . private_key <EOL> dsa_obj = DSA . construct ( ( y , g , p , q , x ) ) <EOL> message_hash = hashlib . sha1 ( message ) . digest ( ) <EOL> random_number = random . get_random_number_from_range ( <NUM_LIT:2> , q ) <EOL> random_data = number . long_to_bytes ( random_number ) <EOL> r , s = dsa_obj . sign ( message_hash , random_data ) <EOL> signature = number . long_to_bytes ( r , <NUM_LIT:20> ) + number . long_to_bytes ( s , <NUM_LIT:20> ) <EOL> return packet . pack_payload ( DSS_SIG_PAYLOAD , <EOL> ( '<STR_LIT>' , <EOL> signature ) ) <EOL> sign . __doc__ = public_private_key . SSH_Public_Private_Key . sign . __doc__ <EOL> def verify ( self , message , signature ) : <EOL> p , q , g , y = self . public_key <EOL> dss , blob = packet . unpack_payload ( DSS_SIG_PAYLOAD , signature ) <EOL> if dss != '<STR_LIT>' : <EOL> raise ValueError ( dss ) <EOL> assert ( len ( blob ) == <NUM_LIT> ) <EOL> r = number . bytes_to_long ( blob [ : <NUM_LIT:20> ] ) <EOL> s = number . bytes_to_long ( blob [ <NUM_LIT:20> : ] ) <EOL> dsa_obj = DSA . construct ( ( y , g , p , q ) ) <EOL> hash_of_message = hashlib . sha1 ( message ) . digest ( ) <EOL> return dsa_obj . verify ( hash_of_message , ( r , s ) ) <EOL> verify . __doc__ = public_private_key . SSH_Public_Private_Key . verify . __doc__ <EOL> DSS_PUBLIC_KEY_PAYLOAD = ( packet . STRING , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> packet . MPINT <EOL> ) <EOL> DSS_PRIVATE_KEY_PAYLOAD = ( packet . STRING , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> packet . MPINT , <EOL> ) <EOL> DSS_SIG_PAYLOAD = ( packet . STRING , <EOL> packet . STRING <EOL> ) </s>
