MOD: making more progress to having the jpg image binary data into a hash

This commit is contained in:
JohnE 2016-09-09 11:07:18 -07:00
parent 5bc89da407
commit 5b835a2fe2
3 changed files with 68 additions and 20 deletions

View File

@ -11,13 +11,26 @@ class Signature:
key_data = None
pub_key = None
sig_data = None
hh = None
#
def __init__(self):
hh = SHA512.new()
self.genKeys()
#
def genSig(self, bin_data):
def genSig(self, hshh):
signer = PKCS1_v1_5.new(self.key_data)
self.sig_data = signer.sign(hshh)
return self.sig_data
#
def verifySig(self, hshh, bin_sig):
verifier = PKCS1_v1_5.new(self.pub_key)
return verifier.verify(hshh, bin_sig)
#
def genSig222(self, bin_data):
hshh = SHA512.new()
hshh.update(bin_data)
signer = PKCS1_v1_5.new(self.key_data)
@ -25,7 +38,7 @@ class Signature:
return self.sig_data
#
def verifySig(self, bin_data, bin_sig):
def verifySig222(self, bin_data, bin_sig):
hshh = SHA512.new()
hshh.update(bin_data)
verifier = PKCS1_v1_5.new(self.pub_key)

View File

@ -29,6 +29,11 @@ class JpgBin:
data_idx = 0
data_len = 0
fh = None
hh = None
markers = {
'SOS': 0xffd9
}
continue_process = True
@ -48,20 +53,39 @@ class JpgBin:
return False
#
def processFile(self, fhandle):
self.fh = fhandle
def processFile(self, file_h):
self.fh = file_h
self.getMoreBytes(True)
if (self.data_buf):
if (not self.__isJPG()):
return False
while(self.continue_process):
self.findMarker()
self.findAllMarker()
self.getMoreBytes()
return True
return False
#
def genHash(self, file_h, hash_h):
self.hh = hash_h
self.processFile(file_h)
while(self.continue_process):
if (self.findMarker(self.makers['SOS'])):
self.genImgHash()
self.getMoreBytes()
return self.hh
#
def genImgHash(self):
self.hh.update(self.data_buf[self.data_idx:])
while(self.continue_process):
self.getMoreBytes()
self.hh.update(self.data_buf)
#
def getMoreBytes(self, force_bytes=False):
if (self.data_idx >= (self.data_len-1) or force_bytes):
@ -91,7 +115,12 @@ class JpgBin:
return pos
#
def findMarker(self):
def findMarker(self, marker):
pass
#
def findAllMarker(self):
(word_b,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
hex_str = word_b.to_bytes(2, 'big').hex()
# RST 0xD(n) (n==0..7)
@ -138,11 +167,27 @@ class JpgBin:
else:
self.data_idx += 1
#
# Image Metadata, Exif
#
#
def markerAppData(self):
self.calcSeekBytes()
#
def markerComment(self):
self.calcSeekBytes()
#
# Image Data
#
#
def markerSOS(self):
self.calcSeekBytes()
def markerRST(self):
self.data_idx += 2
def markerDQT(self):
self.calcSeekBytes()
@ -161,18 +206,10 @@ class JpgBin:
def markerDHT(self):
self.calcSeekBytes()
def markerSOS(self):
self.calcSeekBytes()
def markerRST(self):
self.data_idx += 2
def markerEOI(self):
self.data_idx += 2
# self.continue_process = False
def markerAppData(self):
self.calcSeekBytes()
def __repr__(self):
pass

View File

@ -17,13 +17,11 @@ class JpgTools:
#
def jpgHash(self):
pass
#
def getBytes(self, fname):
if (not self.fh):
self.fh = open(fname, "rb")
self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE)
self.jpg = JpgBin()
retval = self.jpg.processFile(self.fh)
print("processFile()=={}".format(retval))
#
def processFile(self, fname):