Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : QYVORA7# File : Tests/QyvoraSymmetricTests/Vectors/tools/extract-rfc8439.py8# Module : Tests9# Repository : https://git.spboucher.ai/qyvora10# Project Website : Not specified11# Created : 2026-12-0412# Last Modified : 2026-12-0413#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: contact@spboucher.ai22# Development : dev@spboucher.ai23# Support : support@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041"""Extracts the hex dumps of RFC 8439 (sections 2.x and Appendix A) into JSON.4243usage: python3 -I extract-rfc8439.py <rfc8439.txt> <out.json>44"""45import json, re, sys4647src, dst = sys.argv[1], sys.argv[2]48lines = open(src, encoding="utf-8").read().split("\n")49sec_re = re.compile(r"^(\d\.\d(?:\.\d)?|A\.\d)\. (.*)$")50dump_re = re.compile(r"^\s+(\d{3}) ((?:[0-9a-f]{2} ?)+)")51vec_re = re.compile(r"^\s+Test Vector #(\d+):")52ctr_re = re.compile(r"^\s+(?:Initial )?Block Counter = (\d+)")5354records = []55cur = None56section = None57label = None58last_text = None59started = False60for ln in lines:61 if ln.startswith("2.3.2. Test Vector for the ChaCha20 Block Function"):62 started = True63 if not started:64 continue65 if ln.startswith("Appendix B."):66 break67 if not ln.strip() or ln.startswith("Nir & Langley") or ln.startswith("RFC 8439") or "\f" in ln:68 continue69 m = sec_re.match(ln)70 if m:71 section = m.group(1)72 cur = {"section": section, "vector": 0, "fields": {}}73 records.append(cur)74 label = None75 continue76 m = vec_re.match(ln)77 if m:78 cur = {"section": section, "vector": int(m.group(1)), "fields": {}}79 records.append(cur)80 label = None81 continue82 m = ctr_re.match(ln)83 if m and cur is not None:84 cur["counter"] = int(m.group(1))85 continue86 m = dump_re.match(ln)87 if m and cur is not None:88 off = int(m.group(1))89 data = m.group(2).replace(" ", "")90 if off == 0:91 label = last_text.strip().rstrip(":")92 if label in cur["fields"]:93 label = label + " (2)"94 cur["fields"][label] = ""95 assert len(cur["fields"][label]) == off * 2, (section, label, off)96 cur["fields"][label] += data97 continue98 last_text = ln99100records = [r for r in records if r["fields"]]101json.dump({"source": "RFC 8439 (https://www.rfc-editor.org/rfc/rfc8439.txt), hex dumps of sections 2.4.2-2.8.2 and Appendix A",102 "records": records}, open(dst, "w"), indent=1)103for r in records:104 print(r["section"], r["vector"], r.get("counter"), {k: len(v) // 2 for k, v in r["fields"].items()})105