| 90 | } |
| 91 | |
| 92 | func GetMaskData(epoch uint64, encodeKey common.Hash, chunkSize int, maskBuffer []byte) []byte { |
| 93 | if len(maskBuffer) != chunkSize { |
| 94 | maskBuffer = make([]byte, chunkSize) |
| 95 | } |
| 96 | |
| 97 | cache := Cache(epoch) |
| 98 | size := pora.DatasetSizeForEpoch(epoch) |
| 99 | |
| 100 | realHash := make([]byte, len(encodeKey)+8) |
| 101 | copy(realHash, encodeKey[:]) |
| 102 | |
| 103 | for i := 0; i < (chunkSize+pora.GetMixBytes()-1)/pora.GetMixBytes(); i++ { |
| 104 | binary.BigEndian.PutUint64(realHash[len(encodeKey):], uint64(i)) |
| 105 | mask := pora.HashimotoForMaskLight(size, cache.Cache, realHash) |
| 106 | if len(mask) != pora.GetMixBytes() { |
| 107 | panic("#mask != MixBytes") |
| 108 | } |
| 109 | copy(maskBuffer[i*pora.GetMixBytes():], mask) |
| 110 | } |
| 111 | |
| 112 | return maskBuffer |
| 113 | } |