public IFfxModeBlockCipher Get(AlgoMode algoMode)
        {
            switch (algoMode)
            {
            case AlgoMode.AES_FF1_v1_0:
                return(new Ff1BlockCipher(_engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes), _modeFactory, _aesFfInternals));

            case AlgoMode.AES_FF3_1_v1_0:
                return(new Ff3_1BlockCipher(_engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes), _modeFactory, _aesFfInternals));

            default:
                throw new ArgumentException($"Invalid {nameof(algoMode)} of {algoMode} passed into factory.");
            }
        }
Exemplo n.º 2
0
        public MonteCarloTdesCfbp(IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory modeFactory, IMonteCarloKeyMakerTdes keyMaker, BlockCipherModesOfOperation mode)
        {
            _algo = modeFactory.GetStandardCipher(
                engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Tdes),
                mode
                );
            _keyMaker = keyMaker;
            switch (mode)
            {
            case BlockCipherModesOfOperation.CfbpBit:
                Shift = 1;
                break;

            case BlockCipherModesOfOperation.CfbpByte:
                Shift = 8;
                break;

            case BlockCipherModesOfOperation.CfbpBlock:
                Shift = 64;
                break;

            default:
                throw new ArgumentException(nameof(mode));
            }
        }
Exemplo n.º 3
0
 public MonteCarloTdesCbci(IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory modeFactory, IMonteCarloKeyMakerTdes keyMaker)
 {
     _algo = modeFactory.GetStandardCipher(
         engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Tdes),
         BlockCipherModesOfOperation.Ecb
         );
     _keyMaker = keyMaker;
 }
Exemplo n.º 4
0
 public MonteCarloAesCbcCts(IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory modeFactory, IMonteCarloKeyMakerAes keyMaker, BlockCipherModesOfOperation mode)
 {
     _algo = modeFactory.GetStandardCipher(
         engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes),
         mode
         );
     _keyMaker = keyMaker;
 }
Exemplo n.º 5
0
 public MonteCarloTdesCfb(
     IBlockCipherEngineFactory engineFactory,
     IModeBlockCipherFactory modeFactory,
     IMonteCarloKeyMakerTdes keyMaker,
     int shiftSize,
     BlockCipherModesOfOperation mode
     )
 {
     _algo = modeFactory.GetStandardCipher(
         engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Tdes),
         mode
         );
     _keyMaker = keyMaker;
     Shift     = shiftSize;
 }
Exemplo n.º 6
0
        public BitString Prf(BitString x, BitString key)
        {
            // This method runs cbc mac on the full block string against the key
            var engine = _engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes);
            var mode   = _modeFactory.GetStandardCipher(engine, BlockCipherModesOfOperation.CbcMac);

            var param = new ModeBlockCipherParameters(
                BlockCipherDirections.Encrypt,
                new BitString(engine.BlockSizeBits),
                key,
                x
                );

            return(mode.ProcessPayload(param).Result);
        }
Exemplo n.º 7
0
        public MonteCarloAesCfb(
            IBlockCipherEngineFactory engineFactory,
            IModeBlockCipherFactory modeFactory,
            IMonteCarloKeyMakerAes keyMaker,
            int shiftSize,
            BlockCipherModesOfOperation mode
            )
        {
            var engine = engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes);

            _algo = modeFactory.GetStandardCipher(
                engine,
                mode
                );
            _keyMaker      = keyMaker;
            _blockSizeBits = engine.BlockSizeBits;
            Shift          = shiftSize;
        }
Exemplo n.º 8
0
 public CmacTdes(IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory modeFactory)
 {
     Engine   = engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Tdes);
     AlgoMode = modeFactory.GetStandardCipher(Engine, BlockCipherModesOfOperation.Ecb);
 }
Exemplo n.º 9
0
 public DrbgCounterAes(IEntropyProvider entropyProvider, IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory cipherFactory, DrbgParameters drbgParameters)
     : base(entropyProvider, drbgParameters)
 {
     Cipher = cipherFactory.GetStandardCipher(
         engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes), BlockCipherModesOfOperation.Ecb);
 }
Exemplo n.º 10
0
 protected KeyWrapBaseAes(IBlockCipherEngineFactory engineFactory, IModeBlockCipherFactory cipherFactory)
 {
     Cipher = cipherFactory.GetStandardCipher(engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes), BlockCipherModesOfOperation.Ecb);
 }
Exemplo n.º 11
0
        public virtual BitString GCTR(BitString icb, BitString x, BitString key)
        {
            // ICB must be 128 bits long
            // ThisLogger.Debug("GCTR");
            if (icb.BitLength != 128)
            {
                ThisLogger.Warn($"icbLen:{icb.BitLength}");
                return(null);
            }

            // Step 1: If X is the empty string, then return the empty string as Y
            if (x.BitLength == 0)
            {
                return(new BitString(0));
            }

            var ecb = _modeFactory.GetStandardCipher(
                _engineFactory.GetSymmetricCipherPrimitive(BlockCipherEngines.Aes),
                BlockCipherModesOfOperation.Ecb
                );

            // Step 2: Let n = ceil[ len(X)/128 ]
            int n = x.BitLength.CeilingDivide(128);

            // Step 3: Let X1,X2,...,Xn-1,Xn denote the unique sequence of bit
            // strings such that X = X1 || X2 || ... || Xn-1 || Xn*
            // X1, X2,...,Xn-1 are complete blocks
            // Xn* is either a complete block or a partial block

            // Step 4: Let CB1 = ICB
            // Step 5: For i = 2 to n, let CBi = inc32(CBi-1)
            // Step 6: For i = 1 to n-1, let Yi = Xi xor CIPH_K(CBi)

            BitString cbi = icb;
            BitString Y   = new BitString(0);
            int       sx  = x.BitLength - 128;

            for (int i = 1; i <= (n - 1); ++i, sx -= 128)
            {
                if (i > 1)
                {
                    cbi = inc_s(32, cbi);
                }
                BitString xi       = x.Substring(sx, 128);
                var       cbiParam = new ModeBlockCipherParameters(
                    BlockCipherDirections.Encrypt,
                    key,
                    cbi
                    );
                var       h  = ecb.ProcessPayload(cbiParam);
                BitString yi = BitString.XOR(xi, h.Result);
                Y = Y.ConcatenateBits(yi);    // This is part of Step 8
            }

            // Step 7: Let Yn* = Xn* xor MSB_len(Xn*) (CIPH_K(CBn))
            // i == n case:
            if (n > 1)
            {
                cbi = inc_s(32, cbi);
            }

            var xn        = x.Substring(0, 128 + sx);
            var cbiParam1 = new ModeBlockCipherParameters(
                BlockCipherDirections.Encrypt,
                key,
                cbi
                );
            var h1 = ecb.ProcessPayload(cbiParam1);

            var yn = xn.XOR(h1.Result.GetMostSignificantBits(xn.BitLength));

            Y = Y.ConcatenateBits(yn); // This is part of Step 8

            // Step 8: Let Y = Y1 || ... || Yn*

            // Step 9: Return Y
            return(Y);
        }