Use the blocklength of the actual cipher to append padding (instead of hardcoded
DES-CBC blocklength) git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@682 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -89,13 +89,12 @@ def get_cipher_blocklen(cipherspec):
|
||||
cipher = globals().get(cipherparts[0].upper(), None)
|
||||
return cipher.block_size
|
||||
|
||||
def append_padding(cipherspec, data, padding_class=0x01):
|
||||
def append_padding(blocklen, data, padding_class=0x01):
|
||||
"""Append padding to the data.
|
||||
Length of padding depends on length of data and the block size of the
|
||||
specified encryption algorithm.
|
||||
Different types of padding may be selected via the padding_class parameter
|
||||
"""
|
||||
blocklen = get_cipher_blocklen(cipherspec)
|
||||
|
||||
if padding_class == 0x01: #ISO padding
|
||||
last_block_length = len(data) % blocklen
|
||||
|
||||
@@ -56,6 +56,7 @@ class ControlReferenceTemplate:
|
||||
self.DFref = None
|
||||
self.keylength = None
|
||||
self.algorithm = None
|
||||
self.blocklength = None
|
||||
self.usage_qualifier = None
|
||||
if config != "":
|
||||
self.parse_SE_config(config)
|
||||
@@ -283,7 +284,7 @@ class Security_Environment(object):
|
||||
if authenticate_header:
|
||||
to_authenticate = inttostring(CAPDU.cla) + inttostring(CAPDU.ins)+\
|
||||
inttostring(CAPDU.p1) + inttostring(CAPDU.p2)
|
||||
to_authenticate = vsCrypto.append_padding("DES-CBC", to_authenticate)
|
||||
to_authenticate = vsCrypto.append_padding(self.cct.blocklength, to_authenticate)
|
||||
else:
|
||||
to_authenticate = ""
|
||||
|
||||
@@ -366,7 +367,7 @@ class Security_Environment(object):
|
||||
|
||||
#SM data objects for authentication
|
||||
if tag == SM_Class["CHECKSUM"]:
|
||||
auth = vsCrypto.append_padding("DES-CBC", to_authenticate)
|
||||
auth = vsCrypto.append_padding(self.cct.algorithm, to_authenticate)
|
||||
sw, checksum = self.compute_cryptographic_checksum(0x8E,
|
||||
0x80,
|
||||
auth)
|
||||
@@ -437,9 +438,9 @@ class Security_Environment(object):
|
||||
if sw == SW["NORMAL"]:
|
||||
if self.cct.algorithm == None:
|
||||
raise SwError(SW["CONDITIONSNOTSATISFIED"])
|
||||
elif self.cct.algorithm == "CCT":
|
||||
elif self.cct.algorithm == "CC":
|
||||
tag = SM_Class["CHECKSUM"]
|
||||
padded = vsCrypto.append_padding("DES-ECB", return_data)
|
||||
padded = vsCrypto.append_padding(self.cct.blocklength, return_data)
|
||||
sw, auth = self.compute_cryptographic_checksum(0x8E, 0x80, padded)
|
||||
length = len(auth)
|
||||
return_data += pack([(tag, length, auth)])
|
||||
@@ -638,7 +639,7 @@ class Security_Environment(object):
|
||||
if key == None or algo == None:
|
||||
return SW["ERR_CONDITIONNOTSATISFIED"], ""
|
||||
else:
|
||||
padded = vsCrypto.append_padding(algo, data)
|
||||
padded = vsCrypto.append_padding(vsCrypto.get_cipher_blocklen(algo), data)
|
||||
crypted = vsCrypto.encrypt(algo, key, padded, self.ct.iv)
|
||||
return SW["NORMAL"], crypted
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class ePass_SE(Security_Environment):
|
||||
Security_Environment.__init__(self, MF, SAM)
|
||||
self.ssc = ssc
|
||||
self.cct.algorithm = "CC"
|
||||
self.cct.blocklength = 8
|
||||
self.ct.algorithm = "DES3-CBC"
|
||||
|
||||
def compute_cryptographic_checksum(self, p1, p2, data):
|
||||
|
||||
@@ -67,6 +67,8 @@ class nPA_SE(Security_Environment):
|
||||
def __init__(self, MF, SAM):
|
||||
Security_Environment.__init__(self, MF, SAM)
|
||||
self.at = nPA_AT_CRT()
|
||||
#This breaks support for 3DES
|
||||
self.cct.blocklength = 16
|
||||
self.eac_step = 0
|
||||
self.sec = None
|
||||
self.eac_ctx = None
|
||||
|
||||
Reference in New Issue
Block a user