diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 18:37:51 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 18:37:51 +0700 |
commit | 36c7a0d9a777f0fccffec90aa53a5ba7c648b7de (patch) | |
tree | e9c78f598cf7c29ae29d6c89ba4554634ae89552 /crypto/src/bcpg/Crc24.cs | |
parent | Simplify WithPrecision methods (diff) | |
download | BouncyCastle.NET-ed25519-36c7a0d9a777f0fccffec90aa53a5ba7c648b7de.tar.xz |
Crc24 perf. opts.
Diffstat (limited to 'crypto/src/bcpg/Crc24.cs')
-rw-r--r-- | crypto/src/bcpg/Crc24.cs | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/crypto/src/bcpg/Crc24.cs b/crypto/src/bcpg/Crc24.cs index 5521bbb64..54c9f2f5a 100644 --- a/crypto/src/bcpg/Crc24.cs +++ b/crypto/src/bcpg/Crc24.cs @@ -2,39 +2,34 @@ using System; namespace Org.BouncyCastle.Bcpg { - public class Crc24 + public sealed class Crc24 { private const int Crc24Init = 0x0b704ce; private const int Crc24Poly = 0x1864cfb; - private int crc = Crc24Init; + private int m_crc = Crc24Init; public Crc24() { } - public void Update( - int b) + public void Update(byte b) { - crc ^= b << 16; + m_crc ^= (int)b << 16; for (int i = 0; i < 8; i++) { - crc <<= 1; - if ((crc & 0x1000000) != 0) - { - crc ^= Crc24Poly; - } + int carry = -((m_crc >> 23) & 1) & Crc24Poly; + + m_crc <<= 1; + m_crc ^= carry; } } - public int Value - { - get { return crc; } - } + public int Value => m_crc; public void Reset() { - crc = Crc24Init; + m_crc = Crc24Init; } } } |