• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cipher.SumSHA256函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/skycoin/skycoin/src/cipher.SumSHA256函数的典型用法代码示例。如果您正苦于以下问题:Golang SumSHA256函数的具体用法?Golang SumSHA256怎么用?Golang SumSHA256使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SumSHA256函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestBlockchainTail_03

func TestBlockchainTail_03(t *testing.T) {

	bq := BlockchainTail{}
	bq.Init()

	h1 := cipher.SumSHA256(secp256k1.RandByte(888))
	b1 := BlockBase{Hash: h1, Seqno: 1} // OK to leave '.sig' empty

	r1 := bq.try_append_to_BlockchainTail(&b1)
	if r1 != 0 {
		t.Log("BlockchainTail::try_append_to_BlockchainTail(): initial insert failed.")
		t.Fail()
	}
	if bq.GetNextSeqNo() != b1.Seqno+1 {
		t.Log("BlockchainTail::GetNextSeqNo() failed.")
		t.Fail()
	}

	r1dup := bq.try_append_to_BlockchainTail(&b1)
	if r1dup != 1 {
		t.Log("BlockchainTail::try_append_to_BlockchainTail(): duplicate hash not detected.")
		t.Fail()
	}

	h2 := cipher.SumSHA256(secp256k1.RandByte(888))
	b2 := BlockBase{Hash: h2, Seqno: 2} // OK to leave '.sig' empty

	r2 := bq.try_append_to_BlockchainTail(&b2)
	if r2 != 0 {
		t.Log("BlockchainTail::try_append_to_BlockchainTail(): next insert failed.")
		t.Fail()
	}
	if bq.GetNextSeqNo() != b2.Seqno+1 {
		t.Log("BlockchainTail::GetNextSeqNo() failed.")
		t.Fail()
	}

	h3 := cipher.SumSHA256(secp256k1.RandByte(888))
	b3 := BlockBase{Hash: h3, Seqno: 0} // OK to leave '.sig' empty

	r3 := bq.try_append_to_BlockchainTail(&b3)
	if r3 != 2 {
		t.Log("BlockchainTail::try_append_to_BlockchainTail(): low seqno not detected. ret=", r3)
		t.Fail()
	}

	b3.Seqno = 4
	r4 := bq.try_append_to_BlockchainTail(&b3)
	if r4 != 3 {
		t.Log("BlockchainTail::try_append_to_BlockchainTail(): high seqno not detected.")
		t.Fail()
	}

}
开发者ID:skycoin,项目名称:skycoin,代码行数:54,代码来源:consensus_test.go


示例2: ApplyBlock

//applies block against the current head
func (bc *BlockChain) ApplyBlock(block Block) error {
	//do time check
	//do prevhash check
	//check body hash
	//check BkSeq

	if block.Head.BkSeq != bc.Head().Head.BkSeq+1 {
		return errors.New("block sequence is out of order")
	}
	if block.Head.PrevHash != bc.Head().Head.Hash() {
		return errors.New("block PrevHash does not match current head")
	}
	if block.Head.Time < bc.Head().Head.Time {
		return errors.New("block time invalid")
	}
	if block.Head.BodyHash != cipher.SumSHA256(block.Body) {
		return errors.New("block body hash is wrong")
	}

	if err := bc.VerifyBlockSignature(block); err != nil {
		return errors.New("block signature check failed")
	}

	//block is valid, apply
	bc.Blocks = append(bc.Blocks, block)
	return nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:28,代码来源:chain.go


示例3: TestCrypto2

//test signatures
func TestCrypto2(t *testing.T) {
	a := "5a42c0643bdb465d90bf673b99c14f5fa02db71513249d904573d2b8b63d353d"
	b, err := hex.DecodeString(a)
	if err != nil {
		t.Fatal(err)
	}

	if len(b) != 32 {
		t.Fatal()
	}

	seckey := cipher.NewSecKey(b)
	pubkey := cipher.PubKeyFromSecKey(seckey)

	addr := cipher.AddressFromPubKey(pubkey)
	_ = addr

	test := []byte("test message")
	hash := cipher.SumSHA256(test)
	err = cipher.TestSecKeyHash(seckey, hash)
	if err != nil {
		t.Fatal()
	}

}
开发者ID:skycoin,项目名称:skycoin,代码行数:26,代码来源:coin_test.go


示例4: TestBlockchainTail_02

func TestBlockchainTail_02(t *testing.T) {

	bq := BlockchainTail{}
	bq.Init()

	// Use more than configured length to ensure some elements are
	// removed:
	n := Cfg_blockchain_tail_length * 2

	for i := 0; i < n; i++ {
		x := secp256k1.RandByte(888) // Random data.
		h := cipher.SumSHA256(x)     // Its hash.

		b := BlockBase{Hash: h, Seqno: uint64(i)} // OK to leave '.sig' empty

		bq.append_nocheck(&b)
	}

	if len(bq.blockPtr_slice) != Cfg_blockchain_tail_length {
		t.Log("BlockchainTail::append_nocheck() incorrect append or remove.")
		t.Fail()
	}

	if !bq.is_consistent() {
		t.Log("BlockchainTail::is_consistent()")
		t.Fail()
	}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:28,代码来源:consensus_test.go


示例5: TestBlockStat_01

func TestBlockStat_01(t *testing.T) {
	bs := BlockStat{}
	bs.Init()

	_, seckey := cipher.GenerateKeyPair()
	hash := cipher.SumSHA256(secp256k1.RandByte(888))
	sig := cipher.SignHash(hash, seckey)

	var r int = -1

	r = bs.try_add_hash_and_sig(hash, cipher.Sig{})
	if r != 4 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect invalid signature.")
		t.Fail()
	}
	r = bs.try_add_hash_and_sig(cipher.SHA256{}, sig)
	if r != 4 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect invalid hash and signature.")
		t.Fail()
	}
	r = bs.try_add_hash_and_sig(cipher.SHA256{}, cipher.Sig{})
	if r != 4 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect invalid hash and signature.")
		t.Fail()
	}

	//signer_pubkey, err := cipher.PubKeyFromSig(cipher.Sig{}, cipher.SHA256{})
	//if err != nil {
	//fmt.Printf("Got pubkey='%s' from all-zero sig and all-zero hash.\n", signer_pubkey.Hex())
	//}

	bs.frozen = true
	r2 := bs.try_add_hash_and_sig(hash, sig)
	if r2 != 3 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect frozen.")
		t.Fail()
	}
	bs.frozen = false

	r3 := bs.try_add_hash_and_sig(hash, sig)
	if r3 != 0 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to add.")
		t.Fail()
	}

	sig2 := cipher.SignHash(hash, seckey) // Redo signing.
	r4 := bs.try_add_hash_and_sig(hash, sig2)
	if r4 != 1 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect duplicate (hash,pubkey).")
		t.Fail()
	}

	r5 := bs.try_add_hash_and_sig(hash, sig)
	if r5 != 1 {
		t.Log("BlockStat::try_add_hash_and_sig() failed to detect duplicate (hash,sig).")
		t.Fail()
	}

}
开发者ID:skycoin,项目名称:skycoin,代码行数:59,代码来源:consensus_test.go


示例6: makeUxBodyWithSecret

func makeUxBodyWithSecret(t *testing.T) (coin.UxBody, cipher.SecKey) {
	p, s := cipher.GenerateKeyPair()
	return coin.UxBody{
		SrcTransaction: cipher.SumSHA256(randBytes(t, 128)),
		Address:        cipher.AddressFromPubKey(p),
		Coins:          10e6,
		Hours:          100,
	}, s
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:9,代码来源:unconfirmed_test.go


示例7: NewEmptySimpleWallet

func NewEmptySimpleWallet() Wallet {
	idHash := cipher.SumSHA256(secp256k1.RandByte(256))
	id := WalletID(hex.EncodeToString(idHash[:16]))
	return &SimpleWallet{
		Filename: NewWalletFilename(id),
		Entries:  WalletEntries{},
		ID:       id,
	}
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:9,代码来源:simple.go


示例8: NewBlock

//creates new block
func (bc *BlockChain) NewBlock(seckey cipher.SecKey, blockTime uint64, data []byte) Block {
	var b Block
	b.Head.Time = blockTime
	b.Head.BkSeq = bc.Head().Head.BkSeq + 1
	b.Head.PrevHash = bc.Head().Head.Hash()
	b.Head.BodyHash = cipher.SumSHA256(data)
	b.Body = data
	bc.SignBlock(seckey, &b)
	return b
}
开发者ID:skycoin,项目名称:skycoin,代码行数:11,代码来源:chain.go


示例9: createUnconfirmedTxn

func createUnconfirmedTxn() visor.UnconfirmedTxn {
	now := util.Now()
	return visor.UnconfirmedTxn{
		Txn: coin.Transaction{
			Head: coin.TransactionHeader{
				Hash: cipher.SumSHA256([]byte("cascas")),
			},
		},
		Received:  now,
		Checked:   now,
		Announced: util.ZeroTime(),
	}
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:13,代码来源:visor_test.go


示例10: TestBlockStat_02

func TestBlockStat_02(t *testing.T) {
	bs := BlockStat{}
	bs.Init()

	hash1 := cipher.SumSHA256(secp256k1.RandByte(888))
	n1 := 3

	for i := 0; i < n1; i++ {
		_, seckey := cipher.GenerateKeyPair()
		sig := cipher.SignHash(hash1, seckey)
		bs.try_add_hash_and_sig(hash1, sig)
	}

	hash2 := cipher.SumSHA256(secp256k1.RandByte(888))
	n2 := 2

	for i := 0; i < n2; i++ {
		_, seckey := cipher.GenerateKeyPair()
		sig := cipher.SignHash(hash2, seckey)
		bs.try_add_hash_and_sig(hash2, sig)
	}

	hash3 := cipher.SumSHA256(secp256k1.RandByte(888))
	n3 := 1

	for i := 0; i < n3; i++ {
		_, seckey := cipher.GenerateKeyPair()
		sig := cipher.SignHash(hash3, seckey)
		bs.try_add_hash_and_sig(hash3, sig)
	}

	best_hash, _, _ := bs.GetBestHashPubkeySig()
	if best_hash != hash1 {
		t.Log("BlockStat::try_add_hash_and_sig() or BlockStat::GetBestHashPubkeySig() issue.")
		t.Fail()
	}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:37,代码来源:consensus_test.go


示例11: NewWallet

//Generate Deterministic Wallet
//generates a random seed if seed is ""
func NewWallet(seed string) Wallet {

	//if seed is blank, generate a new seed
	if seed == "" {
		seed_raw := cipher.SumSHA256(secp256k1.RandByte(64))
		seed = hex.EncodeToString(seed_raw[:])
	}

	pub, sec := cipher.GenerateDeterministicKeyPair([]byte(seed[:]))
	return Wallet{
		Meta: map[string]string{
			"filename": NewWalletFilename(),
			"seed":     seed,
			"type":     "deterministic",
			"coin":     "sky"},
		Entry: NewWalletEntryFromKeypair(pub, sec),
	}
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:20,代码来源:deterministic.go


示例12: TestGetTxnsMessageProcess

func TestGetTxnsMessageProcess(t *testing.T) {
	v, _ := setupVisor()
	d, _ := newVisorDaemon(v)
	defer shutdown(d)
	gc := setupExistingPool(d.Pool)
	p := d.Pool
	go p.Pool.ConnectionWriteLoop(gc)
	tx := createUnconfirmedTxn()
	tx.Txn.Head.Hash = cipher.SumSHA256([]byte("asdadwadwada"))
	txns := []cipher.SHA256{tx.Txn.Hash()}
	m := NewGetTxnsMessage(txns)
	m.c = messageContext(addr)
	go p.Pool.ConnectionWriteLoop(m.c.Conn)
	defer m.c.Conn.Close()

	// We don't have any to reply with
	assert.NotPanics(t, func() { m.Process(d) })
	assert.True(t, m.c.Conn.LastSent.IsZero())

	// Disabled, nothing should happen
	d.Visor.Visor.Unconfirmed.Txns[tx.Txn.Hash()] = tx
	d.Visor.Config.Disabled = true
	assert.NotPanics(t, func() { m.Process(d) })
	assert.True(t, m.c.Conn.LastSent.IsZero())

	// We have some to reply with
	d.Visor.Config.Disabled = false
	assert.NotPanics(t, func() { m.Process(d) })
	wait()
	assert.Equal(t, len(p.Pool.SendResults), 1)
	if len(p.Pool.SendResults) == 0 {
		t.Fatal("SendResults empty, would block")
	}
	sr := <-p.Pool.SendResults
	assert.Equal(t, sr.Connection, m.c.Conn)
	assert.Nil(t, sr.Error)
	_, ok := sr.Message.(*GiveTxnsMessage)
	assert.True(t, ok)
	assert.False(t, m.c.Conn.LastSent.IsZero())
	// Should not be broadcast to others
	assert.True(t, gc.LastSent.IsZero())
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:42,代码来源:visor_test.go


示例13: NewWallet

// NewWallet generates Deterministic Wallet
// generates a random seed if seed is ""
func NewWallet(wltName string, opts ...Option) Wallet {
	seedRaw := cipher.SumSHA256(secp256k1.RandByte(64))
	seed := hex.EncodeToString(seedRaw[:])

	w := Wallet{
		Meta: map[string]string{
			"filename": wltName,
			"version":  version,
			"label":    "",
			"seed":     seed,
			"lastSeed": seed,
			"tm":       fmt.Sprintf("%v", time.Now().Unix()),
			"type":     "deterministic",
			"coin":     "sky"},
	}

	for _, opt := range opts {
		opt(&w)
	}

	return w
}
开发者ID:skycoin,项目名称:skycoin,代码行数:24,代码来源:deterministic.go


示例14: main

func main() {
	registerFlags()
	parseFlags()

	w := Wallet{
		Meta:    make(map[string]string), //map[string]string
		Entries: make([]KeyEntry, genCount),
	}

	if BitcoinAddress == false {
		w.Meta = map[string]string{"coin": "skycoin"}
	} else {
		w.Meta = map[string]string{"coin": "bitcoin"}
	}

	if seed == "" { //generate a new seed, as hex string
		seed = cipher.SumSHA256(cipher.RandByte(1024)).Hex()
	}

	w.Meta["seed"] = seed

	seckeys := cipher.GenerateDeterministicKeyPairs([]byte(seed), genCount)

	for i, sec := range seckeys {
		pub := cipher.PubKeyFromSecKey(sec)
		w.Entries[i] = getKeyEntry(pub, sec)
	}

	output, err := json.MarshalIndent(w, "", "    ")
	if err != nil {
		fmt.Printf("Error formating wallet to JSON. Error : %s\n", err.Error())
		return
	}
	fmt.Printf("%s\n", string(output))

}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:36,代码来源:address_gen.go


示例15: HashInner

// Hashes only the Transaction Inputs & Outputs
// This is what is signed
// Client hashes the inner hash with hash of output being spent and signs it with private key
func (self *Transaction) HashInner() cipher.SHA256 {
	b1 := encoder.Serialize(self.In)
	b2 := encoder.Serialize(self.Out)
	b3 := append(b1, b2...)
	return cipher.SumSHA256(b3)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:9,代码来源:transactions.go


示例16: SizeHash

// Returns the encoded size and the hash of it (avoids duplicate encoding)
func (self *Transaction) SizeHash() (int, cipher.SHA256) {
	b := self.Serialize()
	return len(b), cipher.SumSHA256(b)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:5,代码来源:transactions.go


示例17: Hash

// Hashes an entire Transaction struct, including the TransactionHeader
func (self *Transaction) Hash() cipher.SHA256 {
	b := self.Serialize()
	return cipher.SumSHA256(b)
}
开发者ID:keepwalking1234,项目名称:skycoin,代码行数:5,代码来源:transactions.go


示例18: randSHA256

func randSHA256() cipher.SHA256 {
	b := make([]byte, 128)
	rand.Read(b)
	return cipher.SumSHA256(b)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:5,代码来源:readable_test.go


示例19: toWalletID

func (self *DeterministicWalletSeed) toWalletID() WalletID {
	// Uses the first 16 bytes of SHA256(seed) as id
	shaid := cipher.SumSHA256(self[:])
	return WalletID(hex.EncodeToString(shaid[:16]))
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:5,代码来源:deterministic.go


示例20: randSHA256

func randSHA256(t *testing.T) cipher.SHA256 {
	return cipher.SumSHA256(randBytes(t, 128))
}
开发者ID:JmAbuDabi,项目名称:skycoin,代码行数:3,代码来源:outputs_test.go



注:本文中的github.com/skycoin/skycoin/src/cipher.SumSHA256函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang coin.CreateUnspents函数代码示例发布时间:2022-05-28
下一篇:
Golang cipher.PubKeyFromSecKey函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap