mpt-crypto
Confidential Multi-Purpose Tokens Cryptographic Library
Loading...
Searching...
No Matches
mpt_scalar.c File Reference

Scalar Field Arithmetic Abstraction Layer. More...

#include "secp256k1_mpt.h"
#include <string.h>
#include <openssl/crypto.h>
#include "util.h"
#include "int128.h"
#include "int128_impl.h"
#include "scalar.h"
#include "scalar_impl.h"
Include dependency graph for mpt_scalar.c:

Go to the source code of this file.

Macros

#define USE_SCALAR_8X32
#define USE_FIELD_10X26

Functions

void secp256k1_mpt_scalar_add (unsigned char *res, const unsigned char *a, const unsigned char *b)
void secp256k1_mpt_scalar_mul (unsigned char *res, const unsigned char *a, const unsigned char *b)
void secp256k1_mpt_scalar_inverse (unsigned char *res, const unsigned char *in)
void secp256k1_mpt_scalar_negate (unsigned char *res, const unsigned char *in)
void secp256k1_mpt_scalar_reduce32 (unsigned char out32[32], const unsigned char in32[32])

Detailed Description

Scalar Field Arithmetic Abstraction Layer.

This module provides a safe, portable interface for performing arithmetic in the scalar field of the secp256k1 curve (integers modulo \( n \), the group order).

Purpose: While libsecp256k1 exposes point operations via its public API, it does not typically expose low-level scalar arithmetic. However, protocols like Bulletproofs and ElGamal require extensive scalar math (e.g., polynomial evaluation, inner products) to be performed by the client.

Implementation: This file includes internal libsecp256k1 headers (scalar.h, scalar_impl.h) to access the optimized, constant-time scalar implementations.

Operations: All operations are performed modulo the curve order \( n \):

  • Addition: \( a + b \pmod{n} \)
  • Multiplication: \( a \cdot b \pmod{n} \)
  • Inversion: \( a^{-1} \pmod{n} \)
  • Negation: \( -a \pmod{n} \)

Platform Specifics: Includes logic for 128-bit integer support (int128.h) required for efficient computation on modern architectures (e.g., ARM64/Apple Silicon).

Warning
These functions operate on 32-byte big-endian scalars. Inputs must be properly reduced or handled by secp256k1_mpt_scalar_reduce32 before use if they might exceed \( n \).

Definition in file mpt_scalar.c.

Macro Definition Documentation

◆ USE_FIELD_10X26

#define USE_FIELD_10X26

Definition at line 44 of file mpt_scalar.c.

◆ USE_SCALAR_8X32

#define USE_SCALAR_8X32

Definition at line 41 of file mpt_scalar.c.

Function Documentation

◆ secp256k1_mpt_scalar_add()

void secp256k1_mpt_scalar_add ( unsigned char * res,
const unsigned char * a,
const unsigned char * b )

Definition at line 60 of file mpt_scalar.c.

Here is the caller graph for this function:

◆ secp256k1_mpt_scalar_inverse()

void secp256k1_mpt_scalar_inverse ( unsigned char * res,
const unsigned char * in )

Definition at line 86 of file mpt_scalar.c.

Here is the caller graph for this function:

◆ secp256k1_mpt_scalar_mul()

void secp256k1_mpt_scalar_mul ( unsigned char * res,
const unsigned char * a,
const unsigned char * b )

Definition at line 73 of file mpt_scalar.c.

Here is the caller graph for this function:

◆ secp256k1_mpt_scalar_negate()

void secp256k1_mpt_scalar_negate ( unsigned char * res,
const unsigned char * in )

Definition at line 96 of file mpt_scalar.c.

Here is the caller graph for this function:

◆ secp256k1_mpt_scalar_reduce32()

void secp256k1_mpt_scalar_reduce32 ( unsigned char out32[32],
const unsigned char in32[32] )

Definition at line 106 of file mpt_scalar.c.

Here is the caller graph for this function: