Skip to content

Commit fa156fa

Browse files
committed
RFC3394WrapEngine: check input length in unwrap
1 parent ee2d965 commit fa156fa

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/RFC3394WrapEngine.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public byte[] unwrap(
143143
{
144144
throw new IllegalStateException("not set for unwrapping");
145145
}
146+
if (inLen < iv.length)
147+
{
148+
throw new InvalidCipherTextException("unwrap data too short");
149+
}
146150

147151
int n = inLen / 8;
148152

core/src/test/java/org/bouncycastle/crypto/test/AESWrapTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,27 @@ public void performTest()
216216
}
217217

218218
//
219-
// short test
219+
// short tests
220220
//
221221
try
222222
{
223223
wrapper.init(false, key);
224224

225+
wrapper.unwrap(buf, 0, 0);
226+
227+
fail("failed unwrap short test 1.");
228+
}
229+
catch (InvalidCipherTextException e)
230+
{
231+
// expected
232+
}
233+
try
234+
{
235+
wrapper.init(false, key);
236+
225237
wrapper.unwrap(buf, 0, buf.length / 2);
226238

227-
fail("failed unwrap short test.");
239+
fail("failed unwrap short test 2.");
228240
}
229241
catch (InvalidCipherTextException e)
230242
{
@@ -237,7 +249,7 @@ public void performTest()
237249

238250
wrapper.wrap(buf, 0, 15);
239251

240-
fail("ailed wrap length test.");
252+
fail("failed wrap length test.");
241253
}
242254
catch (DataLengthException e)
243255
{

0 commit comments

Comments
 (0)