math

package
v0.0.0-...-06d3eac Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright (C) 2018 NuCypher

This file is part of goUmbral.

goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.

This file is part of goUmbral.

goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.

This file is part of goUmbral.

goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectedBytesLength

func ExpectedBytesLength(curve *openssl.Curve)

func PointLength

func PointLength(curve *openssl.Curve, isCompressed bool) uint

Returns the size (in bytes) of a compressed Point given a curve. If no curve is provided, it returns 0.

Types

type ModBigNum

type ModBigNum struct {
	Bignum openssl.BigNum
	Curve  *openssl.Curve
}

func BytesToModBN

func BytesToModBN(data []byte, curve *openssl.Curve) (*ModBigNum, error)

Returns the ModBigNum associated with the bytes-converted bignum provided by the data argument.

func GenRandModBN

func GenRandModBN(curve *openssl.Curve) (*ModBigNum, error)

Returns a ModBigNum with a cryptographically secure OpenSSL BIGNUM based on the given curve.

func HashToModBN

func HashToModBN(bytes []byte, params *UmbralParameters) (*ModBigNum, error)

Returns a ModBigNum based on provided data hashed by blake2b.

func IntToModBN

func IntToModBN(num int, curve *openssl.Curve) (*ModBigNum, error)

func NewModBigNum

func NewModBigNum(cNum openssl.BigNum, curve *openssl.Curve) (*ModBigNum, error)

func (*ModBigNum) Add

func (z *ModBigNum) Add(x, y *ModBigNum) error

ModBigNum.Add() will perform (x + y) modulo the order of the curve of x and y. It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Add will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Bytes

func (m *ModBigNum) Bytes() ([]byte, error)

func (ModBigNum) Compare

func (m ModBigNum) Compare(other *ModBigNum) int

func (*ModBigNum) Copy

func (m *ModBigNum) Copy() (*ModBigNum, error)

func (*ModBigNum) Div

func (z *ModBigNum) Div(x, y *ModBigNum) error

ModBigNum.Div() will perform (x / y) modulo the order of the curve of x and y. It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Div will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Equals

func (m *ModBigNum) Equals(other *ModBigNum) bool

func (*ModBigNum) Free

func (m *ModBigNum) Free()

func (*ModBigNum) Invert

func (z *ModBigNum) Invert(x *ModBigNum) error

ModBigNum.Invert() computes (x*z)%m==1 where m is the order of the curve of x and z. It will then set z to the result of that operation.

x and z must use the same curve and must be initialized.

Invert will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Mod

func (z *ModBigNum) Mod(x, y *ModBigNum) error

ModBigNum.Mod() will perform (x % y). It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Mod will return the error, and nil otherwise.

func (*ModBigNum) Mul

func (z *ModBigNum) Mul(x, y *ModBigNum) error

ModBigNum.Mul() will perform (x * y) modulo the order of the curve of x and y. It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Mul will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Neg

func (z *ModBigNum) Neg(x *ModBigNum) error

ModBigNum.Neg() computes the modular opposite (i. e., additive inverse) of x. It will then set z to the result of that operation.

x and z must use the same curve and must be initialized.

Neg will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Pow

func (z *ModBigNum) Pow(x, y *ModBigNum) error

ModBigNum.Pow() will perform (x^y) modulo the order of the curve of x and y. It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Pow will return the error if one occurred, and nil otherwise.

func (*ModBigNum) Sub

func (z *ModBigNum) Sub(x, y *ModBigNum) error

ModBigNum.Sub() will perform (x - y) modulo the order of the curve of x and y. It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Sub will return the error if one occurred, and nil otherwise.

type Point

type Point struct {
	ECPoint openssl.ECPoint
	Curve   *openssl.Curve
}

func AffineToPoint

func AffineToPoint(affineX, affineY *big.Int, curve *openssl.Curve) (*Point, error)

Returns a Point object from the given affine coordinates.

func BytesToPoint

func BytesToPoint(data []byte, curve *openssl.Curve) (*Point, error)

func GenRandPoint

func GenRandPoint(curve *openssl.Curve) (*Point, error)

Returns a Point struct with a cryptographically secure EC_POINT based on the provided curve.

This operation isn't safe unless you know the discrete log of the generated Point.

func GetGeneratorFromCurve

func GetGeneratorFromCurve(curve *openssl.Curve) *Point

func NewPoint

func NewPoint(point openssl.ECPoint, curve *openssl.Curve) (*Point, error)

Generate a new Point struct based on the arguments provided.

If point is nil then GetNewPoint will generate a new opensslraphically secure ECPoint and check for errors before returning the new Point.

if point is nil AND the curve group is also nil then GetNewPoint will fail and return the error.

func UnsafeHashToPoint

func UnsafeHashToPoint(data []byte, params *UmbralParameters, label []byte) (*Point, error)

WARNING: Do not use when the input data is secret, as this implementation is not in constant time, and hence, it is not safe with respect to timing attacks. TODO: Check how to uniformly generate ycoords. Currently, it only outputs points where ycoord is even (i.e., starting with 0x02 in compressed notation)

func (*Point) Add

func (z *Point) Add(x, y *Point) error

Point.Add() will perform (x + y). It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Add will return the error if one occurred, and nil otherwise.

func (*Point) Copy

func (m *Point) Copy() (*Point, error)

func (*Point) Equals

func (m *Point) Equals(other *Point) (bool, error)

func (*Point) Free

func (m *Point) Free()

func (*Point) Invert

func (z *Point) Invert(x *Point) error

Point.Invert() will find the inverse of x. It will then set z to the result of that operation.

x must be initialized.

Invert will return the error if one occurred, and nil otherwise.

func (*Point) Mul

func (z *Point) Mul(x *Point, y *ModBigNum) error

Point.Mul() will perform (x * y). It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Mul will return the error if one occurred, and nil otherwise.

func (*Point) Sub

func (z *Point) Sub(x, y *Point) error

Point.Sub() will perform (x - y). It will then set z to the result of that operation.

x, y, and z must use the same curve and must be initialized.

Sub will return the error if one occurred, and nil otherwise.

func (Point) ToAffine

func (m Point) ToAffine() (*big.Int, *big.Int, error)

Returns an x and y coordinate of the Point as a Go big.Int.

func (Point) ToBytes

func (m Point) ToBytes(isCompressed bool) ([]byte, error)

Returns the Point serialized as bytes. It will return a compressed form if isCompressed is set to True.

type UmbralParameters

type UmbralParameters struct {
	Curve *openssl.Curve
	Size  uint
	G     *Point
	U     *Point
}

func NewUmbralParameters

func NewUmbralParameters(curve *openssl.Curve) (*UmbralParameters, error)

func (*UmbralParameters) Equals

func (m *UmbralParameters) Equals(other *UmbralParameters) bool

Jump to

Keyboard shortcuts

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