Esempio n. 1
0
 def __init__(self, b, nr, pi, c, t):
     
     self.f = KeccakP(b, nr)
     self.W = max(b/25, 8)
     self.c = c
     self.motorist = Motorist(self.f, pi, self.W, c, t)
     self.T = Buffer()
     self.SUV = None
Esempio n. 2
0
class Keyak(object):
    def __init__(self, b, nr, pi, c, t):
        
        self.f = KeccakP(b, nr)
        self.W = max(b/25, 8)
        self.c = c
        self.motorist = Motorist(self.f, pi, self.W, c, t)
        self.T = Buffer()
        self.SUV = None

    def setSUV(self, key, nonce=None):
        lk = self.W/8 *int(math.ceil((self.c + 9.0) / self.W))
        self.SUV = KeyPack(key,lk)
        if nonce is not None:
            self.SUV.addNonce(nonce)

    # conor code
    def encrypt(self, data, metadata=''):
        assert(self.SUV is not None)
        self.motorist.startEngine(self.SUV, False, self.T, False, False)
        
        I = Buffer(data)
        O = Buffer()
        A = Buffer(metadata)
        self.motorist.wrap(I, O, A, self.T, False, False)

        return O.data, self.T.data

    def decrypt(self, data, tag,  metadata=''):
        assert(self.SUV is not None)
        self.motorist.startEngine(self.SUV, False, self.T, True, False)
        
        I = Buffer(data)
        O = Buffer()
        A = Buffer(metadata)
        self.motorist.wrap(I, O, A, Buffer(tag), True, False)

        if self.motorist.phase == motorist.Phase.Failed:
            raise Exception('Authentication failed')

        return O.data