pfalcon / pycopy-lib

Standard library of the Pycopy project, minimalist and light-weight Python language implementation
https://github.com/pfalcon/pycopy
Other
246 stars 70 forks source link

Micropython v1.17 SHA1 #69

Open DarrylIdle opened 2 years ago

DarrylIdle commented 2 years ago

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'

DarrylIdle commented 2 years ago

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()

EstebanSteffovski commented 2 years ago

Same thing, but with md5 method AttributeError: 'module' object has no attribute 'md5'

tyoc213 commented 7 months ago

@DarrylIdle @EstebanSteffovski a dir on the module return this

['__class__', '__name__', '__dict__', 'sha1', 'sha256']

so ideally sha1 should be there, but not md5