BcTlsHmac.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
  7. {
  8. internal sealed class BcTlsHmac
  9. : TlsHmac
  10. {
  11. private readonly HMac m_hmac;
  12. internal BcTlsHmac(HMac hmac)
  13. {
  14. this.m_hmac = hmac;
  15. }
  16. public void SetKey(byte[] key, int keyOff, int keyLen)
  17. {
  18. m_hmac.Init(new KeyParameter(key, keyOff, keyLen));
  19. }
  20. public void Update(byte[] input, int inOff, int length)
  21. {
  22. m_hmac.BlockUpdate(input, inOff, length);
  23. }
  24. public byte[] CalculateMac()
  25. {
  26. byte[] rv = new byte[m_hmac.GetMacSize()];
  27. m_hmac.DoFinal(rv, 0);
  28. return rv;
  29. }
  30. public void CalculateMac(byte[] output, int outOff)
  31. {
  32. m_hmac.DoFinal(output, outOff);
  33. }
  34. public int InternalBlockSize
  35. {
  36. get { return m_hmac.GetUnderlyingDigest().GetByteLength(); }
  37. }
  38. public int MacLength
  39. {
  40. get { return m_hmac.GetMacSize(); }
  41. }
  42. public void Reset()
  43. {
  44. m_hmac.Reset();
  45. }
  46. }
  47. }
  48. #pragma warning restore
  49. #endif