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/omega-mv/blob/main/src/fabric/fab_hmac.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / fabric / fab_hmac.om` 146 lines ยท 3142 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 note 4 note src/fabric/fab_hmac.om -- HMAC-SHA256 (RFC 2104), constant-time compare, 5 note canonical LE codecs, and 64-byte stand-in signature for Fabric F5-0. 6 note Composed after seed/ng/sha256.om and src/runtime/aien_machine_id.om. 7 8 const FAB_SIG_BYTES ulong 64 9 10 text t_fab_half2 "AFAB stand-in sig64 half 2" 11 12 fn fab_put_u16 dst edit uchar * pos ulong v ulong to void 13 put dst pos uchar and v 255 14 put dst add pos 1 uchar and shr v 8 255 15 end 16 17 fn fab_put_u32 dst edit uchar * pos ulong v ulong to void 18 for i ulong 4 19 put dst add pos i uchar and shr v mul i 8 255 20 end 21 end 22 23 fn fab_put_u64 dst edit uchar * pos ulong v ulong to void 24 for i ulong 8 25 put dst add pos i uchar and shr v mul i 8 255 26 end 27 end 28 29 fn fab_get_u16 src view uchar * pos ulong to ulong 30 b0 = ulong get src pos 31 b1 = ulong get src add pos 1 32 ret or b0 shl b1 8 33 end 34 35 fn fab_get_u32 src view uchar * pos ulong to ulong 36 v = ulong 0 37 for i ulong 4 38 b = ulong get src add pos i 39 v = or v shl b mul i 8 40 end 41 ret v 42 end 43 44 fn fab_get_u64 src view uchar * pos ulong to ulong 45 v = ulong 0 46 for i ulong 8 47 b = ulong get src add pos i 48 v = or v shl b mul i 8 49 end 50 ret v 51 end 52 53 fn fab_ct_equal a view uchar * b view uchar * n ulong to int 54 acc = ulong 0 55 for i ulong n bound `9223372036854775807` 56 acc = or acc xor ulong get a i ulong get b i 57 end 58 if eq acc 0 59 ret 1 60 end 61 ret 0 62 end 63 64 fn fab_ct_equal64 a view uchar 64 b view uchar 64 to int 65 acc = ulong 0 66 for i ulong 64 67 acc = or acc xor ulong get a i ulong get b i 68 end 69 if eq acc 0 70 ret 1 71 end 72 ret 0 73 end 74 75 fn fab_hmac_sha256 key view uchar * msg view uchar * dst edit uchar 32 to int 76 k = new uchar 64 0 77 inner = new uchar 32 0 78 klen = len key 79 mlen = len msg 80 if gt klen 64 81 for i ulong klen bound 65536 82 put sh_dat i get key i 83 end 84 sh_all klen 85 for i ulong 32 86 put k i get sh_dig i 87 end 88 else 89 for i ulong klen bound 64 90 put k i get key i 91 end 92 end 93 for i ulong 64 94 put sh_dat i uchar xor ulong get k i 54 95 end 96 for i ulong mlen bound 65536 97 put sh_dat add 64 i get msg i 98 end 99 sh_all add 64 mlen 100 for i ulong 32 101 put inner i get sh_dig i 102 end 103 for i ulong 64 104 put sh_dat i uchar xor ulong get k i 92 105 end 106 for i ulong 32 107 put sh_dat add 64 i get inner i 108 end 109 sh_all 96 110 for i ulong 32 111 put dst i get sh_dig i 112 put inner i uchar 0 113 end 114 for i ulong 64 115 put k i uchar 0 116 end 117 ret 0 118 end 119 120 fn fab_hmac_sig64 key view uchar 32 msg view uchar * dst edit uchar 64 to int 121 h1 = new uchar 32 0 122 k2 = new uchar 32 0 123 h2 = new uchar 32 0 124 dom = new uchar 26 0 125 for i ulong 26 126 put dom i get t_fab_half2 i 127 end 128 rc = fab_hmac_sha256 part key 0 32 view msg edit h1 129 if ne rc 0 130 ret sub int 0 1 131 end 132 rc = fab_hmac_sha256 part key 0 32 view dom edit k2 133 if ne rc 0 134 ret sub int 0 1 135 end 136 rc = fab_hmac_sha256 part k2 0 32 view msg edit h2 137 if ne rc 0 138 ret sub int 0 1 139 end 140 for i ulong 32 141 put dst i get h1 i 142 put dst add 32 i get h2 i 143 put k2 i uchar 0 144 end 145 ret 0 146 end