Ejemplo n.º 1
0
 public Lmots(LmotsType type, EntropyProviderTypes entropyType = EntropyProviderTypes.Random)
 {
     var(n, w, p, ls, siglen, typecode) = LmotsModeMapping.GetValsFromType(type);
     _n               = n;
     _w               = w;
     _p               = p;
     _ls              = ls;
     _siglen          = siglen;
     _typecode        = typecode;
     _entropyProvider = _entropyFactory.GetEntropyProvider(entropyType);
     _isRandom        = entropyType == EntropyProviderTypes.Random;
     _sha256          = new NativeFastSha2_256();
 }
Ejemplo n.º 2
0
        private const int H25_PIECE_SIZE = 32768;   // creates 1024 threads

        #endregion Fields

        #region Constructors

        // From an email from Scott Fluhrer:
        // To generate the I value for the LMS tree, we will adapt algorithm A,
        // by setting the I value input to be the all-zeros value, the q value
        // to be 0 and the i value to be 65535; we will use the first 16 bytes of the hash output.
        // Algorithm A:
        // x_q[i] = H(I || u32str(q) || u16str(i) || u8str(0xff) || SEED).
        // UPDATE: I value is now generated separate from SEED. Child I values still computed the same
        public Lms(LmsType lmsType, LmotsType lmotsType,
                   EntropyProviderTypes entropyType = EntropyProviderTypes.Random, BitString seed = null, BitString I = null)
        {
            var(m, h, typecode) = LmsModeMapping.GetValsFromType(lmsType);
            _m        = m;
            _h        = h;
            _typecode = typecode;
            var param = LmotsModeMapping.GetValsFromType(lmotsType);

            _lmotsTypecode   = param.typecode;
            _entropyProvider = _entropyFactory.GetEntropyProvider(entropyType);
            _entropyProvider.AddEntropy(seed);
            SEED = _entropyProvider.GetEntropy(_m * 8);
            _entropyProvider.AddEntropy(I);
            _I        = _entropyProvider.GetEntropy(128);
            _lmots    = new Lmots(lmotsType, entropyType);
            _isRandom = entropyType == EntropyProviderTypes.Random;
            _sha256   = new NativeFastSha2_256();

            // For optimization the balance between interop calls and asynchronization
            if (_h == 5)
            {
                _pieceSize = H5_PIECE_SIZE;
            }
            else if (_h == 10)
            {
                _pieceSize = H10_PIECE_SIZE;
            }
            else if (_h == 15)
            {
                _pieceSize = H15_PIECE_SIZE;
            }
            else if (_h == 20)
            {
                _pieceSize = H20_PIECE_SIZE;
            }
            else
            {
                _pieceSize = H25_PIECE_SIZE;
            }
        }