MOD: making more progress to having the jpg image binary data into a hash
This commit is contained in:
parent
5bc89da407
commit
5b835a2fe2
|
@ -11,13 +11,26 @@ class Signature:
|
||||||
key_data = None
|
key_data = None
|
||||||
pub_key = None
|
pub_key = None
|
||||||
sig_data = None
|
sig_data = None
|
||||||
|
hh = None
|
||||||
|
|
||||||
#
|
#
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
hh = SHA512.new()
|
||||||
self.genKeys()
|
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 = SHA512.new()
|
||||||
hshh.update(bin_data)
|
hshh.update(bin_data)
|
||||||
signer = PKCS1_v1_5.new(self.key_data)
|
signer = PKCS1_v1_5.new(self.key_data)
|
||||||
|
@ -25,7 +38,7 @@ class Signature:
|
||||||
return self.sig_data
|
return self.sig_data
|
||||||
|
|
||||||
#
|
#
|
||||||
def verifySig(self, bin_data, bin_sig):
|
def verifySig222(self, bin_data, bin_sig):
|
||||||
hshh = SHA512.new()
|
hshh = SHA512.new()
|
||||||
hshh.update(bin_data)
|
hshh.update(bin_data)
|
||||||
verifier = PKCS1_v1_5.new(self.pub_key)
|
verifier = PKCS1_v1_5.new(self.pub_key)
|
||||||
|
|
|
@ -29,6 +29,11 @@ class JpgBin:
|
||||||
data_idx = 0
|
data_idx = 0
|
||||||
data_len = 0
|
data_len = 0
|
||||||
fh = None
|
fh = None
|
||||||
|
hh = None
|
||||||
|
|
||||||
|
markers = {
|
||||||
|
'SOS': 0xffd9
|
||||||
|
}
|
||||||
|
|
||||||
continue_process = True
|
continue_process = True
|
||||||
|
|
||||||
|
@ -48,20 +53,39 @@ class JpgBin:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#
|
#
|
||||||
def processFile(self, fhandle):
|
def processFile(self, file_h):
|
||||||
self.fh = fhandle
|
self.fh = file_h
|
||||||
self.getMoreBytes(True)
|
self.getMoreBytes(True)
|
||||||
if (self.data_buf):
|
if (self.data_buf):
|
||||||
if (not self.__isJPG()):
|
if (not self.__isJPG()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
while(self.continue_process):
|
while(self.continue_process):
|
||||||
self.findMarker()
|
self.findAllMarker()
|
||||||
self.getMoreBytes()
|
self.getMoreBytes()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
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):
|
def getMoreBytes(self, force_bytes=False):
|
||||||
if (self.data_idx >= (self.data_len-1) or force_bytes):
|
if (self.data_idx >= (self.data_len-1) or force_bytes):
|
||||||
|
@ -91,7 +115,12 @@ class JpgBin:
|
||||||
return pos
|
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])
|
(word_b,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
||||||
hex_str = word_b.to_bytes(2, 'big').hex()
|
hex_str = word_b.to_bytes(2, 'big').hex()
|
||||||
# RST 0xD(n) (n==0..7)
|
# RST 0xD(n) (n==0..7)
|
||||||
|
@ -138,11 +167,27 @@ class JpgBin:
|
||||||
else:
|
else:
|
||||||
self.data_idx += 1
|
self.data_idx += 1
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Image Metadata, Exif
|
||||||
|
#
|
||||||
|
#
|
||||||
|
def markerAppData(self):
|
||||||
|
self.calcSeekBytes()
|
||||||
#
|
#
|
||||||
def markerComment(self):
|
def markerComment(self):
|
||||||
self.calcSeekBytes()
|
self.calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
# Image Data
|
||||||
|
#
|
||||||
|
#
|
||||||
|
def markerSOS(self):
|
||||||
|
self.calcSeekBytes()
|
||||||
|
|
||||||
|
def markerRST(self):
|
||||||
|
self.data_idx += 2
|
||||||
|
|
||||||
def markerDQT(self):
|
def markerDQT(self):
|
||||||
self.calcSeekBytes()
|
self.calcSeekBytes()
|
||||||
|
|
||||||
|
@ -161,18 +206,10 @@ class JpgBin:
|
||||||
def markerDHT(self):
|
def markerDHT(self):
|
||||||
self.calcSeekBytes()
|
self.calcSeekBytes()
|
||||||
|
|
||||||
def markerSOS(self):
|
|
||||||
self.calcSeekBytes()
|
|
||||||
|
|
||||||
def markerRST(self):
|
|
||||||
self.data_idx += 2
|
|
||||||
|
|
||||||
def markerEOI(self):
|
def markerEOI(self):
|
||||||
self.data_idx += 2
|
self.data_idx += 2
|
||||||
# self.continue_process = False
|
# self.continue_process = False
|
||||||
|
|
||||||
def markerAppData(self):
|
|
||||||
self.calcSeekBytes()
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -17,13 +17,11 @@ class JpgTools:
|
||||||
|
|
||||||
#
|
#
|
||||||
def jpgHash(self):
|
def jpgHash(self):
|
||||||
pass
|
self.fh = open(fname, "rb")
|
||||||
|
self.jpg = JpgBin()
|
||||||
|
retval = self.jpg.processFile(self.fh)
|
||||||
|
|
||||||
#
|
print("processFile()=={}".format(retval))
|
||||||
def getBytes(self, fname):
|
|
||||||
if (not self.fh):
|
|
||||||
self.fh = open(fname, "rb")
|
|
||||||
self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def processFile(self, fname):
|
def processFile(self, fname):
|
||||||
|
|
Loading…
Reference in New Issue