<s> """<STR_LIT>""" <EOL> from . cryptomath import * <EOL> from . asn1parser import ASN1Parser <EOL> from . rsakey import * <EOL> from . pem import * <EOL> class Python_RSAKey ( RSAKey ) : <EOL> def __init__ ( self , n = <NUM_LIT:0> , e = <NUM_LIT:0> , d = <NUM_LIT:0> , p = <NUM_LIT:0> , q = <NUM_LIT:0> , dP = <NUM_LIT:0> , dQ = <NUM_LIT:0> , qInv = <NUM_LIT:0> ) : <EOL> if ( n and not e ) or ( e and not n ) : <EOL> raise AssertionError ( ) <EOL> self . n = n <EOL> self . e = e <EOL> self . d = d <EOL> self . p = p <EOL> self . q = q <EOL> self . dP = dP <EOL> self . dQ = dQ <EOL> self . qInv = qInv <EOL> self . blinder = <NUM_LIT:0> <EOL> self . unblinder = <NUM_LIT:0> <EOL> def hasPrivateKey ( self ) : <EOL> return self . d != <NUM_LIT:0> <EOL> def _rawPrivateKeyOp ( self , m ) : <EOL> if not self . blinder : <EOL> self . unblinder = getRandomNumber ( <NUM_LIT:2> , self . n ) <EOL> self . blinder = powMod ( invMod ( self . unblinder , self . n ) , self . e , <EOL> self . n ) <EOL> m = ( m * self . blinder ) % self . n <EOL> c = self . _rawPrivateKeyOpHelper ( m ) <EOL> c = ( c * self . unblinder ) % self . n <EOL> self . blinder = ( self . blinder * self . blinder ) % self . n <EOL> self . unblinder = ( self . unblinder * self . unblinder ) % self . n <EOL> return c <EOL> def _rawPrivateKeyOpHelper ( self , m ) : <EOL> s1 = powMod ( m , self . dP , self . p ) <EOL> s2 = powMod ( m , self . dQ , self . q ) <EOL> h = ( ( s1 - s2 ) * self . qInv ) % self . p <EOL> c = s2 + self . q * h <EOL> return c <EOL> def _rawPublicKeyOp ( self , c ) : <EOL> m = powMod ( c , self . e , self . n ) <EOL> return m <EOL> def acceptsPassword ( self ) : return False <EOL> def generate ( bits ) : <EOL> key = Python_RSAKey ( ) <EOL> p = getRandomPrime ( bits // <NUM_LIT:2> , False ) <EOL> q = getRandomPrime ( bits // <NUM_LIT:2> , False ) <EOL> t = lcm ( p - <NUM_LIT:1> , q - <NUM_LIT:1> ) <EOL> key . n = p * q <EOL> key . e = <NUM_LIT> L <EOL> key . d = invMod ( key . e , t ) <EOL> key . p = p <EOL> key . q = q <EOL> key . dP = key . d % ( p - <NUM_LIT:1> ) <EOL> key . dQ = key . d % ( q - <NUM_LIT:1> ) <EOL> key . qInv = invMod ( q , p ) <EOL> return key <EOL> generate = staticmethod ( generate ) <EOL> def parsePEM ( s , passwordCallback = None ) : <EOL> """<STR_LIT>""" <EOL> if pemSniff ( s , "<STR_LIT>" ) : <EOL> bytes = dePem ( s , "<STR_LIT>" ) <EOL> return Python_RSAKey . _parsePKCS8 ( bytes ) <EOL> elif pemSniff ( s , "<STR_LIT>" ) : <EOL> bytes = dePem ( s , "<STR_LIT>" ) <EOL> return Python_RSAKey . _parseSSLeay ( bytes ) <EOL> else : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> parsePEM = staticmethod ( parsePEM ) <EOL> def _parsePKCS8 ( bytes ) : <EOL> p = ASN1Parser ( bytes ) <EOL> version = p . getChild ( <NUM_LIT:0> ) . value [ <NUM_LIT:0> ] <EOL> if version != <NUM_LIT:0> : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> rsaOID = p . getChild ( <NUM_LIT:1> ) . value <EOL> if list ( rsaOID ) != [ <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:0> ] : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> privateKeyP = p . getChild ( <NUM_LIT:2> ) <EOL> privateKeyP = ASN1Parser ( privateKeyP . value ) <EOL> return Python_RSAKey . _parseASN1PrivateKey ( privateKeyP ) <EOL> _parsePKCS8 = staticmethod ( _parsePKCS8 ) <EOL> def _parseSSLeay ( bytes ) : <EOL> privateKeyP = ASN1Parser ( bytes ) <EOL> return Python_RSAKey . _parseASN1PrivateKey ( privateKeyP ) <EOL> _parseSSLeay = staticmethod ( _parseSSLeay ) <EOL> def _parseASN1PrivateKey ( privateKeyP ) : <EOL> version = privateKeyP . getChild ( <NUM_LIT:0> ) . value [ <NUM_LIT:0> ] <EOL> if version != <NUM_LIT:0> : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> n = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:1> ) . value ) <EOL> e = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:2> ) . value ) <EOL> d = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:3> ) . value ) <EOL> p = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:4> ) . value ) <EOL> q = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:5> ) . value ) <EOL> dP = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:6> ) . value ) <EOL> dQ = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:7> ) . value ) <EOL> qInv = bytesToNumber ( privateKeyP . getChild ( <NUM_LIT:8> ) . value ) <EOL> return Python_RSAKey ( n , e , d , p , q , dP , dQ , qInv ) <EOL> _parseASN1PrivateKey = staticmethod ( _parseASN1PrivateKey ) </s>
