Development Artifact Cleanup: ✅ BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location - dev/test-nodes/brother_node/: Moved from root directory for better organization - Contains development configuration, test logs, and test chain data - No impact on production systems - purely development/testing artifact ✅ DEVELOPMENT ARTIFACTS IDENTIFIED: - Chain ID: aitbc-brother-chain (test/development chain) - Ports: 8010 (P2P) and 8011 (RPC) - different from production - Environment: .env file with test configuration - Logs: rpc.log and node.log from development testing session (March 15, 2026) ✅ ROOT DIRECTORY CLEANUP: Removed development clutter from production directory - brother_node/ moved to dev/test-nodes/brother_node/ - Root directory now contains only production-ready components - Development artifacts properly organized in dev/ subdirectory DIRECTORY STRUCTURE IMPROVEMENT: 📁 dev/test-nodes/: Development and testing node configurations 🏗️ Root Directory: Clean production structure with only essential components 🧪 Development Isolation: Test environments separated from production BENEFITS: ✅ Clean Production Directory: No development artifacts in root ✅ Better Organization: Development nodes grouped in dev/ subdirectory ✅ Clear Separation: Production vs development environments clearly distinguished ✅ Maintainability: Easier to identify and manage development components RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
83 lines
2.0 KiB
TypeScript
Executable File
83 lines
2.0 KiB
TypeScript
Executable File
// Counter Mode
|
|
|
|
import { ModeOfOperation } from "./mode.js";
|
|
|
|
export class CTR extends ModeOfOperation {
|
|
|
|
// Remaining bytes for the one-time pad
|
|
#remaining: Uint8Array;
|
|
#remainingIndex: number;
|
|
|
|
// The current counter
|
|
#counter: Uint8Array;
|
|
|
|
constructor(key: Uint8Array, initialValue?: number | Uint8Array) {
|
|
super("CTR", key, CTR);
|
|
|
|
this.#counter = new Uint8Array(16)
|
|
this.#counter.fill(0);
|
|
|
|
this.#remaining = this.#counter; // This will be discarded immediately
|
|
this.#remainingIndex = 16;
|
|
|
|
if (initialValue == null) { initialValue = 1; }
|
|
|
|
if (typeof(initialValue) === "number") {
|
|
this.setCounterValue(initialValue);
|
|
} else {
|
|
this.setCounterBytes(initialValue);
|
|
}
|
|
}
|
|
|
|
get counter(): Uint8Array { return new Uint8Array(this.#counter); }
|
|
|
|
setCounterValue(value: number): void {
|
|
if (!Number.isInteger(value) || value < 0 || value > Number.MAX_SAFE_INTEGER) {
|
|
throw new TypeError("invalid counter initial integer value");
|
|
}
|
|
|
|
for (let index = 15; index >= 0; --index) {
|
|
this.#counter[index] = value % 256;
|
|
value = Math.floor(value / 256);
|
|
}
|
|
}
|
|
|
|
setCounterBytes(value: Uint8Array): void {
|
|
if (value.length !== 16) {
|
|
throw new TypeError("invalid counter initial Uint8Array value length");
|
|
}
|
|
|
|
this.#counter.set(value);
|
|
}
|
|
|
|
increment() {
|
|
for (let i = 15; i >= 0; i--) {
|
|
if (this.#counter[i] === 255) {
|
|
this.#counter[i] = 0;
|
|
} else {
|
|
this.#counter[i]++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
encrypt(plaintext: Uint8Array): Uint8Array {
|
|
const crypttext = new Uint8Array(plaintext);
|
|
|
|
for (let i = 0; i < crypttext.length; i++) {
|
|
if (this.#remainingIndex === 16) {
|
|
this.#remaining = this.aes.encrypt(this.#counter);
|
|
this.#remainingIndex = 0;
|
|
this.increment();
|
|
}
|
|
crypttext[i] ^= this.#remaining[this.#remainingIndex++];
|
|
}
|
|
|
|
return crypttext;
|
|
}
|
|
|
|
decrypt(ciphertext: Uint8Array): Uint8Array {
|
|
return this.encrypt(ciphertext);
|
|
}
|
|
}
|