Esempio n. 1
0
 def MsgTestAESCBCSeperate(self,msg):
     groupObj = PairingGroup('SS512')
     ran = groupObj.random(GT)
     a =  AuthenticatedCryptoAbstraction(sha2(ran))
     ct = a.encrypt(msg)        
     b =  AuthenticatedCryptoAbstraction(sha2(ran))
     dmsg = b.decrypt(ct);
     assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)
Esempio n. 2
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(pk, sk, c1)
     if key is False:
         raise Exception("failed to decrypt!")
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)
Esempio n. 3
0
 def encrypt(self, pk, M, object):
     key = self.group.random(GT)
     c1 = abenc.encrypt(pk, key, object)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
Esempio n. 4
0
 def testTamperMac(self):
     key = sha2(PairingGroup('SS512').random(GT))
     m = MessageAuthenticator(key)
     a = m.mac('hello world')
     m1 = MessageAuthenticator(key)
     a["digest"]= "tampered" 
     assert not m1.verify(a), "expected message to verify";
Esempio n. 5
0
 def encrypt(self, pk, ID, M):
     if type(M) != bytes: raise "message not right type!"
     key = group.random(GT)
     c1 = ibenc.encrypt(pk, ID, key)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
Esempio n. 6
0
 def keyenc(self, params, ID, msg):
     s = group.random()
     A = sha2(params['v']**s)  # session key
     B = params['Y']**s
     C = (params['X']**s) * (params['g']**(s * ID))
     # use prf here?
     ciph = {'B': B, 'C': C}
     return (A, ciph)  # user must destroy A since it protects the msg
Esempio n. 7
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(pk, sk, c1)
     if key is False:
         print ("[WARNING] key failed to decrypt, message not intented for this device.")
         return None
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)
Esempio n. 8
0
 def testTamperAlg(self):
     key = sha2(PairingGroup('SS512').random(GT))
     m = MessageAuthenticator(key)
     a = m.mac('hello world')
     m1 = MessageAuthenticator(key)
     m1._algorithm = "alg" # bypassing the algorithm check to verify the mac is over the alg + data 
     a["alg"]= "alg" 
     assert not m1.verify(a), "expected message to verify";
Esempio n. 9
0
 def encrypt(self, gp, pk, M, policy_str):
     if type(M) != bytes and type(policy_str) != str:
         raise Exception("message and policy not right type!")
     key = group.random(GT)
     c1 = abencma.encrypt(gp, pk, key, policy_str)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
Esempio n. 10
0
 def decrypt(self, pk, ID, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = ibenc.decrypt(pk, ID, c1)
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)
Esempio n. 11
0
 def keydec(self, pk, dID, CT):
     A, B, C = CT['A'], CT['B'], CT['C']
     v_s = pair(((B**dID['r']) * C), dID['K'])
     return sha2(v_s)
Esempio n. 12
0
 def testSeperateVerify(self):
     key = sha2(PairingGroup('SS512').random(GT))
     m = MessageAuthenticator(key)
     a = m.mac('hello world')
     m1 = MessageAuthenticator(key)
     assert m1.verify(a), "expected message to verify";
Esempio n. 13
0
 def MsgtestAESCBC(self,msg):
     groupObj = PairingGroup('SS512')
     a =  AuthenticatedCryptoAbstraction(sha2(groupObj.random(GT)))
     ct = a.encrypt(msg)
     dmsg = a.decrypt(ct);
     assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)