package secp256k1-internal

  1. Overview
  2. Docs
type t

A scalar modulo the group order of the secp256k1 curve.

val zero : unit -> t
val one : unit -> t
val copy : t -> t
val const : ?d7:int32 -> ?d6:int32 -> ?d5:int32 -> ?d4:int32 -> ?d3:int32 -> ?d2:int32 -> ?d1:int32 -> ?d0:int32 -> unit -> t
val clear : t -> unit

Clear a scalar to prevent the leak of sensitive data.

val get_bits : t -> int -> int -> int

get_bits a offset count Access bits from a scalar. All requested bits must belong to the same 32-bit limb.

val get_bits_var : t -> int -> int -> int

get_bits a offset count Access bits from a scalar. Not constant time.

val set_b32 : t -> Cstruct.t -> bool

Set a scalar from a big endian byte array.

val set_int : t -> int -> unit

Set a scalar to an unsigned integer.

val get_b32 : Cstruct.t -> t -> unit

Convert a scalar to a byte array.

val add : t -> t -> t -> bool

add r a b Add two scalars together (modulo the group order). Returns whether it overflowed.

val cadd_bit : t -> int -> bool -> unit

cadd_bit r bit flag Conditionally add a power of two to a scalar. The result is not allowed to overflow.

val mul : t -> t -> t -> unit

mul r a b Multiply two scalars (modulo the group order).

val shr_int : t -> int -> int

Shift a scalar right by some amount strictly between 0 and 16, returning the low bits that were shifted off

val inverse : t -> t -> unit

inverse r a Compute the inverse of a scalar (modulo the group order).

val inverse_var : t -> t -> unit

inverse_var r a Compute the inverse of a scalar (modulo the group order), without constant-time guarantee.

val negate : t -> t -> unit

negate r a Compute the complement of a scalar (modulo the group order).

val is_zero : t -> bool

Check whether a scalar equals zero.

val is_one : t -> bool

Check whether a scalar equals one.

val is_even : t -> bool

Check whether a scalar, considered as an nonnegative integer, is even.

val is_high : t -> bool

Check whether a scalar is higher than the group order divided by 2.

val cond_negate : t -> bool -> bool

Conditionally negate a number, in constant time. Returns true if the number was negated, false otherwise

val equal : t -> t -> bool

Compare two scalars.

val mul_shift_var : t -> t -> t -> int -> unit

Multiply a and b (without taking the modulus!), divide by 2**shift, and round to the nearest integer. Shift must be at least 256.