interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / tls / test / fips / driver.om

264 lines · 6514 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note driver.om: test driver for om/tls/fips.om (program mode, built with om/tls/build.sh after the
3note whole library). usage: driver [drbgerr]
4note 1. pre-operational self-tests: fips_check 0 (KATs), fips_check 1 (DRBG KAT); state words
5note 2. entropy input: 4096 health-tested getrandom bytes; the start-up test ran; every drawn
6note sample entered the APT window (1024 + 4096 + 32 samples leave its position at 32)
7note 3. health-test controls on fips_ht: a run of 7 equal samples passes and 8 trip the RCT
8note (cut-off 8); a window with 34 copies of its first sample passes and 35 trip the APT
9note (W 512, cut-off 35)
10note 4. approved-mode DRBG: instantiate, two prediction-resistant requests (64 and 32 bytes) whose
11note first 32 bytes differ; the reseed counter shows a reseed before each request
12note 5. X25519 pairwise consistency test on a good key pair; tls_rand in both modes; tls_wipe
13note zeroes the approved-mode DRBG state in c
14note 6. the latch: a wrong public key fails the PCT (detail 21) or, with drbgerr, a DRBG in its
15note error state fails the request (detail 20); afterwards entropy, DRBG, fips_check,
16note tls_connect (TLS_ERR_SELFTEST, before any I/O), tls_seal and tls_open all refuse
17note When a self-test fails in step 1 the driver prints "REFUSED detail D", runs the refusal
18note checks of step 6 and exits 3 when they hold. Otherwise prints "FAIL check N got G want W" per
19note failed check and "fips driver: C checks, F failed"; exit 0 only when F is 0.
20
21global fdob uchar 32
22global fdst ulong 4
23text fdtf "FAIL check "
24text fdtg " got "
25text fdtw " want "
26text fdtr "REFUSED detail "
27text fdts "fips driver: "
28text fdtc " checks, "
29text fdtx " failed\n"
30text fdtnl "\n"
31text fdhost "fips.example"
32note "TLS_ERR_SELFTEST" and "drbgerr" as hex (fips_cmp compares against hex texts)
33text fdhexn "544c535f4552525f53454c4654455354"
34text fdhexm "64726267657272"
35text fdhexe "656367656e657272"
36
37fn fdprn v ulong to void
38x = v
39k = ulong 0
40while true bound 21
41put fdob sub 31 k uchar add 48 rem x 10
42k = add k 1
43x = div x 10
44if eq x 0
45break
46end
47end
48r = write 1 fdob sub 32 k k
49end
50
51note one check: id, got, want
52fn fdt id ulong got ulong want ulong to void
53put fdst 0 add get fdst 0 1
54if ne got want
55put fdst 1 add get fdst 1 1
56r = write 1 fdtf 0 len fdtf
57fdprn id
58r = write 1 fdtg 0 len fdtg
59fdprn got
60r = write 1 fdtw 0 len fdtw
61fdprn want
62r = write 1 fdtnl 0 1
63end
64end
65
66note 1 when a holds a nonzero byte
67fn fdnz a view uchar * to ulong
68d = ulong 0
69for i ulong len a
70d = or d ulong get a i
71end
72if eq d 0
73ret 0
74end
75ret 1
76end
77
78note 1 when a and b (same length) differ
79fn fddiff a view uchar * b view uchar * to ulong
80d = ulong 0
81for i ulong len a
82d = or d xor ulong get a i ulong get b i
83end
84if eq d 0
85ret 0
86end
87ret 1
88end
89
90note reset the health-test state (not the start-up flag)
91fn fdhr to void
92for i ulong 6
93put FPST add 3 i 0
94end
95end
96
97note feed n copies of sample x, then one sample y
98fn fdrun x ulong n ulong y ulong to ulong
99fdhr
100for i ulong n
101fips_ht x
102end
103fips_ht y
104ret get FPST 8
105end
106
107note one APT window: sample 0x41 at the multiples of 15 below 15n (n copies spread over the
108note whole 512-sample window; n = 35 puts the last at 510), 0x80 + (i % 64) elsewhere (no runs)
109fn fdapt n ulong to ulong
110fdhr
111for i ulong 512
112if eq and lt i mul 15 n eq rem i 15 0 1
113fips_ht 65
114else
115fips_ht add 128 and i 63
116end
117end
118ret get FPST 8
119end
120
121note refusal checks once the module is in its error state (id base 60)
122fn fdref c edit uchar * to void
123z = new uchar 16 0
124n = new uchar 64 0
125fdt 60 fips_bad 1
126fdt 61 tls_init c fdhost 0 0
127fdt 62 tls_connect c z 0 TLESELF
128fdt 63 ulong get c TLPH 3
129k = tls_errname TLESELF n
130fdt 64 fips_cmp part n 0 k fdhexn 0
131fdt 65 tls_seal c 0 TLESELF
132fdt 66 tls_open c 0 TLESELF
133end
134
135note approved-mode ECDH key generation draws from the DRBG at c[TLDRBG]: its state must change
136fn fdecg c edit uchar * b edit uchar * to void
137for i ulong DRSZ
138put b i get c add TLDRBG i
139end
140fdt 44 tls_ecgen c 32 0
141fdt 45 fddiff part c TLDRBG DRSZ part b 0 DRSZ 1
142fdt 46 tls_ecgen c 48 0
143fdt 47 fdnz part c TLECQ3 97 1
144end
145
146note ecgenerr: a key generation that cannot succeed (nb 40) latches the error state with detail 21
147fn fdecx c edit uchar * to void
148fdt 76 tls_init c fdhost 4 0
149fdt 77 fips_drbgnew part c TLDRBG DRSZ 0
150fdt 70 tls_ecgen c 40 TLESELF
151fdt 71 fips_detail 21
152fdt 72 fdnz part c TLECD2 145 0
153end
154
155note steps 2-5 (id base 10)
156fn fdpos c edit uchar TLCSZ st edit uchar 128 b edit uchar 4096 k edit uchar 32 q edit uchar 32 to void
157fdt 10 fips_entropy b 0
158fdt 11 get FPST 9 1
159fdt 12 get FPST 8 0
160fdt 13 fdnz b 1
161fdt 14 fips_entropy k 0
162fdt 15 get FPST 7 32
163fdt 20 fdrun 66 7 67 0
164fdt 21 fdrun 66 8 67 1
165fdt 23 fdapt 34 0
166fdt 24 fdapt 35 2
167fdhr
168fdt 25 fips_bad 0
169fdt 30 fips_drbgnew st 0
170fdt 31 ulong get st DRFL 1
171fdt 32 fips_drbgget st part b 0 64 0
172fdt 33 fips_drbgget st q 0
173fdt 34 fddiff part b 0 32 q 1
174fdt 35 fdnz part b 0 64 1
175fdt 36 drbg_rd st DRCTR 2
176fdt 40 fips_entropy k 0
177fdt 41 x25519_base q k 0
178fdt 42 fips_pctx k q 0
179fdt 43 fips_bad 0
180fdt 50 tls_init c fdhost 4 0
181fdt 51 fips_drbgnew part c TLDRBG DRSZ 0
182fdt 52 tls_rand c k 0
183fdt 53 fdnz k 1
184fdecg c b
185fdt 57 drbg_rd part c TLDRBG DRSZ DRCTR 2
186tls_wipe c
187fdt 58 fdnz part c TLDRBG DRSZ 0
188fdt 54 tls_init c fdhost 0 0
189fdt 55 tls_rand c k 0
190fdt 56 fdnz k 1
191end
192
193note the driver mode from argv[1]: 0 none, 1 drbgerr, 2 ecgenerr
194fn fdmode to ulong
195a = new uchar 16 0
196if lt argcnt 2
197ret 0
198end
199l = argread 1 a 0 16
200if eq l 7
201if eq fips_cmp part a 0 7 fdhexm 0
202ret 1
203end
204end
205if eq l 8
206if eq fips_cmp part a 0 8 fdhexe 0
207ret 2
208end
209end
210ret 0
211end
212
213fn main to int
214c = new uchar TLCSZ 0
215st = new uchar 128 0
216b = new uchar 4096 0
217k = new uchar 32 0
218q = new uchar 32 0
219mode = fdmode
220d = fips_check 0
221if eq d 0
222d = fips_check 1
223end
224if ne d 0
225r = write 1 fdtr 0 len fdtr
226fdprn d
227r = write 1 fdtnl 0 1
228fdref c
229if eq get fdst 1 0
230ret 3
231end
232ret 1
233end
234fdt 1 get FPST 0 1
235fdt 2 get FPST 2 1
236fdpos c st b k q
237if eq mode 0
238put q 0 uchar xor ulong get q 0 1
239fdt 70 fips_pctx k q 1
240fdt 71 fips_detail 21
241end
242if eq mode 2
243fdecx c
244end
245if eq mode 1
246put st DRERR 1
247fdt 70 fips_drbgget st part b 0 32 1
248fdt 71 fips_detail 20
249fdt 72 fdnz part b 0 32 0
250end
251fdt 73 fips_entropy part b 0 32 1
252fdt 74 fips_drbgget st part b 0 32 1
253fdt 75 fips_check 0 fips_detail
254fdref c
255r = write 1 fdts 0 len fdts
256fdprn get fdst 0
257r = write 1 fdtc 0 len fdtc
258fdprn get fdst 1
259r = write 1 fdtx 0 len fdtx
260if and gt get fdst 0 0 eq get fdst 1 0
261ret 0
262end
263ret 1
264end