#include "bromberg_sl2.h"
#include <stdio.h>

// External declarations
extern hash_matrix_t BYTE_LOOKUPS[256];
extern void init_lookup_tables(void);

// Initialize the library
void bromberg_init(void) {
    init_lookup_tables();
}

// Hash a byte array
hash_matrix_t bromberg_hash(const uint8_t* bytes, size_t len) {
    hash_matrix_t acc = MATRIX_I;

    for (size_t i = 0; i < len; i++) {
        acc = matmul(acc, BYTE_LOOKUPS[bytes[i]]);
    }

    return acc;
}

// Compose two hashes
hash_matrix_t bromberg_compose(hash_matrix_t h1, hash_matrix_t h2) {
    return matmul(h1, h2);
}

// Convert hash to hex string (64 hex chars)
void bromberg_to_hex(hash_matrix_t h, char out[65]) {
    sprintf(out, "%016llx%016llx%016llx%016llx",
            (unsigned long long)h.m[0],
            (unsigned long long)h.m[1],
            (unsigned long long)h.m[2],
            (unsigned long long)h.m[3]);
}
