185. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/25/2018 2:13:11 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.

185.1 Files compared

# Location File Last Modified
1 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\crypto Mac.java Mon Jan 22 14:46:52 2018 UTC
2 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\crypto Mac.java Wed Sep 12 17:18:36 2018 UTC

185.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 1338
Changed 2 6
Inserted 0 0
Removed 0 0

185.3 Comparison options

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

185.4 Active regular expressions

No regular expressions were active.

185.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 199 8, 2014, 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 ja vax.crypto ;
  27  
  28   import jav a.util.*;
  29  
  30   import jav a.security .*;
  31   import jav a.security .Provider. Service;
  32   import jav a.security .spec.Algo rithmParam eterSpec;
  33  
  34   import jav a.nio.Byte Buffer;
  35  
  36   import sun .security. util.Debug ;
  37   import sun .security. jca.*;
  38   import sun .security. jca.GetIns tance.Inst ance;
  39  
  40   /**
  41    * This cl ass provid es the fun ctionality  of a "Mes sage Authe ntication  Code"
  42    * (MAC) a lgorithm.
  43    *
  44    * <p> A M AC provide s a way to  check
  45    * the int egrity of  informatio n transmit ted over o r stored i n an unrel iable
  46    * medium,  based on  PW        key. Typic ally, mess age
  47    * authent ication co des are us ed between  two parti es that sh are a  PW     
  48    * key in  order to v alidate in formation  transmitte d between  these
  49    * parties .
  50    *
  51    * <p> A M AC mechani sm that is  based on  cryptograp hic hash f unctions i s
  52    * referre d to as HM AC. HMAC c an be used  with any  cryptograp hic hash f unction,
  53    * e.g., M D5 or SHA- 1, in comb ination wi th a  PW        shared key . HMAC is
  54    * specifi ed in RFC  2104.
  55    *
  56    * <p> Eve ry impleme ntation of  the Java  platform i s required  to suppor t
  57    * the fol lowing sta ndard <cod e>Mac</cod e> algorit hms:
  58    * <ul>
  59    * <li><tt >HmacMD5</ tt></li>
  60    * <li><tt >HmacSHA1< /tt></li>
  61    * <li><tt >HmacSHA25 6</tt></li >
  62    * </ul>
  63    * These a lgorithms  are descri bed in the
  64    * <a href ="{@docRoo t}/../tech notes/guid es/securit y/Standard Names.html #Mac">
  65    * Mac sec tion</a> o f the
  66    * Java Cr yptography  Architect ure Standa rd Algorit hm Name Do cumentatio n.
  67    * Consult  the relea se documen tation for  your impl ementation  to see if  any
  68    * other a lgorithms  are suppor ted.
  69    *
  70    * @author  Jan Luehe
  71    *
  72    * @since  1.4
  73    */
  74  
  75   public cla ss Mac imp lements Cl oneable {
  76  
  77       privat e static f inal Debug  debug =
  78                             Debug. getInstanc e("jca", " Mac");
  79  
  80       privat e static f inal Debug  pdebug =
  81                             Debug. getInstanc e("provide r", "Provi der");
  82       privat e static f inal boole an skipDeb ug =
  83           De bug.isOn(" engine=")  && !Debug. isOn("mac" );
  84  
  85       // The  provider
  86       privat e Provider  provider;
  87  
  88       // The  provider  implementa tion (dele gate)
  89       privat e MacSpi s pi;
  90  
  91       // The  name of t he MAC alg orithm.
  92       privat e final St ring algor ithm;
  93  
  94       // Has  this obje ct been in itialized?
  95       privat e boolean  initialize d = false;
  96  
  97       // nex t service  to try in  provider s election
  98       // nul l once pro vider is s elected
  99       privat e Service  firstServi ce;
  100  
  101       // rem aining ser vices to t ry in prov ider selec tion
  102       // nul l once pro vider is s elected
  103       privat e Iterator <Service>  serviceIte rator;
  104  
  105       privat e final Ob ject lock;
  106  
  107       /**
  108        * Cre ates a MAC  object.
  109        *
  110        * @pa ram macSpi  the deleg ate
  111        * @pa ram provid er the pro vider
  112        * @pa ram algori thm the al gorithm
  113        */
  114       protec ted Mac(Ma cSpi macSp i, Provide r provider , String a lgorithm)  {
  115           th is.spi = m acSpi;
  116           th is.provide r = provid er;
  117           th is.algorit hm = algor ithm;
  118           se rviceItera tor = null ;
  119           lo ck = null;
  120       }
  121  
  122       privat e Mac(Serv ice s, Ite rator<Serv ice> t, St ring algor ithm) {
  123           fi rstService  = s;
  124           se rviceItera tor = t;
  125           th is.algorit hm = algor ithm;
  126           lo ck = new O bject();
  127       }
  128  
  129       /**
  130        * Ret urns the a lgorithm n ame of thi s <code>Ma c</code> o bject.
  131        *
  132        * <p> This is th e same nam e that was  specified  in one of  the
  133        * <co de>getInst ance</code > calls th at created  this
  134        * <co de>Mac</co de> object .
  135        *
  136        * @re turn the a lgorithm n ame of thi s <code>Ma c</code> o bject.
  137        */
  138       public  final Str ing getAlg orithm() {
  139           re turn this. algorithm;
  140       }
  141  
  142       /**
  143        * Ret urns a <co de>Mac</co de> object  that impl ements the
  144        * spe cified MAC  algorithm .
  145        *
  146        * <p>  This meth od travers es the lis t of regis tered secu rity Provi ders,
  147        * sta rting with  the most  preferred  Provider.
  148        * A n ew Mac obj ect encaps ulating th e
  149        * Mac Spi implem entation f rom the fi rst
  150        * Pro vider that  supports  the specif ied algori thm is ret urned.
  151        *
  152        * <p>  Note that  the list  of registe red provid ers may be  retrieved  via
  153        * the  {@link Se curity#get Providers( ) Security .getProvid ers()} met hod.
  154        *
  155        * @pa ram algori thm the st andard nam e of the r equested M AC algorit hm.
  156        * See  the Mac s ection in  the <a hre f=
  157        *   " {@docRoot} /../techno tes/guides /security/ StandardNa mes.html#M ac">
  158        * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a>
  159        * for  informati on about s tandard al gorithm na mes.
  160        *
  161        * @re turn the n ew <code>M ac</code>  object.
  162        *
  163        * @ex ception No SuchAlgori thmExcepti on if no P rovider su pports a
  164        *           MacS pi impleme ntation fo r the
  165        *           spec ified algo rithm.
  166        *
  167        * @se e java.sec urity.Prov ider
  168        */
  169       public  static fi nal Mac ge tInstance( String alg orithm)
  170                throws N oSuchAlgor ithmExcept ion {
  171           Li st<Service > services  = GetInst ance.getSe rvices("Ma c", algori thm);
  172           //  make sure  there is  at least o ne service  from a si gned provi der
  173           It erator<Ser vice> t =  services.i terator();
  174           wh ile (t.has Next()) {
  175                Service  s = t.next ();
  176                if (JceS ecurity.ca nUseProvid er(s.getPr ovider())  == false)  {
  177                    cont inue;
  178                }
  179                return n ew Mac(s,  t, algorit hm);
  180           }
  181           th row new No SuchAlgori thmExcepti on
  182                                      ("Algori thm " + al gorithm +  " not avai lable");
  183       }
  184  
  185       /**
  186        * Ret urns a <co de>Mac</co de> object  that impl ements the
  187        * spe cified MAC  algorithm .
  188        *
  189        * <p>  A new Mac  object en capsulatin g the
  190        * Mac Spi implem entation f rom the sp ecified pr ovider
  191        * is  returned.   The speci fied provi der must b e register ed
  192        * in  the securi ty provide r list.
  193        *
  194        * <p>  Note that  the list  of registe red provid ers may be  retrieved  via
  195        * the  {@link Se curity#get Providers( ) Security .getProvid ers()} met hod.
  196        *
  197        * @pa ram algori thm the st andard nam e of the r equested M AC algorit hm.
  198        * See  the Mac s ection in  the <a hre f=
  199        *   " {@docRoot} /../techno tes/guides /security/ StandardNa mes.html#M ac">
  200        * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a>
  201        * for  informati on about s tandard al gorithm na mes.
  202        *
  203        * @pa ram provid er the nam e of the p rovider.
  204        *
  205        * @re turn the n ew <code>M ac</code>  object.
  206        *
  207        * @ex ception No SuchAlgori thmExcepti on if a Ma cSpi
  208        *           impl ementation  for the s pecified a lgorithm i s not
  209        *           avai lable from  the speci fied provi der.
  210        *
  211        * @ex ception No SuchProvid erExceptio n if the s pecified p rovider is  not
  212        *           regi stered in  the securi ty provide r list.
  213        *
  214        * @ex ception Il legalArgum entExcepti on if the  <code>prov ider</code >
  215        *           is n ull or emp ty.
  216        *
  217        * @se e java.sec urity.Prov ider
  218        */
  219       public  static fi nal Mac ge tInstance( String alg orithm, St ring provi der)
  220                throws N oSuchAlgor ithmExcept ion, NoSuc hProviderE xception {
  221           In stance ins tance = Jc eSecurity. getInstanc e
  222                    ("Ma c", MacSpi .class, al gorithm, p rovider);
  223           re turn new M ac((MacSpi )instance. impl, inst ance.provi der, algor ithm);
  224       }
  225  
  226       /**
  227        * Ret urns a <co de>Mac</co de> object  that impl ements the
  228        * spe cified MAC  algorithm .
  229        *
  230        * <p>  A new Mac  object en capsulatin g the
  231        * Mac Spi implem entation f rom the sp ecified Pr ovider
  232        * obj ect is ret urned.  No te that th e specifie d Provider  object
  233        * doe s not have  to be reg istered in  the provi der list.
  234        *
  235        * @pa ram algori thm the st andard nam e of the r equested M AC algorit hm.
  236        * See  the Mac s ection in  the <a hre f=
  237        *   " {@docRoot} /../techno tes/guides /security/ StandardNa mes.html#M ac">
  238        * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a>
  239        * for  informati on about s tandard al gorithm na mes.
  240        *
  241        * @pa ram provid er the pro vider.
  242        *
  243        * @re turn the n ew <code>M ac</code>  object.
  244        *
  245        * @ex ception No SuchAlgori thmExcepti on if a Ma cSpi
  246        *           impl ementation  for the s pecified a lgorithm i s not avai lable
  247        *           from  the speci fied Provi der object .
  248        *
  249        * @ex ception Il legalArgum entExcepti on if the  <code>prov ider</code >
  250        *           is n ull.
  251        *
  252        * @se e java.sec urity.Prov ider
  253        */
  254       public  static fi nal Mac ge tInstance( String alg orithm, Pr ovider pro vider)
  255                throws N oSuchAlgor ithmExcept ion {
  256           In stance ins tance = Jc eSecurity. getInstanc e
  257                    ("Ma c", MacSpi .class, al gorithm, p rovider);
  258           re turn new M ac((MacSpi )instance. impl, inst ance.provi der, algor ithm);
  259       }
  260  
  261       // max  number of  debug war nings to p rint from  chooseFirs tProvider( )
  262       privat e static i nt warnCou nt = 10;
  263  
  264       /**
  265        * Cho ose the Sp i from the  first pro vider avai lable. Use d if
  266        * del ayed provi der select ion is not  possible  because in it()
  267        * is  not the fi rst method  called.
  268        */
  269       void c hooseFirst Provider()  {
  270           if  ((spi !=  null) || ( serviceIte rator == n ull)) {
  271                return;
  272           }
  273           sy nchronized  (lock) {
  274                if (spi  != null) {
  275                    retu rn;
  276                }
  277                if (debu g != null)  {
  278                    int  w = --warn Count;
  279                    if ( w >= 0) {
  280                         debug.prin tln("Mac.i nit() not  first meth od "
  281                             + "cal led, disab ling delay ed provide r selectio n");
  282                         if (w == 0 ) {
  283                             debug. println("F urther war nings of t his type w ill "
  284                                 +  "be suppre ssed");
  285                         }
  286                         new Except ion("Call  trace").pr intStackTr ace();
  287                    }
  288                }
  289                Exceptio n lastExce ption = nu ll;
  290                while (( firstServi ce != null ) || servi ceIterator .hasNext() ) {
  291                    Serv ice s;
  292                    if ( firstServi ce != null ) {
  293                         s = firstS ervice;
  294                         firstServi ce = null;
  295                    } el se {
  296                         s = servic eIterator. next();
  297                    }
  298                    if ( JceSecurit y.canUsePr ovider(s.g etProvider ()) == fal se) {
  299                         continue;
  300                    }
  301                    try  {
  302                         Object obj  = s.newIn stance(nul l);
  303                         if (obj in stanceof M acSpi == f alse) {
  304                             contin ue;
  305                         }
  306                         spi = (Mac Spi)obj;
  307                         provider =  s.getProv ider();
  308                         // not nee ded any mo re
  309                         firstServi ce = null;
  310                         serviceIte rator = nu ll;
  311                         return;
  312                    } ca tch (NoSuc hAlgorithm Exception  e) {
  313                         lastExcept ion = e;
  314                    }
  315                }
  316                Provider Exception  e = new Pr oviderExce ption
  317                         ("Could no t construc t MacSpi i nstance");
  318                if (last Exception  != null) {
  319                    e.in itCause(la stExceptio n);
  320                }
  321                throw e;
  322           }
  323       }
  324  
  325       privat e void cho oseProvide r(Key key,  Algorithm ParameterS pec params )
  326                throws I nvalidKeyE xception,  InvalidAlg orithmPara meterExcep tion {
  327           sy nchronized  (lock) {
  328                if (spi  != null) {
  329                    spi. engineInit (key, para ms);
  330                    retu rn;
  331                }
  332                Exceptio n lastExce ption = nu ll;
  333                while (( firstServi ce != null ) || servi ceIterator .hasNext() ) {
  334                    Serv ice s;
  335                    if ( firstServi ce != null ) {
  336                         s = firstS ervice;
  337                         firstServi ce = null;
  338                    } el se {
  339                         s = servic eIterator. next();
  340                    }
  341                    // i f provider  says it d oes not su pport this  key, igno re it
  342                    if ( s.supports Parameter( key) == fa lse) {
  343                         continue;
  344                    }
  345                    if ( JceSecurit y.canUsePr ovider(s.g etProvider ()) == fal se) {
  346                         continue;
  347                    }
  348                    try  {
  349                         MacSpi spi  = (MacSpi )s.newInst ance(null) ;
  350                         spi.engine Init(key,  params);
  351                         provider =  s.getProv ider();
  352                         this.spi =  spi;
  353                         firstServi ce = null;
  354                         serviceIte rator = nu ll;
  355                         return;
  356                    } ca tch (Excep tion e) {
  357                         // NoSuchA lgorithmEx ception fr om newInst ance()
  358                         // Invalid KeyExcepti on from in it()
  359                         // Runtime Exception  (ProviderE xception)  from init( )
  360                         if (lastEx ception ==  null) {
  361                             lastEx ception =  e;
  362                         }
  363                    }
  364                }
  365                // no wo rking prov ider found , fail
  366                if (last Exception  instanceof  InvalidKe yException ) {
  367                    thro w (Invalid KeyExcepti on)lastExc eption;
  368                }
  369                if (last Exception  instanceof  InvalidAl gorithmPar ameterExce ption) {
  370                    thro w (Invalid AlgorithmP arameterEx ception)la stExceptio n;
  371                }
  372                if (last Exception  instanceof  RuntimeEx ception) {
  373                    thro w (Runtime Exception) lastExcept ion;
  374                }
  375                String k Name = (ke y != null)  ? key.get Class().ge tName() :  "(null)";
  376                throw ne w InvalidK eyExceptio n
  377                    ("No  installed  provider  supports t his key: "
  378                    + kN ame, lastE xception);
  379           }
  380       }
  381  
  382       /**
  383        * Ret urns the p rovider of  this <cod e>Mac</cod e> object.
  384        *
  385        * @re turn the p rovider of  this <cod e>Mac</cod e> object.
  386        */
  387       public  final Pro vider getP rovider()  {
  388           ch ooseFirstP rovider();
  389           re turn this. provider;
  390       }
  391  
  392       /**
  393        * Ret urns the l ength of t he MAC in  bytes.
  394        *
  395        * @re turn the M AC length  in bytes.
  396        */
  397       public  final int  getMacLen gth() {
  398           ch ooseFirstP rovider();
  399           re turn spi.e ngineGetMa cLength();
  400       }
  401  
  402       /**
  403        * Ini tializes t his <code> Mac</code>  object wi th the giv en key.
  404        *
  405        * @pa ram key th e key.
  406        *
  407        * @ex ception In validKeyEx ception if  the given  key is in appropriat e for
  408        * ini tializing  this MAC.
  409        */
  410       public  final voi d init(Key  key) thro ws Invalid KeyExcepti on {
  411           tr y {
  412                if (spi  != null) {
  413                    spi. engineInit (key, null );
  414                } else {
  415                    choo seProvider (key, null );
  416                }
  417           }  catch (Inv alidAlgori thmParamet erExceptio n e) {
  418                throw ne w InvalidK eyExceptio n("init()  failed", e );
  419           }
  420           in itialized  = true;
  421  
  422           if  (!skipDeb ug && pdeb ug != null ) {
  423                pdebug.p rintln("Ma c." + algo rithm + "  algorithm  from: " +
  424                    this .provider. getName()) ;
  425           }
  426       }
  427  
  428       /**
  429        * Ini tializes t his <code> Mac</code>  object wi th the giv en key and
  430        * alg orithm par ameters.
  431        *
  432        * @pa ram key th e key.
  433        * @pa ram params  the algor ithm param eters.
  434        *
  435        * @ex ception In validKeyEx ception if  the given  key is in appropriat e for
  436        * ini tializing  this MAC.
  437        * @ex ception In validAlgor ithmParame terExcepti on if the  given algo rithm
  438        * par ameters ar e inapprop riate for  this MAC.
  439        */
  440       public  final voi d init(Key  key, Algo rithmParam eterSpec p arams)
  441                throws I nvalidKeyE xception,  InvalidAlg orithmPara meterExcep tion {
  442           if  (spi != n ull) {
  443                spi.engi neInit(key , params);
  444           }  else {
  445                choosePr ovider(key , params);
  446           }
  447           in itialized  = true;
  448  
  449           if  (!skipDeb ug && pdeb ug != null ) {
  450                pdebug.p rintln("Ma c." + algo rithm + "  algorithm  from: " +
  451                    this .provider. getName()) ;
  452           }
  453       }
  454  
  455       /**
  456        * Pro cesses the  given byt e.
  457        *
  458        * @pa ram input  the input  byte to be  processed .
  459        *
  460        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  461        * ini tialized.
  462        */
  463       public  final voi d update(b yte input)  throws Il legalState Exception  {
  464           ch ooseFirstP rovider();
  465           if  (initiali zed == fal se) {
  466                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  467           }
  468           sp i.engineUp date(input );
  469       }
  470  
  471       /**
  472        * Pro cesses the  given arr ay of byte s.
  473        *
  474        * @pa ram input  the array  of bytes t o be proce ssed.
  475        *
  476        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  477        * ini tialized.
  478        */
  479       public  final voi d update(b yte[] inpu t) throws  IllegalSta teExceptio n {
  480           ch ooseFirstP rovider();
  481           if  (initiali zed == fal se) {
  482                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  483           }
  484           if  (input !=  null) {
  485                spi.engi neUpdate(i nput, 0, i nput.lengt h);
  486           }
  487       }
  488  
  489       /**
  490        * Pro cesses the  first <co de>len</co de> bytes  in <code>i nput</code >,
  491        * sta rting at < code>offse t</code> i nclusive.
  492        *
  493        * @pa ram input  the input  buffer.
  494        * @pa ram offset  the offse t in <code >input</co de> where  the input  starts.
  495        * @pa ram len th e number o f bytes to  process.
  496        *
  497        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  498        * ini tialized.
  499        */
  500       public  final voi d update(b yte[] inpu t, int off set, int l en)
  501                throws I llegalStat eException  {
  502           ch ooseFirstP rovider();
  503           if  (initiali zed == fal se) {
  504                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  505           }
  506  
  507           if  (input !=  null) {
  508                if ((off set < 0) | | (len > ( input.leng th - offse t)) || (le n < 0))
  509                    thro w new Ille galArgumen tException ("Bad argu ments");
  510                spi.engi neUpdate(i nput, offs et, len);
  511           }
  512       }
  513  
  514       /**
  515        * Pro cesses <co de>input.r emaining() </code> by tes in the  ByteBuffe r
  516        * <co de>input</ code>, sta rting at < code>input .position( )</code>.
  517        * Upo n return,  the buffer 's positio n will be  equal to i ts limit;
  518        * its  limit wil l not have  changed.
  519        *
  520        * @pa ram input  the ByteBu ffer
  521        *
  522        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  523        * ini tialized.
  524        * @si nce 1.5
  525        */
  526       public  final voi d update(B yteBuffer  input) {
  527           ch ooseFirstP rovider();
  528           if  (initiali zed == fal se) {
  529                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  530           }
  531           if  (input ==  null) {
  532                throw ne w IllegalA rgumentExc eption("Bu ffer must  not be nul l");
  533           }
  534           sp i.engineUp date(input );
  535       }
  536  
  537       /**
  538        * Fin ishes the  MAC operat ion.
  539        *
  540        * <p> A call to  this metho d resets t his <code> Mac</code>  object to  the
  541        * sta te it was  in when pr eviously i nitialized  via a cal l to
  542        * <co de>init(Ke y)</code>  or
  543        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  544        * Tha t is, the  object is  reset and  available  to generat e another  MAC from
  545        * the  same key,  if desire d, via new  calls to  <code>upda te</code>  and
  546        * <co de>doFinal </code>.
  547        * (In  order to  reuse this  <code>Mac </code> ob ject with  a differen t key,
  548        * it  must be re initialize d via a ca ll to <cod e>init(Key )</code> o r
  549        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  550        *
  551        * @re turn the M AC result.
  552        *
  553        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  554        * ini tialized.
  555        */
  556       public  final byt e[] doFina l() throws  IllegalSt ateExcepti on {
  557           ch ooseFirstP rovider();
  558           if  (initiali zed == fal se) {
  559                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  560           }
  561           by te[] mac =  spi.engin eDoFinal() ;
  562           sp i.engineRe set();
  563           re turn mac;
  564       }
  565  
  566       /**
  567        * Fin ishes the  MAC operat ion.
  568        *
  569        * <p> A call to  this metho d resets t his <code> Mac</code>  object to  the
  570        * sta te it was  in when pr eviously i nitialized  via a cal l to
  571        * <co de>init(Ke y)</code>  or
  572        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  573        * Tha t is, the  object is  reset and  available  to generat e another  MAC from
  574        * the  same key,  if desire d, via new  calls to  <code>upda te</code>  and
  575        * <co de>doFinal </code>.
  576        * (In  order to  reuse this  <code>Mac </code> ob ject with  a differen t key,
  577        * it  must be re initialize d via a ca ll to <cod e>init(Key )</code> o r
  578        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  579        *
  580        * <p> The MAC re sult is st ored in <c ode>output </code>, s tarting at
  581        * <co de>outOffs et</code>  inclusive.
  582        *
  583        * @pa ram output  the buffe r where th e MAC resu lt is stor ed
  584        * @pa ram outOff set the of fset in <c ode>output </code> wh ere the MA C is
  585        * sto red
  586        *
  587        * @ex ception Sh ortBufferE xception i f the give n output b uffer is t oo small
  588        * to  hold the r esult
  589        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  590        * ini tialized.
  591        */
  592       public  final voi d doFinal( byte[] out put, int o utOffset)
  593           th rows Short BufferExce ption, Ill egalStateE xception
  594       {
  595           ch ooseFirstP rovider();
  596           if  (initiali zed == fal se) {
  597                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  598           }
  599           in t macLen =  getMacLen gth();
  600           if  (output = = null ||  output.len gth-outOff set < macL en) {
  601                throw ne w ShortBuf ferExcepti on
  602                    ("Ca nnot store  MAC in ou tput buffe r");
  603           }
  604           by te[] mac =  doFinal() ;
  605           Sy stem.array copy(mac,  0, output,  outOffset , macLen);
  606           re turn;
  607       }
  608  
  609       /**
  610        * Pro cesses the  given arr ay of byte s and fini shes the M AC operati on.
  611        *
  612        * <p> A call to  this metho d resets t his <code> Mac</code>  object to  the
  613        * sta te it was  in when pr eviously i nitialized  via a cal l to
  614        * <co de>init(Ke y)</code>  or
  615        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  616        * Tha t is, the  object is  reset and  available  to generat e another  MAC from
  617        * the  same key,  if desire d, via new  calls to  <code>upda te</code>  and
  618        * <co de>doFinal </code>.
  619        * (In  order to  reuse this  <code>Mac </code> ob ject with  a differen t key,
  620        * it  must be re initialize d via a ca ll to <cod e>init(Key )</code> o r
  621        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  622        *
  623        * @pa ram input  data in by tes
  624        * @re turn the M AC result.
  625        *
  626        * @ex ception Il legalState Exception  if this <c ode>Mac</c ode> has n ot been
  627        * ini tialized.
  628        */
  629       public  final byt e[] doFina l(byte[] i nput) thro ws Illegal StateExcep tion
  630       {
  631           ch ooseFirstP rovider();
  632           if  (initiali zed == fal se) {
  633                throw ne w IllegalS tateExcept ion("MAC n ot initial ized");
  634           }
  635           up date(input );
  636           re turn doFin al();
  637       }
  638  
  639       /**
  640        * Res ets this < code>Mac</ code> obje ct.
  641        *
  642        * <p> A call to  this metho d resets t his <code> Mac</code>  object to  the
  643        * sta te it was  in when pr eviously i nitialized  via a cal l to
  644        * <co de>init(Ke y)</code>  or
  645        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  646        * Tha t is, the  object is  reset and  available  to generat e another  MAC from
  647        * the  same key,  if desire d, via new  calls to  <code>upda te</code>  and
  648        * <co de>doFinal </code>.
  649        * (In  order to  reuse this  <code>Mac </code> ob ject with  a differen t key,
  650        * it  must be re initialize d via a ca ll to <cod e>init(Key )</code> o r
  651        * <co de>init(Ke y, Algorit hmParamete rSpec)</co de>.
  652        */
  653       public  final voi d reset()  {
  654           ch ooseFirstP rovider();
  655           sp i.engineRe set();
  656       }
  657  
  658       /**
  659        * Ret urns a clo ne if the  provider i mplementat ion is clo neable.
  660        *
  661        * @re turn a clo ne if the  provider i mplementat ion is clo neable.
  662        *
  663        * @ex ception Cl oneNotSupp ortedExcep tion if th is is call ed on a
  664        * del egate that  does not  support <c ode>Clonea ble</code> .
  665        */
  666       public  final Obj ect clone( ) throws C loneNotSup portedExce ption {
  667           ch ooseFirstP rovider();
  668           Ma c that = ( Mac)super. clone();
  669           th at.spi = ( MacSpi)thi s.spi.clon e();
  670           re turn that;
  671       }
  672   }