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 / acvp / mlkemacvp.om

130 lines · 2515 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note mlkemacvp.om: ACVP ML-KEM (FIPS 203) response engine for om/tls/mlkem.om (ML-KEM-768). The program
3note is acvpio.om || mlkemacvp.om || acvpmain.om, composed after sha3.om and mlkem.om (run.sh does
4note this). Records on stdin, as in acvp.om (hex, "-" = empty, ID echoed first):
5note Q ID D Z mlkem_keygen (ML-KEM.KeyGen_internal) -> ID RC EK DK
6note P ID EK M mlkem_encaps (ML-KEM.Encaps_internal, 7.2 checks) -> ID RC C K
7note U ID DK C mlkem_decaps (ML-KEM.Decaps_internal, 7.3 checks) -> ID RC K
8note Y ID DK decapsulation key check: mlkem_decaps on DK and an all-zero 1088-byte ciphertext;
9note its 7.3 input checks (lengths, H(ek) == h) run before any decapsulation -> ID RC
10note Z ID EK encapsulation key check: mlkem_encaps on EK and an all-zero m; its 7.2 input
11note checks (length, modulus) run first -> ID RC
12note RC is the library's return code (0 ok, 1 modulus check failed, 2 bad length, 3 hash check failed).
13
14note copy a[o..o+32) into d
15fn mkcp a view uchar * o ulong d edit uchar 32 to void
16for i ulong 32
17put d i get a add o i
18end
19end
20
21fn recq a edit uchar * b edit uchar * to void
22d = new uchar 32 0
23z = new uchar 32 0
24drid
25dl = drhex a
26zl = drhex part a 32 32
27dreor
28if ne dl 32
29drbad
30end
31if ne zl 32
32drbad
33end
34if isbad
35ret
36end
37mkcp a 0 d
38mkcp a 32 z
39rc = mlkem_keygen d z part a 0 1184 part b 0 2400
40ofld rc
41ohex part a 0 1184
42ohex part b 0 2400
43end
44
45fn recp a edit uchar * b edit uchar * to void
46m = new uchar 32 0
47ss = new uchar 32 0
48drid
49el = drhex a
50ml = drhex b
51dreor
52if ne ml 32
53drbad
54end
55if isbad
56ret
57end
58mkcp b 0 m
59rc = mlkem_encaps part a 0 el m part b 0 1088 ss
60ofld rc
61ohex part b 0 1088
62ohex ss
63end
64
65fn recu a edit uchar * b edit uchar * to void
66ss = new uchar 32 0
67drid
68dl = drhex a
69cl = drhex b
70dreor
71if isbad
72ret
73end
74rc = mlkem_decaps part a 0 dl part b 0 cl ss
75ofld rc
76ohex ss
77end
78
79fn recy a edit uchar * to void
80ct = new uchar 1088 0
81ss = new uchar 32 0
82drid
83dl = drhex a
84dreor
85if isbad
86ret
87end
88rc = mlkem_decaps part a 0 dl ct ss
89ofld rc
90end
91
92fn recz a edit uchar * to void
93m = new uchar 32 0
94ct = new uchar 1088 0
95ss = new uchar 32 0
96drid
97el = drhex a
98dreor
99if isbad
100ret
101end
102rc = mlkem_encaps part a 0 el m ct ss
103ofld rc
104end
105
106fn drrec a edit uchar * b edit uchar * c edit uchar * to void
107op = drpeek
108dradv
109if eq op 81
110recq a b
111ret
112end
113if eq op 80
114recp a b
115ret
116end
117if eq op 85
118recu a b
119ret
120end
121if eq op 89
122recy a
123ret
124end
125if eq op 90
126recz a
127ret
128end
129drbad
130end