cardano-crypto-class-2.5.1.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellNone
LanguageHaskell2010

Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Synopsis

Unsafe Types

newtype ScalarPtr Source #

Constructors

ScalarPtr (Ptr Word8) 

newtype PointPtr curve Source #

A pointer to a (projective) point one of the two elliptical curves

Constructors

PointPtr (Ptr Word8) 

newtype AffinePtr curve Source #

A pointer to an affine point on one of the two elliptical curves

Constructors

AffinePtr (Ptr Word8) 

Instances

Instances details
BLS curve ⇒ Eq (AffinePtr curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

(==) ∷ AffinePtr curve → AffinePtr curve → Bool #

(/=) ∷ AffinePtr curve → AffinePtr curve → Bool #

newtype PointArrayPtr curve Source #

A pointer to an array of pointers to points

Constructors

PointArrayPtr (Ptr Void) 

newtype AffineArrayPtr curve Source #

A pointer to an array of pointers to affine points

Constructors

AffineArrayPtr (Ptr Void) 

newtype AffineBlockPtr curve Source #

A pointer to a contiguous array of affine points

Constructors

AffineBlockPtr (Ptr Void) 

Phantom Types

data Curve1 Source #

Instances

Instances details
BLS Curve1 Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

c_blst_on_curve ∷ PointPtr Curve1 → IO Bool Source #

c_blst_add_or_double ∷ PointPtr Curve1 → PointPtr Curve1 → PointPtr Curve1 → IO () Source #

c_blst_mult ∷ PointPtr Curve1 → PointPtr Curve1 → ScalarPtr → CSize → IO () Source #

c_blst_cneg ∷ PointPtr Curve1 → Bool → IO () Source #

c_blst_scratch_sizeof ∷ Proxy Curve1 → CSize → CSize Source #

c_blst_to_affines ∷ AffineBlockPtr Curve1 → PointArrayPtr Curve1 → CSize → IO () Source #

c_blst_mult_pippenger ∷ PointPtr Curve1 → AffineArrayPtr Curve1 → CSize → ScalarArrayPtr → CSize → ScratchPtr → IO () Source #

c_blst_hash ∷ PointPtr Curve1 → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO () Source #

c_blst_compress ∷ Ptr CChar → PointPtr Curve1 → IO () Source #

c_blst_serialize ∷ Ptr CChar → PointPtr Curve1 → IO () Source #

c_blst_uncompress ∷ AffinePtr Curve1 → Ptr CChar → IO CInt Source #

c_blst_deserialize ∷ AffinePtr Curve1 → Ptr CChar → IO CInt Source #

c_blst_in_g ∷ PointPtr Curve1 → IO Bool Source #

c_blst_to_affine ∷ AffinePtr Curve1 → PointPtr Curve1 → IO () Source #

c_blst_from_affine ∷ PointPtr Curve1 → AffinePtr Curve1 → IO () Source #

c_blst_affine_in_g ∷ AffinePtr Curve1 → IO Bool Source #

c_blst_generator ∷ PointPtr Curve1 Source #

c_blst_p_is_equal ∷ PointPtr Curve1 → PointPtr Curve1 → IO Bool Source #

c_blst_p_is_inf ∷ PointPtr Curve1 → IO Bool Source #

c_blst_sk_to_pk ∷ PointPtr Curve1 → ScalarPtr → IO () Source #

c_blst_sign ∷ PointPtr (DualCurve Curve1) → PointPtr (DualCurve Curve1) → ScalarPtr → IO () Source #

c_blst_core_verify ∷ AffinePtr Curve1 → AffinePtr (DualCurve Curve1) → Bool → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO CInt Source #

millerSide ∷ PairingSide Curve1 → PT

sizePoint_ ∷ Proxy Curve1 → CSize

serializedSizePoint_ ∷ Proxy Curve1 → CSize

compressedSizePoint_ ∷ Proxy Curve1 → CSize

sizeAffine_ ∷ Proxy Curve1 → CSize

data Curve2 Source #

Instances

Instances details
BLS Curve2 Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

c_blst_on_curve ∷ PointPtr Curve2 → IO Bool Source #

c_blst_add_or_double ∷ PointPtr Curve2 → PointPtr Curve2 → PointPtr Curve2 → IO () Source #

c_blst_mult ∷ PointPtr Curve2 → PointPtr Curve2 → ScalarPtr → CSize → IO () Source #

c_blst_cneg ∷ PointPtr Curve2 → Bool → IO () Source #

c_blst_scratch_sizeof ∷ Proxy Curve2 → CSize → CSize Source #

c_blst_to_affines ∷ AffineBlockPtr Curve2 → PointArrayPtr Curve2 → CSize → IO () Source #

c_blst_mult_pippenger ∷ PointPtr Curve2 → AffineArrayPtr Curve2 → CSize → ScalarArrayPtr → CSize → ScratchPtr → IO () Source #

c_blst_hash ∷ PointPtr Curve2 → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO () Source #

c_blst_compress ∷ Ptr CChar → PointPtr Curve2 → IO () Source #

c_blst_serialize ∷ Ptr CChar → PointPtr Curve2 → IO () Source #

c_blst_uncompress ∷ AffinePtr Curve2 → Ptr CChar → IO CInt Source #

c_blst_deserialize ∷ AffinePtr Curve2 → Ptr CChar → IO CInt Source #

c_blst_in_g ∷ PointPtr Curve2 → IO Bool Source #

c_blst_to_affine ∷ AffinePtr Curve2 → PointPtr Curve2 → IO () Source #

c_blst_from_affine ∷ PointPtr Curve2 → AffinePtr Curve2 → IO () Source #

c_blst_affine_in_g ∷ AffinePtr Curve2 → IO Bool Source #

c_blst_generator ∷ PointPtr Curve2 Source #

c_blst_p_is_equal ∷ PointPtr Curve2 → PointPtr Curve2 → IO Bool Source #

c_blst_p_is_inf ∷ PointPtr Curve2 → IO Bool Source #

c_blst_sk_to_pk ∷ PointPtr Curve2 → ScalarPtr → IO () Source #

c_blst_sign ∷ PointPtr (DualCurve Curve2) → PointPtr (DualCurve Curve2) → ScalarPtr → IO () Source #

c_blst_core_verify ∷ AffinePtr Curve2 → AffinePtr (DualCurve Curve2) → Bool → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO CInt Source #

millerSide ∷ PairingSide Curve2 → PT

sizePoint_ ∷ Proxy Curve2 → CSize

serializedSizePoint_ ∷ Proxy Curve2 → CSize

compressedSizePoint_ ∷ Proxy Curve2 → CSize

sizeAffine_ ∷ Proxy Curve2 → CSize

type family DualCurve curve = dual | dual → curve where ... Source #

A type family mapping a curve to its dual curve (its an involution).

Error codes

Safe types

data Affine curve Source #

Instances

Instances details
BLS curve ⇒ Eq (Affine curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

(==) ∷ Affine curve → Affine curve → Bool #

(/=) ∷ Affine curve → Affine curve → Bool #

type family AffineSize curve where ... Source #

Type family to get the size of an affine point on a given curve

Equations

AffineSize Curve1 = 96 
AffineSize Curve2 = 192 

data BLSTError Source #

newtype Point curve Source #

A point on an elliptic curve. This type guarantees that the point is part of the | prime order subgroup.

Constructors

Point (PinnedSizedBytes (PointSize curve)) 

Instances

Instances details
Show (Point curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

showsPrec ∷ Int → Point curve → ShowS #

show ∷ Point curve → String #

showList ∷ [Point curve] → ShowS #

NFData (Point curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

rnf ∷ Point curve → () #

BLS curve ⇒ Eq (Point curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

(==) ∷ Point curve → Point curve → Bool #

(/=) ∷ Point curve → Point curve → Bool #

NoThunks (Point curve) Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

noThunks ∷ Context → Point curve → IO (Maybe ThunkInfo) Source #

wNoThunks ∷ Context → Point curve → IO (Maybe ThunkInfo) Source #

showTypeOf ∷ Proxy (Point curve) → String Source #

type family PointSize curve where ... Source #

Type family to get the size of a point on a given curve

Equations

PointSize Curve1 = 144 
PointSize Curve2 = 288 

type family CompressedPointSize (curve ∷ Type) ∷ Nat where ... Source #

Type family to get the size of a compressed point on a given curve

data PT Source #

Target element without the final exponantiation. By defining target elements | as such, we save up the final exponantiation when computing a pairing, and only | compute it when necessary (e.g. comparison with another point or serialisation)

Instances

Instances details
Eq PT Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

(==) ∷ PT → PT → Bool #

(/=) ∷ PT → PT → Bool #

newtype Scalar Source #

Constructors

Scalar (PinnedSizedBytes 32) 

newtype Fr Source #

Constructors

Fr (PinnedSizedBytes 32) 

Instances

Instances details
Eq Fr Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

(==) ∷ Fr → Fr → Bool #

(/=) ∷ Fr → Fr → Bool #

unsafePointFromPointPtr ∷ ∀ curve. BLS curve ⇒ PointPtr curve → Point curve Source #

The period of scalars

scalarPeriod ∷ Integer Source #

The period of scalar modulo operations.

Curve abstraction

class (KnownNat (PointSize curve), KnownNat (AffineSize curve), KnownNat (CompressedPointSize curve), KnownNat (SerializedPointSize curve)) ⇒ BLS curve where Source #

BLS curve operations. Class methods are low-level; user code will want to use higher-level wrappers such as blsAddOrDouble, blsMult, blsCneg, blsNeg, etc.

Methods

c_blst_on_curve ∷ PointPtr curve → IO Bool Source #

c_blst_add_or_double ∷ PointPtr curve → PointPtr curve → PointPtr curve → IO () Source #

c_blst_mult ∷ PointPtr curve → PointPtr curve → ScalarPtr → CSize → IO () Source #

c_blst_cneg ∷ PointPtr curve → Bool → IO () Source #

c_blst_scratch_sizeof ∷ Proxy curve → CSize → CSize Source #

c_blst_to_affines ∷ AffineBlockPtr curve → PointArrayPtr curve → CSize → IO () Source #

c_blst_mult_pippenger ∷ PointPtr curve → AffineArrayPtr curve → CSize → ScalarArrayPtr → CSize → ScratchPtr → IO () Source #

c_blst_hash ∷ PointPtr curve → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO () Source #

c_blst_compress ∷ Ptr CChar → PointPtr curve → IO () Source #

c_blst_serialize ∷ Ptr CChar → PointPtr curve → IO () Source #

c_blst_uncompress ∷ AffinePtr curve → Ptr CChar → IO CInt Source #

c_blst_deserialize ∷ AffinePtr curve → Ptr CChar → IO CInt Source #

c_blst_in_g ∷ PointPtr curve → IO Bool Source #

c_blst_to_affine ∷ AffinePtr curve → PointPtr curve → IO () Source #

c_blst_from_affine ∷ PointPtr curve → AffinePtr curve → IO () Source #

c_blst_affine_in_g ∷ AffinePtr curve → IO Bool Source #

c_blst_generator ∷ PointPtr curve Source #

c_blst_p_is_equal ∷ PointPtr curve → PointPtr curve → IO Bool Source #

c_blst_p_is_inf ∷ PointPtr curve → IO Bool Source #

c_blst_sk_to_pk ∷ PointPtr curve → ScalarPtr → IO () Source #

c_blst_sign ∷ PointPtr (DualCurve curve) → PointPtr (DualCurve curve) → ScalarPtr → IO () Source #

c_blst_core_verify ∷ AffinePtr curve → AffinePtr (DualCurve curve) → Bool → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO CInt Source #

Core signature verification function. This function is used with the following signature:

c_blst_core_verify @curve pk sig True msg msgLen dst dstLen aug augLen

where the True indicates we are using the `Hash to Curve` method.

Instances

Instances details
BLS Curve1 Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

c_blst_on_curve ∷ PointPtr Curve1 → IO Bool Source #

c_blst_add_or_double ∷ PointPtr Curve1 → PointPtr Curve1 → PointPtr Curve1 → IO () Source #

c_blst_mult ∷ PointPtr Curve1 → PointPtr Curve1 → ScalarPtr → CSize → IO () Source #

c_blst_cneg ∷ PointPtr Curve1 → Bool → IO () Source #

c_blst_scratch_sizeof ∷ Proxy Curve1 → CSize → CSize Source #

c_blst_to_affines ∷ AffineBlockPtr Curve1 → PointArrayPtr Curve1 → CSize → IO () Source #

c_blst_mult_pippenger ∷ PointPtr Curve1 → AffineArrayPtr Curve1 → CSize → ScalarArrayPtr → CSize → ScratchPtr → IO () Source #

c_blst_hash ∷ PointPtr Curve1 → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO () Source #

c_blst_compress ∷ Ptr CChar → PointPtr Curve1 → IO () Source #

c_blst_serialize ∷ Ptr CChar → PointPtr Curve1 → IO () Source #

c_blst_uncompress ∷ AffinePtr Curve1 → Ptr CChar → IO CInt Source #

c_blst_deserialize ∷ AffinePtr Curve1 → Ptr CChar → IO CInt Source #

c_blst_in_g ∷ PointPtr Curve1 → IO Bool Source #

c_blst_to_affine ∷ AffinePtr Curve1 → PointPtr Curve1 → IO () Source #

c_blst_from_affine ∷ PointPtr Curve1 → AffinePtr Curve1 → IO () Source #

c_blst_affine_in_g ∷ AffinePtr Curve1 → IO Bool Source #

c_blst_generator ∷ PointPtr Curve1 Source #

c_blst_p_is_equal ∷ PointPtr Curve1 → PointPtr Curve1 → IO Bool Source #

c_blst_p_is_inf ∷ PointPtr Curve1 → IO Bool Source #

c_blst_sk_to_pk ∷ PointPtr Curve1 → ScalarPtr → IO () Source #

c_blst_sign ∷ PointPtr (DualCurve Curve1) → PointPtr (DualCurve Curve1) → ScalarPtr → IO () Source #

c_blst_core_verify ∷ AffinePtr Curve1 → AffinePtr (DualCurve Curve1) → Bool → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO CInt Source #

millerSide ∷ PairingSide Curve1 → PT

sizePoint_ ∷ Proxy Curve1 → CSize

serializedSizePoint_ ∷ Proxy Curve1 → CSize

compressedSizePoint_ ∷ Proxy Curve1 → CSize

sizeAffine_ ∷ Proxy Curve1 → CSize

BLS Curve2 Source # 
Instance details

Defined in Cardano.Crypto.EllipticCurve.BLS12_381.Internal

Methods

c_blst_on_curve ∷ PointPtr Curve2 → IO Bool Source #

c_blst_add_or_double ∷ PointPtr Curve2 → PointPtr Curve2 → PointPtr Curve2 → IO () Source #

c_blst_mult ∷ PointPtr Curve2 → PointPtr Curve2 → ScalarPtr → CSize → IO () Source #

c_blst_cneg ∷ PointPtr Curve2 → Bool → IO () Source #

c_blst_scratch_sizeof ∷ Proxy Curve2 → CSize → CSize Source #

c_blst_to_affines ∷ AffineBlockPtr Curve2 → PointArrayPtr Curve2 → CSize → IO () Source #

c_blst_mult_pippenger ∷ PointPtr Curve2 → AffineArrayPtr Curve2 → CSize → ScalarArrayPtr → CSize → ScratchPtr → IO () Source #

c_blst_hash ∷ PointPtr Curve2 → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO () Source #

c_blst_compress ∷ Ptr CChar → PointPtr Curve2 → IO () Source #

c_blst_serialize ∷ Ptr CChar → PointPtr Curve2 → IO () Source #

c_blst_uncompress ∷ AffinePtr Curve2 → Ptr CChar → IO CInt Source #

c_blst_deserialize ∷ AffinePtr Curve2 → Ptr CChar → IO CInt Source #

c_blst_in_g ∷ PointPtr Curve2 → IO Bool Source #

c_blst_to_affine ∷ AffinePtr Curve2 → PointPtr Curve2 → IO () Source #

c_blst_from_affine ∷ PointPtr Curve2 → AffinePtr Curve2 → IO () Source #

c_blst_affine_in_g ∷ AffinePtr Curve2 → IO Bool Source #

c_blst_generator ∷ PointPtr Curve2 Source #

c_blst_p_is_equal ∷ PointPtr Curve2 → PointPtr Curve2 → IO Bool Source #

c_blst_p_is_inf ∷ PointPtr Curve2 → IO Bool Source #

c_blst_sk_to_pk ∷ PointPtr Curve2 → ScalarPtr → IO () Source #

c_blst_sign ∷ PointPtr (DualCurve Curve2) → PointPtr (DualCurve Curve2) → ScalarPtr → IO () Source #

c_blst_core_verify ∷ AffinePtr Curve2 → AffinePtr (DualCurve Curve2) → Bool → Ptr CChar → CSize → Ptr CChar → CSize → Ptr CChar → CSize → IO CInt Source #

millerSide ∷ PairingSide Curve2 → PT

sizePoint_ ∷ Proxy Curve2 → CSize

serializedSizePoint_ ∷ Proxy Curve2 → CSize

compressedSizePoint_ ∷ Proxy Curve2 → CSize

sizeAffine_ ∷ Proxy Curve2 → CSize

Pairing check

FP12 functions

Scalar functions

Marshalling functions

sizePoint ∷ ∀ curve. BLS curve ⇒ Proxy curve → Int Source #

Sizes of various representations of elliptic curve points. | Size of a curve point in memory

withPoint ∷ ∀ a curve. Point curve → (PointPtr curve → IO a) → IO a Source #

withNewPoint ∷ ∀ curve a. BLS curve ⇒ (PointPtr curve → IO a) → IO (a, Point curve) Source #

withNewPoint_ ∷ BLS curve ⇒ (PointPtr curve → IO a) → IO a Source #

withNewPoint' ∷ BLS curve ⇒ (PointPtr curve → IO a) → IO (Point curve) Source #

clonePoint ∷ ∀ curve. BLS curve ⇒ Point curve → IO (Point curve) Source #

compressedSizePoint ∷ ∀ curve. BLS curve ⇒ Proxy curve → Int Source #

Size of a curved point when serialized in compressed form

serializedSizePoint ∷ ∀ curve. BLS curve ⇒ Proxy curve → Int Source #

Size of a curved point when serialized in uncompressed form

sizeAffine ∷ ∀ curve. BLS curve ⇒ Proxy curve → Int Source #

In-memory size of the affine representation of a curve point

withAffine ∷ ∀ a curve. Affine curve → (AffinePtr curve → IO a) → IO a Source #

withNewAffine ∷ ∀ curve a. BLS curve ⇒ (AffinePtr curve → IO a) → IO (a, Affine curve) Source #

withNewAffine_ ∷ BLS curve ⇒ (AffinePtr curve → IO a) → IO a Source #

withNewAffine' ∷ BLS curve ⇒ (AffinePtr curve → IO a) → IO (Affine curve) Source #

withPointArray ∷ [Point curve] → (Int → PointArrayPtr curve → IO a) → IO a Source #

withPT ∷ PT → (PTPtr → IO a) → IO a Source #

withNewPT ∷ (PTPtr → IO a) → IO (a, PT) Source #

withNewPT_ ∷ (PTPtr → IO a) → IO a Source #

withNewPT' ∷ (PTPtr → IO a) → IO PT Source #

withScalar ∷ Scalar → (ScalarPtr → IO a) → IO a Source #

withNewScalar ∷ (ScalarPtr → IO a) → IO (a, Scalar) Source #

withNewScalar_ ∷ (ScalarPtr → IO a) → IO a Source #

withScalarArray ∷ [Scalar] → (Int → ScalarArrayPtr → IO a) → IO a Source #

withFr ∷ Fr → (FrPtr → IO a) → IO a Source #

withNewFr ∷ (FrPtr → IO a) → IO (a, Fr) Source #

withNewFr_ ∷ (FrPtr → IO a) → IO a Source #

withNewFr' ∷ (FrPtr → IO a) → IO Fr Source #

Utility

integerAsCStrL ∷ Int → Integer → (Ptr CChar → Int → IO a) → IO a Source #

Point1/G1 operations

blsInGroup ∷ BLS curve ⇒ Point curve → Bool Source #

Check whether a point is in the group corresponding to its elliptic curve

blsAddOrDouble ∷ BLS curve ⇒ Point curve → Point curve → Point curve Source #

Curve point addition.

blsMult ∷ BLS curve ⇒ Point curve → Integer → Point curve Source #

Scalar multiplication of a curve point. The scalar will be brought into the range of modular arithmetic by means of a modulo operation over the scalarPeriod. Negative number will also be brought to the range [0, scalarPeriod - 1] via modular reduction.

blsCneg ∷ BLS curve ⇒ Point curve → Bool → Point curve Source #

Conditional curve point negation. blsCneg x cond = if cond then neg x else x

blsNeg ∷ BLS curve ⇒ Point curve → Point curve Source #

Unconditional curve point negation

blsMSM ∷ ∀ curve. BLS curve ⇒ [(Integer, Point curve)] → Point curve Source #

Multi-scalar multiplication using the Pippenger algorithm. The scalars will be brought into the range of modular arithmetic by means of a modulo operation over the scalarPeriod. Negative numbers will also be brought to the range [0, scalarPeriod - 1] via modular reduction.

blsCompress ∷ ∀ curve. BLS curve ⇒ Point curve → ByteString Source #

blsSerialize ∷ ∀ curve. BLS curve ⇒ Point curve → ByteString Source #

blsUncompress ∷ ∀ curve. BLS curve ⇒ ByteString → Either BLSTError (Point curve) Source #

blsDeserialize ∷ ∀ curve. BLS curve ⇒ ByteString → Either BLSTError (Point curve) Source #

blsHash ∷ BLS curve ⇒ ByteString → Maybe ByteString → Maybe ByteString → Point curve Source #

blsHash msg mDST mAug generates the elliptic curve blsHash for the given message msg; mDST and mAug are the optional aug and dst arguments.

blsGenerator ∷ BLS curve ⇒ Point curve Source #

blsIsInf ∷ BLS curve ⇒ Point curve → Bool Source #

Infinity check on curve points.

blsZero ∷ ∀ curve. BLS curve ⇒ Point curve Source #

toAffine ∷ BLS curve ⇒ Point curve → Affine curve Source #

fromAffine ∷ BLS curve ⇒ Affine curve → Point curve Source #

affineInG ∷ BLS curve ⇒ Affine curve → Bool Source #

PT operations

ptMult ∷ PT → PT → PT Source #

Scalar / Fr operations

Pairings

finalVerifyPairs ∷ ∀ curve. BLS curve ⇒ PairingSide curve → PairingSide curve → Bool Source #