Beispiel #1
0
        public void Reset()
        {
            SecurityAssert.SAssert(state != HMACState.Uninitialised);

            var iPadKey = XorKey(key, 0x36);

            digest.Reset();
            digest.Update(iPadKey, 0, iPadKey.Length);

            state = HMACState.InnerHashing;
        }
Beispiel #2
0
        public void Reset()
        {
            SecurityAssert.Assert(_state != HMACState.Uninitialised);

            var iPadKey = XorKey(_key, 0x36);

            _digest.Reset();
            _digest.Update(iPadKey);

            _state = HMACState.InnerHashing;
        }
Beispiel #3
0
        public HMAC(IDigest digest, byte[] key)
        {
            SecurityAssert.NotNull(digest);
            SecurityAssert.NotNull(key);

            _digest = digest;
            _key    = new byte[digest.BlockSize / 8];

            _state = HMACState.Uninitialised;
            ProcessInputKey(key);
            _state = HMACState.ProcessedKey;

            Reset();
        }
Beispiel #4
0
        public HMAC(IDigest digest, byte[] key)
        {
            SecurityAssert.NotNull(digest);
            SecurityAssert.NotNull(key);

            this.digest = digest;
            this.key = new byte[digest.BlockSize / 8];

            ProcessInputKey(key);

            state = HMACState.ProcessedKey;

            Reset();
        }
Beispiel #5
0
        public byte[] Digest()
        {
            SecurityAssert.SAssert(state == HMACState.InnerHashing);

            state = HMACState.HashingDone;

            var innerHash = digest.Digest();

            var oPadKey = XorKey(key, 0x5c);
            digest.Reset();
            digest.Update(oPadKey, 0, oPadKey.Length);
            digest.Update(innerHash, 0, innerHash.Length);

            return digest.Digest();
        }
Beispiel #6
0
        public void Digest(Span <byte> output)
        {
            SecurityAssert.Assert(_state == HMACState.InnerHashing);

            _state = HMACState.HashingDone;

            var innerHash = _digest.DigestBuffer();

            var oPadKey = XorKey(_key, 0x5c);

            _digest.Reset();
            _digest.Update(oPadKey);
            _digest.Update(innerHash);

            _digest.Digest(output);
        }
Beispiel #7
0
        private void ProcessInputKey(byte[] bytes)
        {
            var blockLength = _digest.BlockSize / 8;

            if (bytes.Length > blockLength)
            {
                _state = HMACState.Uninitialised;

                _digest.Reset();
                _digest.Update(bytes);
                _digest.Digest(_key.AsSpan());
            }
            else
            {
                Array.Copy(bytes, _key, bytes.Length);
            }
        }
Beispiel #8
0
        private void ProcessInputKey(byte[] bytes)
        {
            var blockLength = digest.BlockSize / 8;

            if (bytes.Length > blockLength)
            {
                state = HMACState.Uninitialised;

                digest.Reset();
                digest.Update(bytes, 0, bytes.Length);
                var keyHash = digest.Digest();

                Array.Copy(keyHash, key, keyHash.Length);
            }
            else
            {
                Array.Copy(bytes, key, bytes.Length);
            }

        }