Example #1
0
        internal LiteHmac(PAL_HashAlgorithm algorithm, ReadOnlySpan <byte> key, bool preinitialize)
        {
            int hashSizeInBytes = 0;

            _ctx = Interop.AppleCrypto.HmacCreate(algorithm, ref hashSizeInBytes);

            if (hashSizeInBytes < 0)
            {
                _ctx.Dispose();
                throw new PlatformNotSupportedException(
                          SR.Format(
                              SR.Cryptography_UnknownHashAlgorithm,
                              Enum.GetName(typeof(Interop.AppleCrypto.PAL_HashAlgorithm), algorithm)));
            }

            if (_ctx.IsInvalid)
            {
                _ctx.Dispose();
                throw new CryptographicException();
            }

            if (preinitialize)
            {
                if (Interop.AppleCrypto.HmacInit(_ctx, key) != Success)
                {
                    _ctx.Dispose();
                    throw new CryptographicException();
                }
            }

            _hashSizeInBytes = hashSizeInBytes;
        }
Example #2
0
 public override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _ctx?.Dispose();
         Array.Clear(_key, 0, _key.Length);
     }
 }
Example #3
0
            internal AppleHmacProvider(Interop.AppleCrypto.PAL_HashAlgorithm algorithm, byte[] key)
            {
                _key = key.CloneByteArray();
                int hashSizeInBytes = 0;

                _ctx = Interop.AppleCrypto.HmacCreate(algorithm, ref hashSizeInBytes);

                if (hashSizeInBytes < 0)
                {
                    _ctx.Dispose();
                    throw new PlatformNotSupportedException(
                              SR.Format(
                                  SR.Cryptography_UnknownHashAlgorithm,
                                  Enum.GetName(typeof(Interop.AppleCrypto.PAL_HashAlgorithm), algorithm)));
                }

                if (_ctx.IsInvalid)
                {
                    _ctx.Dispose();
                    throw new CryptographicException();
                }

                HashSizeInBytes = hashSizeInBytes;
            }
Example #4
0
 public void Dispose()
 {
     _ctx.Dispose();
 }