func (dag *Dagger) Eval(N *big.Int) *big.Int { pow := BigPow(2, 26) dag.xn = pow.Div(N, pow) sha := sha3.NewKeccak224() sha.Reset() ret := new(big.Int) for k := 0; k < 4; k++ { d := sha3.NewKeccak224() b := new(big.Int) d.Reset() d.Write(dag.hash.Bytes()) d.Write(dag.xn.Bytes()) d.Write(N.Bytes()) d.Write(big.NewInt(int64(k)).Bytes()) b.SetBytes(Sum(d)) pk := (b.Uint64() & 0x1ffffff) sha.Write(dag.Node(9, pk).Bytes()) } return ret.SetBytes(Sum(sha)) }
func (dag *Dagger) Node(L uint64, i uint64) *big.Int { if L == i { return dag.hash } var m *big.Int if L == 9 { m = big.NewInt(16) } else { m = big.NewInt(3) } sha := sha3.NewKeccak224() sha.Reset() d := sha3.NewKeccak224() b := new(big.Int) ret := new(big.Int) for k := 0; k < int(m.Uint64()); k++ { d.Reset() d.Write(dag.hash.Bytes()) d.Write(dag.xn.Bytes()) d.Write(big.NewInt(int64(L)).Bytes()) d.Write(big.NewInt(int64(i)).Bytes()) d.Write(big.NewInt(int64(k)).Bytes()) b.SetBytes(Sum(d)) pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1) sha.Write(dag.Node(L-1, pk).Bytes()) } ret.SetBytes(Sum(sha)) return ret }
func Sha3Bin(data []byte) []byte { d := sha3.NewKeccak224() d.Reset() d.Write(data) return d.Sum(nil) }