crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC 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.

ZooBC 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 ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC 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.

ZooBC 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 ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC 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.

ZooBC 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 ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC 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.

ZooBC 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 ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC 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.

ZooBC 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 ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Package splitmix64 implements a 64 bit SplittableRandom PRNG. This is a fixed-increment version of Java 8's SplittableRandom generator. Period: 2^64. State size: 64 bits. See http://dx.doi.org/10.1145/2714064.2660195 and http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html It is a very fast generator passing BigCrush. It is used in the xoroshiro128+ and xorshift1024* generators to initialize their state arrays.

Package xoroshiro provides an implementation for a pseudo-random number generator (PRNG) using the xoroshiro128** and xoroshiro128+ algorithms.

Period: 2^128-1. State size: 128 bits.

Go implementation based on a C reference implementation by David Blackman and Sebastiano Vigna. For further information: http://xoshiro.di.unimi.it/

Index

Examples

Constants

View Source
const (
	PseudoRandomXoroshiro128 = iota
	PseudoRandomSha3256
)

Variables

View Source
var LastRequestTimestamp uint64

Functions

func OpenSSLDecrypt

func OpenSSLDecrypt(passphrase, encryptedBase64String string) ([]byte, error)

OpenSSLDecrypt string that was encrypted using OpenSSL and AES-256-CBC

func PseudoRandomGenerator

func PseudoRandomGenerator(id, offset uint64, algo int) (pr uint64)

PseudoRandomGenerator using multple algorithms

func VerifyAuthAPI

func VerifyAuthAPI(
	ownerAddress []byte,
	auth string,
	requestType model.RequestType,
) error

VerifyAuthAPI verify the request body and the signature of the request message, checking include request type checking, and the validity of the signature to the owner address return nil if valid, and Blocker object otherwise

Types

type OpenSSLCreds

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

type RandomNumberGenerator

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

func NewRandomNumberGenerator

func NewRandomNumberGenerator() *RandomNumberGenerator

func (*RandomNumberGenerator) Next

func (r *RandomNumberGenerator) Next() int64

func (*RandomNumberGenerator) Reset

func (r *RandomNumberGenerator) Reset(prefix string, seed []byte) error

type Rng

type Rng struct {
	State uint64 // Internal state value
}

Rng encapsulates a splitmix64 PRNG. The State value is exported so that the generator can be initialized and seeded in a single line of code:

rng := splitmix64.Rng{seed}
// is equivalent to
rng := splitmix64.Rng{}
rng.Seed(int64(seed))

func (*Rng) Int63

func (rng *Rng) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rng) Seed

func (rng *Rng) Seed(seed int64)

Seed uses the provided seed value to initialize the generator to a deterministic state.

func (*Rng) Uint64

func (rng *Rng) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

type Rng128P

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

Rng128P encapsulates a xoroshiro128+ PRNG.

xoroshiro128+ 1.0 is Blackman & Vigna's best and fastest small-state generator for floating-point numbers. They suggest to use its upper bits for floating-point generation, as it is slightly faster than xoroshiro128**. It passes all tests the authors are aware of except for the four lower bits, which might fail linearity tests (and just those), so if low linear complexity is not considered an issue (as it is usually the case) it can be used to generate 64-bit outputs, too; moreover, this generator has a very mild Hamming-weight dependency making our test (http://prng.di.unimi.it/hwd.php) fail after 5 TB of output; the authors believe this slight bias cannot affect any application. If you are concerned, use xoroshiro128** or xoshiro256+.

The authors suggest to use a sign test to extract a random Boolean value, and right shifts to extract subsets of bits.

Note that the Go implementation of Rand.Float64 uses the upper bits as suggested.

Example
src := Rng128P{}
src.Seed(SEED2)
rng := rand.New(&src)
for i := 0; i < 4; i++ {
	fmt.Printf(" %d", rng.Uint32())
}
fmt.Println("")
for i := 0; i < 4; i++ {
	fmt.Printf(" %d", rng.Uint64())
}
fmt.Println("")
// Play craps
for i := 0; i < 10; i++ {
	fmt.Printf(" %d%d", rng.Intn(6)+1, rng.Intn(6)+1)
}
Output:

3672052799 776653214 1122818236 1139848352
 14850484681238877506 7018105211938886447 5908230704518956940 2042158984393296588
 65 53 21 56 44 16 23 42 55 41

func (*Rng128P) Int63

func (rng *Rng128P) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rng128P) Seed

func (rng *Rng128P) Seed(seed int64)

Seed uses the provided seed value to initialize the generator to a deterministic state.

func (*Rng128P) Uint64

func (rng *Rng128P) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

type Rng128SS

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

Rng128SS encapsulates a xoroshiro128** PRNG.

xoroshiro128** 1.0 is Blackman & Vigna's all-purpose, rock-solid, small-state generator. It is extremely (sub-ns) fast and it passes all tests the authors are aware of, but its state space is large enough only for mild parallelism.

For generating just floating-point numbers, xoroshiro128+ is even faster (but it has a very mild bias, see notes in the comments).

Example
src := Rng128SS{}
src.Seed(SEED2)
rng := rand.New(&src)
for i := 0; i < 4; i++ {
	fmt.Printf(" %d", rng.Uint32())
}
fmt.Println("")
for i := 0; i < 4; i++ {
	fmt.Printf(" %d", rng.Uint64())
}
fmt.Println("")
// Play craps
for i := 0; i < 10; i++ {
	fmt.Printf(" %d%d", rng.Intn(6)+1, rng.Intn(6)+1)
}
Output:

901646676 398979522 1208087553 1093404254
 17905646702528074117 5693647338227160345 1089260090730707711 12276528025967720504
 41 35 56 61 56 35 31 12 63 54

func (*Rng128SS) Int63

func (rng *Rng128SS) Int63() int64

Int63 returns a non-negative pseudo-random 63-bit integer as an int64.

func (*Rng128SS) Seed

func (rng *Rng128SS) Seed(seed int64)

Seed uses the provided seed value to initialize the generator to a deterministic state.

func (*Rng128SS) Uint64

func (rng *Rng128SS) Uint64() uint64

Uint64 returns a pseudo-random 64-bit value as a uint64.

type Signature

type Signature struct {
}

Signature object handle signing and verifying different signature

func NewSignature

func NewSignature() *Signature

NewSignature create new instance of signature object

func (*Signature) GenerateAccountFromSeed

func (*Signature) GenerateAccountFromSeed(accountType accounttype.AccountTypeInterface, seed string, optionalParams ...interface{}) (
	privateKey, publicKey []byte,
	publicKeyString, encodedAddress string,
	fullAccountAddress []byte,
	err error,
)

GenerateAccountFromSeed to generate account based on provided seed

func (*Signature) GenerateBlockSeed

func (*Signature) GenerateBlockSeed(payload []byte, nodeSeed string) []byte

GenerateBlockSeed special method for generating block seed using zed

func (*Signature) Sign

func (*Signature) Sign(
	payload []byte,
	accountTypeEnum model.AccountType,
	seed string,
	optionalParams ...interface{},
) ([]byte, error)

Sign accept account ID and payload to be signed then return the signature byte based on the signature method associated with account.Type

func (*Signature) SignByNode

func (*Signature) SignByNode(payload []byte, nodeSeed string) []byte

SignByNode special method for signing block only, there will be no multiple signature options

func (*Signature) VerifyNodeSignature

func (*Signature) VerifyNodeSignature(payload, signature, nodePublicKey []byte) bool

VerifyNodeSignature Verify a signature of a block or message signed with a node private key Note: this function is a wrapper around the ed25519 algorithm

func (*Signature) VerifySignature

func (*Signature) VerifySignature(payload, signature, accountAddress []byte) error

VerifySignature accept payload (before without signature), signature and the account id then verify the signature + public key against the payload based on the

type SignatureInterface

type SignatureInterface interface {
	Sign(payload []byte, accountType model.AccountType, seed string, optionalParams ...interface{}) ([]byte, error)
	SignByNode(payload []byte, nodeSeed string) []byte
	VerifySignature(payload, signature, accountAddress []byte) error
	VerifyNodeSignature(payload, signature []byte, nodePublicKey []byte) bool
	GenerateAccountFromSeed(accountType accounttype.AccountTypeInterface, seed string, optionalParams ...interface{}) (
		privateKey, publicKey []byte,
		publicKeyString, encodedAddress string,
		fullAccountAddress []byte,
		err error,
	)
	GenerateBlockSeed(payload []byte, nodeSeed string) []byte
}

SignatureInterface represent interface of signature

Jump to

Keyboard shortcuts

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