def encipher(self, p1, p2, data): """ Encipher data using key, algorithm, IV and Padding specified by the current Security environment. :returns: raw data (no TLV coding). """ algo = self.ct.algorithm key = self.ct.key if key == None or algo == None: raise SwError(SW["ERR_CONDITIONNOTSATISFIED"]) else: padded = vsCrypto.append_padding(vsCrypto.get_cipher_blocklen(algo), data) crypted = vsCrypto.encrypt(algo, key, padded, self.ct.iv) return crypted
def external_authenticate(self, p1, p2, data): """ Authenticate the terminal to the card. Check whether Terminal correctly encrypted the given challenge or not """ if self.last_challenge is None: raise SwError(SW["ERR_CONDITIONNOTSATISFIED"]) key = self._get_referenced_key(p1, p2) if p1 == 0x00: #No information given cipher = get_referenced_cipher(self.cipher) else: cipher = get_referenced_cipher(p1) blocklen = vsCrypto.get_cipher_blocklen(cipher) reference = vsCrypto.append_padding(blocklen, self.last_challenge) reference = vsCrypto.encrypt(cipher, key, reference) if (reference == data): #Invalidate last challenge self.last_challenge = None return SW["NORMAL"], "" else: raise SwError(SW["WARN_NOINFO63"])
def external_authenticate(self, p1, p2, data): """ Authenticate the terminal to the card. Check whether Terminal correctly encrypted the given challenge or not """ if self.last_challenge is None: raise SwError(SW["ERR_CONDITIONNOTSATISFIED"]) key = self._get_referenced_key(p1, p2) if p1 == 0x00: #No information given cipher = get_referenced_cipher(self.cipher) else: cipher = get_referenced_cipher(p1) blocklen = vsCrypto.get_cipher_blocklen(cipher) reference = vsCrypto.append_padding(blocklen, self.last_challenge) reference = vsCrypto.encrypt(cipher, key, reference) if(reference == data): #Invalidate last challenge self.last_challenge = None return SW["NORMAL"], "" else: raise SwError(SW["WARN_NOINFO63"])