MCPcopy Create free account
hub / github.com/pyca/cryptography / load_kasvs_dh_vectors

Function load_kasvs_dh_vectors

tests/utils.py:542–594  ·  view source on GitHub ↗

Loads data out of the KASVS key exchange vector data

(vector_data)

Source from the content-addressed store, hash-verified

540
541
542def load_kasvs_dh_vectors(vector_data):
543 """
544 Loads data out of the KASVS key exchange vector data
545 """
546
547 vectors = []
548 data: typing.Dict[str, typing.Any] = {"fail_z": False, "fail_agree": False}
549
550 for line in vector_data:
551 line = line.strip()
552
553 if not line or line.startswith("#"):
554 continue
555
556 if line.startswith("P = "):
557 data["p"] = int(line.split("=")[1], 16)
558 elif line.startswith("Q = "):
559 data["q"] = int(line.split("=")[1], 16)
560 elif line.startswith("G = "):
561 data["g"] = int(line.split("=")[1], 16)
562 elif line.startswith("Z = "):
563 z_hex = line.split("=")[1].strip().encode("ascii")
564 data["z"] = binascii.unhexlify(z_hex)
565 elif line.startswith("XstatCAVS = "):
566 data["x1"] = int(line.split("=")[1], 16)
567 elif line.startswith("YstatCAVS = "):
568 data["y1"] = int(line.split("=")[1], 16)
569 elif line.startswith("XstatIUT = "):
570 data["x2"] = int(line.split("=")[1], 16)
571 elif line.startswith("YstatIUT = "):
572 data["y2"] = int(line.split("=")[1], 16)
573 elif line.startswith("Result = "):
574 result_str = line.split("=")[1].strip()
575 match = KASVS_RESULT_REGEX.match(result_str)
576 assert match is not None
577
578 if match.group(1) == "F":
579 if int(match.group(2)) in (5, 10):
580 data["fail_z"] = True
581 else:
582 data["fail_agree"] = True
583
584 vectors.append(data)
585
586 data = {
587 "p": data["p"],
588 "q": data["q"],
589 "g": data["g"],
590 "fail_z": False,
591 "fail_agree": False,
592 }
593
594 return vectors
595
596
597def load_kasvs_ecdh_vectors(vector_data):

Callers 1

Calls 1

unhexlifyMethod · 0.80

Tested by 1