Exemple #1
0
func NewSkein512() hash.Hash {
	res, err := skein.New(512, 512)
	if err != nil {
		return nil
	}
	return res
}
Exemple #2
0
func NewSkein1024() hash.Hash {
	res, err := skein.New(1024, 1024)
	if err != nil {
		return nil
	}
	return res
}
Exemple #3
0
func NewSkein256() hash.Hash {
	res, err := skein.New(256, 256)
	if err != nil {
		return nil
	}
	return res
}
Exemple #4
0
func checkKATVectors(ks *katScanner) bool {
	kr := new(katResult)

	var tree, mac, normal int

	for ks.fillResult(kr) {
		if strings.Contains(string(kr.restOfLine), "Tree") {
			tree++
			continue
		}
		if strings.Contains(string(kr.restOfLine), "MAC") {
			skein, _ := skein.NewMac(kr.stateSize, kr.hashBitLength, kr.macKey)
			skein.UpdateBits(kr.msg, kr.msgLength)
			hash := skein.DoFinal()
			if ret := bytes.Compare(hash, kr.result); ret != 0 {
				fmt.Printf("%d-%d-%d-%s\n", kr.stateSize, kr.hashBitLength,
					kr.msgLength, string(kr.restOfLine))
				fmt.Printf("Computed mac:\n%s\n", hex.EncodeToString(hash))
				fmt.Printf("Expected mac:\n%s\n", hex.EncodeToString(kr.result))
				return false
			}
			// do it second time with same instance to check if context was
			// reset correctly
			skein.UpdateBits(kr.msg, kr.msgLength)
			hash = skein.DoFinal()
			if ret := bytes.Compare(hash, kr.result); ret != 0 {
				fmt.Printf("%d-%d-%d-%s\n", kr.stateSize, kr.hashBitLength,
					kr.msgLength, string(kr.restOfLine))
				fmt.Printf("Computed mac after reset:\n%s\n", hex.EncodeToString(hash))
				fmt.Printf("Expected mac:\n%s\n", hex.EncodeToString(kr.result))
				return false
			}
			mac++
			continue
		}
		skein, _ := skein.New(kr.stateSize, kr.hashBitLength)
		skein.UpdateBits(kr.msg, kr.msgLength)
		hash := skein.DoFinal()
		if ret := bytes.Compare(hash, kr.result); ret != 0 {
			fmt.Printf("%d-%d-%d-%s\n", kr.stateSize, kr.hashBitLength,
				kr.msgLength, string(kr.restOfLine))
			fmt.Printf("Computed hash:\n%s\n", hex.EncodeToString(hash))
			fmt.Printf("Expected result:\n%s\n", hex.EncodeToString(kr.result))
			return false
		}
		// do it second time with same instance to check if context was reset
		// correctly
		skein.UpdateBits(kr.msg, kr.msgLength)
		hash = skein.DoFinal()
		if ret := bytes.Compare(hash, kr.result); ret != 0 {
			fmt.Printf("%d-%d-%d-%s\n", kr.stateSize, kr.hashBitLength,
				kr.msgLength, string(kr.restOfLine))
			fmt.Printf("Computed hash after reset:\n%s\n", hex.EncodeToString(hash))
			fmt.Printf("Expected result:\n%s\n", hex.EncodeToString(kr.result))
			return false
		}
		normal++
	}
	fmt.Printf("(Tree: %d), mac: %d, normal: %d, Skein tests total: %d\n",
		tree, mac, normal, mac+normal)
	return true
}