summary refs log tree commit diff
path: root/crypto/src/bcpg/Crc24.cs
blob: 5521bbb6453cec568543d28dac78b4871ebe26db (plain) (blame)
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
40
using System;

namespace Org.BouncyCastle.Bcpg
{
    public class Crc24
    {
        private const int Crc24Init = 0x0b704ce;
        private const int Crc24Poly = 0x1864cfb;

        private int crc = Crc24Init;

        public Crc24()
        {
        }

        public void Update(
            int b)
        {
            crc ^= b << 16;
            for (int i = 0; i < 8; i++)
            {
                crc <<= 1;
                if ((crc & 0x1000000) != 0)
                {
                    crc ^= Crc24Poly;
                }
            }
        }

		public int Value
		{
			get { return crc; }
		}

		public void Reset()
        {
            crc = Crc24Init;
        }
    }
}