Esempio n. 1
0
func freshSumRipemd160(b []byte) Ripemd160 {
	sh := ripemd160.New()
	sh.Write(b)
	h := Ripemd160{}
	h.Set(sh.Sum(nil))
	return h
}
Esempio n. 2
0
func TestPubKeyToAddressHash(t *testing.T) {
	p, _ := GenerateKeyPair()
	h := p.ToAddressHash()
	// Should be Ripemd160(SHA256(SHA256()))
	x := sha256.Sum256(p[:])
	x = sha256.Sum256(x[:])
	rh := ripemd160.New()
	rh.Write(x[:])
	y := rh.Sum(nil)
	assert.True(t, bytes.Equal(h[:], y))
}
Esempio n. 3
0
File: hash.go Progetto: up4k/skycoin
package coin

import (
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"github.com/skycoin/skycoin/src/lib/ripemd160"
	"hash"
	"log"
)

var (
	sha256Hash    hash.Hash = sha256.New()
	ripemd160Hash hash.Hash = ripemd160.New()
)

// Ripemd160

type Ripemd160 [20]byte

func (self *Ripemd160) Set(b []byte) {
	if len(b) != 20 {
		log.Panic("Invalid ripemd160 length")
	}
	copy(self[:], b[:])
}

func HashRipemd160(data []byte) Ripemd160 {
	ripemd160Hash.Reset()
	ripemd160Hash.Write(data)
	sum := ripemd160Hash.Sum(nil)