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

Function padded

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

* Anhaengen der Laenge nach der Merkle-Damgard-Vorschrift, die sha1 und sha256 * teilen: ein 0x80-Byte, Nullen bis 56 mod 64, dann die Bitlaenge big-endian.

(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

42 * teilen: ein 0x80-Byte, Nullen bis 56 mod 64, dann die Bitlaenge big-endian.
43 */
44function padded(bytes: Uint8Array): Uint32Array {
45 const bitLength = bytes.length * 8;
46 const blocks = Math.ceil((bytes.length + 9) / 64);
47 const words = new Uint32Array(blocks * 16);
48 for (let i = 0; i < bytes.length; i += 1) {
49 words[i >> 2] |= bytes[i] << (24 - (i % 4) * 8);
50 }
51 words[bytes.length >> 2] |= 0x80 << (24 - (bytes.length % 4) * 8);
52 // Die obere Haelfte der 64-Bit-Laenge bleibt null: eine Eingabe jenseits
53 // von 512 MB kommt hier nicht vor, und sie zu behaupten waere schlimmer,
54 // als sie nicht zu unterstuetzen.
55 words[blocks * 16 - 1] = bitLength >>> 0;
56 words[blocks * 16 - 2] = Math.floor(bitLength / 0x100000000);
57 return words;
58}
59
60const rotl = (value: number, by: number): number => (value << by) | (value >>> (32 - by));
61const rotr = (value: number, by: number): number => (value >>> by) | (value << (32 - by));

Callers 2

sha1BytesFunction · 0.85
sha256BytesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected