pycopy-lib
pycopy-lib copied to clipboard
Micropython v1.17 SHA1
Hi,
I'm very new to the Raspberry Pi ecosystem. I've been trying to make a Raspberry Pi Pico totp generator and have gotten to the point of displaying a totp code. Since totp is built around SHA1 by default I've been trying to do the following to no avail. I'm using Thonny as the IDE of choice to work in and have installed the micropython-hashlib v0.0.1 latest stable.
import time import ubinascii import uhashlib import lcd from machine import Pin
totp = [("Discord ", 'JBSWY3DPEHPK3PXP')]
TEST = True ALWAYS_ON = True ON_SECONDS = 10 EPOCH_DELTA = 1638239843 SECS_DAY = 86400 SHA1 = uhashlib.sha1 LCD = lcd.LCD_1inch14()
def HMAC(k, m): SHA1_BLOCK_SIZE = 64 KEY_BLOCK = k + (b'\0' * (SHA1_BLOCK_SIZE - len(k))) KEY_INNER = bytes((x ^ 0x36) for x in KEY_BLOCK) KEY_OUTER = bytes((x ^ 0x5C) for x in KEY_BLOCK) inner_message = KEY_INNER + m outer_message = KEY_OUTER + SHA1(inner_message).digest() return SHA1(outer_message)
I get the following message: AttributeError: 'module' object has no attribute 'sha1'
I've also tried switching uhaslib to hashlib but still no dice. When exploring the package it has _sha224.py, _sha256.py, etc but no _sha1.py and init.py shows sha1 in the def init()
Same thing, but with md5 method AttributeError: 'module' object has no attribute 'md5'
@DarrylIdle @EstebanSteffovski a dir on the module return this
['__class__', '__name__', '__dict__', 'sha1', 'sha256']
so ideally sha1
should be there, but not md5