MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sha256Bytes

Function sha256Bytes

graph-ui/src/core/hash.ts:121–161  ·  view source on GitHub ↗

sha256 einer Bytefolge, synchron. Der Fallback fuer `crypto.subtle`.

(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

119
120/** sha256 einer Bytefolge, synchron. Der Fallback fuer `crypto.subtle`. */
121function sha256Bytes(bytes: Uint8Array): string {
122 const words = padded(bytes);
123 const h = new Uint32Array([
124 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
125 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
126 ]);
127 const w = new Uint32Array(64);
128
129 for (let block = 0; block < words.length; block += 16) {
130 for (let i = 0; i < 16; i += 1) {
131 w[i] = words[block + i];
132 }
133 for (let i = 16; i < 64; i += 1) {
134 const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
135 const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
136 w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
137 }
138 let [a, b, c, d, e, f, g, hh] = [h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7]];
139 for (let i = 0; i < 64; i += 1) {
140 const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
141 const ch = (e & f) ^ (~e & g);
142 const temp1 = (hh + s1 + ch + SHA256_K[i] + w[i]) >>> 0;
143 const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
144 const maj = (a & b) ^ (a & c) ^ (b & c);
145 const temp2 = (s0 + maj) >>> 0;
146 hh = g;
147 g = f;
148 f = e;
149 e = (d + temp1) >>> 0;
150 d = c;
151 c = b;
152 b = a;
153 a = (temp1 + temp2) >>> 0;
154 }
155 const next = [a, b, c, d, e, f, g, hh];
156 for (let i = 0; i < 8; i += 1) {
157 h[i] = (h[i] + next[i]) >>> 0;
158 }
159 }
160 return toHex(h);
161}
162
163/** sha1 eines Textes als Hex, synchron. */
164export function sha1Hex(text: string): string {

Callers 1

sha256HexSyncFunction · 0.85

Calls 3

paddedFunction · 0.85
rotrFunction · 0.85
toHexFunction · 0.85

Tested by

no test coverage detected