forked from SAFTehnika/Xamarin-NRF-DFU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRC32.cs
39 lines (37 loc) · 1.01 KB
/
CRC32.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2018 SAF Tehnika. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text;
namespace Plugin.XamarinNordicDFU
{
public class CRC32
{
public uint Value { get; private set; }
private const uint polinomial = 0xEDB88320U;
public CRC32()
{
this.Reset();
}
public void Update(byte[] p_data, uint size)
{
Value = ~(Value);
for (uint i = 0; i < size; i++)
{
Value = Value ^ p_data[i];
for (uint j = 8; j > 0; j--)
{
Value = (Value >> 1) ^ (polinomial & ((Value & 1) > 0 ? 0xFFFFFFFF : 0));
}
}
Value = ~Value;
}
public void Update(byte[] data)
{
this.Update(data, (uint)data.Length);
}
public void Reset()
{
Value = 0x0;
}
}
}