@@ -125,10 +125,8 @@ public short doFinal(byte[] inBuff, short inOffset, short inLength,
125
125
if (len != 256 || outBuff [0 ] != 0 ) {
126
126
CryptoException .throwIt (CryptoException .ILLEGAL_VALUE );
127
127
}
128
- inBuff = outBuff ;
129
- inOffset = (short ) (outOffset + 1 );
130
- return rsaOAEPDecode (inBuff , inOffset , (short ) (len - 1 ), outBuff ,
131
- outOffset );
128
+ Util .arrayCopyNonAtomic (outBuff , (short ) (outOffset + 1 ), outBuff , (short ) 0 , (short ) (len -1 ));
129
+ return rsaOAEPDecode (outBuff , (short ) 0 , (short ) (len - 1 ));
132
130
133
131
}
134
132
@@ -177,7 +175,7 @@ private void I2OS(short i, byte[] out, short offset) {
177
175
}
178
176
179
177
private short rsaOAEPDecode (byte [] encodedMsg , short encodedMsgOff ,
180
- short encodedMsgLen , byte [] msg , short offset ) {
178
+ short encodedMsgLen ) {
181
179
MessageDigest .OneShot md = null ;
182
180
byte [] tmpArray = KMAndroidSEProvider .getInstance ().tmpArray ;
183
181
@@ -232,22 +230,26 @@ private short rsaOAEPDecode(byte[] encodedMsg, short encodedMsgOff,
232
230
// encoding parameters is calculated and then copied from the
233
231
// starting of the block and a variable length of 0's are
234
232
// appended to the end of the hash till the 0x01 byte.
235
- short start = 0 ;
233
+ short start = ( short ) ( encodedMsgOff + encodedMsgLen ) ;
236
234
for (short i = (short ) (encodedMsgOff + 2 * hLen );
237
235
i < (short ) (encodedMsgOff + encodedMsgLen ); i ++) {
238
- if (i == (short ) ((encodedMsgOff + encodedMsgLen ) - 1 )) {
239
- // Bad Padding.
240
- CryptoException .throwIt (CryptoException .ILLEGAL_VALUE );
241
- }
242
- if (encodedMsg [i ] != 0 ) {
236
+ if ((encodedMsg [i ] != 0 )) {
243
237
start = i ;
244
238
break ;
245
239
}
246
240
}
247
- // Copy the message
248
- Util .arrayCopyNonAtomic (encodedMsg , (short ) (start + 1 ), msg , offset ,
249
- (short ) (encodedMsgLen - ((start - encodedMsgOff ) + 1 )));
250
- return (short ) (encodedMsgLen - ((start - encodedMsgOff ) + 1 ));
241
+ if ((start >= (short )(encodedMsgOff + encodedMsgLen )) ||
242
+ (encodedMsg [start ] != 0x01 )) {
243
+ // Bad Padding.
244
+ CryptoException .throwIt (CryptoException .ILLEGAL_VALUE );
245
+ }
246
+ start ++; // Message starting pos.
247
+ if (start < (short )(encodedMsgOff + encodedMsgLen )) {
248
+ // Copy the message
249
+ Util .arrayCopyNonAtomic (encodedMsg , start , encodedMsg , encodedMsgOff ,
250
+ (short ) (encodedMsgLen - (start - encodedMsgOff )));
251
+ }
252
+ return (short ) (encodedMsgLen - (start - encodedMsgOff ));
251
253
252
254
} finally {
253
255
if (md != null ) {
0 commit comments