/// <summary> /// Internal private hashing method. /// /// This is the new hashing algorithm from other clients. /// Found to be fast and have very good distribution. /// /// UPDATE: this is dog slow under java. Maybe under .NET? /// </summary> /// <param name="key">string to hash</param> /// <returns>hashcode for this string using memcached's hashing algorithm</returns> private static int NewHashingAlgorithm(string key) { CRCTool checksum = new CRCTool(); checksum.Init(CRCTool.CRCCode.CRC32); int crc = (int)checksum.crctablefast(UTF8Encoding.UTF8.GetBytes(key)); return((crc >> 16) & 0x7fff); }
protected override Variant fixupImpl() { var elem = elements["ref"]; byte[] data = elem.Value.Value; CRCTool crcTool = new CRCTool(); crcTool.Init(type); return(new Variant((uint)crcTool.crctablefast(data))); }
protected override Variant fixupImpl() { var elem = elements["ref"]; var data = elem.Value; data.Seek(0, System.IO.SeekOrigin.Begin); CRCTool crcTool = new CRCTool(); crcTool.Init(type); return(new Variant((uint)crcTool.crctablefast(data))); }
protected override Variant fixupImpl() { var ref1 = elements["ref1"]; var ref2 = elements["ref2"]; byte[] data1 = ref1.Value.Value; byte[] data2 = ref2.Value.Value; byte[] data3 = new byte[data1.Length + data2.Length]; Buffer.BlockCopy(data1, 0, data3, 0, data1.Length); Buffer.BlockCopy(data2, 0, data3, data1.Length, data2.Length); CRCTool crcTool = new CRCTool(); crcTool.Init(type); return(new Variant((uint)crcTool.crctablefast(data3))); }
protected override Variant fixupImpl() { var ref1 = elements["ref1"]; var ref2 = elements["ref2"]; var data = new BitStreamList(); data.Add(ref1.Value); data.Add(ref2.Value); data.Seek(0, System.IO.SeekOrigin.Begin); CRCTool crcTool = new CRCTool(); crcTool.Init(type); return(new Variant((uint)crcTool.crctablefast(data))); }
public void TestFixupBefore() { // Verify that in a DOM with Fixups before Relations, the fixup runs // after the relation has. // In this case the data model is: // CRC, 4 byte number whose value is the CRC of the data model // Len, 4 byte number whose value is the size of the data model // Data, 5 byte string. // The CRC should include the computed size relation. string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Peach>" + " <DataModel name=\"TheDataModel\">" + " <Block>" + " <Number name=\"CRC\" size=\"32\" signed=\"false\">" + " <Fixup class=\"Crc32Fixup\">" + " <Param name=\"ref\" value=\"TheDataModel\"/>" + " </Fixup>" + " </Number>" + " </Block>" + " <Number name=\"len\" size=\"32\" signed=\"false\">" + " <Relation type=\"size\" of=\"TheDataModel\" />" + " </Number>" + " <Blob name=\"Data\" value=\"Hello\">" + " <Hint name=\"BlobMutator-How\" value=\"ExpandAllRandom\"/>" + " </Blob>" + " </DataModel>" + " <StateModel name=\"TheState\" initialState=\"Initial\">" + " <State name=\"Initial\">" + " <Action type=\"output\">" + " <DataModel ref=\"TheDataModel\"/>" + " </Action>" + " </State>" + " </StateModel>" + " <Test name=\"Default\">" + " <StateModel ref=\"TheState\"/>" + " <Publisher class=\"Null\"/>" + " <Strategy class=\"RandomDeterministic\"/>" + " </Test>" + "</Peach>"; PitParser parser = new PitParser(); Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml))); dom.tests[0].includedMutators = new List <string>(); dom.tests[0].includedMutators.Add("BlobMutator"); RunConfiguration config = new RunConfiguration(); Engine e = new Engine(null); e.startFuzzing(dom, config); Assert.AreEqual(2, dataModels.Count); byte[] dm1 = dataModels[0].Value.ToArray(); byte[] dm2 = dataModels[1].Value.ToArray(); Assert.AreEqual(4 + 4 + 5, dm1.Length); Assert.Greater(dm2.Length, dm1.Length); var data = Bits.Fmt("{0:L32}{1:L32}{2}", 0, 13, "Hello"); var crc = new CRCTool(); crc.Init(CRCTool.CRCCode.CRC32); data.Seek(0, SeekOrigin.Begin); data.WriteBits(Endian.Little.GetBits((uint)crc.crctablefast(data.ToArray()), 32), 32); byte[] final = data.ToArray(); Assert.AreEqual(final, dm1); }
/// <summary> /// Internal private hashing method. /// /// This is the new hashing algorithm from other clients. /// Found to be fast and have very good distribution. /// /// UPDATE: this is dog slow under java. Maybe under .NET? /// </summary> /// <param name="key">string to hash</param> /// <returns>hashcode for this string using memcached's hashing algorithm</returns> private static int NewHashingAlgorithm(string key) { CRCTool checksum = new CRCTool(); checksum.Init(CRCTool.CRCCode.CRC32); int crc = (int)checksum.crctablefast(UTF8Encoding.UTF8.GetBytes(key)); return (crc >> 16) & 0x7fff; }