Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/argon2/test/gen/vectors.py # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / argon2 / test / gen / vectors.py` 104 lines ยท 4641 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 """Vector generator for om/argon2 (test only; nothing here ships). 3 4 vectors.py ORACLE > ../vectors/go-diff.txt the committed corpus 5 vectors.py ORACLE random SEED N > FILE N random small parameter sets (run.sh, optional) 6 7 Builds the case list below (seeded, deterministic), runs the Go referee ORACLE (gen/oracle, built 8 from golang.org/x/crypto v0.54.0, the version tailscale.com v1.102.0 pins) on it, and prints one 9 line per case: the driver input line followed by the expected tag in lowercase hex. 10 case T M P TL PW SALT KEY AD TAG 11 tka SEC TAG 12 """ 13 import random 14 import subprocess 15 import sys 16 17 18 def hx(b): 19 return b.hex() or "-" 20 21 22 def cases(): 23 rng = random.Random(9106) 24 rb = rng.randbytes 25 out = [] 26 # (t, m KiB, p, tag length, |P|, |S|, |K|, |X|) 27 sets = [ 28 (1, 8, 1, 32, 32, 16, 0, 0), # smallest memory: m' = 8, one lane 29 (2, 64, 1, 32, 0, 16, 0, 0), # empty password 30 (3, 32, 4, 32, 32, 16, 8, 12), # RFC 9106 5.2 shape, random bytes 31 (1, 37, 2, 32, 16, 16, 0, 0), # m not a multiple of 4p: m' = 32 32 (2, 63, 3, 16, 10, 8, 0, 0), # p = 3, m' = 60 33 (3, 100, 5, 24, 20, 12, 4, 0), # p = 5, m' = 100, with K 34 (1, 64, 8, 32, 8, 8, 0, 5), # p = 8 (minimum m = 8p), with X 35 (4, 256, 16, 32, 32, 16, 0, 0), # p = 16 36 (2, 1536, 3, 32, 32, 16, 0, 0), # p = 3, segment length exactly 128 37 (1, 1024, 1, 32, 32, 16, 0, 0), # segment length 256: 2 address blocks 38 (2, 2048, 2, 32, 32, 16, 32, 32), # segment length 256, K and X 39 (1, 4096, 1, 64, 64, 32, 0, 0), # segment length 1024: 8 address blocks 40 (1, 512, 1, 32, 32, 16, 0, 0), # segment length 128 from index 2: one address block 41 (1, 16, 2, 4, 3, 8, 0, 0), # tag length 4 (minimum) 42 (1, 16, 2, 5, 3, 8, 0, 0), # tag length 5 43 (1, 16, 1, 63, 12, 16, 0, 0), # tag 63 44 (1, 16, 1, 64, 12, 16, 0, 0), # tag 64: last single BLAKE2b call 45 (1, 16, 1, 65, 12, 16, 0, 0), # tag 65: first H' chain (r = 1) 46 (1, 16, 1, 96, 12, 16, 0, 0), # tag 96 47 (1, 16, 1, 100, 12, 16, 0, 0), # tag 100 48 (1, 16, 1, 128, 12, 16, 0, 0), # tag 128 49 (1, 16, 1, 129, 12, 16, 0, 0), # tag 129 50 (1, 16, 1, 512, 12, 16, 0, 0), # tag 512 51 (1, 16, 1, 1024, 12, 16, 0, 0), # tag 1024 (maximum) 52 (5, 48, 3, 32, 200, 300, 32, 400), # long inputs 53 (1, 32, 1, 32, 4000, 16, 64, 4000), # H0 input of several BLAKE2b blocks 54 (1, 8, 1, 32, 65480, 16, 0, 0), # H0 input at the 65496-byte capacity 55 (1, 16384, 1, 32, 32, 16, 0, 0), # 16 MiB, one lane 56 (1, 16384, 4, 32, 32, 39, 0, 0), # 16 MiB, four lanes 57 (2, 16383, 4, 32, 16, 16, 0, 0), # m' = 16368 58 (4, 16384, 4, 32, 32, 39, 0, 0), # TKA cost parameters, random salt 59 ] 60 for t, m, p, tl, pn, sn, kn, xn in sets: 61 out.append("case %d %d %d %d %s %s %s %s" % ( 62 t, m, p, tl, hx(rb(pn)), hx(rb(sn)), hx(rb(kn)), hx(rb(xn)))) 63 for n in (0, 1, 16, 32, 32, 32, 32, 33, 64, 1024): 64 out.append("tka %s" % hx(rb(n))) 65 return out 66 67 68 def randcases(seed, count): 69 """count random small parameter sets: t 1..4, p 1..8, m 8p..8p+120, T 4..200, random input 70 lengths (|P| 0..300, |S| 0..64, |K| 0..64, |X| 0..64, each 0 with probability 1/4).""" 71 rng = random.Random(seed) 72 73 def ln(hi): 74 return 0 if rng.random() < 0.25 else rng.randint(1, hi) 75 76 out = [] 77 for _ in range(count): 78 p = rng.randint(1, 8) 79 out.append("case %d %d %d %d %s %s %s %s" % ( 80 rng.randint(1, 4), rng.randint(8 * p, 8 * p + 120), p, rng.randint(4, 200), 81 hx(rng.randbytes(ln(300))), hx(rng.randbytes(ln(64))), 82 hx(rng.randbytes(ln(64))), hx(rng.randbytes(ln(64))))) 83 return out 84 85 86 def main(): 87 oracle = sys.argv[1] 88 if len(sys.argv) == 5 and sys.argv[2] == "random": 89 lines = randcases(int(sys.argv[3]), int(sys.argv[4])) 90 elif len(sys.argv) == 2: 91 lines = cases() 92 else: 93 sys.exit(__doc__) 94 feed = "".join(l.split(" ", 1)[1] + "\n" if l.startswith("case ") else l + "\n" for l in lines) 95 res = subprocess.run([oracle], input=feed.encode(), capture_output=True, check=True) 96 tags = res.stdout.decode().split("\n")[:-1] 97 if len(tags) != len(lines): 98 sys.exit("oracle returned %d lines for %d cases" % (len(tags), len(lines))) 99 for l, t in zip(lines, tags): 100 print(l, t) 101 102 103 if __name__ == "__main__": 104 main()