Overview

FreeWorld OS provides comprehensive system libraries for mathematical operations, cryptography, and compression. These libraries are available to all user-space applications and provide high-performance implementations of essential algorithms.

Math Library

The Math Library provides a complete set of mathematical functions for scientific and engineering applications.

Features

  • ✅ Trigonometric functions (sin, cos, tan, asin, acos, atan, atan2)
  • ✅ Hyperbolic functions (sinh, cosh, tanh)
  • ✅ Exponential and logarithmic functions (exp, log, log10, log2)
  • ✅ Power functions (pow, sqrt, cbrt, hypot)
  • ✅ Rounding functions (floor, ceil, trunc, round)
  • ✅ Modulo and absolute value (fmod, fabs)
  • ✅ Special functions (erf, erfc, tgamma, lgamma)
  • ✅ Bessel functions (j0, j1, jn, y0, y1, yn)
  • ✅ Classification functions (isfinite, isinf, isnan, isnormal, signbit, fpclassify)

API Functions

; Trigonometric
math_sin(x) -> sin(x)
math_cos(x) -> cos(x)
math_tan(x) -> tan(x)
math_asin(x) -> asin(x)
math_acos(x) -> acos(x)
math_atan(x) -> atan(x)
math_atan2(y, x) -> atan2(y, x)

; Exponential/Logarithmic
math_exp(x) -> e^x
math_log(x) -> ln(x)
math_log10(x) -> log₁₀(x)
math_log2(x) -> log₂(x)
math_pow(x, y) -> x^y

; Square root and power
math_sqrt(x) -> √x
math_cbrt(x) -> ∛x
math_hypot(x, y) -> √(x² + y²)

; Rounding
math_floor(x) -> floor(x)
math_ceil(x) -> ceil(x)
math_trunc(x) -> trunc(x)
math_round(x) -> round(x)

; Other
math_fmod(x, y) -> x mod y
math_fabs(x) -> |x|

Crypto Library

The Crypto Library provides comprehensive cryptographic functions for encryption, hashing, authentication, and key management.

Hash Algorithms

  • ✅ MD5 (128-bit digest)
  • ✅ SHA-1 (160-bit digest)
  • ✅ SHA-256 (256-bit digest)
  • ✅ SHA-512 (512-bit digest)
  • ✅ SHA-3-256 (256-bit digest)
  • ✅ SHA-3-512 (512-bit digest)
  • ✅ BLAKE2b (512-bit digest)
  • ✅ BLAKE2s (256-bit digest)

Cipher Algorithms

  • ✅ AES-128 (ECB, CBC, CTR, GCM, XTS modes)
  • ✅ AES-192 (ECB, CBC, CTR, GCM, XTS modes)
  • ✅ AES-256 (ECB, CBC, CTR, GCM, XTS modes)
  • ✅ ChaCha20 (stream cipher)
  • ✅ 3DES (legacy support)
  • ✅ Blowfish (legacy support)

Additional Features

  • ✅ HMAC (Hash-based Message Authentication Code)
  • ✅ PBKDF2 (Password-Based Key Derivation Function)
  • ✅ Random number generation (RDRAND support)
  • ✅ Digital signature verification (RSA, ECDSA, EdDSA)
  • ✅ Key pair generation

API Functions

; Hashing
crypto_hash_init(algorithm, context) -> status
crypto_hash_update(context, data, length) -> status
crypto_hash_final(context, digest) -> digest_length
crypto_hash_compute(algorithm, data, length, digest) -> digest_length

; Encryption
crypto_cipher_init(algorithm, mode, context) -> status
crypto_cipher_set_key(context, key, key_length) -> status
crypto_cipher_set_iv(context, iv, iv_length) -> status
crypto_cipher_encrypt(context, input, output, length) -> bytes_encrypted
crypto_cipher_decrypt(context, input, output, length) -> bytes_decrypted

; Authentication
crypto_hmac(algorithm, key, key_length, data, data_length, mac) -> mac_length
crypto_pbkdf2(password, password_len, salt, salt_len, iterations, key_len, key) -> status

; Random
crypto_random_bytes(buffer, length) -> status

; Signatures
crypto_verify_signature(public_key, message, message_len, signature, sig_len) -> valid
crypto_generate_keypair(algorithm, key_size, public_key, private_key) -> status

Compression Library

The Compression Library provides user-space compression and decompression functions, complementing the kernel-level decompression support.

Supported Algorithms

  • ✅ GZIP (DEFLATE algorithm)
  • ✅ XZ (LZMA2 algorithm)
  • ✅ ZSTD (Zstandard algorithm)
  • ✅ LZ4 (fast compression)
  • ✅ ZLIB (DEFLATE variant)
  • ✅ BZIP2 (Burrows-Wheeler transform)

API Functions

; Compression
compress_init(algorithm, level, context) -> status
compress_data(context, input, input_len, output, output_size) -> compressed_size
compress_get_size(algorithm, uncompressed_size) -> estimated_size

; Decompression
decompress_data(context, input, input_len, output, output_size) -> decompressed_size
decompress_get_size(compressed_buffer, algorithm) -> decompressed_size

Build System

System libraries are built using Makefiles in their respective directories:

cd lib/math && make      # Builds lib/libmath.a
cd lib/crypto && make    # Builds lib/libcrypto.a
cd lib/compression && make  # Builds lib/libcompression.a

Applications can link against these libraries:

gcc -o app app.c -Llib -lmath -lcrypto -lcompression

Usage Examples

Math Library

; Calculate sine
movsd xmm0, [angle]
call math_sin
; Result in XMM0

; Calculate power
movsd xmm0, [base]
movsd xmm1, [exponent]
call math_pow
; Result in XMM0

Crypto Library

; Compute SHA-256 hash
mov rdi, HASH_SHA256
mov rsi, data_buffer
mov rdx, data_length
mov rcx, digest_buffer
call crypto_hash_compute
; Digest in digest_buffer (32 bytes)

Compression Library

; Compress data
mov rdi, context
mov rsi, input_buffer
mov rdx, input_length
mov rcx, output_buffer
mov r8, output_size
call compress_data
; Compressed size in RAX