Exemplo n.º 1
0
 def _decrypt(self, block, bLen):
     if bLen % AES_BLOCK_SIZE:
         log.error("Sugar, why do you give me a block the wrong size: %d not modulo of %d" % (bLen, AES_BLOCK_SIZE))
         return None
     buf = (ctypes.c_ubyte * AES_BLOCK_SIZE)()
     dest = (ctypes.c_ubyte * bLen)()
     num = ctypes.c_uint()
     ##log.debug('BEFORE %s'%( myhex(self.aes_key_ctx.getCounter())) )
     # void AES_ctr128_encrypt(
     #      const unsigned char *in, unsigned char *out, const unsigned long length,
     #           const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE],
     #        	  unsigned char ecount_buf[AES_BLOCK_SIZE],  unsigned int *num)
     # debug counter overflow
     ###last=self.aes_key_ctx.getCounter()[-1]
     ###before=self.getCounter()
     self._AES_ctr(
         ctypes.byref(block),
         ctypes.byref(dest),
         bLen,
         ctypes.byref(self.key),
         ctypes.byref(self.counter),
         ctypes.byref(buf),
         ctypes.byref(num),
     )
     """
 newlast=self.aes_key_ctx.getCounter()[-1]
 if newlast < last :
   log.warning('Counter has overflown')
   after=self.getCounter()
   log.warning('Before %s'%(before))
   log.warning('After  %s'%(after))
 """
     ##log.debug('AFTER  %s'%( myhex(self.aes_key_ctx.getCounter())) )
     return model.array2bytes(dest)
Exemplo n.º 2
0
 def _decrypt(self,block, bLen):
   if bLen % AES_BLOCK_SIZE:
     log.error("Sugar, why do you give me a block the wrong size: %d not modulo of %d"%(bLen, AES_BLOCK_SIZE))
     return None
   buf=(ctypes.c_ubyte*AES_BLOCK_SIZE)()
   dest=(ctypes.c_ubyte*bLen)()
   num=ctypes.c_uint()
   log.debug('BEFORE a %s : decrypt %d bytes'%( repr(self.getCounter()) , bLen ) )
   #void AES_ctr128_encrypt(
   #      const unsigned char *in, unsigned char *out, const unsigned long length, 
   #           const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE],     
   #        	  unsigned char ecount_buf[AES_BLOCK_SIZE],  unsigned int *num)
   # debug counter overflow
   ###last=self.aes_key_ctx.getCounter()[-1]
   ###before=self.getCounter()
   self._AES_ctr( ctypes.byref(block), ctypes.byref(dest), bLen, ctypes.byref(self.key), 
             ctypes.byref(self.counter), ctypes.byref(buf), ctypes.byref(num) ) 
   '''
   newlast=self.aes_key_ctx.getCounter()[-1]
   if newlast < last :
     log.warning('Counter has overflown')
     after=self.getCounter()
     log.warning('Before %s'%(before))
     log.warning('After  %s'%(after))
   '''
   log.debug('AFTER a %s'%repr(self.getCounter()))
   #log.debug('AFTER x %s'%( myhex(self.aes_key_ctx.getCounter())) )
   return model.array2bytes(dest)
Exemplo n.º 3
0
 def _decrypt(self, src, bLen):
     if bLen % AES_BLOCK_SIZE:
         log.error("Sugar, why do you give me a block the wrong size: %d not modulo of %d" % (bLen, AES_BLOCK_SIZE))
         return None
     buf = (ctypes.c_ubyte * AES_BLOCK_SIZE)()
     dest = (ctypes.c_ubyte * bLen)()
     enc = ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic
     ##log.debug('BEFORE %s'%( myhex(self.aes_key_ctx.getCounter())) )
     # void AES_cbc_encrypt(
     #      const unsigned char *in, unsigned char *out, const unsigned long length,
     #           const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], const int enc
     #        	  )
     self._AES_cbc(ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), ctypes.byref(self.iv), enc)
     ##log.debug('AFTER  %s'%( myhex(self.aes_key_ctx.getCounter())) )
     print self, repr(model.array2bytes(dest))
     return model.array2bytes(dest)
Exemplo n.º 4
0
 def _decrypt(self, src, bLen):
     dest = (ctypes.c_ubyte * bLen)()
     enc = ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic
     # void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
     #      const CAST_KEY *ks, unsigned char *iv, int enc);
     self._CAST_cbc(ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), ctypes.byref(self.iv), enc)
     # print self, repr(model.array2bytes(dest))
     return model.array2bytes(dest)
Exemplo n.º 5
0
    def _decrypt(self, src, bLen):
        dest = (ctypes.c_ubyte * bLen)()

        # void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
        #    unsigned char *outdata);
        self._RC4(ctypes.byref(self.key), bLen, ctypes.byref(src), ctypes.byref(dest))

        # print self, repr(model.array2bytes(dest))
        return model.array2bytes(dest)
Exemplo n.º 6
0
  def _decrypt(self, src, bLen):
    dest=(ctypes.c_ubyte*bLen)()

    #void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
		#    unsigned char *outdata);
    self._RC4( ctypes.byref(self.key), bLen, ctypes.byref(src), ctypes.byref(dest) ) 

    #print self, repr(model.array2bytes(dest))
    return model.array2bytes(dest)
Exemplo n.º 7
0
  def _decrypt(self, src, bLen):
    dest=(ctypes.c_ubyte*bLen)()
    enc=ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic
    #void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
		#      const CAST_KEY *ks, unsigned char *iv, int enc);
    self._CAST_cbc( ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), 
              ctypes.byref(self.iv), enc ) 
    #print self, repr(model.array2bytes(dest))
    return model.array2bytes(dest)
Exemplo n.º 8
0
 def _decrypt(self, src, bLen):
     BF_ROUNDS = 16
     BF_BLOCK = 8
     dest = (ctypes.c_ubyte * bLen)()
     enc = ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic ## ctx.evpCipherCtx.encrypt [0,1]
     # void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
     # 	const BF_KEY *schedule, unsigned char *ivec, int enc);
     self._BF_cbc(ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), ctypes.byref(self.iv), enc)
     # print self, repr(model.array2bytes(dest))
     return model.array2bytes(dest)
Exemplo n.º 9
0
 def _decrypt(self, src, bLen):
   BF_ROUNDS	= 16
   BF_BLOCK = 8
   dest=(ctypes.c_ubyte*bLen)()
   enc=ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic ## ctx.evpCipherCtx.encrypt [0,1]
   #void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
   #	const BF_KEY *schedule, unsigned char *ivec, int enc);
   self._BF_cbc( ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), 
             ctypes.byref(self.iv), enc ) 
   #print self, repr(model.array2bytes(dest))
   return model.array2bytes(dest)
Exemplo n.º 10
0
 def _decrypt(self, src, bLen):
   if bLen % AES_BLOCK_SIZE:
     log.error("Sugar, why do you give me a block the wrong size: %d not modulo of %d"%(bLen, AES_BLOCK_SIZE))
     return None
   buf=(ctypes.c_ubyte*AES_BLOCK_SIZE)() # TODO string_at + from_address
   dest=(ctypes.c_ubyte*bLen)() # TODO string_at + from_address
   enc=ctypes.c_uint(0)  ## 0 is decrypt for inbound traffic
   #log.debug('BEFORE %s'%( myhex(self.aes_key_ctx.getCounter())) )
   #void AES_cbc_encrypt(
   #      const unsigned char *in, unsigned char *out, const unsigned long length, 
   #           const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], const int enc
   #        	  )
   self._AES_cbc( ctypes.byref(src), ctypes.byref(dest), bLen, ctypes.byref(self.key), 
             ctypes.byref(self.iv), enc ) 
   ##log.debug('AFTER  %s'%( myhex(self.aes_key_ctx.getCounter())) )
   #print self, repr(model.array2bytes(dest))
   return model.array2bytes(dest)
Exemplo n.º 11
0
 def getDk(self):
   return array2bytes(self.dk)
Exemplo n.º 12
0
 def getCounter(self):
   return array2bytes(self.aes_counter)
Exemplo n.º 13
0
def EVP_CIPHER_CTX_getIV(self):
  return array2bytes(self.iv)
Exemplo n.º 14
0
def BF_KEY_getS(self):
  return array2bytes(self.S)
Exemplo n.º 15
0
def BF_KEY_getP(self):
  return array2bytes(self.P)
Exemplo n.º 16
0
 def getIV(self):
   #return pointer2bytes(model.getRef(ctypes.Array, getaddress(self.iv)), self.block_size) 
   return model.array2bytes(model.getRef( model.get_subtype(self.iv), getaddress(self.iv)) )
Exemplo n.º 17
0
 def getKey(self):
   #return pointer2bytes(self.key,self.key_len)
   return model.array2bytes( model.getRef( model.get_subtype(self.key), getaddress(self.key)) )
Exemplo n.º 18
0
def RC4_KEY_getData(self):
  return array2bytes(self.data)
Exemplo n.º 19
0
 def getEk(self):
   return array2bytes(self.ek)
Exemplo n.º 20
0
def CAST_KEY_getData(self):
  return array2bytes(self.data)
Exemplo n.º 21
0
 def getIV(self):
   return array2bytes(self.r_iv)
Exemplo n.º 22
0
 def getCounter(self):
   #return myhex(self.aes_key_ctx.getCounter())
   return model.array2bytes(self.counter)