123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
- {
- public class KdfCounterParameters : IDerivationParameters
- {
- private byte[] ki;
- private byte[] fixedInputDataCounterPrefix;
- private byte[] fixedInputDataCounterSuffix;
- private int r;
- /// <summary>
- /// Base constructor - suffix fixed input data only.
- /// </summary>
- /// <param name="ki">the KDF seed</param>
- /// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param>
- /// <param name="r">length of the counter in bits</param>
- public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterSuffix, int r) : this(ki, null, fixedInputDataCounterSuffix, r)
- {
- }
- /// <summary>
- /// Base constructor - prefix and suffix fixed input data.
- /// </summary>
- /// <param name="ki">the KDF seed</param>
- /// <param name="fixedInputDataCounterPrefix">fixed input data to precede counter</param>
- /// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param>
- /// <param name="r">length of the counter in bits.</param>
- public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterPrefix, byte[] fixedInputDataCounterSuffix, int r)
- {
- if (ki == null)
- {
- throw new ArgumentException("A KDF requires Ki (a seed) as input");
- }
- this.ki = Arrays.Clone(ki);
- if (fixedInputDataCounterPrefix == null)
- {
- this.fixedInputDataCounterPrefix = new byte[0];
- }
- else
- {
- this.fixedInputDataCounterPrefix = Arrays.Clone(fixedInputDataCounterPrefix);
- }
- if (fixedInputDataCounterSuffix == null)
- {
- this.fixedInputDataCounterSuffix = new byte[0];
- }
- else
- {
- this.fixedInputDataCounterSuffix = Arrays.Clone(fixedInputDataCounterSuffix);
- }
- if (r != 8 && r != 16 && r != 24 && r != 32)
- {
- throw new ArgumentException("Length of counter should be 8, 16, 24 or 32");
- }
- this.r = r;
- }
- public byte[] Ki
- {
- get { return ki; }
- }
- public byte[] FixedInputData
- {
- get { return Arrays.Clone(fixedInputDataCounterSuffix); }
- }
- public byte[] FixedInputDataCounterPrefix
- {
- get { return Arrays.Clone(fixedInputDataCounterPrefix); }
- }
- public byte[] FixedInputDataCounterSuffix
- {
- get { return Arrays.Clone(fixedInputDataCounterSuffix); }
- }
- public int R
- {
- get { return r; }
- }
- }
- }
- #pragma warning restore
- #endif
|