Cross-Language Security Module Interface

Side-channel claim limit. Nothing on this page claims constant-time behaviour or side-channel resistance for any target: the side-channel harness covers nothing (finding A48) and no measurement exists. The Rust and C cores are designed for constant time and unmeasured; managed runtimes (JIT, GC, bounds checks) make no timing claim. Where this page names constant-time or side-channel techniques, in prose or in code, they are design intent or recommendations, not measured properties.

Overview

The MetaMUI Security Module provides a standardized interface for security-critical operations across all language implementations. This ensures consistent security guarantees regardless of the implementation language.

Core Components

1. Secure Random Number Generation

interface SecureRandom {
    // Generate cryptographically secure random bytes
    generateBytes(length: number): Uint8Array
    
    // Generate random integer in range [0, max)
    generateInt(max: bigint): bigint
    
    // Reseed with additional entropy
    reseed(additionalEntropy?: Uint8Array): void
    
    // Get RNG health status
    getHealthStatus(): HealthStatus
}

enum HealthStatus {
    Healthy,
    Warning,
    Critical,
    Failed
}

2. Secure Memory Management

interface SecureMemory {
    // Allocate secure memory that will be zeroized on deallocation
    allocate(size: number): SecureBuffer
    
    // Securely clear memory
    zeroize(buffer: Uint8Array): void
    
    // Compare buffers in constant time
    constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean
    
    // Copy buffer in constant time
    constantTimeCopy(dest: Uint8Array, src: Uint8Array): void
}

interface SecureBuffer {
    // Get underlying data (use with caution)
    getData(): Uint8Array
    
    // Get size
    getSize(): number
    
    // Explicit zeroization
    zeroize(): void
    
    // Automatic zeroization on garbage collection
    [Symbol.dispose](): void
}

3. Key Management

interface KeyManager {
    // Generate key with specified algorithm
    generateKey(algorithm: KeyAlgorithm, params?: KeyParams): CryptoKey
    
    // Import key from raw bytes
    importKey(
        format: KeyFormat,
        keyData: Uint8Array,
        algorithm: KeyAlgorithm,
        extractable: boolean,
        keyUsages: KeyUsage[]
    ): CryptoKey
    
    // Export key (if extractable)
    exportKey(format: KeyFormat, key: CryptoKey): Uint8Array
    
    // Derive key from master key
    deriveKey(
        algorithm: KdfAlgorithm,
        masterKey: CryptoKey,
        derivedKeyAlgorithm: KeyAlgorithm,
        extractable: boolean,
        keyUsages: KeyUsage[]
    ): CryptoKey
    
    // Securely destroy key
    destroyKey(key: CryptoKey): void
}

interface CryptoKey {
    algorithm: KeyAlgorithm
    extractable: boolean
    type: KeyType
    usages: KeyUsage[]
    handle: opaque  // Language-specific secure handle
}

4. Cryptographic Operations

interface CryptoOperations {
    // Encrypt data
    encrypt(
        algorithm: EncryptionAlgorithm,
        key: CryptoKey,
        plaintext: Uint8Array,
        additionalData?: Uint8Array
    ): EncryptionResult
    
    // Decrypt data
    decrypt(
        algorithm: EncryptionAlgorithm,
        key: CryptoKey,
        ciphertext: Uint8Array,
        nonce: Uint8Array,
        tag?: Uint8Array,
        additionalData?: Uint8Array
    ): Uint8Array
    
    // Sign data
    sign(
        algorithm: SignatureAlgorithm,
        key: CryptoKey,
        data: Uint8Array
    ): Uint8Array
    
    // Verify signature
    verify(
        algorithm: SignatureAlgorithm,
        key: CryptoKey,
        signature: Uint8Array,
        data: Uint8Array
    ): boolean
    
    // Hash data
    hash(algorithm: HashAlgorithm, data: Uint8Array): Uint8Array
}

interface EncryptionResult {
    ciphertext: Uint8Array
    nonce: Uint8Array
    tag?: Uint8Array  // For AEAD modes
}

5. Security Audit

interface SecurityAudit {
    // Log security event
    logEvent(event: SecurityEvent): void
    
    // Get audit entries
    getEntries(filter?: AuditFilter): AuditEntry[]
    
    // Clear audit log (requires special permission)
    clearLog(authorization: Authorization): void
    
    // Export audit log
    exportLog(format: ExportFormat): Uint8Array
}

interface SecurityEvent {
    type: EventType
    severity: EventSeverity
    details: Record<string, any>
    timestamp?: number  // Auto-generated if not provided
}

interface AuditEntry {
    id: string
    event: SecurityEvent
    timestamp: number
    signature?: Uint8Array  // For tamper detection
}

Implementation Requirements

1. Language-Specific Implementations

Each language must provide:

2. Security Requirements

All implementations MUST:

3. Cross-Language Compatibility

Standard Algorithms

Symmetric Encryption

Asymmetric Encryption

Digital Signatures

Key Derivation

Hash Functions

Error Handling

All operations should use consistent error codes:

enum SecurityError {
    // Initialization errors
    NotInitialized = 1000,
    AlreadyInitialized = 1001,
    
    // Key errors
    InvalidKey = 2000,
    KeyNotFound = 2001,
    KeyExpired = 2002,
    KeyUsageViolation = 2003,
    
    // Operation errors
    InvalidAlgorithm = 3000,
    InvalidParameter = 3001,
    BufferTooSmall = 3002,
    
    // Verification errors
    VerificationFailed = 4000,
    IntegrityCheckFailed = 4001,
    
    // System errors
    OutOfMemory = 5000,
    EntropyFailure = 5001,
    HardwareError = 5002,
    
    // Self-test errors
    SelfTestFailed = 6001
}

Usage Example

// Initialize security module
const security = new SecurityModule({
    auditLogging: true
});

// Generate secure random
const random = security.secureRandom();
const nonce = random.generateBytes(12);

// Create encryption key
const keyManager = security.keyManager();
const key = await keyManager.generateKey('AES-GCM', { length: 256 });

// Encrypt data
const crypto = security.cryptoOperations();
const result = await crypto.encrypt(
    'AES-GCM',
    key,
    plaintext,
    additionalData
);

// Secure cleanup
security.secureMemory().zeroize(plaintext);
keyManager.destroyKey(key);

Testing Requirements

  1. Unit tests for each component
  2. Integration tests for cross-component operations
  3. Security-specific tests:
    • Timing attack resistance
    • Memory leak detection
    • Zeroization verification
    • Side-channel analysis
  4. Cross-language compatibility tests
  5. Performance benchmarks
  6. Fuzzing tests

Certification

Implementations should support: