Esempio n. 1
0
        public KeygenDerivedkeys GenerateKey(byte[] baseSeed)
        {
            byte[] preparedSeed     = new byte[DrbgCtx.NFC3D_DRBG_MAX_SEED_SIZE];
            var    preparedSeedSize = PrepareSeed(baseSeed, preparedSeed);

            return(DrbgCtx.GenerateBytes(this.hmacKey, preparedSeed, preparedSeedSize));
        }
Esempio n. 2
0
        public static KeygenDerivedkeys GenerateBytes(byte[] hmacKey, byte[] seed, int seedSize)
        {
            int offset     = 0;
            int outputSize = 16 * 3;

            byte[] temp   = new byte[NFC3D_DRBG_OUTPUT_SIZE];
            byte[] output = new byte[outputSize];

            DrbgCtx rngCtx = new DrbgCtx(hmacKey, seed, seedSize);

            while (outputSize > 0)
            {
                if (outputSize < NFC3D_DRBG_OUTPUT_SIZE)
                {
                    rngCtx.Step(temp, 0);
                    Array.Copy(temp, 0, output, offset, outputSize);
                    break;
                }

                rngCtx.Step(output, offset);
                offset     += NFC3D_DRBG_OUTPUT_SIZE;
                outputSize -= NFC3D_DRBG_OUTPUT_SIZE;
            }

            var outkeys = new KeygenDerivedkeys
            {
                aesKey  = new byte[16],
                aesIV   = new byte[16],
                hmacKey = new byte[16]
            };

            Array.Copy(output, 0, outkeys.aesKey, 0, outkeys.aesKey.Length);
            Array.Copy(output, 16, outkeys.aesIV, 0, outkeys.aesIV.Length);
            Array.Copy(output, 32, outkeys.hmacKey, 0, outkeys.hmacKey.Length);

            return(outkeys);
        }