jdk/src/share/classes/sun/security/provider/DigestBase.java
changeset 12685 8a448b5b9006
parent 5506 202f599c92aa
child 14342 8435a30053c1
equal deleted inserted replaced
12676:3b7fae360d04 12685:8a448b5b9006
    37  * implement the following methods:
    37  * implement the following methods:
    38  *
    38  *
    39  *  . abstract void implCompress(byte[] b, int ofs);
    39  *  . abstract void implCompress(byte[] b, int ofs);
    40  *  . abstract void implDigest(byte[] out, int ofs);
    40  *  . abstract void implDigest(byte[] out, int ofs);
    41  *  . abstract void implReset();
    41  *  . abstract void implReset();
    42  *  . public abstract Object clone();
       
    43  *
    42  *
    44  * See the inline documentation for details.
    43  * See the inline documentation for details.
    45  *
    44  *
    46  * @since   1.5
    45  * @since   1.5
    47  * @author  Andreas Sterbenz
    46  * @author  Andreas Sterbenz
    59     // size of the input to the compression function in bytes
    58     // size of the input to the compression function in bytes
    60     private final int blockSize;
    59     private final int blockSize;
    61     // buffer to store partial blocks, blockSize bytes large
    60     // buffer to store partial blocks, blockSize bytes large
    62     // Subclasses should not access this array directly except possibly in their
    61     // Subclasses should not access this array directly except possibly in their
    63     // implDigest() method. See MD5.java as an example.
    62     // implDigest() method. See MD5.java as an example.
    64     final byte[] buffer;
    63     byte[] buffer;
    65     // offset into buffer
    64     // offset into buffer
    66     private int bufOfs;
    65     private int bufOfs;
    67 
    66 
    68     // number of bytes processed so far. subclasses should not modify
    67     // number of bytes processed so far. subclasses should not modify
    69     // this value.
    68     // this value.
    79         super();
    78         super();
    80         this.algorithm = algorithm;
    79         this.algorithm = algorithm;
    81         this.digestLength = digestLength;
    80         this.digestLength = digestLength;
    82         this.blockSize = blockSize;
    81         this.blockSize = blockSize;
    83         buffer = new byte[blockSize];
    82         buffer = new byte[blockSize];
    84     }
       
    85 
       
    86     /**
       
    87      * Constructor for cloning. Replicates common data.
       
    88      */
       
    89     DigestBase(DigestBase base) {
       
    90         this.algorithm = base.algorithm;
       
    91         this.digestLength = base.digestLength;
       
    92         this.blockSize = base.blockSize;
       
    93         this.buffer = base.buffer.clone();
       
    94         this.bufOfs = base.bufOfs;
       
    95         this.bytesProcessed = base.bytesProcessed;
       
    96     }
    83     }
    97 
    84 
    98     // return digest length. See JCA doc.
    85     // return digest length. See JCA doc.
    99     protected final int engineGetDigestLength() {
    86     protected final int engineGetDigestLength() {
   100         return digestLength;
    87         return digestLength;
   204      * Reset subclass specific state to their initial values. DigestBase
   191      * Reset subclass specific state to their initial values. DigestBase
   205      * calls this method when necessary.
   192      * calls this method when necessary.
   206      */
   193      */
   207     abstract void implReset();
   194     abstract void implReset();
   208 
   195 
   209     /**
   196     public Object clone() throws CloneNotSupportedException {
   210      * Clone this digest. Should be implemented as "return new MyDigest(this)".
   197         DigestBase copy = (DigestBase) super.clone();
   211      * That constructor should first call "super(baseDigest)" and then copy
   198         copy.buffer = copy.buffer.clone();
   212      * subclass specific data.
   199         return copy;
   213      */
   200     }
   214     public abstract Object clone();
       
   215 
   201 
   216     // padding used for the MD5, and SHA-* message digests
   202     // padding used for the MD5, and SHA-* message digests
   217     static final byte[] padding;
   203     static final byte[] padding;
   218 
   204 
   219     static {
   205     static {
   221         // and an additional 8 bytes for the high 8 bytes of the 16
   207         // and an additional 8 bytes for the high 8 bytes of the 16
   222         // byte bit counter in SHA-384/512
   208         // byte bit counter in SHA-384/512
   223         padding = new byte[136];
   209         padding = new byte[136];
   224         padding[0] = (byte)0x80;
   210         padding[0] = (byte)0x80;
   225     }
   211     }
   226 
       
   227 }
   212 }