Browse Source

use bytes.fromhex instead...

main
John-Mark Gurney 3 years ago
parent
commit
d0c6981410
1 changed files with 5 additions and 6 deletions
  1. +5
    -6
      lora_comms.py

+ 5
- 6
lora_comms.py View File

@@ -25,7 +25,6 @@
import os import os
import unittest import unittest


from binascii import a2b_hex
from ctypes import Structure, POINTER, CFUNCTYPE, pointer, sizeof from ctypes import Structure, POINTER, CFUNCTYPE, pointer, sizeof
from ctypes import c_uint8, c_uint16, c_ssize_t, c_size_t, c_uint64, c_int from ctypes import c_uint8, c_uint16, c_ssize_t, c_size_t, c_uint64, c_int
from ctypes import CDLL from ctypes import CDLL
@@ -233,16 +232,16 @@ class TestX25519(unittest.TestCase):


def test_rfc7748_6_1(self): def test_rfc7748_6_1(self):
# KAT from https://datatracker.ietf.org/doc/html/rfc7748#section-6.1 # KAT from https://datatracker.ietf.org/doc/html/rfc7748#section-6.1
apriv = a2b_hex('77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a')
apriv = bytes.fromhex('77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a')


akey = X25519(apriv) akey = X25519(apriv)
self.assertEqual(akey.getpub(), a2b_hex('8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a'))
self.assertEqual(akey.getpub(), bytes.fromhex('8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a'))


bpriv = a2b_hex('5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb')
bpriv = bytes.fromhex('5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb')
bkey = X25519(bpriv) bkey = X25519(bpriv)
self.assertEqual(bkey.getpub(), a2b_hex('de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f'))
self.assertEqual(bkey.getpub(), bytes.fromhex('de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f'))


ss = a2b_hex('4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742')
ss = bytes.fromhex('4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742')
self.assertEqual(akey.dh(bkey.getpub()), ss) self.assertEqual(akey.dh(bkey.getpub()), ss)
self.assertEqual(bkey.dh(akey.getpub()), ss) self.assertEqual(bkey.dh(akey.getpub()), ss)




Loading…
Cancel
Save