Ejemplo n.º 1
0
        // From email with Scott Fluhrer:
        // To generate the SEED for a child LMS tree, we will adapt algorithm A by using the
        // I value of the parent LMS tree the q value to be the LMS index of the child, and the i value to be 65534.
        // Algorithm A:
        // x_q[i] = H(I || u32str(q) || u16str(i) || u8str(0xff) || SEED).
        // UPDATE: Generate child I from algorithm A using the I value of the parent LMS tree, the q value
        // to be the LMS index of the child, and the i value to be 65535; the I value will be the first 128 bits of the hash.
        public Hss(int layers, LmsType[] lmsTypes, LmotsType[] lmotsTypes,
                   EntropyProviderTypes entropyType = EntropyProviderTypes.Random, BitString seed = null, BitString rootI = null)
        {
            _entropyType     = entropyType;
            _entropyProvider = _entropyFactory.GetEntropyProvider(entropyType);
            _entropyProvider.AddEntropy(seed);
            SEED = _entropyProvider.GetEntropy(256);    // for now will only be 256 bits (m = 256)
            _entropyProvider.AddEntropy(rootI);
            RootI   = _entropyProvider.GetEntropy(128);
            _sha256 = new NativeFastSha2_256();

            _lms        = new Lms[layers];
            _lmsTypes   = lmsTypes;
            _lmotsTypes = lmotsTypes;
            _lms[0]     = new Lms(lmsTypes[0], lmotsTypes[0], entropyType, SEED, rootI);
            var parentSeed = SEED;
            var parentI    = RootI;

            for (int i = 1; i < layers; i++)
            {
                var childSeed = _sha256.HashMessage(parentI
                                                    .ConcatenateBits(new BitString(0, 32))
                                                    .ConcatenateBits(new BitString(65534, 16))
                                                    .ConcatenateBits(new BitString("ff", 8))
                                                    .ConcatenateBits(parentSeed)).Digest;
                var I = _sha256.HashMessage(parentI
                                            .ConcatenateBits(new BitString(0, 32))
                                            .ConcatenateBits(new BitString(65535, 16))
                                            .ConcatenateBits(new BitString("ff", 8))
                                            .ConcatenateBits(parentSeed)).Digest.MSBSubstring(0, 128);
                _lms[i]    = new Lms(lmsTypes[i], lmotsTypes[i], entropyType, childSeed, I);
                parentSeed = childSeed;
                parentI    = I;
            }
        }
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;
            }
        }
Ejemplo n.º 3
0
 public void AddEntropy(BigInteger entropy)
 {
     _entropyProvider.AddEntropy(entropy);
 }
Ejemplo n.º 4
0
 public void AddEntropy(BitString entropy)
 {
     _entropy.AddEntropy(entropy);
 }