    001    package org.bouncycastle.crypto;
    002
    003    public class BufferedBlockCipher
    004    {
    005        protected byte[] field_71801_a;
    006        protected int field_71799_b;
    007        protected boolean field_71800_c;
    008        protected BlockCipher field_71797_d;
    009        protected boolean field_71798_e;
    010        protected boolean field_71796_f;
    011
    012        protected BufferedBlockCipher() {}
    013
    014        public BufferedBlockCipher(BlockCipher par1BlockCipher)
    015        {
    016            this.field_71797_d = par1BlockCipher;
    017            this.field_71801_a = new byte[par1BlockCipher.getBlockSize()];
    018            this.field_71799_b = 0;
    019            String var2 = par1BlockCipher.getAlgorithmName();
    020            int var3 = var2.indexOf(47) + 1;
    021            this.field_71796_f = var3 > 0 && var2.startsWith("PGP", var3);
    022
    023            if (this.field_71796_f)
    024            {
    025                this.field_71798_e = true;
    026            }
    027            else
    028            {
    029                this.field_71798_e = var3 > 0 && (var2.startsWith("CFB", var3) || var2.startsWith("OFB", var3) || var2.startsWith("OpenPGP", var3) || var2.startsWith("SIC", var3) || var2.startsWith("GCTR", var3));
    030            }
    031        }
    032
    033        public void init(boolean par1, CipherParameters par2CipherParameters) throws IllegalArgumentException
    034        {
    035            this.field_71800_c = par1;
    036            this.func_71794_b();
    037            this.field_71797_d.func_71805_a(par1, par2CipherParameters);
    038        }
    039
    040        public int func_71792_a()
    041        {
    042            return this.field_71797_d.getBlockSize();
    043        }
    044
    045        public int func_71793_a(int par1)
    046        {
    047            int var2 = par1 + this.field_71799_b;
    048            int var3;
    049
    050            if (this.field_71796_f)
    051            {
    052                var3 = var2 % this.field_71801_a.length - (this.field_71797_d.getBlockSize() + 2);
    053            }
    054            else
    055            {
    056                var3 = var2 % this.field_71801_a.length;
    057            }
    058
    059            return var2 - var3;
    060        }
    061
    062        public int func_71789_b(int par1)
    063        {
    064            return par1 + this.field_71799_b;
    065        }
    066
    067        public int func_71791_a(byte[] par1ArrayOfByte, int par2, int par3, byte[] par4ArrayOfByte, int par5) throws DataLengthException, IllegalStateException
    068        {
    069            if (par3 < 0)
    070            {
    071                throw new IllegalArgumentException("Can\'t have a negative input length!");
    072            }
    073            else
    074            {
    075                int var6 = this.func_71792_a();
    076                int var7 = this.func_71793_a(par3);
    077
    078                if (var7 > 0 && par5 + var7 > par4ArrayOfByte.length)
    079                {
    080                    throw new DataLengthException("output buffer too short");
    081                }
    082                else
    083                {
    084                    int var8 = 0;
    085                    int var9 = this.field_71801_a.length - this.field_71799_b;
    086
    087                    if (par3 > var9)
    088                    {
    089                        System.arraycopy(par1ArrayOfByte, par2, this.field_71801_a, this.field_71799_b, var9);
    090                        var8 += this.field_71797_d.func_71806_a(this.field_71801_a, 0, par4ArrayOfByte, par5);
    091                        this.field_71799_b = 0;
    092                        par3 -= var9;
    093
    094                        for (par2 += var9; par3 > this.field_71801_a.length; par2 += var6)
    095                        {
    096                            var8 += this.field_71797_d.func_71806_a(par1ArrayOfByte, par2, par4ArrayOfByte, par5 + var8);
    097                            par3 -= var6;
    098                        }
    099                    }
    100
    101                    System.arraycopy(par1ArrayOfByte, par2, this.field_71801_a, this.field_71799_b, par3);
    102                    this.field_71799_b += par3;
    103
    104                    if (this.field_71799_b == this.field_71801_a.length)
    105                    {
    106                        var8 += this.field_71797_d.func_71806_a(this.field_71801_a, 0, par4ArrayOfByte, par5 + var8);
    107                        this.field_71799_b = 0;
    108                    }
    109
    110                    return var8;
    111                }
    112            }
    113        }
    114
    115        public int func_71790_a(byte[] par1ArrayOfByte, int par2) throws DataLengthException, IllegalStateException
    116        {
    117            int var4;
    118
    119            try
    120            {
    121                int var3 = 0;
    122
    123                if (par2 + this.field_71799_b > par1ArrayOfByte.length)
    124                {
    125                    throw new DataLengthException("output buffer too short for doFinal()");
    126                }
    127
    128                if (this.field_71799_b != 0)
    129                {
    130                    if (!this.field_71798_e)
    131                    {
    132                        throw new DataLengthException("data not block size aligned");
    133                    }
    134
    135                    this.field_71797_d.func_71806_a(this.field_71801_a, 0, this.field_71801_a, 0);
    136                    var3 = this.field_71799_b;
    137                    this.field_71799_b = 0;
    138                    System.arraycopy(this.field_71801_a, 0, par1ArrayOfByte, par2, var3);
    139                }
    140
    141                var4 = var3;
    142            }
    143            finally
    144            {
    145                this.func_71794_b();
    146            }
    147
    148            return var4;
    149        }
    150
    151        public void func_71794_b()
    152        {
    153            for (int var1 = 0; var1 < this.field_71801_a.length; ++var1)
    154            {
    155                this.field_71801_a[var1] = 0;
    156            }
    157
    158            this.field_71799_b = 0;
    159            this.field_71797_d.func_71803_c();
    160        }
    161    }