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 | AESWrapCipher.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 | AESWrapCipher.java | Wed Sep 12 16:22:11 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 4 | 1016 |
Changed | 3 | 6 |
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 4, 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.util.Arr ays; | |
29 | import jav a.security .*; | |
30 | import jav a.security .spec.*; | |
31 | import jav ax.crypto. *; | |
32 | import jav ax.crypto. spec.*; | |
33 | ||
34 | /** | |
35 | * This cl ass implem ents the A ES KeyWrap algorithm as define d | |
36 | * in <a h ref=http:/ /www.w3.or g/TR/xmlen c-core/#se c-Alg-Symm etricKeyWr ap> | |
37 | * "XML En cryption S yntax and Processing " section 5.6.3 "AES Key Wrap" . | |
38 | * Note: o nly <code> ECB</code> mode and <code>NoPa dding</cod e> padding | |
39 | * can be used for t his algori thm. | |
40 | * | |
41 | * @author Valerie P eng | |
42 | * | |
43 | * | |
44 | * @see AE SCipher | |
45 | */ | |
46 | abstract c lass AESWr apCipher e xtends Cip herSpi { | |
47 | public static fi nal class General ex tends AESW rapCipher { | |
48 | pu blic Gener al() { | |
49 | super(-1 ); | |
50 | } | |
51 | } | |
52 | public static fi nal class AES128 ext ends AESWr apCipher { | |
53 | pu blic AES12 8() { | |
54 | super(16 ); | |
55 | } | |
56 | } | |
57 | public static fi nal class AES192 ext ends AESWr apCipher { | |
58 | pu blic AES19 2() { | |
59 | super(24 ); | |
60 | } | |
61 | } | |
62 | public static fi nal class AES256 ext ends AESWr apCipher { | |
63 | pu blic AES25 6() { | |
64 | super(32 ); | |
65 | } | |
66 | } | |
67 | privat e static f inal byte[ ] IV = { | |
68 | (b yte) 0xA6, (byte) 0x A6, (byte) 0xA6, (by te) 0xA6, | |
69 | (b yte) 0xA6, (byte) 0x A6, (byte) 0xA6, (by te) 0xA6 | |
70 | }; | |
71 | ||
72 | privat e static f inal int b lksize = A ESConstant s.AES_BLOC K_SIZE; | |
73 | ||
74 | /* | |
75 | * int ernal ciph er object which does the real work. | |
76 | */ | |
77 | privat e AESCrypt cipher; | |
78 | ||
79 | /* | |
80 | * are we encryp ting or de crypting? | |
81 | */ | |
82 | privat e boolean decrypting = false; | |
83 | ||
84 | /* | |
85 | * nee ded to sup port AES o ids which associates a fixed k ey size | |
86 | * to the cipher object. | |
87 | */ | |
88 | privat e final in t fixedKey Size; // i n bytes, - 1 if no re striction | |
89 | ||
90 | /** | |
91 | * Cre ates an in stance of AES KeyWra p cipher w ith defaul t | |
92 | * mod e, i.e. "E CB" and pa dding sche me, i.e. " NoPadding" . | |
93 | */ | |
94 | public AESWrapCi pher(int k eySize) { | |
95 | ci pher = new AESCrypt( ); | |
96 | fi xedKeySize = keySize ; | |
97 | ||
98 | } | |
99 | ||
100 | /** | |
101 | * Set s the mode of this c ipher. Onl y "ECB" mo de is acce pted for t his | |
102 | * cip her. | |
103 | * | |
104 | * @pa ram mode t he cipher mode | |
105 | * | |
106 | * @ex ception No SuchAlgori thmExcepti on if the requested cipher mod e | |
107 | * is not "ECB". | |
108 | */ | |
109 | protec ted void e ngineSetMo de(String mode) | |
110 | th rows NoSuc hAlgorithm Exception { | |
111 | if (!mode.eq ualsIgnore Case("ECB" )) { | |
112 | throw ne w NoSuchAl gorithmExc eption(mod e + " cann ot be used "); | |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
117 | * Set s the padd ing mechan ism of thi s cipher. Only "NoPa dding" sch mem | |
118 | * is accepted f or this ci pher. | |
119 | * | |
120 | * @pa ram paddin g the padd ing mechan ism | |
121 | * | |
122 | * @ex ception No SuchPaddin gException if the re quested pa dding mech anism | |
123 | * is not "NoPad ding". | |
124 | */ | |
125 | protec ted void e ngineSetPa dding(Stri ng padding ) | |
126 | th rows NoSuc hPaddingEx ception { | |
127 | if (!padding .equalsIgn oreCase("N oPadding") ) { | |
128 | throw ne w NoSuchPa ddingExcep tion(paddi ng + " can not be use d"); | |
129 | } | |
130 | } | |
131 | ||
132 | /** | |
133 | * Ret urns the b lock size (in bytes) . i.e. 16 bytes. | |
134 | * | |
135 | * @re turn the b lock size (in bytes) , i.e. 16 bytes. | |
136 | */ | |
137 | protec ted int en gineGetBlo ckSize() { | |
138 | re turn blksi ze; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Ret urns the l ength in b ytes that an output buffer wou ld need to be | |
143 | * giv en the inp ut length <code>inpu tLen</code > (in byte s). | |
144 | * | |
145 | * <p> The actual output le ngth of th e next <co de>update< /code> or | |
146 | * <co de>doFinal </code> ca ll may be smaller th an the len gth return ed | |
147 | * by this metho d. | |
148 | * | |
149 | * @pa ram inputL en the inp ut length (in bytes) | |
150 | * | |
151 | * @re turn the r equired ou tput buffe r size (in bytes) | |
152 | */ | |
153 | protec ted int en gineGetOut putSize(in t inputLen ) { | |
154 | // can only return an upper-limi t if not i nitialized yet. | |
155 | in t result = 0; | |
156 | if (decrypti ng) { | |
157 | result = inputLen - 8; | |
158 | } else { | |
159 | result = Math.addE xact(input Len, 8); | |
160 | } | |
161 | re turn (resu lt < 0? 0: result); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Ret urns the i nitializat ion vector (IV) whic h is null for this c ipher. | |
166 | * | |
167 | * @re turn null for this c ipher. | |
168 | */ | |
169 | protec ted byte[] engineGet IV() { | |
170 | re turn null; | |
171 | } | |
172 | ||
173 | /** | |
174 | * Ini tializes t his cipher with a ke y and a so urce of ra ndomness. | |
175 | * | |
176 | * <p> The cipher only supp orts the f ollowing t wo operati on modes:< b> | |
177 | * Cip her.WRAP_M ODE, and < b> | |
178 | * Cip her.UNWRAP _MODE. | |
179 | * <p> For modes other than the above two, Unsu pportedOpe rationExce ption | |
180 | * wil l be throw n. | |
181 | * | |
182 | * @pa ram opmode the opera tion mode of this ci pher. Only | |
183 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) a re accepte d. | |
184 | * @param k ey the PW key. | |
185 | * @pa ram random the sourc e of rando mness. | |
186 | * | |
187 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
188 | * ini tializing this ciphe r. | |
189 | */ | |
190 | protec ted void e ngineInit( int opmode , Key key, SecureRan dom random ) | |
191 | th rows Inval idKeyExcep tion { | |
192 | if (opmode = = Cipher.W RAP_MODE) { | |
193 | decrypti ng = false ; | |
194 | } else if (o pmode == C ipher.UNWR AP_MODE) { | |
195 | decrypti ng = true; | |
196 | } else { | |
197 | throw ne w Unsuppor tedOperati onExceptio n("This ci pher can " + | |
198 | "onl y be used for key wr apping and unwrappin g"); | |
199 | } | |
200 | AE SCipher.ch eckKeySize (key, fixe dKeySize); | |
201 | ci pher.init( decrypting , key.getA lgorithm() , key.getE ncoded()); | |
202 | } | |
203 | ||
204 | /** | |
205 | * Ini tializes t his cipher with a ke y, a set o f algorith m paramete rs, | |
206 | * and a source of randomn ess. | |
207 | * | |
208 | * <p> The cipher only supp orts the f ollowing t wo operati on modes:< b> | |
209 | * Cip her.WRAP_M ODE, and < b> | |
210 | * Cip her.UNWRAP _MODE. | |
211 | * <p> For modes other than the above two, Unsu pportedOpe rationExce ption | |
212 | * wil l be throw n. | |
213 | * | |
214 | * @pa ram opmode the opera tion mode of this ci pher. Only | |
215 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) a re accepte d. | |
216 | * @param k ey the PW key. | |
217 | * @pa ram params the algor ithm param eters; mus t be null for this c ipher. | |
218 | * @pa ram random the sourc e of rando mness. | |
219 | * | |
220 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
221 | * ini tializing this ciphe r | |
222 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
223 | * par ameters is not null. | |
224 | */ | |
225 | protec ted void e ngineInit( int opmode , Key key, | |
226 | AlgorithmP arameterSp ec params, | |
227 | SecureRand om random) | |
228 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
229 | if (params ! = null) { | |
230 | throw ne w InvalidA lgorithmPa rameterExc eption("Th is cipher " + | |
231 | "doe s not acce pt any par ameters"); | |
232 | } | |
233 | en gineInit(o pmode, key , random); | |
234 | } | |
235 | ||
236 | /** | |
237 | * Ini tializes t his cipher with a ke y, a set o f algorith m paramete rs, | |
238 | * and a source of randomn ess. | |
239 | * | |
240 | * <p> The cipher only supp orts the f ollowing t wo operati on modes:< b> | |
241 | * Cip her.WRAP_M ODE, and < b> | |
242 | * Cip her.UNWRAP _MODE. | |
243 | * <p> For modes other than the above two, Unsu pportedOpe rationExce ption | |
244 | * wil l be throw n. | |
245 | * | |
246 | * @pa ram opmode the opera tion mode of this ci pher. Only | |
247 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) a re accepte d. | |
248 | * @param k ey the PW key. | |
249 | * @pa ram params the algor ithm param eters; mus t be null for this c ipher. | |
250 | * @pa ram random the sourc e of rando mness. | |
251 | * | |
252 | * @ex ception In validKeyEx ception if the given key is in appropriat e. | |
253 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
254 | * par ameters is not null. | |
255 | */ | |
256 | protec ted void e ngineInit( int opmode , Key key, | |
257 | AlgorithmP arameters params, | |
258 | SecureRand om random) | |
259 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
260 | if (params ! = null) { | |
261 | throw ne w InvalidA lgorithmPa rameterExc eption("Th is cipher " + | |
262 | "doe s not acce pt any par ameters"); | |
263 | } | |
264 | en gineInit(o pmode, key , random); | |
265 | } | |
266 | ||
267 | /** | |
268 | * Thi s operatio n is not s upported b y this cip her. | |
269 | * Sin ce it's im possible t o initiali ze this ci pher given the | |
270 | * cur rent Ciphe r.engineIn it(...) im plementati on, | |
271 | * Ill egalStateE xception w ill always be thrown upon invo cation. | |
272 | * | |
273 | * @pa ram in the input buf fer. | |
274 | * @pa ram inOffs et the off set in <co de>in</cod e> where t he input | |
275 | * sta rts. | |
276 | * @pa ram inLen the input length. | |
277 | * | |
278 | * @re turn n/a. | |
279 | * | |
280 | * @ex ception Il legalState Exception upon invoc ation of t his method . | |
281 | */ | |
282 | protec ted byte[] engineUpd ate(byte[] in, int i nOffset, i nt inLen) { | |
283 | th row new Il legalState Exception( "Cipher ha s not been initializ ed"); | |
284 | } | |
285 | ||
286 | /** | |
287 | * Thi s operatio n is not s upported b y this cip her. | |
288 | * Sin ce it's im possible t o initiali ze this ci pher given the | |
289 | * cur rent Ciphe r.engineIn it(...) im plementati on, | |
290 | * Ill egalStateE xception w ill always be thrown upon invo cation. | |
291 | * | |
292 | * @pa ram in the input buf fer. | |
293 | * @pa ram inOffs et the off set in <co de>in</cod e> where t he input | |
294 | * sta rts. | |
295 | * @pa ram inLen the input length. | |
296 | * @pa ram out th e buffer f or the res ult. | |
297 | * @pa ram outOff set the of fset in <c ode>out</c ode> where the resul t | |
298 | * is stored. | |
299 | * | |
300 | * @re turn n/a. | |
301 | * | |
302 | * @ex ception Il legalState Exception upon invoc ation of t his method . | |
303 | */ | |
304 | protec ted int en gineUpdate (byte[] in , int inOf fset, int inLen, | |
305 | byte[] ou t, int out Offset) | |
306 | th rows Short BufferExce ption { | |
307 | th row new Il legalState Exception( "Cipher ha s not been initializ ed"); | |
308 | } | |
309 | ||
310 | /** | |
311 | * Thi s operatio n is not s upported b y this cip her. | |
312 | * Sin ce it's im possible t o initiali ze this ci pher given the | |
313 | * cur rent Ciphe r.engineIn it(...) im plementati on, | |
314 | * Ill egalStateE xception w ill always be thrown upon invo cation. | |
315 | * | |
316 | * @pa ram in the input buf fer | |
317 | * @pa ram inOffs et the off set in <co de>in</cod e> where t he input | |
318 | * sta rts | |
319 | * @pa ram inLen the input length. | |
320 | * | |
321 | * @re turn n/a. | |
322 | * | |
323 | * @ex ception Il legalState Exception upon invoc ation of t his method . | |
324 | */ | |
325 | protec ted byte[] engineDoF inal(byte[ ] input, i nt inputOf fset, | |
326 | int i nputLen) | |
327 | th rows Illeg alBlockSiz eException , BadPaddi ngExceptio n { | |
328 | th row new Il legalState Exception( "Cipher ha s not been initializ ed"); | |
329 | } | |
330 | ||
331 | /** | |
332 | * Thi s operatio n is not s upported b y this cip her. | |
333 | * Sin ce it's im possible t o initiali ze this ci pher given the | |
334 | * cur rent Ciphe r.engineIn it(...) im plementati on, | |
335 | * Ill egalStateE xception w ill always be thrown upon invo cation. | |
336 | * | |
337 | * @pa ram in the input buf fer. | |
338 | * @pa ram inOffs et the off set in <co de>in</cod e> where t he input | |
339 | * sta rts. | |
340 | * @pa ram inLen the input length. | |
341 | * @pa ram out th e buffer f or the res ult. | |
342 | * @pa ram outOff set the of set in <co de>out</co de> where the result | |
343 | * is stored. | |
344 | * | |
345 | * @re turn n/a. | |
346 | * | |
347 | * @ex ception Il legalState Exception upon invoc ation of t his method . | |
348 | */ | |
349 | protec ted int en gineDoFina l(byte[] i n, int inO ffset, int inLen, | |
350 | byte[] o ut, int ou tOffset) | |
351 | th rows Illeg alBlockSiz eException , ShortBuf ferExcepti on, | |
352 | BadPa ddingExcep tion { | |
353 | th row new Il legalState Exception( "Cipher ha s not been initializ ed"); | |
354 | } | |
355 | ||
356 | /** | |
357 | * Ret urns the p arameters used with this ciphe r which is always nu ll | |
358 | * for this ciph er. | |
359 | * | |
360 | * @re turn null since this cipher do es not use any param eters. | |
361 | */ | |
362 | protec ted Algori thmParamet ers engine GetParamet ers() { | |
363 | re turn null; | |
364 | } | |
365 | ||
366 | /** | |
367 | * Ret urns the k ey size of the given key objec t in numbe r of bits. | |
368 | * | |
369 | * @pa ram key th e key obje ct. | |
370 | * | |
371 | * @re turn the " effective" key size of the giv en key obj ect. | |
372 | * | |
373 | * @ex ception In validKeyEx ception if <code>key </code> is invalid. | |
374 | */ | |
375 | protec ted int en gineGetKey Size(Key k ey) throws InvalidKe yException { | |
376 | by te[] encod ed = key.g etEncoded( ); | |
377 | if (!AESCryp t.isKeySiz eValid(enc oded.lengt h)) { | |
378 | throw ne w InvalidK eyExceptio n("Invalid key lengt h: " + | |
379 | encoded. length + " bytes"); | |
380 | } | |
381 | re turn Math. multiplyEx act(encode d.length, 8); | |
382 | } | |
383 | ||
384 | /** | |
385 | * Wra p a key. | |
386 | * | |
387 | * @pa ram key th e key to b e wrapped. | |
388 | * | |
389 | * @re turn the w rapped key . | |
390 | * | |
391 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block | |
392 | * cip her, no pa dding has been reque sted, and the length of the | |
393 | * enc oding of t he key to be wrapped is not a | |
394 | * mul tiple of t he block s ize. | |
395 | * | |
396 | * @ex ception In validKeyEx ception if it is imp ossible or unsafe to | |
397 | * wra p the key with this cipher (e. g., a hard ware prote cted key i s | |
398 | * bei ng passed to a softw are only c ipher). | |
399 | */ | |
400 | protec ted byte[] engineWra p(Key key) | |
401 | th rows Illeg alBlockSiz eException , InvalidK eyExceptio n { | |
402 | by te[] keyVa l = key.ge tEncoded() ; | |
403 | if ((keyVal == null) | | (keyVal. length == 0)) { | |
404 | throw ne w InvalidK eyExceptio n("Cannot get an enc oding of " + | |
405 | "the key to be wra pped"); | |
406 | } | |
407 | by te[] out = new byte[ Math.addEx act(keyVal .length, 8 )]; | |
408 | ||
409 | if (keyVal.l ength == 8 ) { | |
410 | System.a rraycopy(I V, 0, out, 0, IV.len gth); | |
411 | System.a rraycopy(k eyVal, 0, out, IV.le ngth, 8); | |
412 | cipher.e ncryptBloc k(out, 0, out, 0); | |
413 | } else { | |
414 | if (keyV al.length % 8 != 0) { | |
415 | thro w new Ille galBlockSi zeExceptio n("length of the " + | |
416 | "to be wra pped key s hould be m ultiples o f 8 bytes" ); | |
417 | } | |
418 | System.a rraycopy(I V, 0, out, 0, IV.len gth); | |
419 | System.a rraycopy(k eyVal, 0, out, IV.le ngth, keyV al.length) ; | |
420 | int N = keyVal.len gth/8; | |
421 | byte[] b uffer = ne w byte[blk size]; | |
422 | for (int j = 0; j < 6; j++) { | |
423 | for (int i = 1 ; i <= N; i++) { | |
424 | int T = i + j*N; | |
425 | System.arr aycopy(out , 0, buffe r, 0, IV.l ength); | |
426 | System.arr aycopy(out , i*8, buf fer, IV.le ngth, 8); | |
427 | cipher.enc ryptBlock( buffer, 0, buffer, 0 ); | |
428 | for (int k = 1; T != 0; k++) { | |
429 | byte v = (byte) T; | |
430 | buffer [IV.length - k] ^= v ; | |
431 | T >>>= 8; | |
432 | } | |
433 | System.arr aycopy(buf fer, 0, ou t, 0, IV.l ength); | |
434 | System.arr aycopy(buf fer, 8, ou t, 8*i, 8) ; | |
435 | } | |
436 | } | |
437 | } | |
438 | re turn out; | |
439 | } | |
440 | ||
441 | /** | |
442 | * Unw rap a prev iously wra pped key. | |
443 | * | |
444 | * @pa ram wrappe dKey the k ey to be u nwrapped. | |
445 | * | |
446 | * @pa ram wrappe dKeyAlgori thm the al gorithm th e wrapped key is for . | |
447 | * | |
448 | * @pa ram wrappe dKeyType t he type of the wrapp ed key. | |
449 | * Thi s is one o f <code>Ci pher.SECRE T_KEY</cod e>, | |
450 | * <co de>Cipher. PRIVATE_KE Y</code>, or <code>C ipher.PUBL IC_KEY</co de>. | |
451 | * | |
452 | * @re turn the u nwrapped k ey. | |
453 | * | |
454 | * @ex ception No SuchAlgori thmExcepti on if no i nstalled p roviders | |
455 | * can create ke ys of type <code>wra ppedKeyTyp e</code> f or the | |
456 | * <co de>wrapped KeyAlgorit hm</code>. | |
457 | * | |
458 | * @ex ception In validKeyEx ception if <code>wra ppedKey</c ode> does not | |
459 | * rep resent a w rapped key of type < code>wrapp edKeyType< /code> for | |
460 | * the <code>wra ppedKeyAlg orithm</co de>. | |
461 | */ | |
462 | protec ted Key en gineUnwrap (byte[] wr appedKey, | |
463 | String wr appedKeyAl gorithm, | |
464 | int wrapp edKeyType) | |
465 | th rows Inval idKeyExcep tion, NoSu chAlgorith mException { | |
466 | in t wrappedK eyLen = wr appedKey.l ength; | |
467 | // ensure th e wrappedK ey length is multipl es of 8 by tes and no n-zero | |
468 | if (wrappedK eyLen == 0 ) { | |
469 | throw ne w InvalidK eyExceptio n("The wra pped key i s empty"); | |
470 | } | |
471 | if (wrappedK eyLen % 8 != 0) { | |
472 | throw ne w InvalidK eyExceptio n | |
473 | ("Th e wrapped key has in valid key length"); | |
474 | } | |
475 | by te[] out = new byte[ wrappedKey Len - 8]; | |
476 | by te[] buffe r = new by te[blksize ]; | |
477 | if (wrappedK eyLen == 1 6) { | |
478 | cipher.d ecryptBloc k(wrappedK ey, 0, buf fer, 0); | |
479 | for (int i = 0; i < IV.lengt h; i++) { | |
480 | if ( IV[i] != b uffer[i]) { | |
481 | throw new InvalidKey Exception( "Integrity check fai led"); | |
482 | } | |
483 | } | |
484 | System.a rraycopy(b uffer, IV. length, ou t, 0, out. length); | |
485 | } else { | |
486 | System.a rraycopy(w rappedKey, 0, buffer , 0, IV.le ngth); | |
487 | System.a rraycopy(w rappedKey, IV.length , out, 0, out.length ); | |
488 | int N = out.length /8; | |
489 | for (int j = 5; j >= 0; j--) { | |
490 | for (int i = N ; i > 0; i --) { | |
491 | int T = i + j*N; | |
492 | System.arr aycopy(out , 8*(i-1), buffer, I V.length, 8); | |
493 | for (int k = 1; T != 0; k++) { | |
494 | byte v = (byte) T; | |
495 | buffer [IV.length - k] ^= v ; | |
496 | T >>>= 8; | |
497 | } | |
498 | cipher.dec ryptBlock( buffer, 0, buffer, 0 ); | |
499 | System.arr aycopy(buf fer, IV.le ngth, out, 8*(i-1), 8); | |
500 | } | |
501 | } | |
502 | for (int i = 0; i < IV.lengt h; i++) { | |
503 | if ( IV[i] != b uffer[i]) { | |
504 | throw new InvalidKey Exception( "Integrity check fai led"); | |
505 | } | |
506 | } | |
507 | } | |
508 | re turn Const ructKeys.c onstructKe y(out, wra ppedKeyAlg orithm, | |
509 | wrappedK eyType); | |
510 | } | |
511 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.