mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 05:43:00 -08:00
Merge branch 'drizzt-twofish'
This commit is contained in:
commit
5245df218c
3 files changed
+92
-5
No files matched your search
@@ -76,7 +76,10 @@ public class CipherFactory {
|
||||
new byte[]{(byte)0x31, (byte)0xC1, (byte)0xF2, (byte)0xE6, (byte)0xBF, (byte)0x71, (byte)0x43, (byte)0x50,
|
||||
(byte)0xBE, (byte)0x58, (byte)0x05, (byte)0x21, (byte)0x6A, (byte)0xFC, 0x5A, (byte)0xFF
|
||||
});
|
||||
|
||||
public static final UUID TWOFISH_CIPHER = Types.bytestoUUID(
|
||||
new byte[]{(byte)0xAD, (byte)0x68, (byte)0xF2, (byte)0x9F, (byte)0x57, (byte)0x6F, (byte)0x4B, (byte)0xB9,
|
||||
(byte)0xA3, (byte)0x6A, (byte)0xD4, (byte)0x7A, (byte)0xF9, (byte)0x65, (byte)0x34, (byte)0x6C
|
||||
});
|
||||
|
||||
/** Generate appropriate cipher based on KeePass 2.x UUID's
|
||||
* @param uuid
|
||||
@@ -96,6 +99,17 @@ public class CipherFactory {
|
||||
|
||||
cipher.init(opmode, new SecretKeySpec(key, "AES"), new IvParameterSpec(IV));
|
||||
|
||||
return cipher;
|
||||
} else if ( uuid.equals(TWOFISH_CIPHER) ) {
|
||||
Cipher cipher;
|
||||
if (opmode == Cipher.ENCRYPT_MODE) {
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/ZeroBytePadding", androidOverride);
|
||||
} else {
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/NoPadding", androidOverride);
|
||||
}
|
||||
|
||||
cipher.init(opmode, new SecretKeySpec(key, "AES"), new IvParameterSpec(IV));
|
||||
|
||||
return cipher;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.bouncycastle.crypto.paddings;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
|
||||
/**
|
||||
* A padder that adds NULL byte padding to a block.
|
||||
*/
|
||||
public class ZeroBytePadding
|
||||
implements BlockCipherPadding
|
||||
{
|
||||
/**
|
||||
* Initialise the padder.
|
||||
*
|
||||
* @param random - a SecureRandom if available.
|
||||
*/
|
||||
public void init(SecureRandom random)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// nothing to do.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the padder implements.
|
||||
*
|
||||
* @return the name of the algorithm the padder implements.
|
||||
*/
|
||||
public String getPaddingName()
|
||||
{
|
||||
return "ZeroByte";
|
||||
}
|
||||
|
||||
/**
|
||||
* add the pad bytes to the passed in block, returning the
|
||||
* number of bytes added.
|
||||
*/
|
||||
public int addPadding(
|
||||
byte[] in,
|
||||
int inOff)
|
||||
{
|
||||
int added = (in.length - inOff);
|
||||
|
||||
while (inOff < in.length)
|
||||
{
|
||||
in[inOff] = (byte) 0;
|
||||
inOff++;
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the number of pad bytes present in the block.
|
||||
*/
|
||||
public int padCount(byte[] in)
|
||||
throws InvalidCipherTextException
|
||||
{
|
||||
int count = in.length;
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
if (in[count - 1] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
count--;
|
||||
}
|
||||
|
||||
return in.length - count;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,9 @@ import org.bouncycastle.crypto.modes.OFBBlockCipher;
|
||||
import org.bouncycastle.crypto.modes.OpenPGPCFBBlockCipher;
|
||||
import org.bouncycastle.crypto.modes.PGPCFBBlockCipher;
|
||||
import org.bouncycastle.crypto.modes.SICBlockCipher;
|
||||
*/
|
||||
import org.bouncycastle.crypto.paddings.BlockCipherPadding;
|
||||
/*
|
||||
import org.bouncycastle.crypto.paddings.ISO10126d2Padding;
|
||||
import org.bouncycastle.crypto.paddings.ISO7816d4Padding;
|
||||
*/
|
||||
@@ -48,8 +50,8 @@ import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||
/*
|
||||
import org.bouncycastle.crypto.paddings.TBCPadding;
|
||||
import org.bouncycastle.crypto.paddings.X923Padding;
|
||||
import org.bouncycastle.crypto.paddings.ZeroBytePadding;
|
||||
*/
|
||||
import org.bouncycastle.crypto.paddings.ZeroBytePadding;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
||||
@@ -343,11 +345,11 @@ public class JCEBlockCipher extends WrapCipherSpi
|
||||
{
|
||||
cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher());
|
||||
}
|
||||
/*
|
||||
else if (paddingName.equals("ZEROBYTEPADDING"))
|
||||
{
|
||||
cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
|
||||
}
|
||||
/*
|
||||
else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
|
||||
{
|
||||
cipher = new BufferedGenericBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
|
||||
@@ -1290,12 +1292,10 @@ public class JCEBlockCipher extends WrapCipherSpi
|
||||
this.cipher = new PaddedBufferedBlockCipher(cipher);
|
||||
}
|
||||
|
||||
/*
|
||||
BufferedGenericBlockCipher(BlockCipher cipher, BlockCipherPadding padding)
|
||||
{
|
||||
this.cipher = new PaddedBufferedBlockCipher(cipher, padding);
|
||||
}
|
||||
*/
|
||||
|
||||
public void init(boolean forEncryption, CipherParameters params)
|
||||
throws IllegalArgumentException
|
||||
|
||||
Reference in new issue
Block a user