gocrypt

package module
v0.0.0-...-9f657d6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigEEA

func BigEEA(ri_, rj_ *big.Int) (*big.Int, *big.Int, *big.Int)

func CodeBlock

func CodeBlock(s string) string

func EEA

func EEA(ri, rj int) (int, int, int)

func FermatTest

func FermatTest(p *big.Int, s int, rnd *rand.Rand) bool

func PolynomialEEA

func PolynomialEEA(ri, rj *Polynomial) (*Polynomial, *Polynomial, *Polynomial)

Types

type AESCipher

type AESCipher struct {
	BlockLength int // block length in bytes
	Keys        [][]byte
}

func NewAESCipher

func NewAESCipher(key []byte) (*AESCipher, error)

func (AESCipher) Decrypt

func (cipher AESCipher) Decrypt(input, output []byte) error

func (AESCipher) Encrypt

func (cipher AESCipher) Encrypt(input, output []byte) error

func (*AESCipher) GenerateSubkeys

func (cipher *AESCipher) GenerateSubkeys(key []byte) error

type AffinePoint

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

func NewAffinePoint

func NewAffinePoint(x_, y_ *big.Int) AffinePoint

func NullAffinePoint

func NullAffinePoint() AffinePoint

func (AffinePoint) Clone

func (p AffinePoint) Clone() AffinePoint

func (AffinePoint) Equals

func (p AffinePoint) Equals(q AffinePoint) bool

func (AffinePoint) GetX

func (p AffinePoint) GetX() *big.Int

func (AffinePoint) GetY

func (p AffinePoint) GetY() *big.Int

func (AffinePoint) IsZero

func (p AffinePoint) IsZero() bool

func (*AffinePoint) Set

func (p *AffinePoint) Set(q AffinePoint)

func (*AffinePoint) SetX

func (p *AffinePoint) SetX(x *big.Int)

func (*AffinePoint) SetY

func (p *AffinePoint) SetY(y *big.Int)

func (*AffinePoint) SetZero

func (p *AffinePoint) SetZero()

func (AffinePoint) String

func (p AffinePoint) String() string

type AsciiAlphabet

type AsciiAlphabet struct {
	// contains filtered or unexported fields
}
var RstAsciiAlphabet AsciiAlphabet = AsciiAlphabet{65, 122}
var StdAsciiAlphabet AsciiAlphabet = AsciiAlphabet{32, 126}

func (AsciiAlphabet) Geti

func (alphabet AsciiAlphabet) Geti() int

func (AsciiAlphabet) Getj

func (alphabet AsciiAlphabet) Getj() int

type Base64

type Base64 struct{}

func (Base64) ReadFile

func (Base64) ReadFile(filename string) ([]byte, error)

func (Base64) ReadString

func (Base64) ReadString(str string) ([]byte, error)

func (Base64) WriteFile

func (Base64) WriteFile(filename string, b []byte) error

func (Base64) WriteString

func (Base64) WriteString(b []byte) string

type BigPrimeField

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

func NewBigPrimeField

func NewBigPrimeField(p_ *big.Int) BigPrimeField

func (BigPrimeField) Add

func (f BigPrimeField) Add(r, a, b *big.Int) *big.Int

func (BigPrimeField) Div

func (f BigPrimeField) Div(r, a, b *big.Int) *big.Int

func (BigPrimeField) IsOne

func (f BigPrimeField) IsOne(a *big.Int) bool

func (BigPrimeField) IsZero

func (f BigPrimeField) IsZero(a *big.Int) bool

func (BigPrimeField) Modp

func (f BigPrimeField) Modp(r, a *big.Int) *big.Int

func (BigPrimeField) Mul

func (f BigPrimeField) Mul(r, a, b *big.Int) *big.Int

func (BigPrimeField) Neg

func (f BigPrimeField) Neg(r, a *big.Int) *big.Int

func (BigPrimeField) Sub

func (f BigPrimeField) Sub(r, a, b *big.Int) *big.Int

type BinaryExtensionField

type BinaryExtensionField struct {
	IP *BinaryPolynomial
}

func NewBinaryExtensionField

func NewBinaryExtensionField(ip *BinaryPolynomial) BinaryExtensionField

func (BinaryExtensionField) Add

func (BinaryExtensionField) Div

func (BinaryExtensionField) IsOne

func (BinaryExtensionField) IsZero

func (BinaryExtensionField) Mul

func (BinaryExtensionField) One

func (BinaryExtensionField) Sub

func (BinaryExtensionField) Zero

type BinaryPolynomial

type BinaryPolynomial struct {
	Terms []byte
}

func NewBinaryPolynomial

func NewBinaryPolynomial(n int) *BinaryPolynomial

func (*BinaryPolynomial) Add

func (r *BinaryPolynomial) Add(a, b *BinaryPolynomial)

func (*BinaryPolynomial) AddTerm

func (r *BinaryPolynomial) AddTerm(c, e int)

func (*BinaryPolynomial) Clone

func (r *BinaryPolynomial) Clone() *BinaryPolynomial

func (*BinaryPolynomial) Degree

func (r *BinaryPolynomial) Degree() int

func (*BinaryPolynomial) Div

func (r *BinaryPolynomial) Div(a, b *BinaryPolynomial)

func (*BinaryPolynomial) Equals

func (r *BinaryPolynomial) Equals(a *BinaryPolynomial) bool

func (*BinaryPolynomial) Exponents

func (r *BinaryPolynomial) Exponents() []int

func (*BinaryPolynomial) Lead

func (r *BinaryPolynomial) Lead() (int, int)

func (*BinaryPolynomial) Mod

func (r *BinaryPolynomial) Mod(a, b *BinaryPolynomial)

func (*BinaryPolynomial) Mul

func (r *BinaryPolynomial) Mul(a, b *BinaryPolynomial)

func (*BinaryPolynomial) Neg

func (*BinaryPolynomial) Realloc

func (r *BinaryPolynomial) Realloc(n int)

func (*BinaryPolynomial) Resize

func (r *BinaryPolynomial) Resize(n int)

func (*BinaryPolynomial) Set

func (*BinaryPolynomial) SetZero

func (r *BinaryPolynomial) SetZero()

func (*BinaryPolynomial) Shrink

func (r *BinaryPolynomial) Shrink()

func (*BinaryPolynomial) String

func (r *BinaryPolynomial) String() string

func (*BinaryPolynomial) Sub

func (r *BinaryPolynomial) Sub(a, b *BinaryPolynomial)

type Bits

type Bits []byte

func (Bits) Clear

func (x Bits) Clear()

func (Bits) Clr

func (x Bits) Clr(i int)

func (Bits) Dec

func (x Bits) Dec()

func (Bits) Equals

func (y Bits) Equals(x []byte) bool

func (Bits) Hex

func (bits Bits) Hex() string

func (Bits) Inc

func (x Bits) Inc()

func (Bits) Map

func (output Bits) Map(input []byte, table [][]int)

func (Bits) MapInjective

func (output Bits) MapInjective(input []byte, table []int)

Injective mapping of input bits to output bits. The mapping is defined by the table. The jth bit in the output slice is copied from position i = table[j] in the input. (Input and output may NOT point to the same array.)

func (Bits) MapSurjective

func (output Bits) MapSurjective(input []byte, table []int)

Surjective mapping of input bits to output bits. The mapping is defined by the table. The ith bit in the input slice is mapped to position j = table[i] in the output. (Input and output may NOT point to the same array!)

func (Bits) Read

func (Bits) Read(str string) Bits

func (Bits) Reverse

func (y Bits) Reverse(x []byte)

func (Bits) ReverseEndian

func (y Bits) ReverseEndian(x []byte)

func (Bits) Rotate

func (y Bits) Rotate(x []byte, n int)

func (Bits) RotateLeft

func (y Bits) RotateLeft(x []byte, n uint)

func (Bits) RotateRight

func (y Bits) RotateRight(x []byte, n uint)

func (Bits) Set

func (x Bits) Set(i int)

func (Bits) String

func (bits Bits) String() string

func (Bits) Swap

func (x Bits) Swap(i, j int)

func (Bits) Xor

func (z Bits) Xor(x, y []byte)

compute element-wise xor: z = x (+) y

type BlockCipher

type BlockCipher interface {
	Encrypt(input, output []byte) error
	Decrypt(input, output []byte) error
	GetBlockLength() int
}

type ByteMatrix

type ByteMatrix []byte

func NewByteMatrix

func NewByteMatrix(a []byte) ByteMatrix

type ByteVector

type ByteVector byte

func ByteMmulV

func ByteMmulV(a ByteMatrix, b ByteVector) ByteVector

func ByteVaddV

func ByteVaddV(a ByteVector, b ByteVector) ByteVector

func NewByteVector

func NewByteVector(a byte) ByteVector

type CBCCipher

type CBCCipher struct {
	BlockCipher
	// contains filtered or unexported fields
}

func NewCBCCipher

func NewCBCCipher(cipher BlockCipher, iv []byte) (*CBCCipher, error)

func (CBCCipher) Decrypt

func (cipher CBCCipher) Decrypt(input, output []byte) error

func (CBCCipher) Encrypt

func (cipher CBCCipher) Encrypt(input, output []byte) error

type CTRCipher

type CTRCipher struct {
	BlockCipher
	// contains filtered or unexported fields
}

func NewCTRCipher

func NewCTRCipher(cipher BlockCipher, iv []byte) (*CTRCipher, error)

func (*CTRCipher) Decrypt

func (cipher *CTRCipher) Decrypt(input, output []byte) error

func (*CTRCipher) Encrypt

func (cipher *CTRCipher) Encrypt(input, output []byte) error

func (*CTRCipher) Reset

func (cipher *CTRCipher) Reset() error

func (*CTRCipher) SetIV

func (cipher *CTRCipher) SetIV(iv []byte) error

type Cipher

type Cipher interface {
	Generate(args ...interface{})
	Encrypt(m Message) Message
	Decrypt(m Message) Message
}

type DESCipher

type DESCipher struct {
	FeistelNetwork
}

func NewDESCipher

func NewDESCipher(key Key) (*DESCipher, error)

func (DESCipher) Decrypt

func (cipher DESCipher) Decrypt(input, output []byte) error

func (DESCipher) Encrypt

func (cipher DESCipher) Encrypt(input, output []byte) error

func (*DESCipher) GenerateSubkeys

func (cipher *DESCipher) GenerateSubkeys(key []byte) error

func (DESCipher) RotateKey

func (des DESCipher) RotateKey(key []byte, n int)

func (DESCipher) RoundFunction

func (des DESCipher) RoundFunction(key, input, output []byte)

func (DESCipher) Sbox

func (DESCipher) Sbox(input, output []byte)

type ECBCipher

type ECBCipher struct {
	BlockCipher
}

func NewECBCipher

func NewECBCipher(cipher BlockCipher) *ECBCipher

func (ECBCipher) Decrypt

func (cipher ECBCipher) Decrypt(input, output []byte) error

func (ECBCipher) Encrypt

func (cipher ECBCipher) Encrypt(input, output []byte) error

type ECC

type ECC struct {
	Curve EllipticCurve
	G     AffinePoint
	N, H  *big.Int
}
var Secp192k1 ECC
var Secp192r1 ECC
var Secp224k1 ECC
var Secp224r1 ECC
var Secp256k1 ECC
var Secp256r1 ECC
var Secp384r1 ECC
var Secp521r1 ECC

func NewECC

func NewECC(p, a, b, x_, y_, n_, h_ *big.Int) ECC

func (ECC) Base

func (ecc ECC) Base() AffinePoint

func (ECC) Eval

func (ecc ECC) Eval(a AffinePoint, b *big.Int) AffinePoint

type EllipticCurve

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

func NewEllipticCurve

func NewEllipticCurve(a_, b_, p *big.Int) EllipticCurve

func (EllipticCurve) AddAffine

func (ec EllipticCurve) AddAffine(p, q AffinePoint) AffinePoint

func (EllipticCurve) AddMixed

func (EllipticCurve) AffineFromProjective

func (ec EllipticCurve) AffineFromProjective(p ProjectivePoint) AffinePoint

func (EllipticCurve) DoubleProjective

func (ec EllipticCurve) DoubleProjective(p ProjectivePoint) ProjectivePoint

func (EllipticCurve) FeasibleAffinePoint

func (ec EllipticCurve) FeasibleAffinePoint(p AffinePoint) bool

func (EllipticCurve) MulIntAffine

func (ec EllipticCurve) MulIntAffine(p AffinePoint, n *big.Int) AffinePoint

func (EllipticCurve) MulIntProjective

func (ec EllipticCurve) MulIntProjective(q AffinePoint, n *big.Int) AffinePoint

func (EllipticCurve) NegAffine

func (ec EllipticCurve) NegAffine(p AffinePoint) AffinePoint

func (EllipticCurve) NegProjective

func (ec EllipticCurve) NegProjective(p ProjectivePoint) ProjectivePoint

type ExtensionField

type ExtensionField struct {
	IP *Polynomial
}

func NewExtensionField

func NewExtensionField(ip *Polynomial) ExtensionField

func (ExtensionField) Add

func (f ExtensionField) Add(a, b *Polynomial) *Polynomial

func (ExtensionField) Div

func (f ExtensionField) Div(a, b *Polynomial) *Polynomial

func (ExtensionField) IsOne

func (f ExtensionField) IsOne(a *Polynomial) bool

func (ExtensionField) IsZero

func (f ExtensionField) IsZero(a *Polynomial) bool

func (ExtensionField) Mul

func (f ExtensionField) Mul(a, b *Polynomial) *Polynomial

func (ExtensionField) One

func (f ExtensionField) One() *Polynomial

func (ExtensionField) Sub

func (f ExtensionField) Sub(a, b *Polynomial) *Polynomial

func (ExtensionField) Zero

func (f ExtensionField) Zero() *Polynomial

type FeistelNetwork

type FeistelNetwork struct {
	BlockLength int // block length in bytes
	Keys        [][]byte
	F           RoundFunction
}

func NewFeistelNetwork

func NewFeistelNetwork(blockLength int, keys [][]byte, f RoundFunction) FeistelNetwork

func (FeistelNetwork) Decrypt

func (network FeistelNetwork) Decrypt(input, output []byte) error

func (FeistelNetwork) Encrypt

func (network FeistelNetwork) Encrypt(input, output []byte) error

func (FeistelNetwork) GetBlockLength

func (network FeistelNetwork) GetBlockLength() int

type FieldFloat

type FieldFloat interface {
	Neg(a float64) float64
	Add(a, b float64) float64
	Sub(a, b float64) float64
	Mul(a, b float64) float64
	Div(a, b float64) float64
	IsZero(a float64) bool
	IsOne(a float64) bool
	Zero() float64
	One() float64
}

type FieldInt

type FieldInt interface {
	Neg(a int) int
	Add(a, b int) int
	Sub(a, b int) int
	Mul(a, b int) int
	Div(a, b int) int
	IsZero(a int) bool
	IsOne(a int) bool
	Zero() int
	One() int
}

type FieldPolynomial

type FieldPolynomial interface {
	Neg(a *Polynomial) *Polynomial
	Add(a, b *Polynomial) *Polynomial
	Sub(a, b *Polynomial) *Polynomial
	Mul(a, b *Polynomial) *Polynomial
	Div(a, b *Polynomial) *Polynomial
	IsZero(a *Polynomial) bool
	IsOne(a *Polynomial) bool
	Zero() *Polynomial
	One() *Polynomial
}

type Key

type Key []byte

func NewKey

func NewKey(n int) Key

func (*Key) Read

func (key *Key) Read(filename string) (Key, error)

func (Key) String

func (k Key) String() string

func (Key) Uint64Slice

func (k Key) Uint64Slice() []uint64

func (Key) Write

func (key Key) Write(filename string) error

type Message

type Message []byte

func NewMessage

func NewMessage(text string) Message

func NullMessage

func NullMessage(n int) Message

func (Message) Base64String

func (m Message) Base64String() string

func (Message) String

func (m Message) String() string

type PermutationCipher

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

func NewAsciiPermutationCipher

func NewAsciiPermutationCipher(alphabet AsciiAlphabet) PermutationCipher

func NewPermutationCipher

func NewPermutationCipher() PermutationCipher

func (*PermutationCipher) Decrypt

func (cipher *PermutationCipher) Decrypt(m Message) Message

func (*PermutationCipher) Encrypt

func (cipher *PermutationCipher) Encrypt(m Message) Message

func (*PermutationCipher) Generate

func (cipher *PermutationCipher) Generate(args ...interface{})

func (*PermutationCipher) GetKey

func (cipher *PermutationCipher) GetKey() Key

func (*PermutationCipher) Swap

func (cipher *PermutationCipher) Swap(j1, j2 int)

type Polynomial

type Polynomial struct {
	Terms map[int]int
	Field FieldInt
}

func NewPolynomial

func NewPolynomial(field FieldInt) *Polynomial

func (*Polynomial) Add

func (r *Polynomial) Add(a, b *Polynomial)

func (*Polynomial) AddTerm

func (r *Polynomial) AddTerm(c, e int)

func (*Polynomial) Clone

func (r *Polynomial) Clone() *Polynomial

func (*Polynomial) Degree

func (r *Polynomial) Degree() int

func (*Polynomial) Div

func (r *Polynomial) Div(a, b *Polynomial)

func (*Polynomial) Equals

func (r *Polynomial) Equals(a *Polynomial) bool

func (*Polynomial) Exponents

func (r *Polynomial) Exponents() []int

func (*Polynomial) Lead

func (r *Polynomial) Lead() (int, int)

func (*Polynomial) Mod

func (r *Polynomial) Mod(a, b *Polynomial)

func (*Polynomial) Mul

func (r *Polynomial) Mul(a, b *Polynomial)

func (*Polynomial) Neg

func (r *Polynomial) Neg(a *Polynomial)

func (*Polynomial) Set

func (r *Polynomial) Set(a *Polynomial)

func (*Polynomial) SetZero

func (r *Polynomial) SetZero()

func (*Polynomial) String

func (r *Polynomial) String() string

func (*Polynomial) Sub

func (r *Polynomial) Sub(a, b *Polynomial)

type PrimeField

type PrimeField int

func NewPrimeField

func NewPrimeField(p int) PrimeField

func (PrimeField) Add

func (p PrimeField) Add(a, b int) int

func (PrimeField) Div

func (p PrimeField) Div(a, b int) int

func (PrimeField) IsOne

func (p PrimeField) IsOne(a int) bool

func (PrimeField) IsZero

func (p PrimeField) IsZero(a int) bool

func (PrimeField) Modp

func (p PrimeField) Modp(a int) int

func (PrimeField) Mul

func (p PrimeField) Mul(a, b int) int

func (PrimeField) Neg

func (p PrimeField) Neg(a int) int

func (PrimeField) One

func (p PrimeField) One() int

func (PrimeField) Sub

func (p PrimeField) Sub(a, b int) int

func (PrimeField) Zero

func (p PrimeField) Zero() int

type ProjectivePoint

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

func NewProjectivePoint

func NewProjectivePoint(x_, y_, z_ *big.Int) ProjectivePoint

func NullProjectivePoint

func NullProjectivePoint() ProjectivePoint

func (ProjectivePoint) Clone

func (p ProjectivePoint) Clone() ProjectivePoint

func (ProjectivePoint) Equals

func (p ProjectivePoint) Equals(q ProjectivePoint) bool

func (ProjectivePoint) GetX

func (p ProjectivePoint) GetX() *big.Int

func (ProjectivePoint) GetY

func (p ProjectivePoint) GetY() *big.Int

func (ProjectivePoint) GetZ

func (p ProjectivePoint) GetZ() *big.Int

func (ProjectivePoint) IsZero

func (p ProjectivePoint) IsZero() bool

func (*ProjectivePoint) Set

func (p *ProjectivePoint) Set(q ProjectivePoint)

func (*ProjectivePoint) SetAffine

func (p *ProjectivePoint) SetAffine(q AffinePoint)

func (*ProjectivePoint) SetX

func (p *ProjectivePoint) SetX(x *big.Int)

func (*ProjectivePoint) SetY

func (p *ProjectivePoint) SetY(y *big.Int)

func (*ProjectivePoint) SetZ

func (p *ProjectivePoint) SetZ(z *big.Int)

func (*ProjectivePoint) SetZero

func (p *ProjectivePoint) SetZero()

func (ProjectivePoint) String

func (p ProjectivePoint) String() string

type RealField

type RealField struct {
}

func NewRealField

func NewRealField() RealField

func (RealField) Add

func (f RealField) Add(a, b float64) float64

func (RealField) Div

func (f RealField) Div(a, b float64) float64

func (RealField) IsOne

func (f RealField) IsOne(a float64) bool

func (RealField) IsZero

func (f RealField) IsZero(a float64) bool

func (RealField) Mul

func (f RealField) Mul(a, b float64) float64

func (RealField) Neg

func (f RealField) Neg(a float64) float64

func (RealField) One

func (f RealField) One() float64

func (RealField) Sub

func (f RealField) Sub(a, b float64) float64

func (RealField) Zero

func (f RealField) Zero() float64

type RoundFunction

type RoundFunction func(key, input, output []byte)

round function

type TripleDESCipher

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

func NewTripleDESCipher

func NewTripleDESCipher(key Key) (*TripleDESCipher, error)

func (TripleDESCipher) Decrypt

func (cipher TripleDESCipher) Decrypt(input, output []byte) error

func (TripleDESCipher) Encrypt

func (cipher TripleDESCipher) Encrypt(input, output []byte) error

func (TripleDESCipher) GetBlockLength

func (cipher TripleDESCipher) GetBlockLength() int

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

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