Source Code Cross Referenced for MD4Digest.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * Copyright (c) 2000 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
003:         * Permission is hereby granted, free of charge, to any person obtaining a
004:         * copy of this software and associated documentation files (the "Software"),
005:         * to deal in the Software without restriction, including without limitation
006:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
007:         * and/or sell copies of the Software, and to permit persons to whom the
008:         * Software is furnished to do so, subject to the following conditions:
009:         *
010:         * The above copyright notice and this permission notice shall be included
011:         * in all copies or substantial portions of the Software.
012:         *
013:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
014:         * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
015:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
016:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017:         * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
018:         * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
019:         * USE OR OTHER DEALINGS IN THE SOFTWARE.
020:         ******************************************************************************/package net.sourceforge.jtds.util;
021:
022:        /**
023:         * implementation of MD4 as RFC 1320 by R. Rivest, MIT Laboratory for
024:         * Computer Science and RSA Data Security, Inc.
025:         * <p>
026:         * <b>NOTE</b>: This algorithm is only included for backwards compatability
027:         * with legacy applications, it's not secure, don't use it for anything new!
028:         *
029:         * @version $Id: MD4Digest.java,v 1.2 2004/06/27 17:00:55 bheineman Exp $
030:         */
031:        public class MD4Digest extends GeneralDigest {
032:            private static final int DIGEST_LENGTH = 16;
033:
034:            //
035:            // round 1 left rotates
036:            //
037:            private static final int S11 = 3;
038:            private static final int S12 = 7;
039:            private static final int S13 = 11;
040:            private static final int S14 = 19;
041:
042:            //
043:            // round 2 left rotates
044:            //
045:            private static final int S21 = 3;
046:            private static final int S22 = 5;
047:            private static final int S23 = 9;
048:            private static final int S24 = 13;
049:
050:            //
051:            // round 3 left rotates
052:            //
053:            private static final int S31 = 3;
054:            private static final int S32 = 9;
055:            private static final int S33 = 11;
056:            private static final int S34 = 15;
057:
058:            private int H1, H2, H3, H4; // IV's
059:
060:            private int[] X = new int[16];
061:            private int xOff;
062:
063:            /**
064:             * Standard constructor
065:             */
066:            public MD4Digest() {
067:                reset();
068:            }
069:
070:            /**
071:             * Copy constructor.  This will copy the state of the provided
072:             * message digest.
073:             */
074:            public MD4Digest(MD4Digest t) {
075:                super (t);
076:
077:                H1 = t.H1;
078:                H2 = t.H2;
079:                H3 = t.H3;
080:                H4 = t.H4;
081:
082:                System.arraycopy(t.X, 0, X, 0, t.X.length);
083:                xOff = t.xOff;
084:            }
085:
086:            public String getAlgorithmName() {
087:                return "MD4";
088:            }
089:
090:            public int getDigestSize() {
091:                return DIGEST_LENGTH;
092:            }
093:
094:            protected void processWord(byte[] in, int inOff) {
095:                X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8)
096:                        | ((in[inOff + 2] & 0xff) << 16)
097:                        | ((in[inOff + 3] & 0xff) << 24);
098:
099:                if (xOff == 16) {
100:                    processBlock();
101:                }
102:            }
103:
104:            protected void processLength(long bitLength) {
105:                if (xOff > 14) {
106:                    processBlock();
107:                }
108:
109:                X[14] = (int) (bitLength & 0xffffffff);
110:                X[15] = (int) (bitLength >>> 32);
111:            }
112:
113:            private void unpackWord(int word, byte[] out, int outOff) {
114:                out[outOff] = (byte) word;
115:                out[outOff + 1] = (byte) (word >>> 8);
116:                out[outOff + 2] = (byte) (word >>> 16);
117:                out[outOff + 3] = (byte) (word >>> 24);
118:            }
119:
120:            public int doFinal(byte[] out, int outOff) {
121:                finish();
122:
123:                unpackWord(H1, out, outOff);
124:                unpackWord(H2, out, outOff + 4);
125:                unpackWord(H3, out, outOff + 8);
126:                unpackWord(H4, out, outOff + 12);
127:
128:                reset();
129:
130:                return DIGEST_LENGTH;
131:            }
132:
133:            /**
134:             * reset the chaining variables to the IV values.
135:             */
136:            public void reset() {
137:                super .reset();
138:
139:                H1 = 0x67452301;
140:                H2 = 0xefcdab89;
141:                H3 = 0x98badcfe;
142:                H4 = 0x10325476;
143:
144:                xOff = 0;
145:
146:                for (int i = 0; i != X.length; i++) {
147:                    X[i] = 0;
148:                }
149:            }
150:
151:            /*
152:             * rotate int x left n bits.
153:             */
154:            private int rotateLeft(int x, int n) {
155:                return (x << n) | (x >>> (32 - n));
156:            }
157:
158:            /*
159:             * F, G, H and I are the basic MD4 functions.
160:             */
161:            private int F(int u, int v, int w) {
162:                return (u & v) | (~u & w);
163:            }
164:
165:            private int G(int u, int v, int w) {
166:                return (u & v) | (u & w) | (v & w);
167:            }
168:
169:            private int H(int u, int v, int w) {
170:                return u ^ v ^ w;
171:            }
172:
173:            protected void processBlock() {
174:                int a = H1;
175:                int b = H2;
176:                int c = H3;
177:                int d = H4;
178:
179:                //
180:                // Round 1 - F cycle, 16 times.
181:                //
182:                a = rotateLeft((a + F(b, c, d) + X[0]), S11);
183:                d = rotateLeft((d + F(a, b, c) + X[1]), S12);
184:                c = rotateLeft((c + F(d, a, b) + X[2]), S13);
185:                b = rotateLeft((b + F(c, d, a) + X[3]), S14);
186:                a = rotateLeft((a + F(b, c, d) + X[4]), S11);
187:                d = rotateLeft((d + F(a, b, c) + X[5]), S12);
188:                c = rotateLeft((c + F(d, a, b) + X[6]), S13);
189:                b = rotateLeft((b + F(c, d, a) + X[7]), S14);
190:                a = rotateLeft((a + F(b, c, d) + X[8]), S11);
191:                d = rotateLeft((d + F(a, b, c) + X[9]), S12);
192:                c = rotateLeft((c + F(d, a, b) + X[10]), S13);
193:                b = rotateLeft((b + F(c, d, a) + X[11]), S14);
194:                a = rotateLeft((a + F(b, c, d) + X[12]), S11);
195:                d = rotateLeft((d + F(a, b, c) + X[13]), S12);
196:                c = rotateLeft((c + F(d, a, b) + X[14]), S13);
197:                b = rotateLeft((b + F(c, d, a) + X[15]), S14);
198:
199:                //
200:                // Round 2 - G cycle, 16 times.
201:                //
202:                a = rotateLeft((a + G(b, c, d) + X[0] + 0x5a827999), S21);
203:                d = rotateLeft((d + G(a, b, c) + X[4] + 0x5a827999), S22);
204:                c = rotateLeft((c + G(d, a, b) + X[8] + 0x5a827999), S23);
205:                b = rotateLeft((b + G(c, d, a) + X[12] + 0x5a827999), S24);
206:                a = rotateLeft((a + G(b, c, d) + X[1] + 0x5a827999), S21);
207:                d = rotateLeft((d + G(a, b, c) + X[5] + 0x5a827999), S22);
208:                c = rotateLeft((c + G(d, a, b) + X[9] + 0x5a827999), S23);
209:                b = rotateLeft((b + G(c, d, a) + X[13] + 0x5a827999), S24);
210:                a = rotateLeft((a + G(b, c, d) + X[2] + 0x5a827999), S21);
211:                d = rotateLeft((d + G(a, b, c) + X[6] + 0x5a827999), S22);
212:                c = rotateLeft((c + G(d, a, b) + X[10] + 0x5a827999), S23);
213:                b = rotateLeft((b + G(c, d, a) + X[14] + 0x5a827999), S24);
214:                a = rotateLeft((a + G(b, c, d) + X[3] + 0x5a827999), S21);
215:                d = rotateLeft((d + G(a, b, c) + X[7] + 0x5a827999), S22);
216:                c = rotateLeft((c + G(d, a, b) + X[11] + 0x5a827999), S23);
217:                b = rotateLeft((b + G(c, d, a) + X[15] + 0x5a827999), S24);
218:
219:                //
220:                // Round 3 - H cycle, 16 times.
221:                //
222:                a = rotateLeft((a + H(b, c, d) + X[0] + 0x6ed9eba1), S31);
223:                d = rotateLeft((d + H(a, b, c) + X[8] + 0x6ed9eba1), S32);
224:                c = rotateLeft((c + H(d, a, b) + X[4] + 0x6ed9eba1), S33);
225:                b = rotateLeft((b + H(c, d, a) + X[12] + 0x6ed9eba1), S34);
226:                a = rotateLeft((a + H(b, c, d) + X[2] + 0x6ed9eba1), S31);
227:                d = rotateLeft((d + H(a, b, c) + X[10] + 0x6ed9eba1), S32);
228:                c = rotateLeft((c + H(d, a, b) + X[6] + 0x6ed9eba1), S33);
229:                b = rotateLeft((b + H(c, d, a) + X[14] + 0x6ed9eba1), S34);
230:                a = rotateLeft((a + H(b, c, d) + X[1] + 0x6ed9eba1), S31);
231:                d = rotateLeft((d + H(a, b, c) + X[9] + 0x6ed9eba1), S32);
232:                c = rotateLeft((c + H(d, a, b) + X[5] + 0x6ed9eba1), S33);
233:                b = rotateLeft((b + H(c, d, a) + X[13] + 0x6ed9eba1), S34);
234:                a = rotateLeft((a + H(b, c, d) + X[3] + 0x6ed9eba1), S31);
235:                d = rotateLeft((d + H(a, b, c) + X[11] + 0x6ed9eba1), S32);
236:                c = rotateLeft((c + H(d, a, b) + X[7] + 0x6ed9eba1), S33);
237:                b = rotateLeft((b + H(c, d, a) + X[15] + 0x6ed9eba1), S34);
238:
239:                H1 += a;
240:                H2 += b;
241:                H3 += c;
242:                H4 += d;
243:
244:                //
245:                // reset the offset and clean out the word buffer.
246:                //
247:                xOff = 0;
248:
249:                for (int i = 0; i != X.length; i++) {
250:                    X[i] = 0;
251:                }
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.