cardinal

package
v0.0.0-...-7685c8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

cardinal

Package cardinal provides representations for cardinal numbers (cardinalities) used to express the size of algebraic structures such as groups, rings, and fields.

Overview

In cryptographic contexts, the cardinality of a structure may be known, unknown (hidden for security a la groups of unknown order), or infinite. This package provides three implementations of the Cardinal interface to handle these cases uniformly. We stress that the intention of this package is to provide clarity when dealing with cardinalities in a cryptographic context, NOT to implement a mathematically faithful version of cardinal arithmetics.

Key Types

  • Known: A cardinal with a concrete numeric value, stored as big-endian bytes.
  • Unknown: Represents a cardinal whose value is intentionally hidden (e.g., the order of an RSA group without knowledge of the factorization).
  • Infinite: Represents an infinite cardinality (e.g., the integers Z or rationals Q).

Comparison Semantics

The comparison methods follow specific rules based on the nature of each cardinal type:

Equal
LHS \ RHS Known Unknown Infinite
Known values match false false
Unknown false false false
Infinite false false true
  • Known.Equal(Known): True if and only if the numeric values are identical.
  • Unknown.Equal(any): Always false. Unknown values cannot be compared for equality since their values are hidden.
  • Infinite.Equal(Infinite): True. All infinite cardinals are considered equal.
IsLessThanOrEqual
LHS \ RHS Known Unknown Infinite
Known numeric ≤ false false
Unknown false false false
Infinite false false true
  • Known.IsLessThanOrEqual(Known): Standard numeric comparison.
  • Known.IsLessThanOrEqual(Unknown/Infinite): False. Known values cannot be compared to unknown or infinite values.
  • Unknown.IsLessThanOrEqual(any): Always false. No ordering can be established for unknown values.
  • Infinite.IsLessThanOrEqual(Infinite): True. Infinity is considered equal to itself.
  • Infinite.IsLessThanOrEqual(Known/Unknown): False. Infinity is not less than any finite or unknown value.

Type Predicates

  • IsFinite(): True for Known and Unknown, false for Infinite.
  • IsUnknown(): True only for Unknown.
  • IsZero(): True only for Known with value zero.

Documentation

Overview

Package cardinal provides representations for cardinal numbers (cardinalities) used to express the size of algebraic structures such as groups, rings, and fields.

See README.md for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cardinal

type Cardinal = acrtp.Cardinal

Cardinal is an alias for algebra/crtp.Cardinal, which is the interfaces satisfying different types of cardinals.

func Infinite

func Infinite() Cardinal

func New

func New(n uint64) Cardinal

New creates a new Known cardinal from a uint64 value.

func NewFromBig

func NewFromBig(n *big.Int) Cardinal

NewFromBig creates a new Cardinal from a big.Int value.

func NewFromNumeric

func NewFromNumeric(num acrtp.Numeric) Cardinal

NewFromNumeric creates a new Cardinal from a Numeric value.

func Unknown

func Unknown() Cardinal

func Zero

func Zero() Cardinal

Zero returns the zero cardinal.

type Known

type Known []byte

Known represents a cardinal number with a known value.

func (Known) Add

func (k Known) Add(other Cardinal) Cardinal

Add adds two known cardinals.

func (Known) Big

func (k Known) Big() *big.Int

Big returns the big.Int representation of the known cardinal.

func (Known) BitLen

func (k Known) BitLen() int

BitLen returns the bit length of the known cardinal.

func (Known) Bytes

func (k Known) Bytes() []byte

Bytes returns the byte representation of the known cardinal.

func (Known) BytesBE

func (k Known) BytesBE() []byte

BytesBE returns the big-endian byte representation of the known cardinal.

func (Known) Clone

func (k Known) Clone() Cardinal

Clone creates a copy of the known cardinal.

func (Known) Equal

func (k Known) Equal(other Cardinal) bool

Equal checks if the known cardinal is equal to another cardinal.

func (Known) HashCode

func (k Known) HashCode() base.HashCode

HashCode computes the hash code of the known cardinal.

func (Known) IsFinite

func (Known) IsFinite() bool

IsFinite checks if the known cardinal is finite, which is always true for Known.

func (Known) IsLessThanOrEqual

func (k Known) IsLessThanOrEqual(other Cardinal) bool

IsLessThanOrEqual checks if the known cardinal is less than or equal to another cardinal.

func (Known) IsProbablyPrime

func (k Known) IsProbablyPrime() bool

IsProbablyPrime checks if the known cardinal is probably prime.

func (Known) IsUnknown

func (Known) IsUnknown() bool

IsUnknown checks if the known cardinal is unknown, which is always false for Known.

func (Known) IsZero

func (k Known) IsZero() bool

IsZero checks if the known cardinal is zero.

func (Known) Mul

func (k Known) Mul(other Cardinal) Cardinal

Mul multiplies two known cardinals.

func (Known) Nat

func (k Known) Nat() *numct.Nat

Nat returns the numeric representation of the known cardinal.

func (Known) String

func (k Known) String() string

String returns the string representation of the known cardinal.

func (Known) Sub

func (k Known) Sub(other Cardinal) Cardinal

Sub subtracts another known cardinal from the known cardinal.

func (Known) Uint64

func (k Known) Uint64() uint64

Uint64 returns the uint64 representation of the known cardinal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL