summary refs log tree commit diff
path: root/crypto/src/bcpg/Crc24.cs
blob: 54c9f2f5a00d7683692c4691be7160e9abf624c3 (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
using System;

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

        private int m_crc = Crc24Init;

        public Crc24()
        {
        }

        public void Update(byte b)
        {
            m_crc ^= (int)b << 16;
            for (int i = 0; i < 8; i++)
            {
                int carry = -((m_crc >> 23) & 1) & Crc24Poly;

                m_crc <<= 1;
                m_crc ^= carry;
            }
        }

        public int Value => m_crc;

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