from libwifi import * def test_crypto(): x = 32774075109236952337158599048510140249162039589740847669274255820096074575478 y = 65816200486131266053931191249788950977703402544735864608496951271815280382692 assert point_on_curve(x, y) assert not point_on_curve(x, y + 1) def test_sae(): # KDF_Length with 256 bits data = b'p(b\x08\x84%\xd4\xfc\x85\x02`>Z\x8e8\x02\x06\xdcak1_\x8a\xca\x90D2[\xda\x88\x87\xbe' label = "SAE Hunting and Pecking" context = b'\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' result = KDF_Length(data, label, context, 256) assert result == b"\xce\xd7\x0c`n\xc3\xa0V\xbc\xe5J' expected += b'\x80P\x1f[PB\xfaF\x13\xae\xef\xfd\xddBkX\xff\xe03\xd3q(\x80\x9f"S\xad\xfeK:\x98\x90\xde\xdfw' expected += b'\xd5\xe4\xf0O\xcf\x9c\xa1\r^\xf3\xf6\x1fp_\xd9\x13<\xf7\x0e\xf11\x81\x88\xb9\xfe\x80mn\xed\xf2' expected += b'\xdel\x8f8f\\\xd4\x91\x83}|\xd0\x90\xa6I\xac\xca\xdb\x1d4\x00\xf5\xf8\xf5/\xa1' assert result == expected k = 34571911558658786479991772754682275693090212979118519100150784653967632958583 e1x = 35056562182093533434520846036041768262744712948121085631797144112066231820275 e1y = 30178867311470377631935198005507521070028138958470370567962433403317268006022 e1 = ECC.EccPoint(e1x, e1y) s1 = 25673957538626389018921350300691255233489834439459044820849488820063961042178 e2x = 55846548926525467025361797152934092596912359473099878093027981331310692689958 e2y = 25540727936496301520339336932631497861346599764823572263118430938562903665071 e2 = ECC.EccPoint(e2x, e2y) s2 = 89671311642711662572527453485728796207545960881415665173397225314404138450610 confirm = calculate_confirm_eappwd(k, e1, s1, e2, s2) assert confirm == b"n\xe1N\xc1\x86\x0f\x94\x85W*Y\xf8\xf2'\x19\xac\x9c\xf6\xe6\xe6\x14\x8c+\xf7\x0e\xd0\xfdF\x87\x03G\xcc" pwe = derive_pwe_ecc_eappwd("password", "user", "server", 2903600207) assert pwe.x == 65324672961960968584356420288746215288928369435013474055323481826901726558522 assert pwe.y == 81287605691219879983190651062276165371083848816381214499332721121120114417256 pwe = derive_pwe_ecc_eappwd("password", "user", "server", 2546484939) assert pwe.x == 32774075109236952337158599048510140249162039589740847669274255820096074575478 assert pwe.y == 65816200486131266053931191249788950977703402544735864608496951271815280382692 pwe = derive_pwe_ecc_eappwd("hello", "bob", "theserver@example.com", 0xEE04524, curve_name="p521") assert pwe.x == 3008622341264366589487649162226557348235630833654679745848438214237061388319208914517686003128943873854271397962689455307621303688693893126759626682265352869 assert pwe.y == 649775647643090676911381912723346979966421674682002310678312738784243727860456911539411456724737204490685667258758093054491548052506429972664016924839683943