Produced by Araxis Merge on 9/25/2018 2:13:01 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\crypto\provider | AESCipher.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\crypto\provider | AESCipher.java | Wed Sep 12 16:22:09 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1288 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 200 2, 2017, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package co m.sun.cryp to.provide r; | |
27 | ||
28 | import jav a.security .*; | |
29 | import jav a.security .spec.*; | |
30 | import jav ax.crypto. *; | |
31 | import jav ax.crypto. spec.*; | |
32 | import jav ax.crypto. BadPadding Exception; | |
33 | import jav a.nio.Byte Buffer; | |
34 | ||
35 | /** | |
36 | * This cl ass implem ents the A ES algorit hm in its various mo des | |
37 | * (<code> ECB</code> , <code>CF B</code>, <code>OFB< /code>, <c ode>CBC</c ode>, | |
38 | * <code>P CBC</code> ) and padd ing scheme s (<code>P KCS5Paddin g</code>, | |
39 | * <code>N oPadding</ code>, <co de>ISO1012 6Padding</ code>). | |
40 | * | |
41 | * @author Valerie P eng | |
42 | * | |
43 | * | |
44 | * @see AE SCrypt | |
45 | * @see Ci pherBlockC haining | |
46 | * @see El ectronicCo deBook | |
47 | * @see Ci pherFeedba ck | |
48 | * @see Ou tputFeedba ck | |
49 | */ | |
50 | ||
51 | abstract c lass AESCi pher exten ds CipherS pi { | |
52 | public static fi nal class General ex tends AESC ipher { | |
53 | pu blic Gener al() { | |
54 | super(-1 ); | |
55 | } | |
56 | } | |
57 | abstra ct static class OidI mpl extend s AESCiphe r { | |
58 | pr otected Oi dImpl(int keySize, S tring mode , String p adding) { | |
59 | super(ke ySize); | |
60 | try { | |
61 | engi neSetMode( mode); | |
62 | engi neSetPaddi ng(padding ); | |
63 | } catch (GeneralSe curityExce ption gse) { | |
64 | // i nternal er ror; re-th row as pro vider exce ption | |
65 | Prov iderExcept ion pe =ne w Provider Exception( "Internal Error"); | |
66 | pe.i nitCause(g se); | |
67 | thro w pe; | |
68 | } | |
69 | } | |
70 | } | |
71 | public static fi nal class AES128_ECB _NoPadding extends O idImpl { | |
72 | pu blic AES12 8_ECB_NoPa dding() { | |
73 | super(16 , "ECB", " NOPADDING" ); | |
74 | } | |
75 | } | |
76 | public static fi nal class AES192_ECB _NoPadding extends O idImpl { | |
77 | pu blic AES19 2_ECB_NoPa dding() { | |
78 | super(24 , "ECB", " NOPADDING" ); | |
79 | } | |
80 | } | |
81 | public static fi nal class AES256_ECB _NoPadding extends O idImpl { | |
82 | pu blic AES25 6_ECB_NoPa dding() { | |
83 | super(32 , "ECB", " NOPADDING" ); | |
84 | } | |
85 | } | |
86 | public static fi nal class AES128_CBC _NoPadding extends O idImpl { | |
87 | pu blic AES12 8_CBC_NoPa dding() { | |
88 | super(16 , "CBC", " NOPADDING" ); | |
89 | } | |
90 | } | |
91 | public static fi nal class AES192_CBC _NoPadding extends O idImpl { | |
92 | pu blic AES19 2_CBC_NoPa dding() { | |
93 | super(24 , "CBC", " NOPADDING" ); | |
94 | } | |
95 | } | |
96 | public static fi nal class AES256_CBC _NoPadding extends O idImpl { | |
97 | pu blic AES25 6_CBC_NoPa dding() { | |
98 | super(32 , "CBC", " NOPADDING" ); | |
99 | } | |
100 | } | |
101 | public static fi nal class AES128_OFB _NoPadding extends O idImpl { | |
102 | pu blic AES12 8_OFB_NoPa dding() { | |
103 | super(16 , "OFB", " NOPADDING" ); | |
104 | } | |
105 | } | |
106 | public static fi nal class AES192_OFB _NoPadding extends O idImpl { | |
107 | pu blic AES19 2_OFB_NoPa dding() { | |
108 | super(24 , "OFB", " NOPADDING" ); | |
109 | } | |
110 | } | |
111 | public static fi nal class AES256_OFB _NoPadding extends O idImpl { | |
112 | pu blic AES25 6_OFB_NoPa dding() { | |
113 | super(32 , "OFB", " NOPADDING" ); | |
114 | } | |
115 | } | |
116 | public static fi nal class AES128_CFB _NoPadding extends O idImpl { | |
117 | pu blic AES12 8_CFB_NoPa dding() { | |
118 | super(16 , "CFB", " NOPADDING" ); | |
119 | } | |
120 | } | |
121 | public static fi nal class AES192_CFB _NoPadding extends O idImpl { | |
122 | pu blic AES19 2_CFB_NoPa dding() { | |
123 | super(24 , "CFB", " NOPADDING" ); | |
124 | } | |
125 | } | |
126 | public static fi nal class AES256_CFB _NoPadding extends O idImpl { | |
127 | pu blic AES25 6_CFB_NoPa dding() { | |
128 | super(32 , "CFB", " NOPADDING" ); | |
129 | } | |
130 | } | |
131 | public static fi nal class AES128_GCM _NoPadding extends O idImpl { | |
132 | pu blic AES12 8_GCM_NoPa dding() { | |
133 | super(16 , "GCM", " NOPADDING" ); | |
134 | } | |
135 | } | |
136 | public static fi nal class AES192_GCM _NoPadding extends O idImpl { | |
137 | pu blic AES19 2_GCM_NoPa dding() { | |
138 | super(24 , "GCM", " NOPADDING" ); | |
139 | } | |
140 | } | |
141 | public static fi nal class AES256_GCM _NoPadding extends O idImpl { | |
142 | pu blic AES25 6_GCM_NoPa dding() { | |
143 | super(32 , "GCM", " NOPADDING" ); | |
144 | } | |
145 | } | |
146 | ||
147 | // uti lity metho d used by AESCipher and AESWra pCipher | |
148 | static final voi d checkKey Size(Key k ey, int fi xedKeySize ) | |
149 | th rows Inval idKeyExcep tion { | |
150 | if (fixedKey Size != -1 ) { | |
151 | if (key == null) { | |
152 | thro w new Inva lidKeyExce ption("The key must not be nul l"); | |
153 | } | |
154 | byte[] v alue = key .getEncode d(); | |
155 | if (valu e == null) { | |
156 | thro w new Inva lidKeyExce ption("Key encoding must not b e null"); | |
157 | } else i f (value.l ength != f ixedKeySiz e) { | |
158 | thro w new Inva lidKeyExce ption("The key must be " + | |
159 | fixedKeySi ze + " byt es"); | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | /* | |
165 | * int ernal Ciph erCore obj ect which does the r eal work. | |
166 | */ | |
167 | privat e CipherCo re core = null; | |
168 | ||
169 | /* | |
170 | * nee ded to sup port AES o ids which associates a fixed k ey size | |
171 | * to the cipher object. | |
172 | */ | |
173 | privat e final in t fixedKey Size; // i n bytes, - 1 if no re striction | |
174 | ||
175 | /* | |
176 | * nee ded to enf orce ISE t hrown when updateAAD is called after upd ate for GC M mode. | |
177 | */ | |
178 | privat e boolean updateCall ed; | |
179 | ||
180 | /** | |
181 | * Cre ates an in stance of AES cipher with defa ult ECB mo de and | |
182 | * PKC S5Padding. | |
183 | */ | |
184 | protec ted AESCip her(int ke ySize) { | |
185 | co re = new C ipherCore( new AESCry pt(), AESC onstants.A ES_BLOCK_S IZE); | |
186 | fi xedKeySize = keySize ; | |
187 | } | |
188 | ||
189 | /** | |
190 | * Set s the mode of this c ipher. | |
191 | * | |
192 | * @pa ram mode t he cipher mode | |
193 | * | |
194 | * @ex ception No SuchAlgori thmExcepti on if the requested cipher mod e does | |
195 | * not exist | |
196 | */ | |
197 | protec ted void e ngineSetMo de(String mode) | |
198 | th rows NoSuc hAlgorithm Exception { | |
199 | co re.setMode (mode); | |
200 | } | |
201 | ||
202 | /** | |
203 | * Set s the padd ing mechan ism of thi s cipher. | |
204 | * | |
205 | * @pa ram paddin g the padd ing mechan ism | |
206 | * | |
207 | * @ex ception No SuchPaddin gException if the re quested pa dding mech anism | |
208 | * doe s not exis t | |
209 | */ | |
210 | protec ted void e ngineSetPa dding(Stri ng padding Scheme) | |
211 | th rows NoSuc hPaddingEx ception { | |
212 | co re.setPadd ing(paddin gScheme); | |
213 | } | |
214 | ||
215 | /** | |
216 | * Ret urns the b lock size (in bytes) . | |
217 | * | |
218 | * @re turn the b lock size (in bytes) , or 0 if the underl ying algor ithm is | |
219 | * not a block c ipher | |
220 | */ | |
221 | protec ted int en gineGetBlo ckSize() { | |
222 | re turn AESCo nstants.AE S_BLOCK_SI ZE; | |
223 | } | |
224 | ||
225 | /** | |
226 | * Ret urns the l ength in b ytes that an output buffer wou ld need to be in | |
227 | * ord er to hold the resul t of the n ext <code> update</co de> or | |
228 | * <co de>doFinal </code> op eration, g iven the i nput lengt h | |
229 | * <co de>inputLe n</code> ( in bytes). | |
230 | * | |
231 | * <p> This call takes into account a ny unproce ssed (buff ered) data from a | |
232 | * pre vious <cod e>update</ code> call , and padd ing. | |
233 | * | |
234 | * <p> The actual output le ngth of th e next <co de>update< /code> or | |
235 | * <co de>doFinal </code> ca ll may be smaller th an the len gth return ed by | |
236 | * thi s method. | |
237 | * | |
238 | * @pa ram inputL en the inp ut length (in bytes) | |
239 | * | |
240 | * @re turn the r equired ou tput buffe r size (in bytes) | |
241 | */ | |
242 | protec ted int en gineGetOut putSize(in t inputLen ) { | |
243 | re turn core. getOutputS ize(inputL en); | |
244 | } | |
245 | ||
246 | /** | |
247 | * Ret urns the i nitializat ion vector (IV) in a new buffe r. | |
248 | * | |
249 | * <p> This is us eful in th e case whe re a rando m IV has b een create d | |
250 | * (se e <a href = "#init"> init</a>), | |
251 | * or in the con text of pa ssword-bas ed encrypt ion or | |
252 | * dec ryption, w here the I V is deriv ed from a user-provi ded passwo rd. | |
253 | * | |
254 | * @re turn the i nitializat ion vector in a new buffer, or null if t he | |
255 | * und erlying al gorithm do es not use an IV, or if the IV has not y et | |
256 | * bee n set. | |
257 | */ | |
258 | protec ted byte[] engineGet IV() { | |
259 | re turn core. getIV(); | |
260 | } | |
261 | ||
262 | /** | |
263 | * Ret urns the p arameters used with this ciphe r. | |
264 | * | |
265 | * <p> The return ed paramet ers may be the same that were used to in itialize | |
266 | * thi s cipher, or may con tain the d efault set of parame ters or a set of | |
267 | * ran domly gene rated para meters use d by the u nderlying cipher | |
268 | * imp lementatio n (provide d that the underlyin g cipher i mplementat ion | |
269 | * use s a defaul t set of p arameters or creates new param eters if i t needs | |
270 | * par ameters bu t was not initialize d with any ). | |
271 | * | |
272 | * @re turn the p arameters used with this ciphe r, or null if this c ipher | |
273 | * doe s not use any parame ters. | |
274 | */ | |
275 | protec ted Algori thmParamet ers engine GetParamet ers() { | |
276 | re turn core. getParamet ers("AES") ; | |
277 | } | |
278 | ||
279 | /** | |
280 | * Ini tializes t his cipher with a ke y and a so urce of ra ndomness. | |
281 | * | |
282 | * <p> The cipher is initia lized for one of the following four oper ations: | |
283 | * enc ryption, d ecryption, key wrapp ing or key unwrappin g, dependi ng on | |
284 | * the value of <code>opmo de</code>. | |
285 | * | |
286 | * <p> If this ci pher requi res an ini tializatio n vector ( IV), it wi ll get | |
287 | * it from <code >random</c ode>. | |
288 | * Thi s behaviou r should o nly be use d in encry ption or k ey wrappin g | |
289 | * mod e, however . | |
290 | * Whe n initiali zing a cip her that r equires an IV for de cryption o r | |
291 | * key unwrappin g, the IV | |
292 | * (sa me IV that was used for encryp tion or ke y wrapping ) must be provided | |
293 | * exp licitly as a | |
294 | * par ameter, in order to get the co rrect resu lt. | |
295 | * | |
296 | * <p> This metho d also cle ans existi ng buffer and other related st ate | |
297 | * inf ormation. | |
298 | * | |
299 | * @pa ram opmode the opera tion mode of this ci pher (this is one of | |
300 | * the following : | |
301 | * <co de>ENCRYPT _MODE</cod e>, <code> DECRYPT_MO DE</code>, | |
302 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) | |
303 | * @param k ey the PW key | |
304 | * @pa ram random the sourc e of rando mness | |
305 | * | |
306 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
307 | * ini tializing this ciphe r | |
308 | */ | |
309 | protec ted void e ngineInit( int opmode , Key key, SecureRan dom random ) | |
310 | th rows Inval idKeyExcep tion { | |
311 | ch eckKeySize (key, fixe dKeySize); | |
312 | up dateCalled = false; | |
313 | co re.init(op mode, key, random); | |
314 | } | |
315 | ||
316 | /** | |
317 | * Ini tializes t his cipher with a ke y, a set o f | |
318 | * alg orithm par ameters, a nd a sourc e of rando mness. | |
319 | * | |
320 | * <p> The cipher is initia lized for one of the following four oper ations: | |
321 | * enc ryption, d ecryption, key wrapp ing or key unwrappin g, dependi ng on | |
322 | * the value of <code>opmo de</code>. | |
323 | * | |
324 | * <p> If this ci pher (incl uding its underlying feedback or padding scheme) | |
325 | * req uires any random byt es, it wil l get them from <cod e>random</ code>. | |
326 | * | |
327 | * @pa ram opmode the opera tion mode of this ci pher (this is one of | |
328 | * the following : | |
329 | * <co de>ENCRYPT _MODE</cod e>, <code> DECRYPT_MO DE</code>, | |
330 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) | |
331 | * @pa ram key th e encrypti on key | |
332 | * @pa ram params the algor ithm param eters | |
333 | * @pa ram random the sourc e of rando mness | |
334 | * | |
335 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
336 | * ini tializing this ciphe r | |
337 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
338 | * par ameters ar e inapprop riate for this ciphe r | |
339 | */ | |
340 | protec ted void e ngineInit( int opmode , Key key, | |
341 | AlgorithmP arameterSp ec params, | |
342 | SecureRand om random) | |
343 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
344 | ch eckKeySize (key, fixe dKeySize); | |
345 | up dateCalled = false; | |
346 | co re.init(op mode, key, params, r andom); | |
347 | } | |
348 | ||
349 | protec ted void e ngineInit( int opmode , Key key, | |
350 | AlgorithmP arameters params, | |
351 | SecureRand om random) | |
352 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
353 | ch eckKeySize (key, fixe dKeySize); | |
354 | up dateCalled = false; | |
355 | co re.init(op mode, key, params, r andom); | |
356 | } | |
357 | ||
358 | /** | |
359 | * Con tinues a m ultiple-pa rt encrypt ion or dec ryption op eration | |
360 | * (de pending on how this cipher was initializ ed), proce ssing anot her data | |
361 | * par t. | |
362 | * | |
363 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
364 | * buf fer, start ing at <co de>inputOf fset</code >, are pro cessed, an d the | |
365 | * res ult is sto red in a n ew buffer. | |
366 | * | |
367 | * @pa ram input the input buffer | |
368 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
369 | * sta rts | |
370 | * @pa ram inputL en the inp ut length | |
371 | * | |
372 | * @re turn the n ew buffer with the r esult | |
373 | * | |
374 | * @ex ception Il legalState Exception if this ci pher is in a wrong s tate | |
375 | * (e. g., has no t been ini tialized) | |
376 | */ | |
377 | protec ted byte[] engineUpd ate(byte[] input, in t inputOff set, | |
378 | int in putLen) { | |
379 | up dateCalled = true; | |
380 | re turn core. update(inp ut, inputO ffset, inp utLen); | |
381 | } | |
382 | ||
383 | /** | |
384 | * Con tinues a m ultiple-pa rt encrypt ion or dec ryption op eration | |
385 | * (de pending on how this cipher was initializ ed), proce ssing anot her data | |
386 | * par t. | |
387 | * | |
388 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
389 | * buf fer, start ing at <co de>inputOf fset</code >, are pro cessed, an d the | |
390 | * res ult is sto red in the <code>out put</code> buffer, s tarting at | |
391 | * <co de>outputO ffset</cod e>. | |
392 | * | |
393 | * @pa ram input the input buffer | |
394 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
395 | * sta rts | |
396 | * @pa ram inputL en the inp ut length | |
397 | * @pa ram output the buffe r for the result | |
398 | * @pa ram output Offset the offset in <code>out put</code> where the result | |
399 | * is stored | |
400 | * | |
401 | * @re turn the n umber of b ytes store d in <code >output</c ode> | |
402 | * | |
403 | * @ex ception Sh ortBufferE xception i f the give n output b uffer is t oo small | |
404 | * to hold the r esult | |
405 | */ | |
406 | protec ted int en gineUpdate (byte[] in put, int i nputOffset , int inpu tLen, | |
407 | byte[] ou tput, int outputOffs et) | |
408 | th rows Short BufferExce ption { | |
409 | up dateCalled = true; | |
410 | re turn core. update(inp ut, inputO ffset, inp utLen, out put, | |
411 | out putOffset) ; | |
412 | } | |
413 | ||
414 | /** | |
415 | * Enc rypts or d ecrypts da ta in a si ngle-part operation, | |
416 | * or finishes a multiple- part opera tion. | |
417 | * The data is e ncrypted o r decrypte d, dependi ng on how this ciphe r was | |
418 | * ini tialized. | |
419 | * | |
420 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
421 | * buf fer, start ing at <co de>inputOf fset</code >, and any input byt es that | |
422 | * may have been buffered during a p revious <c ode>update </code> op eration, | |
423 | * are processed , with pad ding (if r equested) being appl ied. | |
424 | * The result is stored in a new buf fer. | |
425 | * | |
426 | * <p> The cipher is reset to its ini tial state (uninitia lized) aft er this | |
427 | * cal l. | |
428 | * | |
429 | * @pa ram input the input buffer | |
430 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
431 | * sta rts | |
432 | * @pa ram inputL en the inp ut length | |
433 | * | |
434 | * @re turn the n ew buffer with the r esult | |
435 | * | |
436 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block cipher, | |
437 | * no padding ha s been req uested (on ly in encr yption mod e), and th e total | |
438 | * inp ut length of the dat a processe d by this cipher is not a mult iple of | |
439 | * blo ck size | |
440 | * @ex ception Ba dPaddingEx ception if this ciph er is in d ecryption mode, | |
441 | * and (un)paddi ng has bee n requeste d, but the decrypted data is n ot | |
442 | * bou nded by th e appropri ate paddin g bytes | |
443 | */ | |
444 | protec ted byte[] engineDoF inal(byte[ ] input, i nt inputOf fset, int inputLen) | |
445 | th rows Illeg alBlockSiz eException , BadPaddi ngExceptio n { | |
446 | by te[] out = core.doFi nal(input, inputOffs et, inputL en); | |
447 | up dateCalled = false; | |
448 | re turn out; | |
449 | } | |
450 | ||
451 | /** | |
452 | * Enc rypts or d ecrypts da ta in a si ngle-part operation, | |
453 | * or finishes a multiple- part opera tion. | |
454 | * The data is e ncrypted o r decrypte d, dependi ng on how this ciphe r was | |
455 | * ini tialized. | |
456 | * | |
457 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
458 | * buf fer, start ing at <co de>inputOf fset</code >, and any input byt es that | |
459 | * may have been buffered during a p revious <c ode>update </code> op eration, | |
460 | * are processed , with pad ding (if r equested) being appl ied. | |
461 | * The result is stored in the <code >output</c ode> buffe r, startin g at | |
462 | * <co de>outputO ffset</cod e>. | |
463 | * | |
464 | * <p> The cipher is reset to its ini tial state (uninitia lized) aft er this | |
465 | * cal l. | |
466 | * | |
467 | * @pa ram input the input buffer | |
468 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
469 | * sta rts | |
470 | * @pa ram inputL en the inp ut length | |
471 | * @pa ram output the buffe r for the result | |
472 | * @pa ram output Offset the offset in <code>out put</code> where the result | |
473 | * is stored | |
474 | * | |
475 | * @re turn the n umber of b ytes store d in <code >output</c ode> | |
476 | * | |
477 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block cipher, | |
478 | * no padding ha s been req uested (on ly in encr yption mod e), and th e total | |
479 | * inp ut length of the dat a processe d by this cipher is not a mult iple of | |
480 | * blo ck size | |
481 | * @ex ception Sh ortBufferE xception i f the give n output b uffer is t oo small | |
482 | * to hold the r esult | |
483 | * @ex ception Ba dPaddingEx ception if this ciph er is in d ecryption mode, | |
484 | * and (un)paddi ng has bee n requeste d, but the decrypted data is n ot | |
485 | * bou nded by th e appropri ate paddin g bytes | |
486 | */ | |
487 | protec ted int en gineDoFina l(byte[] i nput, int inputOffse t, int inp utLen, | |
488 | byte[] o utput, int outputOff set) | |
489 | th rows Illeg alBlockSiz eException , ShortBuf ferExcepti on, | |
490 | BadPa ddingExcep tion { | |
491 | in t outLen = core.doFi nal(input, inputOffs et, inputL en, output , | |
492 | output Offset); | |
493 | up dateCalled = false; | |
494 | re turn outLe n; | |
495 | } | |
496 | ||
497 | /** | |
498 | * Re turns the key size o f the give n key obje ct. | |
499 | * | |
500 | * @pa ram key th e key obje ct. | |
501 | * | |
502 | * @re turn the k ey size of the given key objec t. | |
503 | * | |
504 | * @ex ception In validKeyEx ception if <code>key </code> is invalid. | |
505 | */ | |
506 | protec ted int en gineGetKey Size(Key k ey) throws InvalidKe yException { | |
507 | by te[] encod ed = key.g etEncoded( ); | |
508 | if (!AESCryp t.isKeySiz eValid(enc oded.lengt h)) { | |
509 | throw ne w InvalidK eyExceptio n("Invalid AES key l ength: " + | |
510 | encoded. length + " bytes"); | |
511 | } | |
512 | re turn Math. multiplyEx act(encode d.length, 8); | |
513 | } | |
514 | ||
515 | /** | |
516 | * Wra p a key. | |
517 | * | |
518 | * @pa ram key th e key to b e wrapped. | |
519 | * | |
520 | * @re turn the w rapped key . | |
521 | * | |
522 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block | |
523 | * cip her, no pa dding has been reque sted, and the length of the | |
524 | * enc oding of t he key to be wrapped is not a | |
525 | * mul tiple of t he block s ize. | |
526 | * | |
527 | * @ex ception In validKeyEx ception if it is imp ossible or unsafe to | |
528 | * wra p the key with this cipher (e. g., a hard ware prote cted key i s | |
529 | * bei ng passed to a softw are only c ipher). | |
530 | */ | |
531 | protec ted byte[] engineWra p(Key key) | |
532 | th rows Illeg alBlockSiz eException , InvalidK eyExceptio n { | |
533 | re turn core. wrap(key); | |
534 | } | |
535 | ||
536 | /** | |
537 | * Unw rap a prev iously wra pped key. | |
538 | * | |
539 | * @pa ram wrappe dKey the k ey to be u nwrapped. | |
540 | * | |
541 | * @pa ram wrappe dKeyAlgori thm the al gorithm th e wrapped key is for . | |
542 | * | |
543 | * @pa ram wrappe dKeyType t he type of the wrapp ed key. | |
544 | * Thi s is one o f <code>Ci pher.SECRE T_KEY</cod e>, | |
545 | * <co de>Cipher. PRIVATE_KE Y</code>, or <code>C ipher.PUBL IC_KEY</co de>. | |
546 | * | |
547 | * @re turn the u nwrapped k ey. | |
548 | * | |
549 | * @ex ception No SuchAlgori thmExcepti on if no i nstalled p roviders | |
550 | * can create ke ys of type <code>wra ppedKeyTyp e</code> f or the | |
551 | * <co de>wrapped KeyAlgorit hm</code>. | |
552 | * | |
553 | * @ex ception In validKeyEx ception if <code>wra ppedKey</c ode> does not | |
554 | * rep resent a w rapped key of type < code>wrapp edKeyType< /code> for | |
555 | * the <code>wra ppedKeyAlg orithm</co de>. | |
556 | */ | |
557 | protec ted Key en gineUnwrap (byte[] wr appedKey, | |
558 | Str ing wrappe dKeyAlgori thm, | |
559 | int wrappedKe yType) | |
560 | th rows Inval idKeyExcep tion, NoSu chAlgorith mException { | |
561 | re turn core. unwrap(wra ppedKey, w rappedKeyA lgorithm, | |
562 | wra ppedKeyTyp e); | |
563 | } | |
564 | ||
565 | /** | |
566 | * Con tinues a m ulti-part update of the Additi onal Authe ntication | |
567 | * Dat a (AAD), u sing a sub set of the provided buffer. | |
568 | * <p> | |
569 | * Cal ls to this method pr ovide AAD to the cip her when o perating i n | |
570 | * mod es such as AEAD (GCM /CCM). If this ciph er is oper ating in | |
571 | * eit her GCM or CCM mode, all AAD m ust be sup plied befo re beginni ng | |
572 | * ope rations on the ciphe rtext (via the {@cod e update} and {@code | |
573 | * doF inal} meth ods). | |
574 | * | |
575 | * @pa ram src th e buffer c ontaining the AAD | |
576 | * @pa ram offset the offse t in {@cod e src} whe re the AAD input sta rts | |
577 | * @pa ram len th e number o f AAD byte s | |
578 | * | |
579 | * @th rows Illeg alStateExc eption if this ciphe r is in a wrong stat e | |
580 | * (e. g., has no t been ini tialized), does not accept AAD , or if | |
581 | * ope rating in either GCM or CCM mo de and one of the {@ code updat e} | |
582 | * met hods has a lready bee n called f or the act ive | |
583 | * enc ryption/de cryption o peration | |
584 | * @th rows Unsup portedOper ationExcep tion if th is method | |
585 | * has not been overridden by an imp lementatio n | |
586 | * | |
587 | * @si nce 1.8 | |
588 | */ | |
589 | @Overr ide | |
590 | protec ted void e ngineUpdat eAAD(byte[ ] src, int offset, i nt len) { | |
591 | if (core.get Mode() == CipherCore .GCM_MODE && updateC alled) { | |
592 | throw ne w IllegalS tateExcept ion("AAD m ust be sup plied befo re encrypt ion/decryp tion start s"); | |
593 | } | |
594 | co re.updateA AD(src, of fset, len) ; | |
595 | } | |
596 | ||
597 | /** | |
598 | * Con tinues a m ulti-part update of the Additi onal Authe ntication | |
599 | * Dat a (AAD). | |
600 | * <p> | |
601 | * Cal ls to this method pr ovide AAD to the cip her when o perating i n | |
602 | * mod es such as AEAD (GCM /CCM). If this ciph er is oper ating in | |
603 | * eit her GCM or CCM mode, all AAD m ust be sup plied befo re beginni ng | |
604 | * ope rations on the ciphe rtext (via the {@cod e update} and {@code | |
605 | * doF inal} meth ods). | |
606 | * <p> | |
607 | * All {@code sr c.remainin g()} bytes starting at | |
608 | * {@c ode src.po sition()} are proces sed. | |
609 | * Upo n return, the input buffer's p osition wi ll be equa l | |
610 | * to its limit; its limit will not have chang ed. | |
611 | * | |
612 | * @pa ram src th e buffer c ontaining the AAD | |
613 | * | |
614 | * @th rows Illeg alStateExc eption if this ciphe r is in a wrong stat e | |
615 | * (e. g., has no t been ini tialized), does not accept AAD , or if | |
616 | * ope rating in either GCM or CCM mo de and one of the {@ code updat e} | |
617 | * met hods has a lready bee n called f or the act ive | |
618 | * enc ryption/de cryption o peration | |
619 | * @th rows Unsup portedOper ationExcep tion if th is method | |
620 | * has not been overridden by an imp lementatio n | |
621 | * | |
622 | * @si nce 1.8 | |
623 | */ | |
624 | @Overr ide | |
625 | protec ted void e ngineUpdat eAAD(ByteB uffer src) { | |
626 | if (core.get Mode() == CipherCore .GCM_MODE && updateC alled) { | |
627 | throw ne w IllegalS tateExcept ion("AAD m ust be sup plied befo re encrypt ion/decryp tion start s"); | |
628 | } | |
629 | if (src != n ull) { | |
630 | int aadL en = src.l imit() - s rc.positio n(); | |
631 | if (aadL en > 0) { | |
632 | if ( src.hasArr ay()) { | |
633 | int aadOfs = Math.ad dExact(src .arrayOffs et(), src. position() ); | |
634 | core.updat eAAD(src.a rray(), aa dOfs, aadL en); | |
635 | src.positi on(src.lim it()); | |
636 | } el se { | |
637 | byte[] aad = new byt e[aadLen]; | |
638 | src.get(aa d); | |
639 | core.updat eAAD(aad, 0, aadLen) ; | |
640 | } | |
641 | } | |
642 | } | |
643 | } | |
644 | } | |
645 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.