Skip to content

Commit

Permalink
Merge pull request #2 from massmux/checkdevice
Browse files Browse the repository at this point in the history
Checkdevice
  • Loading branch information
massmux authored Jun 4, 2021
2 parents 5788eb3 + fe61071 commit dc1814c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
63 changes: 38 additions & 25 deletions entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@



import subprocess,os
import subprocess,os,sys
import hashlib
import cv2,base64
import sounddevice
Expand All @@ -36,26 +36,32 @@
IMG_SAMPLES = 64
IMG_SAMPLES_SALT = 8



class entropy():

def __init__(self,source='mic'):
self.source=source
self.entropy=0
self.entropy=1
return


def _getsha256(self,z):
return hashlib.sha256(z.encode('utf-8')).hexdigest()


def _getMicSd(self):
"""
creating unique noise by sampling entropy and salting it for SHA256_ROUNDS. Returns sha256 salt hashed noise. python lib
creating unique noise by sampling entropy and salting it for SHA256_ROUNDS. Returns sha256 salt hashed noise.
"""
noise0 = sounddevice.rec(int(SAMPLE_RATE * NOISE_SAMPLE), samplerate=SAMPLE_RATE, channels=2, blocking=True)
salt0 = sounddevice.rec(int(SAMPLE_RATE * NOISE_SAMPLE_SALT), samplerate=SAMPLE_RATE, channels=2, blocking=True)
(noise,salt) =( hashlib.sha256(bytearray(b''.join(noise0))).hexdigest() , hashlib.sha256(bytearray(b''.join(salt0))).hexdigest() )
for i in range(0,SHA256_ROUNDS):
noise=self._getsha256(noise+salt)
try:
noise0 = sounddevice.rec(int(SAMPLE_RATE * NOISE_SAMPLE), samplerate=SAMPLE_RATE, channels=2, blocking=True)
salt0 = sounddevice.rec(int(SAMPLE_RATE * NOISE_SAMPLE_SALT), samplerate=SAMPLE_RATE, channels=2, blocking=True)
(noise,salt) =( hashlib.sha256(bytearray(b''.join(noise0))).hexdigest() , hashlib.sha256(bytearray(b''.join(salt0))).hexdigest() )
for i in range(0,SHA256_ROUNDS):
noise=self._getsha256(noise+salt)
except:
noise=False
return noise


Expand All @@ -67,30 +73,37 @@ def _getImgRnd(self):
img_rnd_result=self._getsha256(img_rnd_result+salt)
return img_rnd_result


def _takePhoto(self):
""" taking multiple photos from webcam in order to create randomness. Returns data and salt """
camera = cv2.VideoCapture(0)
(all_data,all_salt)=("","")
for i in range(IMG_SAMPLES):
return_value, image = camera.read()
ocurrent = base64.b64encode(image)
all_data=all_data+str(ocurrent)
for z in range(IMG_SAMPLES_SALT):
return_value, image = camera.read()
ocurrent = base64.b64encode(image)
all_salt=all_salt+str(ocurrent)
del(camera)
self.img_rnd={ 'base': all_data,
'salt': all_salt
}
""" taking multiple photos from webcam in order to create randomness. Returns data and salt. used device 0 """
try:
camera = cv2.VideoCapture(0)
(all_data,all_salt)=("","")
for i in range(IMG_SAMPLES):
return_value, image = camera.read()
ocurrent = base64.b64encode(image)
all_data=all_data+str(ocurrent)
for z in range(IMG_SAMPLES_SALT):
return_value, image = camera.read()
ocurrent = base64.b64encode(image)
all_salt=all_salt+str(ocurrent)
del(camera)
self.img_rnd={ 'base': all_data,
'salt': all_salt
}
except:
self.img_rnd=False
return self.img_rnd


def getEntropy(self):
""" returns true entropy from chosen source """
if self.source=='mic':
self.entropy=self._getMicSd()
elif self.source=='photo':
self._takePhoto()
self.entropy=self._getImgRnd()
if self._takePhoto():
self.entropy=self._getImgRnd()
else:
self.entropy=False
return self.entropy

5 changes: 4 additions & 1 deletion papergen.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ def clear():
def main():
a = ee.entropy(entropy_source)
clear()
working_message="Getting randomness from mic.. please wait" if entropy_source=='mic' else "Getting randomness from webcam.. please wait"
working_message="Getting data from mic.. please wait" if entropy_source=='mic' else "Getting data from webcam.. please wait"
print (working_message)
priv = a.getEntropy()
if priv==False:
print("Error: sound or video devices not working, aborted")
sys.exit()
oWallet=""
clear()
if wType=='single':
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fido2
httplib2
keyring
libsecp256k1
mnemonic
numpy
oauthlib
pylibscrypt
Expand Down

0 comments on commit dc1814c

Please sign in to comment.