Produced by Araxis Merge on 9/25/2018 2:13:02 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 | PBMAC1Core.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 | PBMAC1Core.java | Wed Sep 12 16:22:40 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 432 |
Changed | 2 | 4 |
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 3, 2013, 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.nio.Byte Buffer; | |
30 | ||
31 | import jav ax.crypto. MacSpi; | |
32 | import jav ax.crypto. SecretKey; | |
33 | import jav ax.crypto. spec.Secre tKeySpec; | |
34 | import jav ax.crypto. spec.PBEKe ySpec; | |
35 | import jav ax.crypto. spec.PBEPa rameterSpe c; | |
36 | import jav a.security .*; | |
37 | import jav a.security .spec.*; | |
38 | ||
39 | /** | |
40 | * This is an implem entation o f the PBMA C1 algorit hms as def ined | |
41 | * in PKCS #5 v2.1 st andard. | |
42 | */ | |
43 | abstract c lass PBMAC 1Core exte nds HmacCo re { | |
44 | ||
45 | // NOT E: this cl ass inheri ts the Clo neable int erface fro m HmacCore | |
46 | // Nee d to overr ide clone( ) if mutab le fields are added. | |
47 | privat e final St ring kdfAl go; | |
48 | privat e final St ring hashA lgo; | |
49 | privat e final in t blockLen gth; // in octets | |
50 | ||
51 | /** | |
52 | * Cre ates an in stance of PBMAC1 acc ording to the select ed | |
53 | * pas sword-base d key deri vation fun ction. | |
54 | */ | |
55 | PBMAC1 Core(Strin g kdfAlgo, String ha shAlgo, in t blockLen gth) | |
56 | th rows NoSuc hAlgorithm Exception { | |
57 | su per(hashAl go, blockL ength); | |
58 | th is.kdfAlgo = kdfAlgo ; | |
59 | th is.hashAlg o = hashAl go; | |
60 | th is.blockLe ngth = blo ckLength; | |
61 | } | |
62 | ||
63 | privat e static P BKDF2Core getKDFImpl (String al go) { | |
64 | PB KDF2Core k df = null; | |
65 | sw itch(algo) { | |
66 | ca se "HmacSH A1": | |
67 | kdf = new PBKD F2Core.Hma cSHA1(); | |
68 | brea k; | |
69 | ca se "HmacSH A224": | |
70 | kdf = new PBKD F2Core.Hma cSHA224(); | |
71 | brea k; | |
72 | ca se "HmacSH A256": | |
73 | kdf = new PBKD F2Core.Hma cSHA256(); | |
74 | brea k; | |
75 | ca se "HmacSH A384": | |
76 | kdf = new PBKD F2Core.Hma cSHA384(); | |
77 | brea k; | |
78 | ca se "HmacSH A512": | |
79 | kdf = new PBKD F2Core.Hma cSHA512(); | |
80 | brea k; | |
81 | de fault: | |
82 | thro w new Prov iderExcept ion( | |
83 | "No MAC im plementati on for " + algo); | |
84 | } | |
85 | re turn kdf; | |
86 | } | |
87 | ||
88 | /** | |
89 | * Initiali zes the HM AC with th e given PW key and al gorithm pa rameters. | |
90 | * | |
91 | * @param k ey the PW key. | |
92 | * @pa ram params the algor ithm param eters. | |
93 | * | |
94 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
95 | * ini tializing this MAC. | |
96 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
97 | * par ameters ar e inapprop riate for this MAC. | |
98 | */ | |
99 | protec ted void e ngineInit( Key key, A lgorithmPa rameterSpe c params) | |
100 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
101 | ch ar[] passw dChars; | |
102 | by te[] salt = null; | |
103 | in t iCount = 0; | |
104 | if (key inst anceof jav ax.crypto. interfaces .PBEKey) { | |
105 | javax.cr ypto.inter faces.PBEK ey pbeKey = | |
106 | (jav ax.crypto. interfaces .PBEKey) k ey; | |
107 | passwdCh ars = pbeK ey.getPass word(); | |
108 | salt = p beKey.getS alt(); // maybe null if unspec ified | |
109 | iCount = pbeKey.ge tIteration Count(); / / maybe 0 if unspeci fied | |
110 | } else if (k ey instanc eof Secret Key) { | |
111 | byte[] p asswdBytes = key.get Encoded(); | |
112 | if ((pas swdBytes = = null) || | |
113 | !(ke y.getAlgor ithm().reg ionMatches (true, 0, "PBE", 0, 3))) { | |
114 | thro w new Inva lidKeyExce ption("Mis sing passw ord"); | |
115 | } | |
116 | passwdCh ars = new char[passw dBytes.len gth]; | |
117 | for (int i=0; i<pa sswdChars. length; i+ +) { | |
118 | pass wdChars[i] = (char) (passwdByt es[i] & 0x 7f); | |
119 | } | |
120 | } else { | |
121 | throw ne w InvalidK eyExceptio n("SecretK ey of PBE type requi red"); | |
122 | } | |
123 | if (params = = null) { | |
124 | // shoul d not auto -generate default va lues since current | |
125 | // javax .crypto.Ma c api does not have any method for calle r to | |
126 | // retri eve the ge nerated de faults. | |
127 | if ((sal t == null) || (iCoun t == 0)) { | |
128 | thro w new Inva lidAlgorit hmParamete rException | |
129 | ("PBEParam eterSpec r equired fo r salt and iteration count"); | |
130 | } | |
131 | } else if (! (params in stanceof P BEParamete rSpec)) { | |
132 | throw ne w InvalidA lgorithmPa rameterExc eption | |
133 | ("PB EParameter Spec type required") ; | |
134 | } else { | |
135 | PBEParam eterSpec p beParams = (PBEParam eterSpec) params; | |
136 | // make sure the p arameter v alues are consistent | |
137 | if (salt != null) { | |
138 | if ( !Arrays.eq uals(salt, pbeParams .getSalt() )) { | |
139 | throw new InvalidAlg orithmPara meterExcep tion | |
140 | ("Inco nsistent v alue of sa lt between key and p arams"); | |
141 | } | |
142 | } else { | |
143 | salt = pbePara ms.getSalt (); | |
144 | } | |
145 | if (iCou nt != 0) { | |
146 | if ( iCount != pbeParams. getIterati onCount()) { | |
147 | throw new InvalidAlg orithmPara meterExcep tion | |
148 | ("Diff erent iter ation coun t between key and pa rams"); | |
149 | } | |
150 | } else { | |
151 | iCou nt = pbePa rams.getIt erationCou nt(); | |
152 | } | |
153 | } | |
154 | // For secur ity purpos e, we need to enforc e a minimu m length | |
155 | // for salt; just requ ire the mi nimum salt length to be 8-byte | |
156 | // which is what PKCS# 5 recommen ds and ope nssl does. | |
157 | if (salt.len gth < 8) { | |
158 | throw ne w InvalidA lgorithmPa rameterExc eption | |
159 | ("Sa lt must be at least 8 bytes lo ng"); | |
160 | } | |
161 | if (iCount < = 0) { | |
162 | throw ne w InvalidA lgorithmPa rameterExc eption | |
163 | ("It erationCou nt must be a positiv e number") ; | |
164 | } | |
165 | ||
166 | PB EKeySpec p beSpec = | |
167 | new PBEK eySpec(pas swdChars, salt, iCou nt, blockL ength); | |
168 | // passw ord char[] was clone d in PBEKe ySpec cons tructor, | |
169 | // so we can zero it out her e | |
170 | ja va.util.Ar rays.fill( passwdChar s, ' '); | |
171 | ||
172 | Se cretKey s = null; | |
173 | PB KDF2Core k df = getKD FImpl(kdfA lgo); | |
174 | tr y { | |
175 | s = kdf. engineGene rateSecret (pbeSpec); | |
176 | ||
177 | } catch (Inv alidKeySpe cException ikse) { | |
178 | InvalidK eyExceptio n ike = | |
179 | new InvalidKey Exception( "Cannot co nstruct PB E key"); | |
180 | ike.init Cause(ikse ); | |
181 | throw ik e; | |
182 | } | |
183 | by te[] deriv edKey = s. getEncoded (); | |
184 | Se cretKey ci pherKey = new Secret KeySpec(de rivedKey, kdfAlgo); | |
185 | ||
186 | su per.engine Init(ciphe rKey, null ); | |
187 | } | |
188 | ||
189 | public static fi nal class HmacSHA1 e xtends PBM AC1Core { | |
190 | pu blic HmacS HA1() thro ws NoSuchA lgorithmEx ception { | |
191 | super("H macSHA1", "SHA1", 64 ); | |
192 | } | |
193 | } | |
194 | ||
195 | public static fi nal class HmacSHA224 extends P BMAC1Core { | |
196 | pu blic HmacS HA224() th rows NoSuc hAlgorithm Exception { | |
197 | super("H macSHA224" , "SHA-224 ", 64); | |
198 | } | |
199 | } | |
200 | ||
201 | public static fi nal class HmacSHA256 extends P BMAC1Core { | |
202 | pu blic HmacS HA256() th rows NoSuc hAlgorithm Exception { | |
203 | super("H macSHA256" , "SHA-256 ", 64); | |
204 | } | |
205 | } | |
206 | ||
207 | public static fi nal class HmacSHA384 extends P BMAC1Core { | |
208 | pu blic HmacS HA384() th rows NoSuc hAlgorithm Exception { | |
209 | super("H macSHA384" , "SHA-384 ", 128); | |
210 | } | |
211 | } | |
212 | ||
213 | public static fi nal class HmacSHA512 extends P BMAC1Core { | |
214 | pu blic HmacS HA512() th rows NoSuc hAlgorithm Exception { | |
215 | super("H macSHA512" , "SHA-512 ", 128); | |
216 | } | |
217 | } | |
218 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.