ring

package
v0.0.0-...-07d6e5f Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: LGPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Origin                            = "github.com/zbohm/lirisi"
	SignatureVersion                  = 1
	Success                           = 0
	PrivateKeyNotFitPublic            = 1
	InsufficientNumberOfPublicKeys    = 2
	PrivateKeyPositionOutOfRange      = 3
	PrivateKeyNotFoundAmongPublicKeys = 4
	UnexpectedCurveType               = 5
	UnexpectedHashType                = 6
	IncorrectNumberOfSignatures       = 7
	InvalidKeyImage                   = 8
	IncorrectChecksum                 = 9
	OIDHasherNotFound                 = 10
	OIDCurveNotFound                  = 11
	UnsupportedCurveHashCombination   = 12
	PointWasNotFound                  = 13
	DecodePEMFailure                  = 14
	UnexpectedRestOfSignature         = 15
	Asn1MarshalFailed                 = 16
	EncodePEMFailed                   = 17
	InvalidPointCoordinates           = 18
	NilPointCoordinates               = 19
	ParseECPrivateKeyFailure          = 20
	Asn1UnmarshalFailed               = 21
	MarshalPKIXPublicKeyFailed        = 22
	ParsePKIXPublicKeyFailed          = 23
	CreateKeyFailed                   = 24
	MarshalKeyFailed                  = 25
)

Status codes for sign/verify functions.

View Source
const LirisiVersion = "0.0.1"

Lirisi application version.

Variables

View Source
var BrainpoolParentCurves = map[string]func() elliptic.Curve{
	"brainpoolP256r1": brainpool.P256t1,
	"brainpoolP384r1": brainpool.P384t1,
	"brainpoolP512r1": brainpool.P512t1,
}

BrainpoolParentCurves maps twisted curves with untwisted parents.

View Source
var BrainpoolZ = map[string]string{
	"brainpoolP256r1": "3E2D4BD9597B58639AE7AA669CAB9837CF5CF20A2C852D10F655668DFC150EF0",
	"brainpoolP384r1": "41DFE8DD399331F7166A66076734A89CD0D2BCDB7D068E44E1F378F41ECBAE97D2D63DBC87BCCDDCCC5DA39E8589291C",
	"brainpoolP512r1": "12EE58E6764838B69782136F0F2D3BA06E27695716054092E60A80BEDB212B64E585D90BCE13761F85C3F1D2A64E3BE8FEA2220F01EBA5EEB0F35DBD29D922AB",
}

BrainpoolZ maps Z values required by GetZinv for function fromTwisted.

View Source
var BrainpoolZinv = map[string]Zinv{}

BrainpoolZinv inverzed Zinv.

View Source
var CurveCodes = map[string]func() elliptic.Curve{
	"secp224r1":  elliptic.P224,
	"prime256v1": elliptic.P256,
	"secp384r1":  elliptic.P384,
	"secp521r1":  elliptic.P521,

	"brainpoolP256r1": brainpool.P256r1,
	"brainpoolP256t1": brainpool.P256t1,
	"brainpoolP384r1": brainpool.P384r1,
	"brainpoolP384t1": brainpool.P384t1,
	"brainpoolP512r1": brainpool.P512r1,
	"brainpoolP512t1": brainpool.P512t1,
	"secp256k1":       crypto.S256,
}

CurveCodes maps curve names to curves available to make signature.

View Source
var ErrorMessages = map[int]string{
	PrivateKeyNotFitPublic:            "Private key not fit public.",
	InsufficientNumberOfPublicKeys:    "Insufficient number of public keys.",
	PrivateKeyPositionOutOfRange:      "Private key position out of range.",
	PrivateKeyNotFoundAmongPublicKeys: "Private key not found among public keys.",
	UnexpectedCurveType:               "Unexpected curve type.",
	UnexpectedHashType:                "Unexpected hash type.",
	IncorrectNumberOfSignatures:       "Incorrect number of signatures.",
	InvalidKeyImage:                   "Invalid key image.",
	IncorrectChecksum:                 "Incorrect checksum.",
	OIDHasherNotFound:                 "OID hasher not found.",
	OIDCurveNotFound:                  "OID curve not found.",
	UnsupportedCurveHashCombination:   "Unsupported curve hash combination.",
	PointWasNotFound:                  "A point on the curve was not found. Please try another case identigier.",
	DecodePEMFailure:                  "Decode PEM failed.",
	UnexpectedRestOfSignature:         "Unexpected rest at the end of signature.",
	Asn1MarshalFailed:                 "ASN1 Marshal failed.",
	EncodePEMFailed:                   "PEM Encode failed.",
	InvalidPointCoordinates:           "Invalid point coordinates.",
	NilPointCoordinates:               "Nil point coordinates.",
	ParseECPrivateKeyFailure:          "Parse EC private key failed.",
	Asn1UnmarshalFailed:               "ASN1 Unmarshal Failed.",
	MarshalPKIXPublicKeyFailed:        "Marshal PKIX public key falied.",
	ParsePKIXPublicKeyFailed:          "Parse PKIX public key falied.",
	CreateKeyFailed:                   "Create key failed.",
	MarshalKeyFailed:                  "Marshal key failed.",
}

ErrorMessages convert status codes to human readable error messages.

View Source
var HashCodes = map[string]func() hash.Hash{
	"sha3-224": sha3.New224,
	"sha3-256": sha3.New256,
	"sha3-384": sha3.New384,
	"sha3-512": sha3.New512,
}

HashCodes maps hash names to hash functions available to make signature. printf "test" | openssl dgst -sha3-256

View Source
var OIDCurves = map[string]func() elliptic.Curve{
	"1.3.132.0.33":          elliptic.P224,
	"1.2.840.10045.3.1.7":   elliptic.P256,
	"1.3.132.0.34":          elliptic.P384,
	"1.3.132.0.35":          elliptic.P521,
	"1.3.36.3.3.2.8.1.1.7":  brainpool.P256r1,
	"1.3.36.3.3.2.8.1.1.8":  brainpool.P256t1,
	"1.3.36.3.3.2.8.1.1.11": brainpool.P384r1,
	"1.3.36.3.3.2.8.1.1.12": brainpool.P384t1,
	"1.3.36.3.3.2.8.1.1.13": brainpool.P512r1,
	"1.3.36.3.3.2.8.1.1.14": brainpool.P512t1,
	"1.3.132.0.10":          crypto.S256,
}

OIDCurves - Object identifier standardized by ITU.

View Source
var OIDHashers = map[string]func() hash.Hash{
	"2.16.840.1.101.3.4.2.7":  sha3.New224,
	"2.16.840.1.101.3.4.2.8":  sha3.New256,
	"2.16.840.1.101.3.4.2.9":  sha3.New384,
	"2.16.840.1.101.3.4.2.10": sha3.New512,
}

OIDHashers - Object identifier standardized by ITU.

View Source
var TwistedCurves = map[string]func() elliptic.Curve{
	"brainpoolP256r1": brainpool.P256r1,
	"brainpoolP384r1": brainpool.P384r1,
	"brainpoolP512r1": brainpool.P512r1,
}

TwistedCurves maps curve names to twisted curves.

Functions

func BuffToInt

func BuffToInt(buff []byte) *big.Int

BuffToInt creates big Int from buffer.

func CreateOID

func CreateOID(s string) asn1.ObjectIdentifier

CreateOID creates asn1.ObjectIdentifier

func CurveHashSupportedCombination

func CurveHashSupportedCombination(curve func() elliptic.Curve, hasher func() hash.Hash) bool

CurveHashSupportedCombination returns true if the curve and hash combination are supported.

func CurvePolynomial

func CurvePolynomial(params *elliptic.CurveParams, x *big.Int) *big.Int

CurvePolynomial returns y calculaged from x. For curves is: (x³ - 3x + B) % P or (x³ - 3x) % P For Secp256k1 is: (x³ + B) % P

func GetCurve

func GetCurve(oid asn1.ObjectIdentifier) (func() elliptic.Curve, bool)

GetCurve returns hash function and error.

func GetCurveName

func GetCurveName(curve elliptic.Curve) string

GetCurveName returns curve name of the curve instace.

func GetCurveOID

func GetCurveOID(curve func() elliptic.Curve) (asn1.ObjectIdentifier, int)

GetCurveOID return OID of elliptic curve.

func GetCurveOIDForCurve

func GetCurveOIDForCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, int)

GetCurveOIDForCurve return OID of elliptic curve instance.

func GetHasher

func GetHasher(oid asn1.ObjectIdentifier) (func() hash.Hash, bool)

GetHasher returns hash function and error.

func GetHasherName

func GetHasherName(fnc func() hash.Hash) string

GetHasherName returns name of hash function.

func GetHasherOID

func GetHasherOID(fnc func() hash.Hash) (asn1.ObjectIdentifier, int)

GetHasherOID return OID of hash function.

func GetZinv

func GetZinv(curveName string) (*big.Int, *big.Int)

GetZinv returns values zinv2, zinv3 for given curve.

func PointsToBytes

func PointsToBytes(points []Point) []byte

PointsToBytes converts Points to bytes.

func Verify

func Verify(sign *Signature, publicKeys []*ecdsa.PublicKey, message []byte, caseIdentifier []byte) int

Verify verifies signature.

Types

type FactoryContext

type FactoryContext struct {
	Curve  elliptic.Curve
	Hasher func() hash.Hash
}

FactoryContext holds curve object and hash function.

func (FactoryContext) FindPointOnCurve

func (fc FactoryContext) FindPointOnCurve(value *big.Int) (*big.Int, *big.Int)

FindPointOnCurve finds point x,y on the curve.

func (FactoryContext) HashPublicKeysIntoPoint

func (fc FactoryContext) HashPublicKeysIntoPoint(publicKeyPoints []Point, caseIdentifier []byte) Point

HashPublicKeysIntoPoint returns a point on the curve created from public keys in this way:

func (FactoryContext) MakeDigest

func (fc FactoryContext) MakeDigest(data []byte) []byte

MakeDigest makes hash digest from data.

func (FactoryContext) PointAdd

func (fc FactoryContext) PointAdd(p1, p2 Point) Point

PointAdd provide add points over elliptic curve.

func (FactoryContext) PointScalarMult

func (fc FactoryContext) PointScalarMult(p Point, n []byte) Point

PointScalarMult provide scalar multiplication over elliptic curve.

type FoldedPublicKeys

type FoldedPublicKeys struct {
	Name      string
	CurveOID  asn1.ObjectIdentifier
	HasherOID asn1.ObjectIdentifier
	Digest    []byte
	Keys      [][]byte
}

FoldedPublicKeys holds data of points of public keys.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point on elliptic curve.

func ConvertPublicKeysToPoints

func ConvertPublicKeysToPoints(publicKeys []*ecdsa.PublicKey) []Point

ConvertPublicKeysToPoints converts public keys into Points.

func (Point) Bytes

func (p Point) Bytes() []byte

Bytes returns bytess of Point.

type PointData

type PointData struct {
	X []byte
	Y []byte
}

PointData holds X,Y coordinates of point. https://tools.ietf.org/html/rfc5480#section-2.2 ECPoint ::= OCTET STRING

func (PointData) Bytes

func (p PointData) Bytes() []byte

Bytes returns bytess of Key image.

type Signature

type Signature struct {
	Name       string
	Version    int
	CurveOID   asn1.ObjectIdentifier
	HasherOID  asn1.ObjectIdentifier
	KeyImage   PointData
	Checksum   []byte
	Signatures [][]byte
}

Signature holds data of ring signature.

func Create

func Create(
	curve func() elliptic.Curve,
	hasher func() hash.Hash,
	privateKey *ecdsa.PrivateKey,
	publicKeys []*ecdsa.PublicKey,
	message []byte,
	caseIdentifier []byte,
) (int, *Signature)

Create makes ring signature.

func MakeSignature

func MakeSignature(
	curve func() elliptic.Curve,
	hasher func() hash.Hash,
	privateKey *ecdsa.PrivateKey,
	publicKeys []*ecdsa.PublicKey,
	privateKeyPosition int,
	message []byte,
	caseIdentifier []byte,
) (int, *Signature)

MakeSignature creates ring signature.

type Zinv

type Zinv struct {
	Zinv2 *big.Int
	Zinv3 *big.Int
}

Zinv values for brainpool R type

Jump to

Keyboard shortcuts

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