1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Add UnknownSecurityElement

Fix parsing of JingleSecurityElements
Switch to 12 byte IV for AES keys
This commit is contained in:
vanitasvitae 2017-08-09 10:45:34 +02:00
parent 792a9a348b
commit a23eb6aeea
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
10 changed files with 128 additions and 48 deletions

View file

@ -32,8 +32,8 @@ public class Aes128GcmNoPadding extends AesGcmNoPadding {
public Aes128GcmNoPadding(byte[] keyAndIv, int MODE) throws NoSuchProviderException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
super(AesGcmNoPadding.copyOfRange(keyAndIv, 0, keyAndIv.length / 2), //Key
AesGcmNoPadding.copyOfRange(keyAndIv, keyAndIv.length / 2, keyAndIv.length), MODE); //IV
super(AesGcmNoPadding.copyOfRange(keyAndIv, 0, 16), // 16 byte key
AesGcmNoPadding.copyOfRange(keyAndIv, 16, keyAndIv.length), MODE); // rest (12 byte) IV
}
@Override

View file

@ -32,8 +32,8 @@ public class Aes256GcmNoPadding extends AesGcmNoPadding {
public Aes256GcmNoPadding(byte[] keyAndIv, int MODE) throws NoSuchProviderException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
super(AesGcmNoPadding.copyOfRange(keyAndIv, 0, keyAndIv.length / 2), //Key
AesGcmNoPadding.copyOfRange(keyAndIv, keyAndIv.length / 2, keyAndIv.length), MODE); //IV
super(AesGcmNoPadding.copyOfRange(keyAndIv, 0, 32), // 32 byte key
AesGcmNoPadding.copyOfRange(keyAndIv, 32, keyAndIv.length), MODE); // rest (12 byte) IV
}
@Override

View file

@ -47,12 +47,12 @@ public abstract class AesGcmNoPadding {
key = keyGenerator.generateKey().getEncoded();
SecureRandom secureRandom = new SecureRandom();
iv = new byte[bytes];
iv = new byte[12];
secureRandom.nextBytes(iv);
keyAndIv = new byte[2 * bytes];
keyAndIv = new byte[bytes + 12];
System.arraycopy(key, 0, keyAndIv, 0, bytes);
System.arraycopy(iv, 0, keyAndIv, bytes, bytes);
System.arraycopy(iv, 0, keyAndIv, bytes, 12);
cipher = Cipher.getInstance(cipherMode, "BC");
SecretKey keySpec = new SecretKeySpec(key, keyType);
@ -86,6 +86,7 @@ public abstract class AesGcmNoPadding {
*/
public AesGcmNoPadding(byte[] key, byte[] iv, int MODE) throws NoSuchPaddingException, NoSuchAlgorithmException,
NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeyException {
assert iv.length == 12;
this.length = key.length * 8;
this.key = key;
this.iv = iv;

View file

@ -42,8 +42,8 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
AesGcmNoPadding aes128 = AesGcmNoPadding.createEncryptionKey(Aes128GcmNoPadding.NAMESPACE);
assertNotNull(aes128);
assertEquals(16, aes128.getKey().length);
assertEquals(16, aes128.getIv().length);
assertEquals(32, aes128.getKeyAndIv().length);
assertEquals(12, aes128.getIv().length);
assertEquals(28, aes128.getKeyAndIv().length);
assertNotNull(aes128.getCipher());
assertEquals(128, aes128.getLength());
}
@ -53,8 +53,8 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
AesGcmNoPadding aes256 = AesGcmNoPadding.createEncryptionKey(Aes256GcmNoPadding.NAMESPACE);
assertNotNull(aes256);
assertEquals(32, aes256.getKey().length);
assertEquals(32, aes256.getIv().length);
assertEquals(64, aes256.getKeyAndIv().length);
assertEquals(12, aes256.getIv().length);
assertEquals(44, aes256.getKeyAndIv().length);
assertNotNull(aes256.getCipher());
assertEquals(256, aes256.getLength());
}