254. EPMO Open Source Coordination Office Redaction File Detail Report

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

254.1 Files compared

# Location File Last Modified
1 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\security\pkcs11 P11Digest.java Mon Jan 22 14:46:54 2018 UTC
2 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\security\pkcs11 P11Digest.java Wed Sep 12 17:53:08 2018 UTC

254.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 640
Changed 1 2
Inserted 0 0
Removed 0 0

254.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

254.4 Active regular expressions

No regular expressions were active.

254.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 200 3, 2012, 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 su n.security .pkcs11;
  27  
  28   import jav a.util.*;
  29   import jav a.nio.Byte Buffer;
  30  
  31   import jav a.security .*;
  32  
  33   import jav ax.crypto. SecretKey;
  34  
  35   import sun .nio.ch.Di rectBuffer ;
  36  
  37   import sun .security. pkcs11.wra pper.*;
  38   import sta tic sun.se curity.pkc s11.wrappe r.PKCS11Co nstants.*;
  39  
  40   /**
  41    * Message Digest imp lementatio n class. T his class  currently  supports
  42    * MD2, MD 5, SHA-1,  SHA-224, S HA-256, SH A-384, and  SHA-512.
  43    *
  44    * Note th at many di gest opera tions are  on fairly  small amou nts of dat a
  45    * (less t han 100 by tes total) . For exam ple, the 2 nd hashing  in HMAC o r
  46    * the PRF  in TLS. I n order to  speed tho se up, we  use some b uffering t o
  47    * minimiz e number o f the Java ->native t ransitions .
  48    *
  49    * @author   Andreas  Sterbenz
  50    * @since    1.5
  51    */
  52   final clas s P11Diges t extends  MessageDig estSpi imp lements Cl oneable {
  53  
  54       /* fie lds initia lized, no  session ac quired */
  55       privat e final st atic int S _BLANK     = 1;
  56  
  57       /* dat a in buffe r, session  acquired,  but diges t not init ialized */
  58       privat e final st atic int S _BUFFERED  = 2;
  59  
  60       /* ses sion initi alized for  digesting  */
  61       privat e final st atic int S _INIT      = 3;
  62  
  63       privat e final st atic int B UFFER_SIZE  = 96;
  64  
  65       // tok en instanc e
  66       privat e final To ken token;
  67  
  68       // alg orithm nam e
  69       privat e final St ring algor ithm;
  70  
  71       // mec hanism id  object
  72       privat e final CK _MECHANISM  mechanism ;
  73  
  74       // len gth of the  digest in  bytes
  75       privat e final in t digestLe ngth;
  76  
  77       // ass ociated se ssion, if  any
  78       privat e Session  session;
  79  
  80       // cur rent state , one of S _* above
  81       privat e int stat e;
  82  
  83       // buf fer to red uce number  of JNI ca lls
  84       privat e byte[] b uffer;
  85  
  86       // off set into t he buffer
  87       privat e int bufO fs;
  88  
  89       P11Dig est(Token  token, Str ing algori thm, long  mechanism)  {
  90           su per();
  91           th is.token =  token;
  92           th is.algorit hm = algor ithm;
  93           th is.mechani sm = new C K_MECHANIS M(mechanis m);
  94           sw itch ((int )mechanism ) {
  95           ca se (int)CK M_MD2:
  96           ca se (int)CK M_MD5:
  97                digestLe ngth = 16;
  98                break;
  99           ca se (int)CK M_SHA_1:
  100                digestLe ngth = 20;
  101                break;
  102           ca se (int)CK M_SHA224:
  103                digestLe ngth = 28;
  104                break;
  105           ca se (int)CK M_SHA256:
  106                digestLe ngth = 32;
  107                break;
  108           ca se (int)CK M_SHA384:
  109                digestLe ngth = 48;
  110                break;
  111           ca se (int)CK M_SHA512:
  112                digestLe ngth = 64;
  113                break;
  114           de fault:
  115                throw ne w Provider Exception( "Unknown m echanism:  " + mechan ism);
  116           }
  117           bu ffer = new  byte[BUFF ER_SIZE];
  118           st ate = S_BL ANK;
  119       }
  120  
  121       // see  JCA spec
  122       protec ted int en gineGetDig estLength( ) {
  123           re turn diges tLength;
  124       }
  125  
  126       privat e void fet chSession( ) {
  127           to ken.ensure Valid();
  128           if  (state ==  S_BLANK)  {
  129                try {
  130                    sess ion = toke n.getOpSes sion();
  131                    stat e = S_BUFF ERED;
  132                } catch  (PKCS11Exc eption e)  {
  133                    thro w new Prov iderExcept ion("No mo re session  available ", e);
  134                }
  135           }
  136       }
  137  
  138       // see  JCA spec
  139       protec ted void e ngineReset () {
  140           to ken.ensure Valid();
  141  
  142           if  (session  != null) {
  143                if (stat e == S_INI T && token .explicitC ancel == t rue) {
  144                    sess ion = toke n.killSess ion(sessio n);
  145                } else {
  146                    sess ion = toke n.releaseS ession(ses sion);
  147                }
  148           }
  149           st ate = S_BL ANK;
  150           bu fOfs = 0;
  151       }
  152  
  153       // see  JCA spec
  154       protec ted byte[]  engineDig est() {
  155           tr y {
  156                byte[] d igest = ne w byte[dig estLength] ;
  157                int n =  engineDige st(digest,  0, digest Length);
  158                return d igest;
  159           }  catch (Dig estExcepti on e) {
  160                throw ne w Provider Exception( "internal  error", e) ;
  161           }
  162       }
  163  
  164       // see  JCA spec
  165       protec ted int en gineDigest (byte[] di gest, int  ofs, int l en)
  166                throws D igestExcep tion {
  167           if  (len < di gestLength ) {
  168                throw ne w DigestEx ception("L ength must  be at lea st " +
  169                         digestLeng th);
  170           }
  171  
  172           fe tchSession ();
  173           tr y {
  174                int n;
  175                if (stat e == S_BUF FERED) {
  176                    n =  token.p11. C_DigestSi ngle(sessi on.id(), m echanism,  buffer, 0,
  177                             bufOfs , digest,  ofs, len);
  178                    bufO fs = 0;
  179                } else {
  180                    if ( bufOfs !=  0) {
  181                         token.p11. C_DigestUp date(sessi on.id(), 0 , buffer,  0,
  182                                 bu fOfs);
  183                         bufOfs = 0 ;
  184                    }
  185                    n =  token.p11. C_DigestFi nal(sessio n.id(), di gest, ofs,  len);
  186                }
  187                if (n !=  digestLen gth) {
  188                    thro w new Prov iderExcept ion("inter nal digest  length er ror");
  189                }
  190                return n ;
  191           }  catch (PKC S11Excepti on e) {
  192                throw ne w Provider Exception( "digest()  failed", e );
  193           }  finally {
  194                engineRe set();
  195           }
  196       }
  197  
  198       // see  JCA spec
  199       protec ted void e ngineUpdat e(byte in)  {
  200           by te[] temp  = { in };
  201           en gineUpdate (temp, 0,  1);
  202       }
  203  
  204       // see  JCA spec
  205       protec ted void e ngineUpdat e(byte[] i n, int ofs , int len)  {
  206           if  (len <= 0 ) {
  207                return;
  208           }
  209  
  210           fe tchSession ();
  211           tr y {
  212                if (stat e == S_BUF FERED) {
  213                    toke n.p11.C_Di gestInit(s ession.id( ), mechani sm);
  214                    stat e = S_INIT ;
  215                }
  216                if ((buf Ofs != 0)  && (bufOfs  + len > b uffer.leng th)) {
  217                    // p rocess the  buffered  data
  218                    toke n.p11.C_Di gestUpdate (session.i d(), 0, bu ffer, 0, b ufOfs);
  219                    bufO fs = 0;
  220                }
  221                if (bufO fs + len >  buffer.le ngth) {
  222                    // p rocess the  new data
  223                    toke n.p11.C_Di gestUpdate (session.i d(), 0, in , ofs, len );
  224                 } else  {
  225                    // b uffer the  new data
  226                    Syst em.arrayco py(in, ofs , buffer,  bufOfs, le n);
  227                    bufO fs += len;
  228                }
  229           }  catch (PKC S11Excepti on e) {
  230                engineRe set();
  231                throw ne w Provider Exception( "update()  failed", e );
  232           }
  233       }
  234  
  235       // Cal led by Sun JSSE via r eflection  during the  SSL 3.0 h andshake i f
  236         // the mas ter  PW        is sensiti ve. We may  want to c onsider ma king this
  237       // met hod public  in a futu re release .
  238       protec ted void i mplUpdate( SecretKey  key) throw s InvalidK eyExceptio n {
  239  
  240           //  SunJSSE c alls this  method onl y if the k ey does no t have a R AW
  241           //  encoding,  i.e. if i t is sensi tive. Ther efore, no  point in c alling
  242           //  SecretKey Factory to  try to co nvert it.  Just verif y it ourse lves.
  243           if  (key inst anceof P11 Key == fal se) {
  244                throw ne w InvalidK eyExceptio n("Not a P 11Key: " +  key);
  245           }
  246           P1 1Key p11Ke y = (P11Ke y)key;
  247           if  (p11Key.t oken != to ken) {
  248                throw ne w InvalidK eyExceptio n("Not a P 11Key of t his provid er: " +
  249                         key);
  250           }
  251  
  252           fe tchSession ();
  253           tr y {
  254                if (stat e == S_BUF FERED) {
  255                    toke n.p11.C_Di gestInit(s ession.id( ), mechani sm);
  256                    stat e = S_INIT ;
  257                }
  258  
  259                if (bufO fs != 0) {
  260                    toke n.p11.C_Di gestUpdate (session.i d(), 0, bu ffer, 0, b ufOfs);
  261                    bufO fs = 0;
  262                }
  263                token.p1 1.C_Digest Key(sessio n.id(), p1 1Key.keyID );
  264           }  catch (PKC S11Excepti on e) {
  265                engineRe set();
  266                throw ne w Provider Exception( "update(Se cretKey) f ailed", e) ;
  267           }
  268       }
  269  
  270       // see  JCA spec
  271       protec ted void e ngineUpdat e(ByteBuff er byteBuf fer) {
  272           in t len = by teBuffer.r emaining() ;
  273           if  (len <= 0 ) {
  274                return;
  275           }
  276  
  277           if  (byteBuff er instanc eof Direct Buffer ==  false) {
  278                super.en gineUpdate (byteBuffe r);
  279                return;
  280           }
  281  
  282           fe tchSession ();
  283           lo ng addr =  ((DirectBu ffer)byteB uffer).add ress();
  284           in t ofs = by teBuffer.p osition();
  285           tr y {
  286                if (stat e == S_BUF FERED) {
  287                    toke n.p11.C_Di gestInit(s ession.id( ), mechani sm);
  288                    stat e = S_INIT ;
  289                }
  290                if (bufO fs != 0) {
  291                    toke n.p11.C_Di gestUpdate (session.i d(), 0, bu ffer, 0, b ufOfs);
  292                    bufO fs = 0;
  293                }
  294                token.p1 1.C_Digest Update(ses sion.id(),  addr + of s, null, 0 , len);
  295                byteBuff er.positio n(ofs + le n);
  296           }  catch (PKC S11Excepti on e) {
  297                engineRe set();
  298                throw ne w Provider Exception( "update()  failed", e );
  299           }
  300       }
  301  
  302       public  Object cl one() thro ws CloneNo tSupported Exception  {
  303           P1 1Digest co py = (P11D igest) sup er.clone() ;
  304           co py.buffer  = buffer.c lone();
  305           tr y {
  306                if (sess ion != nul l) {
  307                    copy .session =  copy.toke n.getOpSes sion();
  308                }
  309                if (stat e == S_INI T) {
  310                    byte [] stateVa lues =
  311                         token.p11. C_GetOpera tionState( session.id ());
  312                    toke n.p11.C_Se tOperation State(copy .session.i d(),
  313                                                     stat eValues, 0 , 0);
  314                }
  315           }  catch (PKC S11Excepti on e) {
  316                throw (C loneNotSup portedExce ption)
  317                    (new  CloneNotS upportedEx ception(al gorithm).i nitCause(e ));
  318           }
  319           re turn copy;
  320       }
  321   }