Пример #1
0
        internal ThreefishTransform(byte[] key, byte[] iv, int feedbackSize, ThreefishTransformMode transformMode,
                                    CipherMode cipherMode, PaddingMode paddingMode)
        {
            this.transformMode = transformMode;
            this.cipherMode    = cipherMode;
            this.paddingMode   = paddingMode;
            cipherBytes        = key.Length;
            cipherWords        = key.Length / 8;
            feedbackBytes      = feedbackSize / 8;
            // Allocate working blocks now so that we don't have to allocate them
            // each time Transform(Final)Block is called
            block       = new ulong[cipherWords];
            tempBlock   = new ulong[cipherWords];
            streamBytes = new byte[cipherBytes];
            depadBuffer = new byte[cipherBytes];
            this.iv     = new ulong[cipherWords];
            GetBytes(iv, 0, this.iv, cipherBytes);
            switch (OutputBlockSize)
            {
            case 256 / 8: cipher = new Threefish256(); break;

            case 512 / 8: cipher = new Threefish512(); break;

            case 1024 / 8: cipher = new Threefish1024(); break;

            default: throw new CryptographicException("Unsupported key/block size.");
            }
            bool e = transformMode == ThreefishTransformMode.Encrypt;

            switch (cipherMode)
            {
            case CipherMode.ECB:
                transformFunc = e ? EcbEncrypt : new TransformFunc(EcbDecrypt);
                break;

            case CipherMode.CBC:
                transformFunc = e ? CbcEncrypt : new TransformFunc(CbcDecrypt);
                break;

            case CipherMode.OFB:
                transformFunc = OfbApplyStream;
                break;

            case CipherMode.CFB:
                transformFunc = e ? CfbEncrypt : new TransformFunc(CfbDecrypt);
                break;

            default:
                throw new CryptographicException("Unsupported cipher mode.");
            }
            var keyWords = new ulong[cipherWords];

            GetBytes(key, 0, keyWords, cipherBytes);
            cipher.SetKey(keyWords);
            InitializeBlocks();
        }
Пример #2
0
 Transform(TransformFunc op, TransformFunc[] ops)
 {
     if (op != null)
     {
         actions.Add(op);
     }
     if (ops != null && ops.Length > 0)
     {
         actions.AddRange(ops);
     }
 }
Пример #3
0
 public static IShaderFilterSettings <T> Configure <T>(this T shader, bool?linearSampling = null,
                                                       ArgumentList arguments             = null, TransformFunc transform = null, int?sizeIndex = null,
                                                       TextureFormat?format = null, IEnumerable <bool> perTextureLinearSampling = null)
     where T : IShaderBase
 {
     return(new ShaderFilterSettings <T>(shader).Configure(linearSampling, arguments, transform, sizeIndex,
                                                           format, perTextureLinearSampling));
 }
Пример #4
0
        public ThreefishTransform(
            byte[] key, byte[] iv, ThreefishTransformType type, CipherMode mode, PaddingMode padding
            )
        {
            _cipherMode  = mode;
            _paddingMode = padding;

            _cipherBytes    = key.Length;
            _cipherWords    = key.Length / 8;
            OutputBlockSize = key.Length;// *8;

            // Allocate working blocks now so that we don't
            // have to allocate them each time
            // Transform(Final)Block is called
            _block       = new ulong[_cipherWords];
            _tempBlock   = new ulong[_cipherWords];
            _streamBytes = new byte[_cipherBytes];

            // Allocate IV and set value
            _iv = new ulong[_cipherWords];
            GetBytes(iv, 0, _iv, _cipherBytes);

            // Figure out which cipher we need based on
            // the cipher bit size
            switch (OutputBlockSize)
            {
            case 32:
                _cipher = new Threefish256();
                break;

            case 64:
                _cipher = new Threefish512();
                break;

            case 128:
                _cipher = new Threefish1024();
                break;

            default:
                throw new CryptographicException("Unsupported key/block size.");
            }

            bool e = (type == ThreefishTransformType.Encrypt);

            switch (_cipherMode)
            {
            case CipherMode.ECB:
                _transformFunc = e ? new TransformFunc(EcbEncrypt) : new TransformFunc(EcbDecrypt);
                break;

            case CipherMode.CBC:
                _transformFunc = e ? new TransformFunc(CbcEncrypt) : new TransformFunc(CbcDecrypt);
                break;

            case CipherMode.OFB:
                _transformFunc = new TransformFunc(OfbApplyStream);
                break;

            case CipherMode.CFB:
                _transformFunc = e ? new TransformFunc(CfbEncrypt) : new TransformFunc(CfbDecrypt);
                break;

            case CipherMode.CTS:
                throw new CryptographicException("CTS mode not supported.");
            }

            // Set the key
            var keyWords = new ulong[_cipherWords];

            GetBytes(key, 0, keyWords, _cipherBytes);
            _cipher.SetKey(keyWords);

            InitializeBlocks();
        }
Пример #5
0
        public ThreefishTransform(
            byte[] key, byte[] iv, ThreefishTransformType type, CipherMode mode, PaddingMode padding
        )
        {
            _cipherMode    = mode;
            _paddingMode   = padding;

            _cipherBytes = key.Length;
            _cipherWords = key.Length / 8;
            OutputBlockSize  = key.Length * 8;

            // Allocate working blocks now so that we don't
            // have to allocate them each time
            // Transform(Final)Block is called
            _block = new ulong[_cipherWords];
            _tempBlock = new ulong[_cipherWords];
            _streamBytes = new byte[_cipherBytes];

            // Allocate IV and set value
            _iv = new ulong[_cipherWords];
            GetBytes(iv, 0, _iv, _cipherBytes);

            // Figure out which cipher we need based on
            // the cipher bit size
            switch (OutputBlockSize)
            {
                case 256:
                    _cipher = new Threefish256();
                    break;
                case 512:
                    _cipher = new Threefish512();
                    break;
                case 1024:
                    _cipher = new Threefish1024();
                    break;

                default:
                    throw new CryptographicException("Unsupported key/block size.");
            }

            bool e = (type == ThreefishTransformType.Encrypt);

            switch(_cipherMode)
            {
                case CipherMode.ECB:
                    _transformFunc = e ? new TransformFunc(EcbEncrypt) : new TransformFunc(EcbDecrypt);
                    break;
                case CipherMode.CBC:
                    _transformFunc = e ? new TransformFunc(CbcEncrypt) : new TransformFunc(CbcDecrypt);
                    break;
                case CipherMode.OFB:
                    _transformFunc = new TransformFunc(OfbApplyStream);
                    break;
                case CipherMode.CFB:
                    _transformFunc = e ? new TransformFunc(CfbEncrypt) : new TransformFunc(CfbDecrypt);
                    break;
                case CipherMode.CTS:
                    throw new CryptographicException("CTS mode not supported.");
            }

            // Set the key
            var keyWords = new ulong[_cipherWords];
            GetBytes(key, 0, keyWords, _cipherBytes);
            _cipher.SetKey(keyWords);

            InitializeBlocks();
        }
Пример #6
0
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ Api.GetHashCode() ^ Type.GetHashCode() ^ Size.GetHashCode() ^ InitFunc.GetHashCode() ^ FreeFunc.GetHashCode() ^ TransformFunc.GetHashCode());
 }
Пример #7
0
 public bool Equals(MetaInfo other)
 {
     return(true && Api.Equals(other.Api) && Type.Equals(other.Type) && Size.Equals(other.Size) && InitFunc.Equals(other.InitFunc) && FreeFunc.Equals(other.FreeFunc) && TransformFunc.Equals(other.TransformFunc));
 }
Пример #8
0
        public ThreefishTransform(
            byte[] key, byte[] iv, ThreefishTransformType type, CipherMode mode, PaddingMode padding
            )
        {
            m_TransformType = type;
            m_CipherMode    = mode;
            m_PaddingMode   = padding;

            m_CipherBytes = key.Length;
            m_CipherWords = key.Length / 8;
            m_CipherBits  = key.Length * 8;

            // Allocate working blocks now so that we don't
            // have to allocate them each time
            // Transform(Final)Block is called
            m_Block = new ulong[m_CipherWords];
            m_TempBlock = new ulong[m_CipherWords];
            m_StreamBytes = new byte[m_CipherBytes];

            // Allocate IV and set value
            m_IV = new ulong[m_CipherWords];
            GetBytes(iv, 0, m_IV, m_CipherBytes);

            // Figure out which cipher we need based on
            // the cipher bit size
            switch (m_CipherBits)
            {
                case 256:
                    m_Cipher = new Threefish256();
                    break;
                case 512:
                    m_Cipher = new Threefish512();
                    break;
                case 1024:
                    m_Cipher = new Threefish1024();
                    break;

                default:
                    throw new CryptographicException("Unsupported key/block size.");
            }

            bool e = (type == ThreefishTransformType.Encrypt);

            switch(m_CipherMode)
            {
                case CipherMode.ECB:
                    m_TransformFunc = e ? new TransformFunc(ECB_Encrypt) : new TransformFunc(ECB_Decrypt);
                    break;
                case CipherMode.CBC:
                    m_TransformFunc = e ? new TransformFunc(CBC_Encrypt) : new TransformFunc(CBC_Decrypt);
                    break;
                case CipherMode.OFB:
                    m_TransformFunc = new TransformFunc(OFB_ApplyStream);
                    break;
                case CipherMode.CFB:
                    m_TransformFunc = e ? new TransformFunc(CFB_Encrypt) : new TransformFunc(CFB_Decrypt);
                    break;
                case CipherMode.CTS:
                    throw new CryptographicException("CTS mode not supported.");
            }

            // Set the key
            ulong[] key_words = new ulong[m_CipherWords];
            GetBytes(key, 0, key_words, m_CipherBytes);
            m_Cipher.SetKey(key_words);

            InitializeBlocks();
        }