Example #1
0
func IdForKey(pk rsa.PublicKey) Id {

	// Write the Rsa64 representation of public key into Sha256
	pk64 := []byte(rsa64.PubToBase64(&pk))
	sha256 := sha256.New()
	for {
		n, err := sha256.Write(pk64)
		if err != nil {
			panic("sha256 malfunction")
		}
		if n == len(pk64) {
			break
		}
		pk64 = pk64[n:]
	}

	// Compute and fold the Sha256 hash
	h := sha256.Sum()
	if len(h) != 32 {
		panic("expecting 32 bytes")
	}

	for i := 1; i < 4; i++ {
		for j := 0; j < 8; j++ {
			h[j] ^= h[8*i+j]
		}
	}
	id64, err := bytes.BytesToInt64(h[0:8])
	if err != nil {
		panic("logic")
	}

	return Id(id64)
}
Example #2
0
func (id Id) Mask() Id {
	sha := sha1.New()
	b := bytes.Int64ToBytes(int64(uint64(id)))
	sha.Write(b)
	sum := sha.Sum()
	i, err := bytes.BytesToInt64(sum[0 : 64/8])
	if err != nil {
		panic("id, mask")
	}
	return Id(uint64(i))
}