当前位置: 首页>>代码示例>>Golang>>正文


Golang Suite.Hash方法代码示例

本文整理汇总了Golang中github.com/dedis/crypto/abstract.Suite.Hash方法的典型用法代码示例。如果您正苦于以下问题:Golang Suite.Hash方法的具体用法?Golang Suite.Hash怎么用?Golang Suite.Hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/dedis/crypto/abstract.Suite的用法示例。


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

示例1: NewFile

func NewFile(suite abstract.Suite, path string) (*File, error) {
	f, err := os.Open(path)
	if err != nil {
		log.Fatal("Failed opening file", path, err)
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return nil, err
	}
	blocks := (fi.Size() + BlockSize - 1) / BlockSize

	x := &File{
		Name:   path,
		Hashes: make(map[string]int64, blocks),
	}

	for i := 0; int64(i) < blocks; i++ {
		tmp := make([]byte, BlockSize)
		_, err := f.Read(tmp)
		if err != nil {
			log.Fatal("Failed reading file", err)
		}
		h := suite.Hash()
		h.Write(tmp)
		x.Hashes[string(h.Sum(nil))] = int64((i * BlockSize))
	}

	return x, nil
}
开发者ID:Xyroe,项目名称:riffle,代码行数:31,代码来源:utils.go

示例2: verifyMessage

func verifyMessage(suite abstract.Suite, m interface{}, hash1 []byte) error {

	// Make a copy of the signature
	x := reflect.ValueOf(m).Elem().FieldByName("Sig")
	sig := reflect.New(x.Type()).Elem()
	sig.Set(x)

	// Reset signature field
	reflect.ValueOf(m).Elem().FieldByName("Sig").Set(reflect.ValueOf(crypto.SchnorrSig{})) // XXX: hack

	// Marshal ...
	mb, err := network.MarshalRegisteredType(m)
	if err != nil {
		return err
	}

	// ... and hash message
	hash2, err := crypto.HashBytes(suite.Hash(), mb)
	if err != nil {
		return err
	}

	// Copy back original signature
	reflect.ValueOf(m).Elem().FieldByName("Sig").Set(sig) // XXX: hack

	// Compare hashes
	if !bytes.Equal(hash1, hash2) {
		return errors.New("Message has a different hash than the given one")
	}

	return nil
}
开发者ID:dedis,项目名称:cothority,代码行数:32,代码来源:randhound.go

示例3: TestSuite

// Apply a standard set of validation tests to a ciphersuite.
func TestSuite(suite abstract.Suite) {

	// Try hashing something
	h := suite.Hash()
	l := h.Size()
	//println("HashLen: ",l)
	h.Write([]byte("abc"))
	hb := h.Sum(nil)
	//println("Hash:")
	//println(hex.Dump(hb))
	if h.Size() != l || len(hb) != l {
		panic("inconsistent hash output length")
	}

	// Generate some pseudorandom bits
	s := suite.Cipher(hb)
	sb := make([]byte, 128)
	s.XORKeyStream(sb, sb)
	//println("Stream:")
	//println(hex.Dump(sb))

	// Test if it generates two fresh keys with nil cipher
	s1 := suite.NewKey(nil)
	s2 := suite.NewKey(nil)
	if s1.Equal(s2) {
		panic("NewKey returns twice the same key given nil")
	}

	// Test if it creates the same with the same seed
	st1 := suite.Cipher(hb)
	st2 := suite.Cipher(hb)
	s3 := suite.NewKey(st1)
	s4 := suite.NewKey(st2)
	if !s3.Equal(s4) {
		panic("NewKey returns two different keys given same stream")
	}

	// Test if it creates two different with random stream
	stream := random.Stream
	s5 := suite.NewKey(stream)
	s6 := suite.NewKey(stream)
	if s5.Equal(s6) {
		panic("NewKey returns same key given random stream")
	}

	// Test the public-key group arithmetic
	TestGroup(suite)
}
开发者ID:LegoShrimp,项目名称:crypto,代码行数:49,代码来源:test.go

示例4: TestSuite

// Apply a standard set of validation tests to a ciphersuite.
func TestSuite(suite abstract.Suite) {

	// Try hashing something
	h := suite.Hash()
	l := h.Size()
	//println("HashLen: ",l)
	h.Write([]byte("abc"))
	hb := h.Sum(nil)
	//println("Hash:")
	//println(hex.Dump(hb))
	if h.Size() != l || len(hb) != l {
		panic("inconsistent hash output length")
	}

	// Generate some pseudorandom bits
	s := suite.Cipher(hb)
	sb := make([]byte, 128)
	s.XORKeyStream(sb, sb)
	//println("Stream:")
	//println(hex.Dump(sb))

	// Test the public-key group arithmetic
	TestGroup(suite)
}
开发者ID:Liamsi,项目名称:crypto,代码行数:25,代码来源:test.go

示例5: HashFileSuite

// HashFileSuite returns the hash of a file using the hashing function of the
// suite given.
func HashFileSuite(suite abstract.Suite, file string) ([]byte, error) {
	return HashFile(suite.Hash(), file)
}
开发者ID:nikirill,项目名称:cothority,代码行数:5,代码来源:hash.go

示例6: HashStreamSuite

// HashStreamSuite will hash the stream using the hashing function of the suite
func HashStreamSuite(suite abstract.Suite, stream io.Reader) ([]byte, error) {
	return HashStream(suite.Hash(), stream)
}
开发者ID:nikirill,项目名称:cothority,代码行数:4,代码来源:hash.go

示例7: HashArgsSuite

// HashArgsSuite makes a new hash from the suite and calls HashArgs
func HashArgsSuite(suite abstract.Suite, args ...encoding.BinaryMarshaler) ([]byte, error) {
	return HashArgs(suite.Hash(), args...)
}
开发者ID:nikirill,项目名称:cothority,代码行数:4,代码来源:hash.go


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