示例#1
0
func (s Secret) deriveRaw(n uint64, id string) (result CValue) {
	args := skein.Args{
		Key:    s[:],
		Person: []byte(personKDF),
		KeyId:  []byte(id),
	}

	var hash skein.Hash
	hash.Init(n, &args)
	_, _ = hash.Read(result[:n])
	return
}
示例#2
0
func TestBasic(t *testing.T) {
	var h skein.Hash

	for num, test := range basicVectors {
		h.Init(uint64(len(test.out)), nil)

		wn, err := h.Write(test.in)
		if wn != len(test.in) || err != nil {
			t.Errorf("basic %d: couldn't write %d bytes (%d, %v)", num, len(test.in), wn, err)
			continue
		}

		out := make([]byte, len(test.out))
		rn, err := h.Read(out)
		if rn != len(out) || err != nil {
			t.Errorf("basic %d: couldn't read %d bytes (%d, %v)", num, len(out), rn, err)
			continue
		}

		if !bytes.Equal(out, test.out) {
			t.Errorf("basic %d: expected %x, got %x", num, test.out, out)
			continue
		}
	}
}
示例#3
0
文件: ntor.go 项目: rallen71366/Dust
func (ntor *NtorHandshake) Finish(inTail, outTail string) (shared Secret, tIn, tOut AuthValue) {
	// The DH parts have already been written into ntor.h.
	hTail := bytes.Join([][]byte{ntor.bHat, ntor.x, ntor.y, []byte(ntorSquawk)}, nil)
	ntor.h.Write(hTail)

	var confSeed CValue
	_, _ = ntor.h.Read(confSeed[:])
	_, _ = ntor.h.Read(shared[:])

	hMacMedial := bytes.Join([][]byte{ntor.bHat, ntor.y, ntor.x, []byte(ntorSquawk)}, nil)
	var hMac skein.Hash
	hMac.InitFrom(&ntorInitialHmac)
	hMac.Write(confSeed[:])
	hMac.Write(hMacMedial)

	hMacIn := hMac.Copy()
	hMacIn.Write([]byte(inTail))
	_, _ = hMacIn.Read(tIn[:])
	hMacOut := hMac.Copy()
	hMacOut.Write([]byte(outTail))
	_, _ = hMacOut.Read(tOut[:])

	return
}