Skip to content

Commit

Permalink
sounddevice only
Browse files Browse the repository at this point in the history
  • Loading branch information
massmux committed Jun 4, 2021
1 parent e0468f4 commit 9f93913
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
import subprocess,os
import hashlib
import cv2,base64
import sounddevice

""" check if sounddevice lib is available, if it is then gets imported """
try:
import sounddevice
mode='sd'
except ImportError:
mode='arec'

""" system constants """

NOISE_SAMPLE = 30 # main sampling seconds
NOISE_SAMPLE = 5 # main sampling seconds
SHA256_ROUNDS = 2048 # sha256 rounds (number)
NOISE_SAMPLE_SALT = 5 # salt sampling seconds
NOISE_SAMPLE_SALT = 3 # salt sampling seconds
SAMPLE_RATE = 44100 # samplerate
SAMPLING_FMT = 'wav'
IMG_SAMPLES = 64
Expand All @@ -51,18 +46,6 @@ def __init__(self,source='mic'):
def _getsha256(self,z):
return hashlib.sha256(z.encode('utf-8')).hexdigest()

def _getMicArec(self):
"""
creating unique noise by sampling entropy and salting it for SHA256_ROUNDS. Returns sha256 salt hashed noise. arec command
"""
mycmd=subprocess.getoutput('arecord -d %s -f dat -t %s -q | sha256sum -b' % (str(NOISE_SAMPLE),SAMPLING_FMT ))
hash0=mycmd[:64]
mysalt=subprocess.getoutput('arecord -d %s -f dat -t %s -q | sha256sum -b' % (str(NOISE_SAMPLE_SALT),SAMPLING_FMT ))
salt0=mysalt[:64]
for i in range(0,SHA256_ROUNDS):
hash0=self._getsha256(hash0+salt0)
return hash0


def _getMicSd(self):
"""
Expand Down Expand Up @@ -105,7 +88,7 @@ def _takePhoto(self):
def getEntropy(self):
""" returns true entropy from chosen source """
if self.source=='mic':
self.entropy=self._getMicArec() if mode=='arec' else self._getMicSd()
self.entropy=self._getMicSd()
elif self.source=='photo':
self._takePhoto()
self.entropy=self._getImgRnd()
Expand Down

0 comments on commit 9f93913

Please sign in to comment.