summary refs log tree commit diff
path: root/crypto/src/bcpg/Crc24.cs
blob: 97846f4fb574f6a5368298f7c16d57e9ce28d44d (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
41
42
43
44
45
46
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;
                }
            }
        }

		[Obsolete("Use 'Value' property instead")]
        public int GetValue()
        {
            return crc;
        }

		public int Value
		{
			get { return crc; }
		}

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