Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micropython v1.17 SHA1 #69

Open
DarrylIdle opened this issue Nov 30, 2021 · 3 comments
Open

Micropython v1.17 SHA1 #69

DarrylIdle opened this issue Nov 30, 2021 · 3 comments

Comments

@DarrylIdle
Copy link

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
Copy link
Author

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
Copy link

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

@tyoc213
Copy link

tyoc213 commented Jan 25, 2024

@DarrylIdle @EstebanSteffovski a dir on the module return this

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

so ideally sha1 should be there, but not md5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants