mte/unikernel/duniverse/mirage-crypto/ec/native/np384_stubs.c

80 lines
1.8 KiB
C
Raw Normal View History

2025-11-11 02:07:51 +01:00
#include "mirage_crypto.h"
/* Microsoft compiler does not support 128-bit integers. Drop down to
* 32-bit for MSVC.
*/
#if defined(ARCH_64BIT) && !defined(_MSC_VER)
#include "np384_64.h"
#define LIMBS 6
#define WORD uint64_t
#define WORDSIZE 64
#else
#include "np384_32.h"
#define LIMBS 12
#define WORD uint32_t
#define WORDSIZE 32
#endif
#define LEN_PRIME 384
#define CURVE_DESCRIPTION fiat_np384
#include "inversion_template.h"
#include <caml/memory.h>
CAMLprim value mc_np384_inv(value out, value in)
{
CAMLparam2(out, in);
inversion((WORD*)Bytes_val(out), (const WORD*)String_val(in));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_mul(value out, value a, value b)
{
CAMLparam3(out, a, b);
fiat_np384_mul((WORD*)Bytes_val(out), (const WORD*)String_val(a), (const WORD*)String_val(b));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_add(value out, value a, value b)
{
CAMLparam3(out, a, b);
fiat_np384_add((WORD*)Bytes_val(out), (const WORD*)String_val(a), (const WORD*)String_val(b));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_one(value out)
{
CAMLparam1(out);
fiat_np384_set_one((WORD*)Bytes_val(out));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_from_bytes(value out, value in)
{
CAMLparam2(out, in);
fiat_np384_from_bytes((WORD*)Bytes_val(out), _st_uint8(in));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_to_bytes(value out, value in)
{
CAMLparam2(out, in);
fiat_np384_to_bytes(Bytes_val(out), (const WORD*)String_val(in));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_from_montgomery(value out, value in)
{
CAMLparam2(out, in);
fiat_np384_from_montgomery((WORD*)Bytes_val(out), (const WORD*)String_val(in));
CAMLreturn(Val_unit);
}
CAMLprim value mc_np384_to_montgomery(value out, value in)
{
CAMLparam2(out, in);
fiat_np384_to_montgomery((WORD*)Bytes_val(out), (const WORD*)String_val(in));
CAMLreturn(Val_unit);
}