Exemplo n.º 1
0
 def __init__(self, d):
     if isinstance(d, int) or isinstance(d, long):
         self.value = d
         self.bytes = crypto.i2b(d)
         return
     if isinstance(d, basestring):
         stream = io.BytesIO(d)
     elif isinstance(d, io.BytesIO):
         stream = d
     bits = crypto.b2i(stream.read(2))
     mpiBytes = int(math.ceil(float(bits) / 8))
     self.bytes = stream.read(mpiBytes)
     self.value = crypto.b2i(self.bytes)
Exemplo n.º 2
0
 def isValid(self, keyMessage):
     """
     Verify the self signature.
     """
     key = keyMessage.packets.get(PublicKeyPacket.TAG)
     if key is None:
         key = keyMessage.packets.get(SecretKeyPacket.TAG)
     if key is None:
         raise Exception('no key in message')
     em = crypto.i2b(crypto.rsaEncrypt(self.signature.value, key.e.value,
                                       key.n.value))
     return encoding.pssVerify(self.hashdata(), em,
                               crypto.HASH_SIZE[crypto.HASH_SHA256] / 8,
                               key.n.bits() - 1, crypto.HASH_SHA256)
Exemplo n.º 3
0
 def __str__(self):
     return ('MPI (%d bits): 0x%s' %
             (self.bits(), crypto.i2b(self.value).encode('hex')))
Exemplo n.º 4
0
 def rep(self, octets = 0):
     return crypto.i2b(self.value, octets)
Exemplo n.º 5
0
 def rep(self):
     return crypto.i2b(self.bits(), 2) + crypto.i2b(self.value)