#include <Arduino.h>

// Define the fe25519 type
typedef struct {uint8_t v[32];} fe25519;

#define fe25519_red avrnacl_fe25519_red

// Forward declaration of the assembly function
extern "C" void bigint_mul256(uint8_t *result, const uint8_t *a, const uint8_t *b);
extern "C" void fe25519_red(uint8_t *result, const uint8_t *input);

// Declare _121666 before it's used
static const fe25519 _121666 = {{0x42, 0xDB, 0x01, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

// Function to multiply a field element by 121666
void fe25519_mul121666(fe25519 *r, const fe25519 *x)
{
  uint8_t t[64];
  bigint_mul256(t, x->v, _121666.v);  // Multiply x by 121666
  fe25519_red(r->v, t);               // Reduce the result mod 2^255-19
}

void setup() {
    Serial.begin(9600);
    Serial.println("Big Integer Multiplication Test");

    // Example big integers
    fe25519 a = {{0x00}};  // Initialize a to 0
    fe25519 result;

    fe25519_mul121666(&result, &a);

    // Print the result after fe25519_mul (reduced modulo 2^255-19)
    Serial.print("result = ");
    for (int i = 0; i < 32; i++)
    {
      Serial.print(result.v[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
}

void loop()
{
  // Empty loop
}