added basic cryptography, advertising, and forwarding functionality to the LoRa handler. Also added a UUID class for generating unique IDs for each device.
also, i have 2 radios now! :D
This commit is contained in:
39
relay/crypt_random.py
Normal file
39
relay/crypt_random.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from machine import ADC
|
||||
import utime
|
||||
import uhashlib
|
||||
|
||||
adc = ADC(26)
|
||||
|
||||
|
||||
def get_entropy(samples: int = 512):
|
||||
entropy = bytearray()
|
||||
|
||||
for _ in range(samples):
|
||||
|
||||
value = adc.read_u16()
|
||||
|
||||
mixed = (
|
||||
value ^
|
||||
(value >> 2) ^
|
||||
(value >> 5) ^
|
||||
utime.ticks_cpu()
|
||||
) & 0xFF
|
||||
|
||||
entropy.append(mixed)
|
||||
|
||||
utime.sleep_us(5)
|
||||
|
||||
return entropy
|
||||
|
||||
def secure_random(num_bytes: int = 32):
|
||||
entropy = get_entropy()
|
||||
|
||||
digest = uhashlib.sha256(entropy).digest()
|
||||
|
||||
output = bytearray()
|
||||
|
||||
while len(output) < num_bytes:
|
||||
digest = uhashlib.sha256(digest).digest()
|
||||
output.extend(digest)
|
||||
|
||||
return bytes(output[:num_bytes])
|
||||
Reference in New Issue
Block a user