2016-09-27 14:48:21 +00:00
|
|
|
|
2016-10-24 13:44:49 +00:00
|
|
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
|
|
|
def generate_secret() -> bytes:
|
|
|
|
'''
|
|
|
|
Generate secret key.
|
|
|
|
'''
|
|
|
|
|
2016-09-27 14:48:21 +00:00
|
|
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
|
|
|
def publickey(secret_key: bytes, compressed: bool=True) -> bytes:
|
|
|
|
'''
|
|
|
|
Computes public key from secret key.
|
|
|
|
'''
|
|
|
|
|
|
|
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
2016-11-08 14:37:48 +00:00
|
|
|
def sign(secret_key: bytes, digest: bytes) -> bytes:
|
2016-09-27 14:48:21 +00:00
|
|
|
'''
|
2016-11-08 14:37:48 +00:00
|
|
|
Uses secret key to produce the signature of the digest.
|
2016-09-27 14:48:21 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
2016-11-08 14:37:48 +00:00
|
|
|
def verify(public_key: bytes, signature: bytes, digest: bytes) -> bool:
|
2016-09-27 14:48:21 +00:00
|
|
|
'''
|
2016-11-08 14:37:48 +00:00
|
|
|
Uses public key to verify the signature of the digest.
|
2016-09-27 14:48:21 +00:00
|
|
|
Returns True on success.
|
|
|
|
'''
|
2016-10-24 13:44:49 +00:00
|
|
|
|
|
|
|
# ../extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h
|
|
|
|
def multiply(secret_key: bytes, public_key: bytes) -> bytes:
|
|
|
|
'''
|
|
|
|
Multiplies point defined by public_key with scalar defined by secret_key
|
|
|
|
Useful for ECDH
|
|
|
|
'''
|