⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cast5engine.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        0xb87242d1, 0x19de7eae, 0x53e561a, 0x15ad6f8c, 0x66626c1c, 0x7154c24c, 0xea082b2a, 0x93eb2939, 0x17dcb0f0, 0x58d4f2ae, 
        0x9ea294fb, 0x52cf564c, 0x9883fe66, 0x2ec40581, 0x763953c3, 0x1d6692e, 0xd3a0c108, 0xa1e7160e, 0xe4f2dfa6, 0x693ed285, 
        0x74904698, 0x4c2b0edd, 0x4f757656, 0x5d393378, 0xa132234f, 0x3d321c5d, 0xc3f5e194, 0x4b269301, 0xc79f022f, 0x3c997e7e, 
        0x5e4f9504, 0x3ffafbbd, 0x76f7ad0e, 0x296693f4, 0x3d1fce6f, 0xc61e45be, 0xd3b5ab34, 0xf72bf9b7, 0x1b0434c0, 0x4e72b567, 
        0x5592a33d, 0xb5229301, 0xcfd2a87f, 0x60aeb767, 0x1814386b, 0x30bcc33d, 0x38a0c07d, 0xfd1606f2, 0xc363519b, 0x589dd390, 
        0x5479f8e6, 0x1cb8d647, 0x97fd61a9, 0xea7759f4, 0x2d57539d, 0x569a58cf, 0xe84e63ad, 0x462e1b78, 0x6580f87e, 0xf3817914, 
        0x91da55f4, 0x40a230f3, 0xd1988f35, 0xb6e318d2, 0x3ffa50bc, 0x3d40f021, 0xc3c0bdae, 0x4958c24c, 0x518f36b2, 0x84b1d370, 
        0xfedce83, 0x878ddada, 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3
    };
    protected static final int S8[] = {
        0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095, 0x7789f8b7, 0xe6c1121b, 0xe241600, 0x52ce8b5, 0x11a9cfb0, 0xe5952f11, 
        0xece7990a, 0x9386d174, 0x2a42931c, 0x76e38111, 0xb12def3a, 0x37ddddfc, 0xde9adeb1, 0xa0cc32c, 0xbe197029, 0x84a00940, 
        0xbb243a0f, 0xb4d137cf, 0xb44e79f0, 0x49eedfd, 0xb15a15d, 0x480d3168, 0x8bbbde5a, 0x669ded42, 0xc7ece831, 0x3f8f95e7, 
        0x72df191b, 0x7580330d, 0x94074251, 0x5c7dcdfa, 0xabbe6d63, 0xaa402164, 0xb301d40a, 0x2e7d1ca, 0x53571dae, 0x7a3182a2, 
        0x12a8ddec, 0xfdaa335d, 0x176f43e8, 0x71fb46d4, 0x38129022, 0xce949ad4, 0xb84769ad, 0x965bd862, 0x82f3d055, 0x66fb9767, 
        0x15b80b4e, 0x1d5b47a0, 0x4cfde06f, 0xc28ec4b8, 0x57e8726e, 0x647a78fc, 0x99865d44, 0x608bd593, 0x6c200e03, 0x39dc5ff6, 
        0x5d0b00a3, 0xae63aff2, 0x7e8bd632, 0x70108c0c, 0xbbd35049, 0x2998df04, 0x980cf42a, 0x9b6df491, 0x9e7edd53, 0x6918548, 
        0x58cb7e07, 0x3b74ef2e, 0x522fffb1, 0xd24708cc, 0x1c7e27cd, 0xa4eb215b, 0x3cf1d2e2, 0x19b47a38, 0x424f7618, 0x35856039, 
        0x9d17dee7, 0x27eb35e6, 0xc9aff67b, 0x36baf5b8, 0x9c467cd, 0xc18910b1, 0xe11dbf7b, 0x6cd1af8, 0x7170c608, 0x2d5e3354, 
        0xd4de495a, 0x64c6d006, 0xbcc0c62c, 0x3dd00db3, 0x708f8f34, 0x77d51b42, 0x264f620f, 0x24b8d2bf, 0x15c1b79e, 0x46a52564, 
        0xf8d7e54e, 0x3e378160, 0x7895cda5, 0x859c15a5, 0xe6459788, 0xc37bc75f, 0xdb07ba0c, 0x676a3ab, 0x7f229b1e, 0x31842e7b, 
        0x24259fd7, 0xf8bef472, 0x835ffcb8, 0x6df4c1f2, 0x96f5b195, 0xfd0af0fc, 0xb0fe134c, 0xe2506d3d, 0x4f9b12ea, 0xf215f225, 
        0xa223736f, 0x9fb4c428, 0x25d04979, 0x34c713f8, 0xc4618187, 0xea7a6e98, 0x7cd16efc, 0x1436876c, 0xf1544107, 0xbedeee14, 
        0x56e9af27, 0xa04aa441, 0x3cf7c899, 0x92ecbae6, 0xdd67016d, 0x151682eb, 0xa842eedf, 0xfdba60b4, 0xf1907b75, 0x20e3030f, 
        0x24d8c29e, 0xe139673b, 0xefa63fb8, 0x71873054, 0xb6f2cf3b, 0x9f326442, 0xcb15a4cc, 0xb01a4504, 0xf1e47d8d, 0x844a1be5, 
        0xbae7dfdc, 0x42cbda70, 0xcd7dae0a, 0x57e85b7a, 0xd53f5af6, 0x20cf4d8c, 0xcea4d428, 0x79d130a4, 0x3486ebfb, 0x33d3cddc, 
        0x77853b53, 0x37effcb5, 0xc5068778, 0xe580b3e6, 0x4e68b8f4, 0xc5c8b37e, 0xd809ea2, 0x398feb7c, 0x132a4f94, 0x43b7950e, 
        0x2fee7d1c, 0x223613bd, 0xdd06caa2, 0x37df932b, 0xc4248289, 0xacf3ebc3, 0x5715f6b7, 0xef3478dd, 0xf267616f, 0xc148cbe4, 
        0x9052815e, 0x5e410fab, 0xb48a2465, 0x2eda7fa4, 0xe87b40e4, 0xe98ea084, 0x5889e9e1, 0xefd390fc, 0xdd07d35b, 0xdb485694, 
        0x38d7e5b2, 0x57720101, 0x730edebc, 0x5b643113, 0x94917e4f, 0x503c2fba, 0x646f1282, 0x7523d24a, 0xe0779695, 0xf9c17a8f, 
        0x7a5b2121, 0xd187b896, 0x29263a4d, 0xba510cdf, 0x81f47c9f, 0xad1163ed, 0xea7b5965, 0x1a00726e, 0x11403092, 0xda6d77, 
        0x4a0cdd61, 0xad1f4603, 0x605bdfb0, 0x9eedc364, 0x22ebe6a8, 0xcee7d28a, 0xa0e736a0, 0x5564a6b9, 0x10853209, 0xc7eb8f37, 
        0x2de705ca, 0x8951570f, 0xdf09822b, 0xbd691a6c, 0xaa12e4f2, 0x87451c0f, 0xe0f6a27a, 0x3ada4819, 0x4cf1764f, 0xd771c2b, 
        0x67cdb156, 0x350d8384, 0x5938fa0f, 0x42399ef3, 0x36997b07, 0xe84093d, 0x4aa93e61, 0x8360d87b, 0x1fa98b0c, 0x1149382c, 
        0xe97625a5, 0x614d1b7, 0xe25244b, 0xc768347, 0x589e8d82, 0xd2059d1, 0xa466bb1e, 0xf8da0a82, 0x4f19130, 0xba6e4ec0, 
        0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e
    };
    protected static final int MAX_ROUNDS = 16;
    protected static final int RED_ROUNDS = 12;
    protected static final int BLOCK_SIZE = 8;
    protected int _Kr[];
    protected int _Km[];
    private boolean _encrypting;
    private byte _workingKey[];
    private int _rounds;

    public CAST5Engine()
    {
        _Kr = new int[17];
        _Km = new int[17];
        _encrypting = false;
        _workingKey = null;
        _rounds = 16;
    }

    public void init(boolean encrypting, CipherParameters params)
    {
        if(params instanceof KeyParameter)
        {
            _encrypting = encrypting;
            _workingKey = ((KeyParameter)params).getKey();
            setKey(_workingKey);
            return;
        } else
        {
            throw new IllegalArgumentException(String.valueOf(String.valueOf((new StringBuffer("Invalid parameter passed to ")).append(getAlgorithmName()).append(" init - ").append(params.getClass().getName()))));
        }
    }

    public String getAlgorithmName()
    {
        return "CAST5";
    }

    public int processBlock(byte in[], int inOff, byte out[], int outOff)
    {
        if(_workingKey == null)
            throw new IllegalStateException(String.valueOf(String.valueOf(getAlgorithmName())).concat(" not initialised"));
        if(inOff + 8 > in.length)
            throw new DataLengthException("Input buffer too short");
        if(outOff + 8 > out.length)
            throw new DataLengthException("Output buffer too short");
        if(_encrypting)
            return encryptBlock(in, inOff, out, outOff);
        else
            return decryptBlock(in, inOff, out, outOff);
    }

    public void reset()
    {
    }

    public int getBlockSize()
    {
        return 8;
    }

    protected void setKey(byte key[])
    {
        if(key.length < 11)
            _rounds = 12;
        int z[] = new int[16];
        int x[] = new int[16];
        for(int i = 0; i < key.length; i++)
            x[i] = key[i] & 0xff;

        int x03 = IntsTo32bits(x, 0);
        int x47 = IntsTo32bits(x, 4);
        int x8B = IntsTo32bits(x, 8);
        int xCF = IntsTo32bits(x, 12);
        int z03 = x03 ^ S5[x[13]] ^ S6[x[15]] ^ S7[x[12]] ^ S8[x[14]] ^ S7[x[8]];
        Bits32ToInts(z03, z, 0);
        int z47 = x8B ^ S5[z[0]] ^ S6[z[2]] ^ S7[z[1]] ^ S8[z[3]] ^ S8[x[10]];
        Bits32ToInts(z47, z, 4);
        int z8B = xCF ^ S5[z[7]] ^ S6[z[6]] ^ S7[z[5]] ^ S8[z[4]] ^ S5[x[9]];
        Bits32ToInts(z8B, z, 8);
        int zCF = x47 ^ S5[z[10]] ^ S6[z[9]] ^ S7[z[11]] ^ S8[z[8]] ^ S6[x[11]];
        Bits32ToInts(zCF, z, 12);
        _Km[1] = S5[z[8]] ^ S6[z[9]] ^ S7[z[7]] ^ S8[z[6]] ^ S5[z[2]];
        _Km[2] = S5[z[10]] ^ S6[z[11]] ^ S7[z[5]] ^ S8[z[4]] ^ S6[z[6]];
        _Km[3] = S5[z[12]] ^ S6[z[13]] ^ S7[z[3]] ^ S8[z[2]] ^ S7[z[9]];
        _Km[4] = S5[z[14]] ^ S6[z[15]] ^ S7[z[1]] ^ S8[z[0]] ^ S8[z[12]];
        z03 = IntsTo32bits(z, 0);
        z47 = IntsTo32bits(z, 4);
        z8B = IntsTo32bits(z, 8);
        zCF = IntsTo32bits(z, 12);
        x03 = z8B ^ S5[z[5]] ^ S6[z[7]] ^ S7[z[4]] ^ S8[z[6]] ^ S7[z[0]];
        Bits32ToInts(x03, x, 0);
        x47 = z03 ^ S5[x[0]] ^ S6[x[2]] ^ S7[x[1]] ^ S8[x[3]] ^ S8[z[2]];
        Bits32ToInts(x47, x, 4);
        x8B = z47 ^ S5[x[7]] ^ S6[x[6]] ^ S7[x[5]] ^ S8[x[4]] ^ S5[z[1]];
        Bits32ToInts(x8B, x, 8);
        xCF = zCF ^ S5[x[10]] ^ S6[x[9]] ^ S7[x[11]] ^ S8[x[8]] ^ S6[z[3]];
        Bits32ToInts(xCF, x, 12);
        _Km[5] = S5[x[3]] ^ S6[x[2]] ^ S7[x[12]] ^ S8[x[13]] ^ S5[x[8]];
        _Km[6] = S5[x[1]] ^ S6[x[0]] ^ S7[x[14]] ^ S8[x[15]] ^ S6[x[13]];
        _Km[7] = S5[x[7]] ^ S6[x[6]] ^ S7[x[8]] ^ S8[x[9]] ^ S7[x[3]];
        _Km[8] = S5[x[5]] ^ S6[x[4]] ^ S7[x[10]] ^ S8[x[11]] ^ S8[x[7]];
        x03 = IntsTo32bits(x, 0);
        x47 = IntsTo32bits(x, 4);
        x8B = IntsTo32bits(x, 8);
        xCF = IntsTo32bits(x, 12);
        z03 = x03 ^ S5[x[13]] ^ S6[x[15]] ^ S7[x[12]] ^ S8[x[14]] ^ S7[x[8]];
        Bits32ToInts(z03, z, 0);
        z47 = x8B ^ S5[z[0]] ^ S6[z[2]] ^ S7[z[1]] ^ S8[z[3]] ^ S8[x[10]];
        Bits32ToInts(z47, z, 4);
        z8B = xCF ^ S5[z[7]] ^ S6[z[6]] ^ S7[z[5]] ^ S8[z[4]] ^ S5[x[9]];
        Bits32ToInts(z8B, z, 8);
        zCF = x47 ^ S5[z[10]] ^ S6[z[9]] ^ S7[z[11]] ^ S8[z[8]] ^ S6[x[11]];
        Bits32ToInts(zCF, z, 12);
        _Km[9] = S5[z[3]] ^ S6[z[2]] ^ S7[z[12]] ^ S8[z[13]] ^ S5[z[9]];
        _Km[10] = S5[z[1]] ^ S6[z[0]] ^ S7[z[14]] ^ S8[z[15]] ^ S6[z[12]];
        _Km[11] = S5[z[7]] ^ S6[z[6]] ^ S7[z[8]] ^ S8[z[9]] ^ S7[z[2]];
        _Km[12] = S5[z[5]] ^ S6[z[4]] ^ S7[z[10]] ^ S8[z[11]] ^ S8[z[6]];
        z03 = IntsTo32bits(z, 0);
        z47 = IntsTo32bits(z, 4);
        z8B = IntsTo32bits(z, 8);
        zCF = IntsTo32bits(z, 12);
        x03 = z8B ^ S5[z[5]] ^ S6[z[7]] ^ S7[z[4]] ^ S8[z[6]] ^ S7[z[0]];
        Bits32ToInts(x03, x, 0);
        x47 = z03 ^ S5[x[0]] ^ S6[x[2]] ^ S7[x[1]] ^ S8[x[3]] ^ S8[z[2]];
        Bits32ToInts(x47, x, 4);
        x8B = z47 ^ S5[x[7]] ^ S6[x[6]] ^ S7[x[5]] ^ S8[x[4]] ^ S5[z[1]];
        Bits32ToInts(x8B, x, 8);
        xCF = zCF ^ S5[x[10]] ^ S6[x[9]] ^ S7[x[11]] ^ S8[x[8]] ^ S6[z[3]];
        Bits32ToInts(xCF, x, 12);
        _Km[13] = S5[x[8]] ^ S6[x[9]] ^ S7[x[7]] ^ S8[x[6]] ^ S5[x[3]];
        _Km[14] = S5[x[10]] ^ S6[x[11]] ^ S7[x[5]] ^ S8[x[4]] ^ S6[x[7]];
        _Km[15] = S5[x[12]] ^ S6[x[13]] ^ S7[x[3]] ^ S8[x[2]] ^ S7[x[8]];
        _Km[16] = S5[x[14]] ^ S6[x[15]] ^ S7[x[1]] ^ S8[x[0]] ^ S8[x[13]];
        x03 = IntsTo32bits(x, 0);
        x47 = IntsTo32bits(x, 4);
        x8B = IntsTo32bits(x, 8);
        xCF = IntsTo32bits(x, 12);
        z03 = x03 ^ S5[x[13]] ^ S6[x[15]] ^ S7[x[12]] ^ S8[x[14]] ^ S7[x[8]];
        Bits32ToInts(z03, z, 0);
        z47 = x8B ^ S5[z[0]] ^ S6[z[2]] ^ S7[z[1]] ^ S8[z[3]] ^ S8[x[10]];
        Bits32ToInts(z47, z, 4);
        z8B = xCF ^ S5[z[7]] ^ S6[z[6]] ^ S7[z[5]] ^ S8[z[4]] ^ S5[x[9]];
        Bits32ToInts(z8B, z, 8);
        zCF = x47 ^ S5[z[10]] ^ S6[z[9]] ^ S7[z[11]] ^ S8[z[8]] ^ S6[x[11]];
        Bits32ToInts(zCF, z, 12);
        _Kr[1] = (S5[z[8]] ^ S6[z[9]] ^ S7[z[7]] ^ S8[z[6]] ^ S5[z[2]]) & 0x1f;
        _Kr[2] = (S5[z[10]] ^ S6[z[11]] ^ S7[z[5]] ^ S8[z[4]] ^ S6[z[6]]) & 0x1f;
        _Kr[3] = (S5[z[12]] ^ S6[z[13]] ^ S7[z[3]] ^ S8[z[2]] ^ S7[z[9]]) & 0x1f;
        _Kr[4] = (S5[z[14]] ^ S6[z[15]] ^ S7[z[1]] ^ S8[z[0]] ^ S8[z[12]]) & 0x1f;
        z03 = IntsTo32bits(z, 0);
        z47 = IntsTo32bits(z, 4);
        z8B = IntsTo32bits(z, 8);
        zCF = IntsTo32bits(z, 12);
        x03 = z8B ^ S5[z[5]] ^ S6[z[7]] ^ S7[z[4]] ^ S8[z[6]] ^ S7[z[0]];
        Bits32ToInts(x03, x, 0);
        x47 = z03 ^ S5[x[0]] ^ S6[x[2]] ^ S7[x[1]] ^ S8[x[3]] ^ S8[z[2]];
        Bits32ToInts(x47, x, 4);
        x8B = z47 ^ S5[x[7]] ^ S6[x[6]] ^ S7[x[5]] ^ S8[x[4]] ^ S5[z[1]];
        Bits32ToInts(x8B, x, 8);
        xCF = zCF ^ S5[x[10]] ^ S6[x[9]] ^ S7[x[11]] ^ S8[x[8]] ^ S6[z[3]];
        Bits32ToInts(xCF, x, 12);
        _Kr[5] = (S5[x[3]] ^ S6[x[2]] ^ S7[x[12]] ^ S8[x[13]] ^ S5[x[8]]) & 0x1f;
        _Kr[6] = (S5[x[1]] ^ S6[x[0]] ^ S7[x[14]] ^ S8[x[15]] ^ S6[x[13]]) & 0x1f;
        _Kr[7] = (S5[x[7]] ^ S6[x[6]] ^ S7[x[8]] ^ S8[x[9]] ^ S7[x[3]]) & 0x1f;
        _Kr[8] = (S5[x[5]] ^ S6[x[4]] ^ S7[x[10]] ^ S8[x[11]] ^ S8[x[7]]) & 0x1f;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -