Skip to content

Fix some errors when cryptography is a newer version #40

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions python/examples/ecdh.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from cryptography.utils import int_from_bytes

import time

Expand Down Expand Up @@ -100,8 +99,8 @@ def ECDH(slot, iface='hid', **kwargs):
# Convert device public key to a cryptography public key object
device_pub = ec.EllipticCurvePublicNumbers(
curve=ec.SECP256R1(),
x=int_from_bytes(device_pub[0:32], byteorder='big'),
y=int_from_bytes(device_pub[32:64], byteorder='big'),
x=int.from_bytes(device_pub[0:32], byteorder='big'),
y=int.from_bytes(device_pub[32:64], byteorder='big'),
).public_key(default_backend())

# Perform the host side ECDH computation
Expand Down
11 changes: 5 additions & 6 deletions python/examples/sign_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec, utils
from cryptography.exceptions import InvalidSignature
from cryptography.utils import int_from_bytes, int_to_bytes
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat

import time
Expand Down Expand Up @@ -99,7 +98,7 @@ def verify_device(message, signature, public_key):
def sign_host(digest, key):
signature = key.sign(digest, ec.ECDSA(utils.Prehashed(hashes.SHA256())))
(r,s) = utils.decode_dss_signature(signature)
signature = int_to_bytes(r, 32) + int_to_bytes(s, 32)
signature = int.to_bytes(r, 32, byteorder='big') + int.to_bytes(s, 32, byteorder='big')
return signature


Expand All @@ -108,14 +107,14 @@ def verify_host(digest, signature, public_key_data):
Verify a signature using the host software
"""
try:
r = int_from_bytes(signature[0:32], byteorder='big', signed=False)
s = int_from_bytes(signature[32:64], byteorder='big', signed=False)
r = int.from_bytes(signature[0:32], byteorder='big', signed=False)
s = int.from_bytes(signature[32:64], byteorder='big', signed=False)
sig = utils.encode_dss_signature(r, s)

public_key = ec.EllipticCurvePublicNumbers(
curve=ec.SECP256R1(),
x=int_from_bytes(public_key_data[0:32], byteorder='big'),
y=int_from_bytes(public_key_data[32:64], byteorder='big'),
x=int.from_bytes(public_key_data[0:32], byteorder='big'),
y=int.from_bytes(public_key_data[32:64], byteorder='big'),
).public_key(default_backend())
public_key.verify(sig, digest, ec.ECDSA(utils.Prehashed(hashes.SHA256())))
return True
Expand Down