Search in sources :

Example 1 with GOFBBlockCipher

use of org.bouncycastle.crypto.modes.GOFBBlockCipher in project XobotOS by xamarin.

the class JCEBlockCipher method engineSetMode.

protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
    modeName = Strings.toUpperCase(mode);
    if (modeName.equals("ECB")) {
        ivLength = 0;
        cipher = new BufferedGenericBlockCipher(baseEngine);
    } else if (modeName.equals("CBC")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new CBCBlockCipher(baseEngine));
    } else if (modeName.startsWith("OFB")) {
        ivLength = baseEngine.getBlockSize();
        if (modeName.length() != 3) {
            int wordSize = Integer.parseInt(modeName.substring(3));
            cipher = new BufferedGenericBlockCipher(new OFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(new OFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
        }
    } else if (modeName.startsWith("CFB")) {
        ivLength = baseEngine.getBlockSize();
        if (modeName.length() != 3) {
            int wordSize = Integer.parseInt(modeName.substring(3));
            cipher = new BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
        }
    } else // END android-removed
    if (modeName.startsWith("SIC")) {
        ivLength = baseEngine.getBlockSize();
        if (ivLength < 16) {
            throw new IllegalArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)");
        }
        cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(new SICBlockCipher(baseEngine)));
    } else if (modeName.startsWith("CTR")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(new SICBlockCipher(baseEngine)));
    } else if (modeName.startsWith("GOFB")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(new GOFBBlockCipher(baseEngine)));
    } else if (modeName.startsWith("CTS")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(new CBCBlockCipher(baseEngine)));
    } else if (modeName.startsWith("CCM")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
    } else // END android-removed
    if (modeName.startsWith("GCM")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new AEADGenericBlockCipher(new GCMBlockCipher(baseEngine));
    } else {
        throw new NoSuchAlgorithmException("can't support mode " + mode);
    }
}
Also used : GOFBBlockCipher(org.bouncycastle.crypto.modes.GOFBBlockCipher) OFBBlockCipher(org.bouncycastle.crypto.modes.OFBBlockCipher) CCMBlockCipher(org.bouncycastle.crypto.modes.CCMBlockCipher) SICBlockCipher(org.bouncycastle.crypto.modes.SICBlockCipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) BufferedBlockCipher(org.bouncycastle.crypto.BufferedBlockCipher) PaddedBufferedBlockCipher(org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher) CTSBlockCipher(org.bouncycastle.crypto.modes.CTSBlockCipher) CBCBlockCipher(org.bouncycastle.crypto.modes.CBCBlockCipher) GOFBBlockCipher(org.bouncycastle.crypto.modes.GOFBBlockCipher) GCMBlockCipher(org.bouncycastle.crypto.modes.GCMBlockCipher)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)1 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)1 CCMBlockCipher (org.bouncycastle.crypto.modes.CCMBlockCipher)1 CFBBlockCipher (org.bouncycastle.crypto.modes.CFBBlockCipher)1 CTSBlockCipher (org.bouncycastle.crypto.modes.CTSBlockCipher)1 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)1 GOFBBlockCipher (org.bouncycastle.crypto.modes.GOFBBlockCipher)1 OFBBlockCipher (org.bouncycastle.crypto.modes.OFBBlockCipher)1 SICBlockCipher (org.bouncycastle.crypto.modes.SICBlockCipher)1 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)1