View Javadoc

1   /**
2    * Copyright Santeri Paavolainen <sjpaavol@cc.helsinki.fi> and Timothy W Macinta
3    * (twm@alum.mit.edu) (optimizations and bug fixes) and individual contributors
4    * by the @author tags. See the COPYRIGHT.txt in the distribution for a full
5    * listing of individual contributors.
6    *
7    * This is free software; you can redistribute it and/or modify it under the
8    * terms of the GNU Lesser General Public License as published by the Free
9    * Software Foundation; either version 2.1 of the License, or (at your option)
10   * any later version.
11   *
12   * This software is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15   * details.
16   *
17   * You should have received a copy of the GNU Lesser General Public License
18   * along with this software; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
20   * site: http://www.fsf.org.
21   */
22  package goldengate.common.digest;
23  
24  /**
25   * Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher<br>
26   * Originally written by Santeri Paavolainen, Helsinki Finland 1996 <br>
27   * (c) Santeri Paavolainen, Helsinki Finland 1996 <br>
28   * Some changes Copyright (c) 2002 Timothy W Macinta <br>
29   * <p>
30   * This library is free software; you can redistribute it and/or modify it under
31   * the terms of the GNU Library General Public License as published by the Free
32   * Software Foundation; either version 2.1 of the License, or (at your option)
33   * any later version.
34   * <p>
35   * This library is distributed in the hope that it will be useful, but WITHOUT
36   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
37   * FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
38   * details.
39   * <p>
40   * You should have received a copy of the GNU Library General Public License
41   * along with this library; if not, write to the Free Software Foundation, Inc.,
42   * 675 Mass Ave, Cambridge, MA 02139, USA.
43   * <p>
44   * See http://www.twmacinta.com/myjava/fast_md5.php for more information on this
45   * file.
46   * <p>
47   * Contains internal state of the MD5 class
48   * <p>
49   * Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util
50   * package only because it came without a package. I was not the the original
51   * author of the code, although I did optimize it (substantially) and fix some
52   * bugs.
53   *
54   * @author Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
55   * @author Timothy W Macinta (twm@alum.mit.edu) (optimizations and bug fixes)
56   **/
57  
58  class MD5State {
59      /**
60       * 128-bit state
61       */
62      protected int state[];
63  
64      /**
65       * 64-bit character count
66       */
67      protected long count;
68  
69      /**
70       * 64-byte buffer (512 bits) for storing to-be-hashed characters
71       */
72      protected byte buffer[];
73  
74      /**
75       * Constructor
76       *
77       */
78      public MD5State() {
79          buffer = new byte[64];
80          count = 0;
81          state = new int[4];
82  
83          state[0] = 0x67452301;
84          state[1] = 0xefcdab89;
85          state[2] = 0x98badcfe;
86          state[3] = 0x10325476;
87  
88      }
89  
90      /**
91       * Create this State as a copy of another state
92       *
93       * @param from
94       */
95      public MD5State(MD5State from) {
96          this();
97  
98          int i;
99  
100         for (i = 0; i < buffer.length; i ++) {
101             buffer[i] = from.buffer[i];
102         }
103 
104         for (i = 0; i < state.length; i ++) {
105             state[i] = from.state[i];
106         }
107 
108         count = from.count;
109     }
110 }