Skip to content

Remove frame-size restrictions. #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/main/java/com/amazonaws/encryptionsdk/AwsCrypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ public void setEncryptionFrameSize(final int frameSize) {
if (frameSize < 0) {
throw new IllegalArgumentException("frameSize must be non-negative");
}
if (frameSize % 16 != 0) {
// For compatibility reasons we'll still enforce this restriction for now.
// TODO: Investigate whether this can be removed.
throw new IllegalArgumentException("frameSize must be a multiple of 16");
}

encryptionFrameSize_ = frameSize;
}

Expand Down
22 changes: 8 additions & 14 deletions src/test/java/com/amazonaws/encryptionsdk/AwsCryptoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ private void doEncryptDecryptWithParsedCiphertext(final int byteSize, final int
@Test
public void encryptDecrypt() {
for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = { 0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize() };
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

for (int i = 0; i < frameSizeToTest.length; i++) {
final int frameSize = frameSizeToTest[i];
Expand Down Expand Up @@ -175,9 +173,7 @@ public void encryptDecryptWithBadSignature() {
if (cryptoAlg.getTrailingSignatureAlgo() == null) {
continue;
}
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = { 0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize() };
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

for (int i = 0; i < frameSizeToTest.length; i++) {
final int frameSize = frameSizeToTest[i];
Expand All @@ -202,9 +198,7 @@ public void encryptDecryptWithBadSignature() {
@Test
public void encryptDecryptWithParsedCiphertext() {
for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = { 0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize() };
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

for (int i = 0; i < frameSizeToTest.length; i++) {
final int frameSize = frameSizeToTest[i];
Expand Down Expand Up @@ -336,9 +330,7 @@ private void doEstimateCiphertextSize(final CryptoAlgorithm cryptoAlg, final int
@Test
public void estimateCiphertextSize() {
for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = { 0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize() };
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

for (int i = 0; i < frameSizeToTest.length; i++) {
final int frameSize = frameSizeToTest[i];
Expand Down Expand Up @@ -664,10 +656,12 @@ public void setValidFrameSize() throws IOException {
assertEquals(setFrameSize, getFrameSize);
}

@Test(expected = IllegalArgumentException.class)
public void unalignedFrameSizesAreRejected() throws IOException {

public void unalignedFrameSizesAreAccepted() throws IOException {
final int frameSize = AwsCrypto.getDefaultCryptoAlgorithm().getBlockSize() - 1;
encryptionClient_.setEncryptionFrameSize(frameSize);

assertEquals(frameSize, encryptionClient_.getEncryptionFrameSize());
}

@Test(expected = IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ public static Collection<Object[]> encryptDecryptParams() {
boolean firstAlgorithm = true;

for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = {
0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize()
};
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

// Our bytesToTest and readLenVals arrays tend to have the bigger numbers towards the end - we'll chop off
// the last few as they take the longest and don't really add that much more coverage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ public static Collection<Object[]> encryptDecryptParams() {
ArrayList<Object[]> cases = new ArrayList<>();

for (final CryptoAlgorithm cryptoAlg : EnumSet.allOf(CryptoAlgorithm.class)) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = { 0, blockSize, blockSize * 2, blockSize * 10,
AwsCrypto.getDefaultFrameSize() };
final int[] frameSizeToTest = TestUtils.getFrameSizesToTest(cryptoAlg);

// iterate over frame size to test
for (int i = 0; i < frameSizeToTest.length; i++) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/amazonaws/encryptionsdk/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,19 @@ public static byte[] insecureRandomBytes(int length) {
public static ByteArrayInputStream insecureRandomStream(int length) {
return new ByteArrayInputStream(ensureRandomCached(length), 0, length);
}

public static int[] getFrameSizesToTest(final CryptoAlgorithm cryptoAlg) {
final int blockSize = cryptoAlg.getBlockSize();
final int[] frameSizeToTest = {
0,
blockSize - 1,
blockSize,
blockSize + 1,
blockSize * 2,
blockSize * 10,
blockSize * 10 + 1,
AwsCrypto.getDefaultFrameSize()
};
return frameSizeToTest;
}
}