├── .gitignore ├── LICENSE ├── PrivacyPolicy.html ├── app ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── hobbyone │ │ └── HashDroid │ │ ├── BaseHash.java │ │ ├── CompareActivity.java │ │ ├── FileActivity.java │ │ ├── HashFactory.java │ │ ├── HashFunctionOperator.java │ │ ├── Haval.java │ │ ├── IMessageDigest.java │ │ ├── MD2.java │ │ ├── MD4.java │ │ ├── MD5.java │ │ ├── MainActivity.java │ │ ├── RipeMD128.java │ │ ├── RipeMD160.java │ │ ├── Sha160.java │ │ ├── Sha256.java │ │ ├── Sha384.java │ │ ├── Sha512.java │ │ ├── TextActivity.java │ │ ├── Tiger.java │ │ ├── UtilServices.java │ │ └── Whirlpool.java │ └── res │ ├── drawable │ ├── custom_background.xml │ ├── ic_menu_about.png │ ├── ic_menu_help.png │ ├── ic_menu_rateit.png │ ├── ic_tab_compare.xml │ ├── ic_tab_compare_grey.png │ ├── ic_tab_compare_white.png │ ├── ic_tab_file.xml │ ├── ic_tab_file_grey.png │ ├── ic_tab_file_white.png │ ├── ic_tab_text.xml │ ├── ic_tab_text_grey.png │ └── ic_tab_text_white.png │ ├── layout │ ├── about.xml │ ├── compare.xml │ ├── file.xml │ ├── help.xml │ ├── main.xml │ └── text.xml │ ├── menu │ └── menu_list.xml │ ├── mipmap-hdpi │ └── icon.png │ ├── mipmap-mdpi │ └── icon.png │ ├── mipmap-xhdpi │ └── icon.png │ ├── mipmap-xxhdpi │ └── icon.png │ ├── mipmap-xxxhdpi │ └── icon.png │ └── values │ ├── help_strings.xml │ └── strings.xml ├── build.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /PrivacyPolicy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |12 | HobbyOne built the Hash Droid app as 13 | an Open Source app. This SERVICE is provided by 14 | HobbyOne at no cost and is intended for use as 15 | is. 16 |
17 |18 | This page is used to inform visitors regarding my 19 | policies with the collection, use, and disclosure of Personal 20 | Information if anyone decided to use my Service. 21 |
22 |23 | If you choose to use my Service, then you agree to 24 | the collection and use of information in relation to this 25 | policy. The Personal Information that I collect is 26 | used for providing and improving the Service. I will not use or share your information with 27 | anyone except as described in this Privacy Policy. 28 |
29 |30 | The terms used in this Privacy Policy have the same meanings 31 | as in our Terms and Conditions, which are accessible at 32 | Hash Droid unless otherwise defined in this Privacy Policy. 33 |
34 |Information Collection and Use
35 |36 | For a better experience, while using our Service, I 37 | may require you to provide us with certain personally 38 | identifiable information. The information that 39 | I request will be retained on your device and is not collected by me in any way. 40 |
41 |43 | The app does use third-party services that may collect 44 | information used to identify you. 45 |
46 |47 | Link to the privacy policy of third-party service providers used 48 | by the app 49 |
50 |Log Data
56 |57 | I want to inform you that whenever you 58 | use my Service, in a case of an error in the app 59 | I collect data and information (through third-party 60 | products) on your phone called Log Data. This Log Data may 61 | include information such as your device Internet Protocol 62 | (“IP”) address, device name, operating system version, the 63 | configuration of the app when utilizing my Service, 64 | the time and date of your use of the Service, and other 65 | statistics. 66 |
67 |Cookies
68 |69 | Cookies are files with a small amount of data that are 70 | commonly used as anonymous unique identifiers. These are sent 71 | to your browser from the websites that you visit and are 72 | stored on your device's internal memory. 73 |
74 |75 | This Service does not use these “cookies” explicitly. However, 76 | the app may use third-party code and libraries that use 77 | “cookies” to collect information and improve their services. 78 | You have the option to either accept or refuse these cookies 79 | and know when a cookie is being sent to your device. If you 80 | choose to refuse our cookies, you may not be able to use some 81 | portions of this Service. 82 |
83 |Service Providers
84 |85 | I may employ third-party companies and 86 | individuals due to the following reasons: 87 |
88 |95 | I want to inform users of this Service 96 | that these third parties have access to their Personal 97 | Information. The reason is to perform the tasks assigned to 98 | them on our behalf. However, they are obligated not to 99 | disclose or use the information for any other purpose. 100 |
101 |Security
102 |103 | I value your trust in providing us your 104 | Personal Information, thus we are striving to use commercially 105 | acceptable means of protecting it. But remember that no method 106 | of transmission over the internet, or method of electronic 107 | storage is 100% secure and reliable, and I cannot 108 | guarantee its absolute security. 109 |
110 |Links to Other Sites
111 |112 | This Service may contain links to other sites. If you click on 113 | a third-party link, you will be directed to that site. Note 114 | that these external sites are not operated by me. 115 | Therefore, I strongly advise you to review the 116 | Privacy Policy of these websites. I have 117 | no control over and assume no responsibility for the content, 118 | privacy policies, or practices of any third-party sites or 119 | services. 120 |
121 |Children’s Privacy
122 |124 | These Services do not address anyone under the age of 13. 125 | I do not knowingly collect personally 126 | identifiable information from children under 13 years of age. In the case 127 | I discover that a child under 13 has provided 128 | me with personal information, I immediately 129 | delete this from our servers. If you are a parent or guardian 130 | and you are aware that your child has provided us with 131 | personal information, please contact me so that 132 | I will be able to do the necessary actions. 133 |
134 |Changes to This Privacy Policy
137 |138 | I may update our Privacy Policy from 139 | time to time. Thus, you are advised to review this page 140 | periodically for any changes. I will 141 | notify you of any changes by posting the new Privacy Policy on 142 | this page. 143 |
144 |This policy is effective as of 2023-12-09
145 |Contact Us
146 |147 | If you have any questions or suggestions about my 148 | Privacy Policy, do not hesitate to contact me at hobbyone.droid@gmail.com. 149 |
150 |This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator
151 | 152 | 153 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.hobbyone.HashDroid" 7 | minSdkVersion 19 8 | targetSdkVersion 26 9 | versionCode 24 10 | versionName "4.3" 11 | // testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | // implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | // implementation 'com.android.support:appcompat-v7:28.0.0' 24 | // testImplementation 'junit:junit:4.12' 25 | // androidTestImplementation 'com.android.support.test:runner:1.0.2' 26 | // androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |42 | * A base abstract class to facilitate hash implementations. 43 | *
44 | */ 45 | public abstract class BaseHash implements IMessageDigest { 46 | 47 | // Constants and variables 48 | // ------------------------------------------------------------------------- 49 | 50 | /** 51 | * The canonical name prefix of the hash. 52 | */ 53 | protected String name; 54 | 55 | /** 56 | * The hash (output) size in bytes. 57 | */ 58 | protected int hashSize; 59 | 60 | /** 61 | * The hash (inner) block size in bytes. 62 | */ 63 | protected int blockSize; 64 | 65 | /** 66 | * Number of bytes processed so far. 67 | */ 68 | protected long count; 69 | 70 | /** 71 | * Temporary input buffer. 72 | */ 73 | protected byte[] buffer; 74 | 75 | // Constructor(s) 76 | // ------------------------------------------------------------------------- 77 | 78 | /** 79 | *80 | * Trivial constructor for use by concrete subclasses. 81 | *
82 | * 83 | * @param name the canonical name prefix of this instance. 84 | * @param hashSize the block size of the output in bytes. 85 | * @param blockSize the block size of the internal transform. 86 | */ 87 | protected BaseHash(String name, int hashSize, int blockSize) { 88 | super(); 89 | 90 | this.name = name; 91 | this.hashSize = hashSize; 92 | this.blockSize = blockSize; 93 | this.buffer = new byte[blockSize]; 94 | 95 | resetContext(); 96 | } 97 | 98 | // Class methods 99 | // ------------------------------------------------------------------------- 100 | 101 | // Instance methods 102 | // ------------------------------------------------------------------------- 103 | 104 | // IMessageDigest interface implementation --------------------------------- 105 | 106 | public String name() { 107 | return name; 108 | } 109 | 110 | public int hashSize() { 111 | return hashSize; 112 | } 113 | 114 | public int blockSize() { 115 | return blockSize; 116 | } 117 | 118 | public void update(byte b) { 119 | // compute number of bytes still unhashed; ie. present in buffer 120 | int i = (int) (count % blockSize); 121 | count++; 122 | buffer[i] = b; 123 | if (i == (blockSize - 1)) { 124 | transform(buffer, 0); 125 | } 126 | } 127 | 128 | public void update(byte[] b) { 129 | update(b, 0, b.length); 130 | } 131 | 132 | public void update(byte[] b, int offset, int len) { 133 | int n = (int) (count % blockSize); 134 | count += len; 135 | int partLen = blockSize - n; 136 | int i = 0; 137 | 138 | if (len >= partLen) { 139 | System.arraycopy(b, offset, buffer, n, partLen); 140 | transform(buffer, 0); 141 | for (i = partLen; i + blockSize - 1 < len; i += blockSize) { 142 | transform(b, offset + i); 143 | } 144 | n = 0; 145 | } 146 | 147 | if (i < len) { 148 | System.arraycopy(b, offset + i, buffer, n, len - i); 149 | } 150 | } 151 | 152 | public byte[] digest() { 153 | byte[] tail = padBuffer(); // pad remaining bytes in buffer 154 | update(tail, 0, tail.length); // last transform of a message 155 | byte[] result = getResult(); // make a result out of context 156 | 157 | reset(); // reset this instance for future re-use 158 | 159 | return result; 160 | } 161 | 162 | public void reset() { // reset this instance for future re-use 163 | count = 0L; 164 | for (int i = 0; i < blockSize; ) { 165 | buffer[i++] = 0; 166 | } 167 | 168 | resetContext(); 169 | } 170 | 171 | // methods to be implemented by concrete subclasses ------------------------ 172 | 173 | public abstract Object clone(); 174 | 175 | public abstract boolean selfTest(); 176 | 177 | /** 178 | *179 | * Returns the byte array to use as padding before completing a hash 180 | * operation. 181 | *
182 | * 183 | * @return the bytes to pad the remaining bytes in the buffer before 184 | * completing a hash operation. 185 | */ 186 | protected abstract byte[] padBuffer(); 187 | 188 | /** 189 | *190 | * Constructs the result from the contents of the current context. 191 | *
192 | * 193 | * @return the output of the completed hash operation. 194 | */ 195 | protected abstract byte[] getResult(); 196 | 197 | /** 198 | * Resets the instance for future re-use. 199 | */ 200 | protected abstract void resetContext(); 201 | 202 | /** 203 | *204 | * The block digest transformation per se. 205 | *
206 | * 207 | * @param in the blockSize long block, as an array of bytes to 208 | * digest. 209 | * @param offset the index where the data to digest is located within the input 210 | * buffer. 211 | */ 212 | protected abstract void transform(byte[] in, int offset); 213 | } 214 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/CompareActivity.java: -------------------------------------------------------------------------------- 1 | /* CompareActivity.java -- 2 | Copyright (C) 2010 Christophe Bouyer (Hobby One) 3 | 4 | This file is part of Hash Droid. 5 | 6 | Hash Droid is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | Hash Droid is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Hash Droid. If not, see42 | * A Factory to instantiate message digest algorithm instances. 43 | *
44 | */ 45 | public class HashFactory { 46 | 47 | // Constants and variables 48 | // ------------------------------------------------------------------------- 49 | 50 | // Constructor(s) 51 | // ------------------------------------------------------------------------- 52 | 53 | /** 54 | * Trivial constructor to enforce Singleton pattern. 55 | */ 56 | private HashFactory() { 57 | super(); 58 | } 59 | 60 | // Class methods 61 | // ------------------------------------------------------------------------- 62 | 63 | /** 64 | *65 | * Return an instance of a hash algorithm given its name. 66 | *
67 | * 68 | * @param name the name of the hash algorithm. 69 | * @return an instance of the hash algorithm, or null if none found. 70 | * @throws InternalError if the implementation does not pass its self- test. 71 | */ 72 | public static IMessageDigest getInstance(String name) { 73 | if (name == null) { 74 | return null; 75 | } 76 | 77 | name = name.trim(); 78 | IMessageDigest result = null; 79 | if (name.equalsIgnoreCase("haval")) 80 | result = new Haval(); 81 | else if (name.equalsIgnoreCase("md2")) 82 | result = new MD2(); 83 | else if (name.equalsIgnoreCase("md4")) 84 | result = new MD4(); 85 | else if (name.equalsIgnoreCase("md5")) 86 | result = new MD5(); 87 | else if (name.equalsIgnoreCase("ripemd-128")) 88 | result = new RipeMD128(); 89 | else if (name.equalsIgnoreCase("ripemd-160")) 90 | result = new RipeMD160(); 91 | else if (name.equalsIgnoreCase("sha-1")) 92 | result = new Sha160(); 93 | else if (name.equalsIgnoreCase("sha-256")) 94 | result = new Sha256(); 95 | else if (name.equalsIgnoreCase("sha-384")) 96 | result = new Sha384(); 97 | else if (name.equalsIgnoreCase("sha-512")) 98 | result = new Sha512(); 99 | else if (name.equalsIgnoreCase("tiger")) 100 | result = new Tiger(); 101 | else if (name.equalsIgnoreCase("whirlpool")) 102 | result = new Whirlpool(); 103 | 104 | return result; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/HashFunctionOperator.java: -------------------------------------------------------------------------------- 1 | /* HashFunctionOperator.java -- 2 | Copyright (C) 2010 Christophe Bouyer (Hobby One) 3 | 4 | This file is part of Hash Droid. 5 | 6 | Hash Droid is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | Hash Droid is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Hash Droid. If not, see42 | * The basic visible methods of any hash algorithm. 43 | *
44 | * 45 | *46 | * A hash (or message digest) algorithm produces its output by iterating a basic 47 | * compression function on blocks of data. 48 | *
49 | */ 50 | public interface IMessageDigest extends Cloneable { 51 | 52 | // Constants 53 | // ------------------------------------------------------------------------- 54 | 55 | // Methods 56 | // ------------------------------------------------------------------------- 57 | 58 | /** 59 | *60 | * Returns the canonical name of this algorithm. 61 | *
62 | * 63 | * @return the canonical name of this instance. 64 | */ 65 | String name(); 66 | 67 | /** 68 | *69 | * Returns the output length in bytes of this message digest algorithm. 70 | *
71 | * 72 | * @return the output length in bytes of this message digest algorithm. 73 | */ 74 | int hashSize(); 75 | 76 | /** 77 | *78 | * Returns the algorithm's (inner) block size in bytes. 79 | *
80 | * 81 | * @return the algorithm's inner block size in bytes. 82 | */ 83 | int blockSize(); 84 | 85 | /** 86 | *87 | * Continues a message digest operation using the input byte. 88 | *
89 | * 90 | * @param b the input byte to digest. 91 | */ 92 | void update(byte b); 93 | 94 | /** 95 | *96 | * Continues a message digest operation, by filling the buffer, processing 97 | * data in the algorithm's HASH_SIZE-bit block(s), updating the context and 98 | * count, and buffering the remaining bytes in buffer for the next 99 | * operation. 100 | *
101 | * 102 | * @param in the input block. 103 | */ 104 | void update(byte[] in); 105 | 106 | /** 107 | *108 | * Continues a message digest operation, by filling the buffer, processing 109 | * data in the algorithm's HASH_SIZE-bit block(s), updating the context and 110 | * count, and buffering the remaining bytes in buffer for the next 111 | * operation. 112 | *
113 | * 114 | * @param in the input block. 115 | * @param offset start of meaningful bytes in input block. 116 | * @param length number of bytes, in input block, to consider. 117 | */ 118 | void update(byte[] in, int offset, int length); 119 | 120 | /** 121 | *122 | * Completes the message digest by performing final operations such as 123 | * padding and resetting the instance. 124 | *
125 | * 126 | * @return the array of bytes representing the hash value. 127 | */ 128 | byte[] digest(); 129 | 130 | /** 131 | *132 | * Resets the current context of this instance clearing any eventually 133 | * cached intermediary values. 134 | *
135 | */ 136 | void reset(); 137 | 138 | /** 139 | *140 | * A basic test. Ensures that the digest of a pre-determined message is 141 | * equal to a known pre-computed value. 142 | *
143 | * 144 | * @return true if the implementation passes a basic self-test. 145 | * Returns false otherwise. 146 | */ 147 | boolean selfTest(); 148 | 149 | /** 150 | *151 | * Returns a clone copy of this instance. 152 | *
153 | * 154 | * @return a clone copy of this instance. 155 | */ 156 | Object clone(); 157 | } 158 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/MD2.java: -------------------------------------------------------------------------------- 1 | /* MD2.java -- 2 | Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * An implementation of the MD2 message digest algorithm. 43 | *
44 | * 45 | *46 | * MD2 is not widely used. Unless it is needed for compatibility with existing 47 | * systems, it is not recommended for use in new applications. 48 | *
49 | * 50 | *51 | * References: 52 | *
53 | * 54 | *BLOCK_LENGTH
117 | * bytes are also used to store the running digest.
118 | */
119 | private byte[] work;
120 |
121 | // Constructor(s)
122 | // -------------------------------------------------------------------------
123 |
124 | /**
125 | * Creates a new MD2 digest ready for use.
126 | */
127 | public MD2() {
128 | super("md2", DIGEST_LENGTH, BLOCK_LENGTH);
129 | }
130 |
131 | /**
132 | * 133 | * Private constructor used for cloning. 134 | *
135 | * 136 | * @param md2 the instance to clone. 137 | */ 138 | private MD2(MD2 md2) { 139 | this(); 140 | 141 | // superclass field 142 | this.count = md2.count; 143 | this.buffer = (byte[]) md2.buffer.clone(); 144 | 145 | // private field 146 | this.checksum = (byte[]) md2.checksum.clone(); 147 | this.work = (byte[]) md2.work.clone(); 148 | } 149 | 150 | // Class methods 151 | // ------------------------------------------------------------------------- 152 | 153 | // Instance methods 154 | // ------------------------------------------------------------------------- 155 | 156 | // java.lang.Cloneable interface implementation ---------------------------- 157 | 158 | public Object clone() { 159 | return new MD2(this); 160 | } 161 | 162 | // Implementation of abstract methods in BaseHash -------------------------- 163 | 164 | protected byte[] getResult() { 165 | byte[] result = new byte[DIGEST_LENGTH]; 166 | 167 | // Encrypt checksum as last block. 168 | encryptBlock(checksum, 0); 169 | 170 | for (int i = 0; i < BLOCK_LENGTH; i++) { 171 | result[i] = work[i]; 172 | } 173 | 174 | return result; 175 | } 176 | 177 | protected void resetContext() { 178 | checksum = new byte[BLOCK_LENGTH]; 179 | work = new byte[BLOCK_LENGTH * 3]; 180 | } 181 | 182 | public boolean selfTest() { 183 | if (valid == null) { 184 | valid = Boolean.valueOf(DIGEST0.equals(UtilServices 185 | .toString(new MD2().digest()))); 186 | } 187 | return valid.booleanValue(); 188 | } 189 | 190 | /** 191 | *
192 | * Generates an array of padding bytes. The padding is defined as
193 | * i
bytes of value i
, where i
is the
194 | * number of bytes to fill the last block of the message to
195 | * BLOCK_LENGTH
bytes (or BLOCK_LENGTH
bytes when
196 | * the last block was completely full).
197 | *
216 | * Adds BLOCK_LENGTH
bytes to the running digest.
217 | *
BLOCK_LENGTH
bytes
220 | * from.
221 | * @param off the offset to start from in the given byte array.
222 | */
223 | protected void transform(byte[] in, int off) {
224 | // encryptBlock(in, off);
225 | // updateCheckSum(in, off);
226 | updateCheckSumAndEncryptBlock(in, off);
227 | }
228 |
229 | // Private instance methods ------------------------------------------------
230 |
231 | /**
232 | * Updates the checksum with the BLOCK_LENGTH
bytes from the
233 | * given array starting at off
.
234 | */
235 | /*
236 | * private void updateCheckSum(byte[] in, int off) { byte l =
237 | * checksum[BLOCK_LENGTH-1]; for (int i = 0; i < BLOCK_LENGTH; i++) { byte b
238 | * = in[off+i]; // l = (byte)((checksum[i] & 0xFF) ^ (PI[((b & 0xFF) ^ (l &
239 | * 0xFF))] & 0xFF)); l = (byte)(checksum[i] ^ PI[(b ^ l) & 0xFF]);
240 | * checksum[i] = l; } }
241 | */
242 |
243 | /**
244 | * Adds a new block (BLOCK_LENGTH
bytes) to the running digest
245 | * from the given byte array starting from the given offset.
246 | */
247 | private void encryptBlock(byte[] in, int off) {
248 | for (int i = 0; i < BLOCK_LENGTH; i++) {
249 | byte b = in[off + i];
250 | work[BLOCK_LENGTH + i] = b;
251 | work[BLOCK_LENGTH * 2 + i] = (byte) (work[i] ^ b);
252 | }
253 |
254 | byte t = 0;
255 | for (int i = 0; i < 18; i++) {
256 | for (int j = 0; j < 3 * BLOCK_LENGTH; j++) {
257 | // t = (byte)((work[j] & 0xFF) ^ (PI[t & 0xFF] & 0xFF));
258 | t = (byte) (work[j] ^ PI[t & 0xFF]);
259 | work[j] = t;
260 | }
261 | // t = (byte)((t + i) & 0xFF);
262 | t = (byte) (t + i);
263 | }
264 | }
265 |
266 | /**
267 | * Optimized method that combines a checksum update and encrypt of a block.
268 | */
269 | private void updateCheckSumAndEncryptBlock(byte[] in, int off) {
270 | byte l = checksum[BLOCK_LENGTH - 1];
271 | for (int i = 0; i < BLOCK_LENGTH; i++) {
272 | byte b = in[off + i];
273 | work[BLOCK_LENGTH + i] = b;
274 | // work[BLOCK_LENGTH*2+i] = (byte)((work[i] & 0xFF) ^ (b & 0xFF));
275 | work[BLOCK_LENGTH * 2 + i] = (byte) (work[i] ^ b);
276 | // l = (byte)((checksum[i] & 0xFF) ^ (PI[((b & 0xFF) ^ (l & 0xFF))]
277 | // & 0xFF));
278 | l = (byte) (checksum[i] ^ PI[(b ^ l) & 0xFF]);
279 | checksum[i] = l;
280 | }
281 |
282 | byte t = 0;
283 | for (int i = 0; i < 18; i++) {
284 | for (int j = 0; j < 3 * BLOCK_LENGTH; j++) {
285 | // t = (byte)((work[j] & 0xFF) ^ (PI[t & 0xFF] & 0xFF));
286 | t = (byte) (work[j] ^ PI[t & 0xFF]);
287 | work[j] = t;
288 | }
289 | // t = (byte)((t + i) & 0xFF);
290 | t = (byte) (t + i);
291 | }
292 | }
293 | }
294 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hobbyone/HashDroid/MD4.java:
--------------------------------------------------------------------------------
1 | /* MD4.java --
2 | Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
3 |
4 | This file is a part of GNU Classpath.
5 |
6 | GNU Classpath is free software; you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation; either version 2 of the License, or (at
9 | your option) any later version.
10 |
11 | GNU Classpath is distributed in the hope that it will be useful, but
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with GNU Classpath; if not, write to the Free Software
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 | USA
20 |
21 | Linking this library statically or dynamically with other modules is
22 | making a combined work based on this library. Thus, the terms and
23 | conditions of the GNU General Public License cover the whole
24 | combination.
25 |
26 | As a special exception, the copyright holders of this library give you
27 | permission to link this library with independent modules to produce an
28 | executable, regardless of the license terms of these independent
29 | modules, and to copy and distribute the resulting executable under
30 | terms of your choice, provided that you also meet, for each linked
31 | independent module, the terms and conditions of the license of that
32 | module. An independent module is a module which is not derived from
33 | or based on this library. If you modify this library, you may extend
34 | this exception to your version of the library, but you are not
35 | obligated to do so. If you do not wish to do so, delete this
36 | exception statement from your version. */
37 |
38 | package com.hobbyone.HashDroid;
39 |
40 | /**
41 | * 42 | * An implementation of Ron Rivest's MD4 message digest algorithm. 43 | *
44 | * 45 | *46 | * MD4 was the precursor to the stronger {@link gnu.crypto.hash.MD5} algorithm, 47 | * and while not considered cryptograpically secure itself, MD4 is in use in 48 | * various applications. It is slightly faster than MD5. 49 | *
50 | * 51 | *52 | * References: 53 | *
54 | * 55 | *
103 | * Public constructor. Initializes the chaining variables, sets the byte
104 | * count to 0
, and creates a new block of 512
105 | * bits.
106 | *
114 | * Trivial private constructor for cloning purposes. 115 | *
116 | * 117 | * @param that the instance to clone. 118 | */ 119 | private MD4(MD4 that) { 120 | this(); 121 | 122 | this.a = that.a; 123 | this.b = that.b; 124 | this.c = that.c; 125 | this.d = that.d; 126 | this.count = that.count; 127 | this.buffer = (byte[]) that.buffer.clone(); 128 | } 129 | 130 | // Class methods 131 | // ------------------------------------------------------------------------- 132 | 133 | // Instance methods 134 | // ------------------------------------------------------------------------- 135 | 136 | // java.lang.Cloneable interface implementation ---------------------------- 137 | 138 | public Object clone() { 139 | return new MD4(this); 140 | } 141 | 142 | // Implementation of abstract methods in BashHash -------------------------- 143 | 144 | protected byte[] getResult() { 145 | byte[] digest = {(byte) a, (byte) (a >>> 8), (byte) (a >>> 16), 146 | (byte) (a >>> 24), (byte) b, (byte) (b >>> 8), 147 | (byte) (b >>> 16), (byte) (b >>> 24), (byte) c, 148 | (byte) (c >>> 8), (byte) (c >>> 16), (byte) (c >>> 24), 149 | (byte) d, (byte) (d >>> 8), (byte) (d >>> 16), 150 | (byte) (d >>> 24)}; 151 | return digest; 152 | } 153 | 154 | protected void resetContext() { 155 | a = A; 156 | b = B; 157 | c = C; 158 | d = D; 159 | } 160 | 161 | public boolean selfTest() { 162 | if (valid == null) { 163 | valid = Boolean.valueOf(DIGEST0.equals(UtilServices 164 | .toString(new MD4().digest()))); 165 | } 166 | return valid.booleanValue(); 167 | } 168 | 169 | protected byte[] padBuffer() { 170 | int n = (int) (count % BLOCK_LENGTH); 171 | int padding = (n < 56) ? (56 - n) : (120 - n); 172 | byte[] pad = new byte[padding + 8]; 173 | 174 | pad[0] = (byte) 0x80; 175 | long bits = count << 3; 176 | pad[padding++] = (byte) bits; 177 | pad[padding++] = (byte) (bits >>> 8); 178 | pad[padding++] = (byte) (bits >>> 16); 179 | pad[padding++] = (byte) (bits >>> 24); 180 | pad[padding++] = (byte) (bits >>> 32); 181 | pad[padding++] = (byte) (bits >>> 40); 182 | pad[padding++] = (byte) (bits >>> 48); 183 | pad[padding] = (byte) (bits >>> 56); 184 | 185 | return pad; 186 | } 187 | 188 | protected void transform(byte[] in, int i) { 189 | int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 190 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 191 | int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 192 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 193 | int X2 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 194 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 195 | int X3 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 196 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 197 | int X4 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 198 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 199 | int X5 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 200 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 201 | int X6 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 202 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 203 | int X7 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 204 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 205 | int X8 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 206 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 207 | int X9 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 208 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 209 | int X10 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 210 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 211 | int X11 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 212 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 213 | int X12 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 214 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 215 | int X13 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 216 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 217 | int X14 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 218 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 219 | int X15 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 220 | | (in[i++] & 0xFF) << 16 | in[i] << 24; 221 | 222 | int aa, bb, cc, dd; 223 | 224 | aa = a; 225 | bb = b; 226 | cc = c; 227 | dd = d; 228 | 229 | aa += ((bb & cc) | ((~bb) & dd)) + X0; 230 | aa = aa << 3 | aa >>> -3; 231 | dd += ((aa & bb) | ((~aa) & cc)) + X1; 232 | dd = dd << 7 | dd >>> -7; 233 | cc += ((dd & aa) | ((~dd) & bb)) + X2; 234 | cc = cc << 11 | cc >>> -11; 235 | bb += ((cc & dd) | ((~cc) & aa)) + X3; 236 | bb = bb << 19 | bb >>> -19; 237 | aa += ((bb & cc) | ((~bb) & dd)) + X4; 238 | aa = aa << 3 | aa >>> -3; 239 | dd += ((aa & bb) | ((~aa) & cc)) + X5; 240 | dd = dd << 7 | dd >>> -7; 241 | cc += ((dd & aa) | ((~dd) & bb)) + X6; 242 | cc = cc << 11 | cc >>> -11; 243 | bb += ((cc & dd) | ((~cc) & aa)) + X7; 244 | bb = bb << 19 | bb >>> -19; 245 | aa += ((bb & cc) | ((~bb) & dd)) + X8; 246 | aa = aa << 3 | aa >>> -3; 247 | dd += ((aa & bb) | ((~aa) & cc)) + X9; 248 | dd = dd << 7 | dd >>> -7; 249 | cc += ((dd & aa) | ((~dd) & bb)) + X10; 250 | cc = cc << 11 | cc >>> -11; 251 | bb += ((cc & dd) | ((~cc) & aa)) + X11; 252 | bb = bb << 19 | bb >>> -19; 253 | aa += ((bb & cc) | ((~bb) & dd)) + X12; 254 | aa = aa << 3 | aa >>> -3; 255 | dd += ((aa & bb) | ((~aa) & cc)) + X13; 256 | dd = dd << 7 | dd >>> -7; 257 | cc += ((dd & aa) | ((~dd) & bb)) + X14; 258 | cc = cc << 11 | cc >>> -11; 259 | bb += ((cc & dd) | ((~cc) & aa)) + X15; 260 | bb = bb << 19 | bb >>> -19; 261 | 262 | aa += ((bb & (cc | dd)) | (cc & dd)) + X0 + 0x5a827999; 263 | aa = aa << 3 | aa >>> -3; 264 | dd += ((aa & (bb | cc)) | (bb & cc)) + X4 + 0x5a827999; 265 | dd = dd << 5 | dd >>> -5; 266 | cc += ((dd & (aa | bb)) | (aa & bb)) + X8 + 0x5a827999; 267 | cc = cc << 9 | cc >>> -9; 268 | bb += ((cc & (dd | aa)) | (dd & aa)) + X12 + 0x5a827999; 269 | bb = bb << 13 | bb >>> -13; 270 | aa += ((bb & (cc | dd)) | (cc & dd)) + X1 + 0x5a827999; 271 | aa = aa << 3 | aa >>> -3; 272 | dd += ((aa & (bb | cc)) | (bb & cc)) + X5 + 0x5a827999; 273 | dd = dd << 5 | dd >>> -5; 274 | cc += ((dd & (aa | bb)) | (aa & bb)) + X9 + 0x5a827999; 275 | cc = cc << 9 | cc >>> -9; 276 | bb += ((cc & (dd | aa)) | (dd & aa)) + X13 + 0x5a827999; 277 | bb = bb << 13 | bb >>> -13; 278 | aa += ((bb & (cc | dd)) | (cc & dd)) + X2 + 0x5a827999; 279 | aa = aa << 3 | aa >>> -3; 280 | dd += ((aa & (bb | cc)) | (bb & cc)) + X6 + 0x5a827999; 281 | dd = dd << 5 | dd >>> -5; 282 | cc += ((dd & (aa | bb)) | (aa & bb)) + X10 + 0x5a827999; 283 | cc = cc << 9 | cc >>> -9; 284 | bb += ((cc & (dd | aa)) | (dd & aa)) + X14 + 0x5a827999; 285 | bb = bb << 13 | bb >>> -13; 286 | aa += ((bb & (cc | dd)) | (cc & dd)) + X3 + 0x5a827999; 287 | aa = aa << 3 | aa >>> -3; 288 | dd += ((aa & (bb | cc)) | (bb & cc)) + X7 + 0x5a827999; 289 | dd = dd << 5 | dd >>> -5; 290 | cc += ((dd & (aa | bb)) | (aa & bb)) + X11 + 0x5a827999; 291 | cc = cc << 9 | cc >>> -9; 292 | bb += ((cc & (dd | aa)) | (dd & aa)) + X15 + 0x5a827999; 293 | bb = bb << 13 | bb >>> -13; 294 | 295 | aa += (bb ^ cc ^ dd) + X0 + 0x6ed9eba1; 296 | aa = aa << 3 | aa >>> -3; 297 | dd += (aa ^ bb ^ cc) + X8 + 0x6ed9eba1; 298 | dd = dd << 9 | dd >>> -9; 299 | cc += (dd ^ aa ^ bb) + X4 + 0x6ed9eba1; 300 | cc = cc << 11 | cc >>> -11; 301 | bb += (cc ^ dd ^ aa) + X12 + 0x6ed9eba1; 302 | bb = bb << 15 | bb >>> -15; 303 | aa += (bb ^ cc ^ dd) + X2 + 0x6ed9eba1; 304 | aa = aa << 3 | aa >>> -3; 305 | dd += (aa ^ bb ^ cc) + X10 + 0x6ed9eba1; 306 | dd = dd << 9 | dd >>> -9; 307 | cc += (dd ^ aa ^ bb) + X6 + 0x6ed9eba1; 308 | cc = cc << 11 | cc >>> -11; 309 | bb += (cc ^ dd ^ aa) + X14 + 0x6ed9eba1; 310 | bb = bb << 15 | bb >>> -15; 311 | aa += (bb ^ cc ^ dd) + X1 + 0x6ed9eba1; 312 | aa = aa << 3 | aa >>> -3; 313 | dd += (aa ^ bb ^ cc) + X9 + 0x6ed9eba1; 314 | dd = dd << 9 | dd >>> -9; 315 | cc += (dd ^ aa ^ bb) + X5 + 0x6ed9eba1; 316 | cc = cc << 11 | cc >>> -11; 317 | bb += (cc ^ dd ^ aa) + X13 + 0x6ed9eba1; 318 | bb = bb << 15 | bb >>> -15; 319 | aa += (bb ^ cc ^ dd) + X3 + 0x6ed9eba1; 320 | aa = aa << 3 | aa >>> -3; 321 | dd += (aa ^ bb ^ cc) + X11 + 0x6ed9eba1; 322 | dd = dd << 9 | dd >>> -9; 323 | cc += (dd ^ aa ^ bb) + X7 + 0x6ed9eba1; 324 | cc = cc << 11 | cc >>> -11; 325 | bb += (cc ^ dd ^ aa) + X15 + 0x6ed9eba1; 326 | bb = bb << 15 | bb >>> -15; 327 | 328 | a += aa; 329 | b += bb; 330 | c += cc; 331 | d += dd; 332 | } 333 | } 334 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/MD5.java: -------------------------------------------------------------------------------- 1 | /* MD5.java -- 2 | Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * The MD5 message-digest algorithm takes as input a message of arbitrary length 43 | * and produces as output a 128-bit "fingerprint" or "message digest" of the 44 | * input. It is conjectured that it is computationally infeasible to produce two 45 | * messages having the same message digest, or to produce any message having a 46 | * given prespecified target message digest. 47 | *
48 | * 49 | *50 | * References: 51 | *
52 | * 53 | *90 | * Private constructor for cloning purposes. 91 | *
92 | * 93 | * @param md the instance to clone. 94 | */ 95 | private MD5(MD5 md) { 96 | this(); 97 | 98 | this.h0 = md.h0; 99 | this.h1 = md.h1; 100 | this.h2 = md.h2; 101 | this.h3 = md.h3; 102 | this.count = md.count; 103 | this.buffer = (byte[]) md.buffer.clone(); 104 | } 105 | 106 | // Class methods 107 | // ------------------------------------------------------------------------- 108 | 109 | // Instance methods 110 | // ------------------------------------------------------------------------- 111 | 112 | // java.lang.Cloneable interface implementation ---------------------------- 113 | 114 | public Object clone() { 115 | return new MD5(this); 116 | } 117 | 118 | // Implementation of concrete methods in BaseHash -------------------------- 119 | 120 | protected synchronized void transform(byte[] in, int i) { 121 | int X0 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 122 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 123 | int X1 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 124 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 125 | int X2 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 126 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 127 | int X3 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 128 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 129 | int X4 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 130 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 131 | int X5 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 132 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 133 | int X6 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 134 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 135 | int X7 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 136 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 137 | int X8 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 138 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 139 | int X9 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 140 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 141 | int X10 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 142 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 143 | int X11 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 144 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 145 | int X12 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 146 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 147 | int X13 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 148 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 149 | int X14 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 150 | | (in[i++] & 0xFF) << 16 | in[i++] << 24; 151 | int X15 = (in[i++] & 0xFF) | (in[i++] & 0xFF) << 8 152 | | (in[i++] & 0xFF) << 16 | in[i] << 24; 153 | 154 | int A = h0; 155 | int B = h1; 156 | int C = h2; 157 | int D = h3; 158 | 159 | // hex constants are from md5.c in FSF Gnu Privacy Guard 0.9.2 160 | // round 1 161 | A += ((B & C) | (~B & D)) + X0 + 0xD76AA478; 162 | A = B + (A << 7 | A >>> -7); 163 | D += ((A & B) | (~A & C)) + X1 + 0xE8C7B756; 164 | D = A + (D << 12 | D >>> -12); 165 | C += ((D & A) | (~D & B)) + X2 + 0x242070DB; 166 | C = D + (C << 17 | C >>> -17); 167 | B += ((C & D) | (~C & A)) + X3 + 0xC1BDCEEE; 168 | B = C + (B << 22 | B >>> -22); 169 | 170 | A += ((B & C) | (~B & D)) + X4 + 0xF57C0FAF; 171 | A = B + (A << 7 | A >>> -7); 172 | D += ((A & B) | (~A & C)) + X5 + 0x4787C62A; 173 | D = A + (D << 12 | D >>> -12); 174 | C += ((D & A) | (~D & B)) + X6 + 0xA8304613; 175 | C = D + (C << 17 | C >>> -17); 176 | B += ((C & D) | (~C & A)) + X7 + 0xFD469501; 177 | B = C + (B << 22 | B >>> -22); 178 | 179 | A += ((B & C) | (~B & D)) + X8 + 0x698098D8; 180 | A = B + (A << 7 | A >>> -7); 181 | D += ((A & B) | (~A & C)) + X9 + 0x8B44F7AF; 182 | D = A + (D << 12 | D >>> -12); 183 | C += ((D & A) | (~D & B)) + X10 + 0xFFFF5BB1; 184 | C = D + (C << 17 | C >>> -17); 185 | B += ((C & D) | (~C & A)) + X11 + 0x895CD7BE; 186 | B = C + (B << 22 | B >>> -22); 187 | 188 | A += ((B & C) | (~B & D)) + X12 + 0x6B901122; 189 | A = B + (A << 7 | A >>> -7); 190 | D += ((A & B) | (~A & C)) + X13 + 0xFD987193; 191 | D = A + (D << 12 | D >>> -12); 192 | C += ((D & A) | (~D & B)) + X14 + 0xA679438E; 193 | C = D + (C << 17 | C >>> -17); 194 | B += ((C & D) | (~C & A)) + X15 + 0x49B40821; 195 | B = C + (B << 22 | B >>> -22); 196 | 197 | // round 2 198 | A += ((B & D) | (C & ~D)) + X1 + 0xF61E2562; 199 | A = B + (A << 5 | A >>> -5); 200 | D += ((A & C) | (B & ~C)) + X6 + 0xC040B340; 201 | D = A + (D << 9 | D >>> -9); 202 | C += ((D & B) | (A & ~B)) + X11 + 0x265E5A51; 203 | C = D + (C << 14 | C >>> -14); 204 | B += ((C & A) | (D & ~A)) + X0 + 0xE9B6C7AA; 205 | B = C + (B << 20 | B >>> -20); 206 | 207 | A += ((B & D) | (C & ~D)) + X5 + 0xD62F105D; 208 | A = B + (A << 5 | A >>> -5); 209 | D += ((A & C) | (B & ~C)) + X10 + 0x02441453; 210 | D = A + (D << 9 | D >>> -9); 211 | C += ((D & B) | (A & ~B)) + X15 + 0xD8A1E681; 212 | C = D + (C << 14 | C >>> -14); 213 | B += ((C & A) | (D & ~A)) + X4 + 0xE7D3FBC8; 214 | B = C + (B << 20 | B >>> -20); 215 | 216 | A += ((B & D) | (C & ~D)) + X9 + 0x21E1CDE6; 217 | A = B + (A << 5 | A >>> -5); 218 | D += ((A & C) | (B & ~C)) + X14 + 0xC33707D6; 219 | D = A + (D << 9 | D >>> -9); 220 | C += ((D & B) | (A & ~B)) + X3 + 0xF4D50D87; 221 | C = D + (C << 14 | C >>> -14); 222 | B += ((C & A) | (D & ~A)) + X8 + 0x455A14ED; 223 | B = C + (B << 20 | B >>> -20); 224 | 225 | A += ((B & D) | (C & ~D)) + X13 + 0xA9E3E905; 226 | A = B + (A << 5 | A >>> -5); 227 | D += ((A & C) | (B & ~C)) + X2 + 0xFCEFA3F8; 228 | D = A + (D << 9 | D >>> -9); 229 | C += ((D & B) | (A & ~B)) + X7 + 0x676F02D9; 230 | C = D + (C << 14 | C >>> -14); 231 | B += ((C & A) | (D & ~A)) + X12 + 0x8D2A4C8A; 232 | B = C + (B << 20 | B >>> -20); 233 | 234 | // round 3 235 | A += (B ^ C ^ D) + X5 + 0xFFFA3942; 236 | A = B + (A << 4 | A >>> -4); 237 | D += (A ^ B ^ C) + X8 + 0x8771F681; 238 | D = A + (D << 11 | D >>> -11); 239 | C += (D ^ A ^ B) + X11 + 0x6D9D6122; 240 | C = D + (C << 16 | C >>> -16); 241 | B += (C ^ D ^ A) + X14 + 0xFDE5380C; 242 | B = C + (B << 23 | B >>> -23); 243 | 244 | A += (B ^ C ^ D) + X1 + 0xA4BEEA44; 245 | A = B + (A << 4 | A >>> -4); 246 | D += (A ^ B ^ C) + X4 + 0x4BDECFA9; 247 | D = A + (D << 11 | D >>> -11); 248 | C += (D ^ A ^ B) + X7 + 0xF6BB4B60; 249 | C = D + (C << 16 | C >>> -16); 250 | B += (C ^ D ^ A) + X10 + 0xBEBFBC70; 251 | B = C + (B << 23 | B >>> -23); 252 | 253 | A += (B ^ C ^ D) + X13 + 0x289B7EC6; 254 | A = B + (A << 4 | A >>> -4); 255 | D += (A ^ B ^ C) + X0 + 0xEAA127FA; 256 | D = A + (D << 11 | D >>> -11); 257 | C += (D ^ A ^ B) + X3 + 0xD4EF3085; 258 | C = D + (C << 16 | C >>> -16); 259 | B += (C ^ D ^ A) + X6 + 0x04881D05; 260 | B = C + (B << 23 | B >>> -23); 261 | 262 | A += (B ^ C ^ D) + X9 + 0xD9D4D039; 263 | A = B + (A << 4 | A >>> -4); 264 | D += (A ^ B ^ C) + X12 + 0xE6DB99E5; 265 | D = A + (D << 11 | D >>> -11); 266 | C += (D ^ A ^ B) + X15 + 0x1FA27CF8; 267 | C = D + (C << 16 | C >>> -16); 268 | B += (C ^ D ^ A) + X2 + 0xC4AC5665; 269 | B = C + (B << 23 | B >>> -23); 270 | 271 | // round 4 272 | A += (C ^ (B | ~D)) + X0 + 0xF4292244; 273 | A = B + (A << 6 | A >>> -6); 274 | D += (B ^ (A | ~C)) + X7 + 0x432AFF97; 275 | D = A + (D << 10 | D >>> -10); 276 | C += (A ^ (D | ~B)) + X14 + 0xAB9423A7; 277 | C = D + (C << 15 | C >>> -15); 278 | B += (D ^ (C | ~A)) + X5 + 0xFC93A039; 279 | B = C + (B << 21 | B >>> -21); 280 | 281 | A += (C ^ (B | ~D)) + X12 + 0x655B59C3; 282 | A = B + (A << 6 | A >>> -6); 283 | D += (B ^ (A | ~C)) + X3 + 0x8F0CCC92; 284 | D = A + (D << 10 | D >>> -10); 285 | C += (A ^ (D | ~B)) + X10 + 0xFFEFF47D; 286 | C = D + (C << 15 | C >>> -15); 287 | B += (D ^ (C | ~A)) + X1 + 0x85845dd1; 288 | B = C + (B << 21 | B >>> -21); 289 | 290 | A += (C ^ (B | ~D)) + X8 + 0x6FA87E4F; 291 | A = B + (A << 6 | A >>> -6); 292 | D += (B ^ (A | ~C)) + X15 + 0xFE2CE6E0; 293 | D = A + (D << 10 | D >>> -10); 294 | C += (A ^ (D | ~B)) + X6 + 0xA3014314; 295 | C = D + (C << 15 | C >>> -15); 296 | B += (D ^ (C | ~A)) + X13 + 0x4E0811A1; 297 | B = C + (B << 21 | B >>> -21); 298 | 299 | A += (C ^ (B | ~D)) + X4 + 0xF7537E82; 300 | A = B + (A << 6 | A >>> -6); 301 | D += (B ^ (A | ~C)) + X11 + 0xBD3AF235; 302 | D = A + (D << 10 | D >>> -10); 303 | C += (A ^ (D | ~B)) + X2 + 0x2AD7D2BB; 304 | C = D + (C << 15 | C >>> -15); 305 | B += (D ^ (C | ~A)) + X9 + 0xEB86D391; 306 | B = C + (B << 21 | B >>> -21); 307 | 308 | h0 += A; 309 | h1 += B; 310 | h2 += C; 311 | h3 += D; 312 | } 313 | 314 | protected byte[] padBuffer() { 315 | int n = (int) (count % BLOCK_SIZE); 316 | int padding = (n < 56) ? (56 - n) : (120 - n); 317 | byte[] result = new byte[padding + 8]; 318 | 319 | // padding is always binary 1 followed by binary 0s 320 | result[0] = (byte) 0x80; 321 | 322 | // save number of bits, casting the long to an array of 8 bytes 323 | long bits = count << 3; 324 | result[padding++] = (byte) bits; 325 | result[padding++] = (byte) (bits >>> 8); 326 | result[padding++] = (byte) (bits >>> 16); 327 | result[padding++] = (byte) (bits >>> 24); 328 | result[padding++] = (byte) (bits >>> 32); 329 | result[padding++] = (byte) (bits >>> 40); 330 | result[padding++] = (byte) (bits >>> 48); 331 | result[padding] = (byte) (bits >>> 56); 332 | 333 | return result; 334 | } 335 | 336 | protected byte[] getResult() { 337 | byte[] result = new byte[]{(byte) h0, (byte) (h0 >>> 8), 338 | (byte) (h0 >>> 16), (byte) (h0 >>> 24), (byte) h1, 339 | (byte) (h1 >>> 8), (byte) (h1 >>> 16), (byte) (h1 >>> 24), 340 | (byte) h2, (byte) (h2 >>> 8), (byte) (h2 >>> 16), 341 | (byte) (h2 >>> 24), (byte) h3, (byte) (h3 >>> 8), 342 | (byte) (h3 >>> 16), (byte) (h3 >>> 24)}; 343 | 344 | return result; 345 | } 346 | 347 | protected void resetContext() { 348 | // magic MD5/RIPEMD128 initialisation constants 349 | h0 = 0x67452301; 350 | h1 = 0xEFCDAB89; 351 | h2 = 0x98BADCFE; 352 | h3 = 0x10325476; 353 | } 354 | 355 | public boolean selfTest() { 356 | if (valid == null) { 357 | valid = Boolean.valueOf(DIGEST0.equals(UtilServices 358 | .toString(new MD5().digest()))); 359 | } 360 | return valid.booleanValue(); 361 | } 362 | } 363 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* MainActivity.java -- 2 | Copyright (C) 2010 Christophe Bouyer (Hobby One) 3 | 4 | This file is part of Hash Droid. 5 | 6 | Hash Droid is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | Hash Droid is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Hash Droid. If not, see42 | * RIPEMD-128 is a 128-bit message digest. 43 | *
44 | * 45 | *46 | * References: 47 | *
48 | * 49 | *116 | * Private constructor for cloning purposes. 117 | *
118 | * 119 | * @param md the instance to clone. 120 | */ 121 | private RipeMD128(RipeMD128 md) { 122 | this(); 123 | 124 | this.h0 = md.h0; 125 | this.h1 = md.h1; 126 | this.h2 = md.h2; 127 | this.h3 = md.h3; 128 | this.count = md.count; 129 | this.buffer = (byte[]) md.buffer.clone(); 130 | } 131 | 132 | // Class methods 133 | // ------------------------------------------------------------------------- 134 | 135 | // Instance methods 136 | // ------------------------------------------------------------------------- 137 | 138 | // java.lang.Cloneable interface implementation ---------------------------- 139 | 140 | public Object clone() { 141 | return new RipeMD128(this); 142 | } 143 | 144 | // Implementation of concrete methods in BaseHash -------------------------- 145 | 146 | protected void transform(byte[] in, int offset) { 147 | int A, B, C, D, Ap, Bp, Cp, Dp, T, s, i; 148 | 149 | // encode 64 bytes from input block into an array of 16 unsigned 150 | // integers. 151 | for (i = 0; i < 16; i++) { 152 | X[i] = (in[offset++] & 0xFF) | (in[offset++] & 0xFF) << 8 153 | | (in[offset++] & 0xFF) << 16 | in[offset++] << 24; 154 | } 155 | 156 | A = Ap = h0; 157 | B = Bp = h1; 158 | C = Cp = h2; 159 | D = Dp = h3; 160 | 161 | for (i = 0; i < 16; i++) { // rounds 0...15 162 | s = S[i]; 163 | T = A + (B ^ C ^ D) + X[i]; 164 | A = D; 165 | D = C; 166 | C = B; 167 | B = T << s | T >>> (32 - s); 168 | 169 | s = Sp[i]; 170 | T = Ap + ((Bp & Dp) | (Cp & ~Dp)) + X[Rp[i]] + 0x50A28BE6; 171 | Ap = Dp; 172 | Dp = Cp; 173 | Cp = Bp; 174 | Bp = T << s | T >>> (32 - s); 175 | } 176 | 177 | for (; i < 32; i++) { // rounds 16...31 178 | s = S[i]; 179 | T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999; 180 | A = D; 181 | D = C; 182 | C = B; 183 | B = T << s | T >>> (32 - s); 184 | 185 | s = Sp[i]; 186 | T = Ap + ((Bp | ~Cp) ^ Dp) + X[Rp[i]] + 0x5C4DD124; 187 | Ap = Dp; 188 | Dp = Cp; 189 | Cp = Bp; 190 | Bp = T << s | T >>> (32 - s); 191 | } 192 | 193 | for (; i < 48; i++) { // rounds 32...47 194 | s = S[i]; 195 | T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1; 196 | A = D; 197 | D = C; 198 | C = B; 199 | B = T << s | T >>> (32 - s); 200 | 201 | s = Sp[i]; 202 | T = Ap + ((Bp & Cp) | (~Bp & Dp)) + X[Rp[i]] + 0x6D703EF3; 203 | Ap = Dp; 204 | Dp = Cp; 205 | Cp = Bp; 206 | Bp = T << s | T >>> (32 - s); 207 | } 208 | 209 | for (; i < 64; i++) { // rounds 48...63 210 | s = S[i]; 211 | T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC; 212 | A = D; 213 | D = C; 214 | C = B; 215 | B = T << s | T >>> (32 - s); 216 | 217 | s = Sp[i]; 218 | T = Ap + (Bp ^ Cp ^ Dp) + X[Rp[i]]; 219 | Ap = Dp; 220 | Dp = Cp; 221 | Cp = Bp; 222 | Bp = T << s | T >>> (32 - s); 223 | } 224 | 225 | T = h1 + C + Dp; 226 | h1 = h2 + D + Ap; 227 | h2 = h3 + A + Bp; 228 | h3 = h0 + B + Cp; 229 | h0 = T; 230 | } 231 | 232 | protected byte[] padBuffer() { 233 | int n = (int) (count % BLOCK_SIZE); 234 | int padding = (n < 56) ? (56 - n) : (120 - n); 235 | byte[] result = new byte[padding + 8]; 236 | 237 | // padding is always binary 1 followed by binary 0s 238 | result[0] = (byte) 0x80; 239 | 240 | // save number of bits, casting the long to an array of 8 bytes 241 | long bits = count << 3; 242 | result[padding++] = (byte) bits; 243 | result[padding++] = (byte) (bits >>> 8); 244 | result[padding++] = (byte) (bits >>> 16); 245 | result[padding++] = (byte) (bits >>> 24); 246 | result[padding++] = (byte) (bits >>> 32); 247 | result[padding++] = (byte) (bits >>> 40); 248 | result[padding++] = (byte) (bits >>> 48); 249 | result[padding] = (byte) (bits >>> 56); 250 | 251 | return result; 252 | } 253 | 254 | protected byte[] getResult() { 255 | byte[] result = new byte[]{(byte) h0, (byte) (h0 >>> 8), 256 | (byte) (h0 >>> 16), (byte) (h0 >>> 24), (byte) h1, 257 | (byte) (h1 >>> 8), (byte) (h1 >>> 16), (byte) (h1 >>> 24), 258 | (byte) h2, (byte) (h2 >>> 8), (byte) (h2 >>> 16), 259 | (byte) (h2 >>> 24), (byte) h3, (byte) (h3 >>> 8), 260 | (byte) (h3 >>> 16), (byte) (h3 >>> 24)}; 261 | 262 | return result; 263 | } 264 | 265 | protected void resetContext() { 266 | // magic RIPEMD128 initialisation constants 267 | h0 = 0x67452301; 268 | h1 = 0xEFCDAB89; 269 | h2 = 0x98BADCFE; 270 | h3 = 0x10325476; 271 | } 272 | 273 | public boolean selfTest() { 274 | if (valid == null) { 275 | valid = Boolean.valueOf(DIGEST0.equals(UtilServices 276 | .toString(new RipeMD128().digest()))); 277 | } 278 | return valid.booleanValue(); 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/RipeMD160.java: -------------------------------------------------------------------------------- 1 | /* RipeMD160.java -- 2 | Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * RIPEMD-160 is a 160-bit message digest. 43 | *
44 | * 45 | *46 | * References: 47 | *
48 | * 49 | *117 | * Private constructor for cloning purposes. 118 | *
119 | * 120 | * @param md the instance to clone. 121 | */ 122 | private RipeMD160(RipeMD160 md) { 123 | this(); 124 | 125 | this.h0 = md.h0; 126 | this.h1 = md.h1; 127 | this.h2 = md.h2; 128 | this.h3 = md.h3; 129 | this.h4 = md.h4; 130 | this.count = md.count; 131 | this.buffer = (byte[]) md.buffer.clone(); 132 | } 133 | 134 | // Class methods 135 | // ------------------------------------------------------------------------- 136 | 137 | // Instance methods 138 | // ------------------------------------------------------------------------- 139 | 140 | // java.lang.Cloneable interface implementation ---------------------------- 141 | 142 | public Object clone() { 143 | return (new RipeMD160(this)); 144 | } 145 | 146 | // Implementation of concrete methods in BaseHash -------------------------- 147 | 148 | protected void transform(byte[] in, int offset) { 149 | int A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, T, s, i; 150 | 151 | // encode 64 bytes from input block into an array of 16 unsigned 152 | // integers 153 | for (i = 0; i < 16; i++) { 154 | X[i] = (in[offset++] & 0xFF) | (in[offset++] & 0xFF) << 8 155 | | (in[offset++] & 0xFF) << 16 | in[offset++] << 24; 156 | } 157 | 158 | A = Ap = h0; 159 | B = Bp = h1; 160 | C = Cp = h2; 161 | D = Dp = h3; 162 | E = Ep = h4; 163 | 164 | for (i = 0; i < 16; i++) { // rounds 0...15 165 | s = S[i]; 166 | T = A + (B ^ C ^ D) + X[i]; 167 | A = E; 168 | E = D; 169 | D = C << 10 | C >>> 22; 170 | C = B; 171 | B = (T << s | T >>> (32 - s)) + A; 172 | 173 | s = Sp[i]; 174 | T = Ap + (Bp ^ (Cp | ~Dp)) + X[Rp[i]] + 0x50A28BE6; 175 | Ap = Ep; 176 | Ep = Dp; 177 | Dp = Cp << 10 | Cp >>> 22; 178 | Cp = Bp; 179 | Bp = (T << s | T >>> (32 - s)) + Ap; 180 | } 181 | 182 | for (; i < 32; i++) { // rounds 16...31 183 | s = S[i]; 184 | T = A + ((B & C) | (~B & D)) + X[R[i]] + 0x5A827999; 185 | A = E; 186 | E = D; 187 | D = C << 10 | C >>> 22; 188 | C = B; 189 | B = (T << s | T >>> (32 - s)) + A; 190 | 191 | s = Sp[i]; 192 | T = Ap + ((Bp & Dp) | (Cp & ~Dp)) + X[Rp[i]] + 0x5C4DD124; 193 | Ap = Ep; 194 | Ep = Dp; 195 | Dp = Cp << 10 | Cp >>> 22; 196 | Cp = Bp; 197 | Bp = (T << s | T >>> (32 - s)) + Ap; 198 | } 199 | 200 | for (; i < 48; i++) { // rounds 32...47 201 | s = S[i]; 202 | T = A + ((B | ~C) ^ D) + X[R[i]] + 0x6ED9EBA1; 203 | A = E; 204 | E = D; 205 | D = C << 10 | C >>> 22; 206 | C = B; 207 | B = (T << s | T >>> (32 - s)) + A; 208 | 209 | s = Sp[i]; 210 | T = Ap + ((Bp | ~Cp) ^ Dp) + X[Rp[i]] + 0x6D703EF3; 211 | Ap = Ep; 212 | Ep = Dp; 213 | Dp = Cp << 10 | Cp >>> 22; 214 | Cp = Bp; 215 | Bp = (T << s | T >>> (32 - s)) + Ap; 216 | } 217 | 218 | for (; i < 64; i++) { // rounds 48...63 219 | s = S[i]; 220 | T = A + ((B & D) | (C & ~D)) + X[R[i]] + 0x8F1BBCDC; 221 | A = E; 222 | E = D; 223 | D = C << 10 | C >>> 22; 224 | C = B; 225 | B = (T << s | T >>> (32 - s)) + A; 226 | 227 | s = Sp[i]; 228 | T = Ap + ((Bp & Cp) | (~Bp & Dp)) + X[Rp[i]] + 0x7A6D76E9; 229 | Ap = Ep; 230 | Ep = Dp; 231 | Dp = Cp << 10 | Cp >>> 22; 232 | Cp = Bp; 233 | Bp = (T << s | T >>> (32 - s)) + Ap; 234 | } 235 | 236 | for (; i < 80; i++) { // rounds 64...79 237 | s = S[i]; 238 | T = A + (B ^ (C | ~D)) + X[R[i]] + 0xA953FD4E; 239 | A = E; 240 | E = D; 241 | D = C << 10 | C >>> 22; 242 | C = B; 243 | B = (T << s | T >>> (32 - s)) + A; 244 | 245 | s = Sp[i]; 246 | T = Ap + (Bp ^ Cp ^ Dp) + X[Rp[i]]; 247 | Ap = Ep; 248 | Ep = Dp; 249 | Dp = Cp << 10 | Cp >>> 22; 250 | Cp = Bp; 251 | Bp = (T << s | T >>> (32 - s)) + Ap; 252 | } 253 | 254 | T = h1 + C + Dp; 255 | h1 = h2 + D + Ep; 256 | h2 = h3 + E + Ap; 257 | h3 = h4 + A + Bp; 258 | h4 = h0 + B + Cp; 259 | h0 = T; 260 | } 261 | 262 | protected byte[] padBuffer() { 263 | int n = (int) (count % BLOCK_SIZE); 264 | int padding = (n < 56) ? (56 - n) : (120 - n); 265 | byte[] result = new byte[padding + 8]; 266 | 267 | // padding is always binary 1 followed by binary 0s 268 | result[0] = (byte) 0x80; 269 | 270 | // save number of bits, casting the long to an array of 8 bytes 271 | long bits = count << 3; 272 | result[padding++] = (byte) bits; 273 | result[padding++] = (byte) (bits >>> 8); 274 | result[padding++] = (byte) (bits >>> 16); 275 | result[padding++] = (byte) (bits >>> 24); 276 | result[padding++] = (byte) (bits >>> 32); 277 | result[padding++] = (byte) (bits >>> 40); 278 | result[padding++] = (byte) (bits >>> 48); 279 | result[padding] = (byte) (bits >>> 56); 280 | 281 | return result; 282 | } 283 | 284 | protected byte[] getResult() { 285 | byte[] result = new byte[]{(byte) h0, (byte) (h0 >>> 8), 286 | (byte) (h0 >>> 16), (byte) (h0 >>> 24), (byte) h1, 287 | (byte) (h1 >>> 8), (byte) (h1 >>> 16), (byte) (h1 >>> 24), 288 | (byte) h2, (byte) (h2 >>> 8), (byte) (h2 >>> 16), 289 | (byte) (h2 >>> 24), (byte) h3, (byte) (h3 >>> 8), 290 | (byte) (h3 >>> 16), (byte) (h3 >>> 24), (byte) h4, 291 | (byte) (h4 >>> 8), (byte) (h4 >>> 16), (byte) (h4 >>> 24)}; 292 | 293 | return result; 294 | } 295 | 296 | protected void resetContext() { 297 | // magic RIPEMD160 initialisation constants 298 | h0 = 0x67452301; 299 | h1 = 0xEFCDAB89; 300 | h2 = 0x98BADCFE; 301 | h3 = 0x10325476; 302 | h4 = 0xC3D2E1F0; 303 | } 304 | 305 | public boolean selfTest() { 306 | if (valid == null) { 307 | valid = Boolean.valueOf(DIGEST0.equals(UtilServices 308 | .toString(new RipeMD160().digest()))); 309 | } 310 | return valid.booleanValue(); 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/Sha160.java: -------------------------------------------------------------------------------- 1 | /* Sha160.java -- 2 | Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * The Secure Hash Algorithm (SHA-1) is required for use with the Digital 43 | * Signature Algorithm (DSA) as specified in the Digital Signature Standard 44 | * (DSS) and whenever a secure hash algorithm is required for federal 45 | * applications. For a message of length less than 2^64 bits, the SHA-1 produces 46 | * a 160-bit condensed representation of the message called a message digest. 47 | * The message digest is used during generation of a signature for the message. 48 | * The SHA-1 is also used to compute a message digest for the received version 49 | * of the message during the process of verifying the signature. Any change to 50 | * the message in transit will, with very high probability, result in a 51 | * different message digest, and the signature will fail to verify. 52 | *
53 | * 54 | *55 | * The SHA-1 is designed to have the following properties: it is computationally 56 | * infeasible to find a message which corresponds to a given message digest, or 57 | * to find two different messages which produce the same message digest. 58 | *
59 | * 60 | *61 | * References: 62 | *
63 | * 64 | *103 | * Private constructor for cloning purposes. 104 | *
105 | * 106 | * @param md the instance to clone. 107 | */ 108 | private Sha160(Sha160 md) { 109 | this(); 110 | 111 | this.h0 = md.h0; 112 | this.h1 = md.h1; 113 | this.h2 = md.h2; 114 | this.h3 = md.h3; 115 | this.h4 = md.h4; 116 | this.count = md.count; 117 | this.buffer = (byte[]) md.buffer.clone(); 118 | } 119 | 120 | // Class methods 121 | // ------------------------------------------------------------------------- 122 | 123 | public static final int[] G(int hh0, int hh1, int hh2, int hh3, int hh4, 124 | byte[] in, int offset) { 125 | // int[] w = new int[80]; 126 | // int i, T; 127 | // for (i = 0; i < 16; i++) { 128 | // w[i] = in[offset++] << 24 | 129 | // (in[offset++] & 0xFF) << 16 | 130 | // (in[offset++] & 0xFF) << 8 | 131 | // (in[offset++] & 0xFF); 132 | // } 133 | // for (i = 16; i < 80; i++) { 134 | // T = w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]; 135 | // w[i] = T << 1 | T >>> 31; 136 | // } 137 | 138 | // return sha(hh0, hh1, hh2, hh3, hh4, in, offset, w); 139 | return sha(hh0, hh1, hh2, hh3, hh4, in, offset); 140 | } 141 | 142 | // Instance methods 143 | // ------------------------------------------------------------------------- 144 | 145 | // java.lang.Cloneable interface implementation ---------------------------- 146 | 147 | public Object clone() { 148 | return new Sha160(this); 149 | } 150 | 151 | // Implementation of concrete methods in BaseHash -------------------------- 152 | 153 | protected void transform(byte[] in, int offset) { 154 | // int i, T; 155 | // for (i = 0; i < 16; i++) { 156 | // W[i] = in[offset++] << 24 | 157 | // (in[offset++] & 0xFF) << 16 | 158 | // (in[offset++] & 0xFF) << 8 | 159 | // (in[offset++] & 0xFF); 160 | // } 161 | // for (i = 16; i < 80; i++) { 162 | // T = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]; 163 | // W[i] = T << 1 | T >>> 31; 164 | // } 165 | 166 | // int[] result = sha(h0, h1, h2, h3, h4, in, offset, W); 167 | int[] result = sha(h0, h1, h2, h3, h4, in, offset); 168 | 169 | h0 = result[0]; 170 | h1 = result[1]; 171 | h2 = result[2]; 172 | h3 = result[3]; 173 | h4 = result[4]; 174 | } 175 | 176 | protected byte[] padBuffer() { 177 | int n = (int) (count % BLOCK_SIZE); 178 | int padding = (n < 56) ? (56 - n) : (120 - n); 179 | byte[] result = new byte[padding + 8]; 180 | 181 | // padding is always binary 1 followed by binary 0s 182 | result[0] = (byte) 0x80; 183 | 184 | // save number of bits, casting the long to an array of 8 bytes 185 | long bits = count << 3; 186 | result[padding++] = (byte) (bits >>> 56); 187 | result[padding++] = (byte) (bits >>> 48); 188 | result[padding++] = (byte) (bits >>> 40); 189 | result[padding++] = (byte) (bits >>> 32); 190 | result[padding++] = (byte) (bits >>> 24); 191 | result[padding++] = (byte) (bits >>> 16); 192 | result[padding++] = (byte) (bits >>> 8); 193 | result[padding] = (byte) bits; 194 | 195 | return result; 196 | } 197 | 198 | protected byte[] getResult() { 199 | byte[] result = new byte[]{(byte) (h0 >>> 24), (byte) (h0 >>> 16), 200 | (byte) (h0 >>> 8), (byte) h0, (byte) (h1 >>> 24), 201 | (byte) (h1 >>> 16), (byte) (h1 >>> 8), (byte) h1, 202 | (byte) (h2 >>> 24), (byte) (h2 >>> 16), (byte) (h2 >>> 8), 203 | (byte) h2, (byte) (h3 >>> 24), (byte) (h3 >>> 16), 204 | (byte) (h3 >>> 8), (byte) h3, (byte) (h4 >>> 24), 205 | (byte) (h4 >>> 16), (byte) (h4 >>> 8), (byte) h4}; 206 | 207 | return result; 208 | } 209 | 210 | protected void resetContext() { 211 | // magic SHA-1/RIPEMD160 initialisation constants 212 | h0 = 0x67452301; 213 | h1 = 0xEFCDAB89; 214 | h2 = 0x98BADCFE; 215 | h3 = 0x10325476; 216 | h4 = 0xC3D2E1F0; 217 | } 218 | 219 | public boolean selfTest() { 220 | if (valid == null) { 221 | Sha160 md = new Sha160(); 222 | md.update((byte) 0x61); // a 223 | md.update((byte) 0x62); // b 224 | md.update((byte) 0x63); // c 225 | String result = UtilServices.toString(md.digest()); 226 | valid = Boolean.valueOf(DIGEST0.equals(result)); 227 | } 228 | return valid.booleanValue(); 229 | } 230 | 231 | // SHA specific methods ---------------------------------------------------- 232 | 233 | private static final synchronized int[] 234 | // sha(int hh0, int hh1, int hh2, int hh3, int hh4, byte[] in, int offset, 235 | // int[] w) { 236 | sha(int hh0, int hh1, int hh2, int hh3, int hh4, byte[] in, int offset) { 237 | int A = hh0; 238 | int B = hh1; 239 | int C = hh2; 240 | int D = hh3; 241 | int E = hh4; 242 | int r, T; 243 | 244 | for (r = 0; r < 16; r++) { 245 | w[r] = in[offset++] << 24 | (in[offset++] & 0xFF) << 16 246 | | (in[offset++] & 0xFF) << 8 | (in[offset++] & 0xFF); 247 | } 248 | for (r = 16; r < 80; r++) { 249 | T = w[r - 3] ^ w[r - 8] ^ w[r - 14] ^ w[r - 16]; 250 | w[r] = T << 1 | T >>> 31; 251 | } 252 | 253 | // rounds 0-19 254 | for (r = 0; r < 20; r++) { 255 | T = (A << 5 | A >>> 27) + ((B & C) | (~B & D)) + E + w[r] 256 | + 0x5A827999; 257 | E = D; 258 | D = C; 259 | C = B << 30 | B >>> 2; 260 | B = A; 261 | A = T; 262 | } 263 | 264 | // rounds 20-39 265 | for (r = 20; r < 40; r++) { 266 | T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0x6ED9EBA1; 267 | E = D; 268 | D = C; 269 | C = B << 30 | B >>> 2; 270 | B = A; 271 | A = T; 272 | } 273 | 274 | // rounds 40-59 275 | for (r = 40; r < 60; r++) { 276 | T = (A << 5 | A >>> 27) + (B & C | B & D | C & D) + E + w[r] 277 | + 0x8F1BBCDC; 278 | E = D; 279 | D = C; 280 | C = B << 30 | B >>> 2; 281 | B = A; 282 | A = T; 283 | } 284 | 285 | // rounds 60-79 286 | for (r = 60; r < 80; r++) { 287 | T = (A << 5 | A >>> 27) + (B ^ C ^ D) + E + w[r] + 0xCA62C1D6; 288 | E = D; 289 | D = C; 290 | C = B << 30 | B >>> 2; 291 | B = A; 292 | A = T; 293 | } 294 | 295 | return new int[]{hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E}; 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/Sha256.java: -------------------------------------------------------------------------------- 1 | /* Sha256.java -- 2 | Copyright (C) 2003, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * Implementation of SHA2-1 [SHA-256] per the IETF Draft Specification. 43 | *
44 | * 45 | *46 | * References: 47 | *
48 | *102 | * Private constructor for cloning purposes. 103 | *
104 | * 105 | * @param md the instance to clone. 106 | */ 107 | private Sha256(Sha256 md) { 108 | this(); 109 | 110 | this.h0 = md.h0; 111 | this.h1 = md.h1; 112 | this.h2 = md.h2; 113 | this.h3 = md.h3; 114 | this.h4 = md.h4; 115 | this.h5 = md.h5; 116 | this.h6 = md.h6; 117 | this.h7 = md.h7; 118 | this.count = md.count; 119 | this.buffer = (byte[]) md.buffer.clone(); 120 | } 121 | 122 | // Class methods 123 | // ------------------------------------------------------------------------- 124 | 125 | public static final int[] G(int hh0, int hh1, int hh2, int hh3, int hh4, 126 | int hh5, int hh6, int hh7, byte[] in, int offset) { 127 | return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); 128 | } 129 | 130 | // Instance methods 131 | // ------------------------------------------------------------------------- 132 | 133 | // java.lang.Cloneable interface implementation ---------------------------- 134 | 135 | public Object clone() { 136 | return new Sha256(this); 137 | } 138 | 139 | // Implementation of concrete methods in BaseHash -------------------------- 140 | 141 | protected void transform(byte[] in, int offset) { 142 | int[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); 143 | 144 | h0 = result[0]; 145 | h1 = result[1]; 146 | h2 = result[2]; 147 | h3 = result[3]; 148 | h4 = result[4]; 149 | h5 = result[5]; 150 | h6 = result[6]; 151 | h7 = result[7]; 152 | } 153 | 154 | protected byte[] padBuffer() { 155 | int n = (int) (count % BLOCK_SIZE); 156 | int padding = (n < 56) ? (56 - n) : (120 - n); 157 | byte[] result = new byte[padding + 8]; 158 | 159 | // padding is always binary 1 followed by binary 0s 160 | result[0] = (byte) 0x80; 161 | 162 | // save number of bits, casting the long to an array of 8 bytes 163 | long bits = count << 3; 164 | result[padding++] = (byte) (bits >>> 56); 165 | result[padding++] = (byte) (bits >>> 48); 166 | result[padding++] = (byte) (bits >>> 40); 167 | result[padding++] = (byte) (bits >>> 32); 168 | result[padding++] = (byte) (bits >>> 24); 169 | result[padding++] = (byte) (bits >>> 16); 170 | result[padding++] = (byte) (bits >>> 8); 171 | result[padding] = (byte) bits; 172 | 173 | return result; 174 | } 175 | 176 | protected byte[] getResult() { 177 | return new byte[]{(byte) (h0 >>> 24), (byte) (h0 >>> 16), 178 | (byte) (h0 >>> 8), (byte) h0, (byte) (h1 >>> 24), 179 | (byte) (h1 >>> 16), (byte) (h1 >>> 8), (byte) h1, 180 | (byte) (h2 >>> 24), (byte) (h2 >>> 16), (byte) (h2 >>> 8), 181 | (byte) h2, (byte) (h3 >>> 24), (byte) (h3 >>> 16), 182 | (byte) (h3 >>> 8), (byte) h3, (byte) (h4 >>> 24), 183 | (byte) (h4 >>> 16), (byte) (h4 >>> 8), (byte) h4, 184 | (byte) (h5 >>> 24), (byte) (h5 >>> 16), (byte) (h5 >>> 8), 185 | (byte) h5, (byte) (h6 >>> 24), (byte) (h6 >>> 16), 186 | (byte) (h6 >>> 8), (byte) h6, (byte) (h7 >>> 24), 187 | (byte) (h7 >>> 16), (byte) (h7 >>> 8), (byte) h7}; 188 | } 189 | 190 | protected void resetContext() { 191 | // magic SHA-256 initialisation constants 192 | h0 = 0x6a09e667; 193 | h1 = 0xbb67ae85; 194 | h2 = 0x3c6ef372; 195 | h3 = 0xa54ff53a; 196 | h4 = 0x510e527f; 197 | h5 = 0x9b05688c; 198 | h6 = 0x1f83d9ab; 199 | h7 = 0x5be0cd19; 200 | } 201 | 202 | public boolean selfTest() { 203 | if (valid == null) { 204 | Sha256 md = new Sha256(); 205 | md.update((byte) 0x61); // a 206 | md.update((byte) 0x62); // b 207 | md.update((byte) 0x63); // c 208 | String result = UtilServices.toString(md.digest()); 209 | valid = Boolean.valueOf(DIGEST0.equals(result)); 210 | } 211 | 212 | return valid.booleanValue(); 213 | } 214 | 215 | // SHA specific methods ---------------------------------------------------- 216 | 217 | private static final synchronized int[] sha(int hh0, int hh1, int hh2, 218 | int hh3, int hh4, int hh5, int hh6, int hh7, byte[] in, int offset) { 219 | int A = hh0; 220 | int B = hh1; 221 | int C = hh2; 222 | int D = hh3; 223 | int E = hh4; 224 | int F = hh5; 225 | int G = hh6; 226 | int H = hh7; 227 | int r, T, T2; 228 | 229 | for (r = 0; r < 16; r++) { 230 | w[r] = (in[offset++] << 24 | (in[offset++] & 0xFF) << 16 231 | | (in[offset++] & 0xFF) << 8 | (in[offset++] & 0xFF)); 232 | } 233 | for (r = 16; r < 64; r++) { 234 | T = w[r - 2]; 235 | T2 = w[r - 15]; 236 | w[r] = ((((T >>> 17) | (T << 15)) ^ ((T >>> 19) | (T << 13)) ^ (T >>> 10)) 237 | + w[r - 7] 238 | + (((T2 >>> 7) | (T2 << 25)) ^ ((T2 >>> 18) | (T2 << 14)) ^ (T2 >>> 3)) + w[r - 16]); 239 | } 240 | 241 | for (r = 0; r < 64; r++) { 242 | T = (H 243 | + (((E >>> 6) | (E << 26)) ^ ((E >>> 11) | (E << 21)) ^ ((E >>> 25) | (E << 7))) 244 | + ((E & F) ^ (~E & G)) + k[r] + w[r]); 245 | T2 = ((((A >>> 2) | (A << 30)) ^ ((A >>> 13) | (A << 19)) ^ ((A >>> 22) | (A << 10))) + ((A & B) 246 | ^ (A & C) ^ (B & C))); 247 | H = G; 248 | G = F; 249 | F = E; 250 | E = D + T; 251 | D = C; 252 | C = B; 253 | B = A; 254 | A = T + T2; 255 | } 256 | 257 | return new int[]{hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, 258 | hh5 + F, hh6 + G, hh7 + H}; 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/Sha384.java: -------------------------------------------------------------------------------- 1 | /* Sha384.java -- 2 | Copyright (C) 2003, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * Implementation of SHA2-2 [SHA-384] per the IETF Draft Specification. 43 | *
44 | * 45 | *46 | * References: 47 | *
48 | *117 | * Private constructor for cloning purposes. 118 | *
119 | * 120 | * @param md the instance to clone. 121 | */ 122 | private Sha384(Sha384 md) { 123 | this(); 124 | 125 | this.h0 = md.h0; 126 | this.h1 = md.h1; 127 | this.h2 = md.h2; 128 | this.h3 = md.h3; 129 | this.h4 = md.h4; 130 | this.h5 = md.h5; 131 | this.h6 = md.h6; 132 | this.h7 = md.h7; 133 | this.count = md.count; 134 | this.buffer = (byte[]) md.buffer.clone(); 135 | } 136 | 137 | // Class methods 138 | // ------------------------------------------------------------------------- 139 | 140 | public static final long[] G(long hh0, long hh1, long hh2, long hh3, 141 | long hh4, long hh5, long hh6, long hh7, byte[] in, int offset) { 142 | return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); 143 | } 144 | 145 | // Instance methods 146 | // ------------------------------------------------------------------------- 147 | 148 | // java.lang.Cloneable interface implementation ---------------------------- 149 | 150 | public Object clone() { 151 | return new Sha384(this); 152 | } 153 | 154 | // Implementation of concrete methods in BaseHash -------------------------- 155 | 156 | protected void transform(byte[] in, int offset) { 157 | long[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); 158 | 159 | h0 = result[0]; 160 | h1 = result[1]; 161 | h2 = result[2]; 162 | h3 = result[3]; 163 | h4 = result[4]; 164 | h5 = result[5]; 165 | h6 = result[6]; 166 | h7 = result[7]; 167 | } 168 | 169 | protected byte[] padBuffer() { 170 | int n = (int) (count % BLOCK_SIZE); 171 | int padding = (n < 112) ? (112 - n) : (240 - n); 172 | byte[] result = new byte[padding + 16]; 173 | 174 | // padding is always binary 1 followed by binary 0s 175 | result[0] = (byte) 0x80; 176 | 177 | // save number of bits, casting the long to an array of 8 bytes 178 | // TODO: FIX Only ~35 bits of 128 bit counter usable this way 179 | long bits = count << 3; 180 | padding += 8; 181 | result[padding++] = (byte) (bits >>> 56); 182 | result[padding++] = (byte) (bits >>> 48); 183 | result[padding++] = (byte) (bits >>> 40); 184 | result[padding++] = (byte) (bits >>> 32); 185 | result[padding++] = (byte) (bits >>> 24); 186 | result[padding++] = (byte) (bits >>> 16); 187 | result[padding++] = (byte) (bits >>> 8); 188 | result[padding] = (byte) bits; 189 | 190 | return result; 191 | } 192 | 193 | protected byte[] getResult() { 194 | return new byte[]{(byte) (h0 >>> 56), (byte) (h0 >>> 48), 195 | (byte) (h0 >>> 40), (byte) (h0 >>> 32), (byte) (h0 >>> 24), 196 | (byte) (h0 >>> 16), (byte) (h0 >>> 8), (byte) h0, 197 | (byte) (h1 >>> 56), (byte) (h1 >>> 48), (byte) (h1 >>> 40), 198 | (byte) (h1 >>> 32), (byte) (h1 >>> 24), (byte) (h1 >>> 16), 199 | (byte) (h1 >>> 8), (byte) h1, (byte) (h2 >>> 56), 200 | (byte) (h2 >>> 48), (byte) (h2 >>> 40), (byte) (h2 >>> 32), 201 | (byte) (h2 >>> 24), (byte) (h2 >>> 16), (byte) (h2 >>> 8), 202 | (byte) h2, (byte) (h3 >>> 56), (byte) (h3 >>> 48), 203 | (byte) (h3 >>> 40), (byte) (h3 >>> 32), (byte) (h3 >>> 24), 204 | (byte) (h3 >>> 16), (byte) (h3 >>> 8), (byte) h3, 205 | (byte) (h4 >>> 56), (byte) (h4 >>> 48), (byte) (h4 >>> 40), 206 | (byte) (h4 >>> 32), (byte) (h4 >>> 24), (byte) (h4 >>> 16), 207 | (byte) (h4 >>> 8), (byte) h4, (byte) (h5 >>> 56), 208 | (byte) (h5 >>> 48), (byte) (h5 >>> 40), (byte) (h5 >>> 32), 209 | (byte) (h5 >>> 24), (byte) (h5 >>> 16), (byte) (h5 >>> 8), 210 | (byte) h5 211 | // (byte)(h6 >>> 56), (byte)(h6 >>> 48), (byte)(h6 >>> 40), (byte)(h6 212 | // >>> 32), 213 | // (byte)(h6 >>> 24), (byte)(h6 >>> 16), (byte)(h6 >>> 8), (byte) h6, 214 | // (byte)(h7 >>> 56), (byte)(h7 >>> 48), (byte)(h7 >>> 40), (byte)(h7 215 | // >>> 32), 216 | // (byte)(h7 >>> 24), (byte)(h7 >>> 16), (byte)(h7 >>> 8), (byte) h7 217 | }; 218 | } 219 | 220 | protected void resetContext() { 221 | // magic SHA-384 initialisation constants 222 | h0 = 0xcbbb9d5dc1059ed8L; 223 | h1 = 0x629a292a367cd507L; 224 | h2 = 0x9159015a3070dd17L; 225 | h3 = 0x152fecd8f70e5939L; 226 | h4 = 0x67332667ffc00b31L; 227 | h5 = 0x8eb44a8768581511L; 228 | h6 = 0xdb0c2e0d64f98fa7L; 229 | h7 = 0x47b5481dbefa4fa4L; 230 | } 231 | 232 | public boolean selfTest() { 233 | if (valid == null) { 234 | Sha384 md = new Sha384(); 235 | md.update((byte) 0x61); // a 236 | md.update((byte) 0x62); // b 237 | md.update((byte) 0x63); // c 238 | String result = UtilServices.toString(md.digest()); 239 | valid = Boolean.valueOf(DIGEST0.equals(result)); 240 | } 241 | return valid.booleanValue(); 242 | } 243 | 244 | // SHA specific methods ---------------------------------------------------- 245 | 246 | private static final synchronized long[] sha(long hh0, long hh1, long hh2, 247 | long hh3, long hh4, long hh5, long hh6, long hh7, byte[] in, 248 | int offset) { 249 | long A = hh0; 250 | long B = hh1; 251 | long C = hh2; 252 | long D = hh3; 253 | long E = hh4; 254 | long F = hh5; 255 | long G = hh6; 256 | long H = hh7; 257 | long T, T2; 258 | int r; 259 | 260 | for (r = 0; r < 16; r++) { 261 | w[r] = (long) in[offset++] << 56 262 | | ((long) in[offset++] & 0xFF) << 48 263 | | ((long) in[offset++] & 0xFF) << 40 264 | | ((long) in[offset++] & 0xFF) << 32 265 | | ((long) in[offset++] & 0xFF) << 24 266 | | ((long) in[offset++] & 0xFF) << 16 267 | | ((long) in[offset++] & 0xFF) << 8 268 | | ((long) in[offset++] & 0xFF); 269 | } 270 | for (r = 16; r < 80; r++) { 271 | T = w[r - 2]; 272 | T2 = w[r - 15]; 273 | w[r] = (((T >>> 19) | (T << 45)) ^ ((T >>> 61) | (T << 3)) ^ (T >>> 6)) 274 | + w[r - 7] 275 | + (((T2 >>> 1) | (T2 << 63)) ^ ((T2 >>> 8) | (T2 << 56)) ^ (T2 >>> 7)) 276 | + w[r - 16]; 277 | } 278 | 279 | for (r = 0; r < 80; r++) { 280 | 281 | T = H 282 | + (((E >>> 14) | (E << 50)) ^ ((E >>> 18) | (E << 46)) ^ ((E >>> 41) | (E << 23))) 283 | + ((E & F) ^ ((~E) & G)) + k[r] + w[r]; 284 | // T IS INCORRECT SOMEHOW 285 | T2 = (((A >>> 28) | (A << 36)) ^ ((A >>> 34) | (A << 30)) ^ ((A >>> 39) | (A << 25))) 286 | + ((A & B) ^ (A & C) ^ (B & C)); 287 | H = G; 288 | G = F; 289 | F = E; 290 | E = D + T; 291 | D = C; 292 | C = B; 293 | B = A; 294 | A = T + T2; 295 | } 296 | 297 | return new long[]{hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, 298 | hh5 + F, hh6 + G, hh7 + H}; 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/Sha512.java: -------------------------------------------------------------------------------- 1 | /* Sha512.java -- 2 | Copyright (C) 2003, 2006 Free Software Foundation, Inc. 3 | 4 | This file is a part of GNU Classpath. 5 | 6 | GNU Classpath is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or (at 9 | your option) any later version. 10 | 11 | GNU Classpath is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Classpath; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 | USA 20 | 21 | Linking this library statically or dynamically with other modules is 22 | making a combined work based on this library. Thus, the terms and 23 | conditions of the GNU General Public License cover the whole 24 | combination. 25 | 26 | As a special exception, the copyright holders of this library give you 27 | permission to link this library with independent modules to produce an 28 | executable, regardless of the license terms of these independent 29 | modules, and to copy and distribute the resulting executable under 30 | terms of your choice, provided that you also meet, for each linked 31 | independent module, the terms and conditions of the license of that 32 | module. An independent module is a module which is not derived from 33 | or based on this library. If you modify this library, you may extend 34 | this exception to your version of the library, but you are not 35 | obligated to do so. If you do not wish to do so, delete this 36 | exception statement from your version. */ 37 | 38 | package com.hobbyone.HashDroid; 39 | 40 | /** 41 | *42 | * Implementation of SHA2-3 [SHA-512] per the IETF Draft Specification. 43 | *
44 | * 45 | *46 | * References: 47 | *
48 | *111 | * Private constructor for cloning purposes. 112 | *
113 | * 114 | * @param md 115 | * the instance to clone. 116 | */ 117 | private Sha512(Sha512 md) { 118 | this(); 119 | 120 | this.h0 = md.h0; 121 | this.h1 = md.h1; 122 | this.h2 = md.h2; 123 | this.h3 = md.h3; 124 | this.h4 = md.h4; 125 | this.h5 = md.h5; 126 | this.h6 = md.h6; 127 | this.h7 = md.h7; 128 | this.count = md.count; 129 | this.buffer = (byte[]) md.buffer.clone(); 130 | } 131 | 132 | // Class methods 133 | // ------------------------------------------------------------------------- 134 | 135 | public static final long[] G(long hh0, long hh1, long hh2, long hh3, 136 | long hh4, long hh5, long hh6, long hh7, byte[] in, int offset) { 137 | return sha(hh0, hh1, hh2, hh3, hh4, hh5, hh6, hh7, in, offset); 138 | } 139 | 140 | // Instance methods 141 | // ------------------------------------------------------------------------- 142 | 143 | // java.lang.Cloneable interface implementation ---------------------------- 144 | 145 | public Object clone() { 146 | return new Sha512(this); 147 | } 148 | 149 | // Implementation of concrete methods in BaseHash -------------------------- 150 | 151 | protected void transform(byte[] in, int offset) { 152 | long[] result = sha(h0, h1, h2, h3, h4, h5, h6, h7, in, offset); 153 | 154 | h0 = result[0]; 155 | h1 = result[1]; 156 | h2 = result[2]; 157 | h3 = result[3]; 158 | h4 = result[4]; 159 | h5 = result[5]; 160 | h6 = result[6]; 161 | h7 = result[7]; 162 | } 163 | 164 | protected byte[] padBuffer() { 165 | int n = (int) (count % BLOCK_SIZE); 166 | int padding = (n < 112) ? (112 - n) : (240 - n); 167 | byte[] result = new byte[padding + 16]; 168 | 169 | // padding is always binary 1 followed by binary 0s 170 | result[0] = (byte) 0x80; 171 | 172 | // save number of bits, casting the long to an array of 8 bytes 173 | // TODO: FIX Only ~35 bits of 128 bit counter usable this way 174 | long bits = count << 3; 175 | padding += 8; 176 | result[padding++] = (byte) (bits >>> 56); 177 | result[padding++] = (byte) (bits >>> 48); 178 | result[padding++] = (byte) (bits >>> 40); 179 | result[padding++] = (byte) (bits >>> 32); 180 | result[padding++] = (byte) (bits >>> 24); 181 | result[padding++] = (byte) (bits >>> 16); 182 | result[padding++] = (byte) (bits >>> 8); 183 | result[padding] = (byte) bits; 184 | 185 | return result; 186 | } 187 | 188 | protected byte[] getResult() { 189 | return new byte[] { (byte) (h0 >>> 56), (byte) (h0 >>> 48), 190 | (byte) (h0 >>> 40), (byte) (h0 >>> 32), (byte) (h0 >>> 24), 191 | (byte) (h0 >>> 16), (byte) (h0 >>> 8), (byte) h0, 192 | (byte) (h1 >>> 56), (byte) (h1 >>> 48), (byte) (h1 >>> 40), 193 | (byte) (h1 >>> 32), (byte) (h1 >>> 24), (byte) (h1 >>> 16), 194 | (byte) (h1 >>> 8), (byte) h1, (byte) (h2 >>> 56), 195 | (byte) (h2 >>> 48), (byte) (h2 >>> 40), (byte) (h2 >>> 32), 196 | (byte) (h2 >>> 24), (byte) (h2 >>> 16), (byte) (h2 >>> 8), 197 | (byte) h2, (byte) (h3 >>> 56), (byte) (h3 >>> 48), 198 | (byte) (h3 >>> 40), (byte) (h3 >>> 32), (byte) (h3 >>> 24), 199 | (byte) (h3 >>> 16), (byte) (h3 >>> 8), (byte) h3, 200 | (byte) (h4 >>> 56), (byte) (h4 >>> 48), (byte) (h4 >>> 40), 201 | (byte) (h4 >>> 32), (byte) (h4 >>> 24), (byte) (h4 >>> 16), 202 | (byte) (h4 >>> 8), (byte) h4, (byte) (h5 >>> 56), 203 | (byte) (h5 >>> 48), (byte) (h5 >>> 40), (byte) (h5 >>> 32), 204 | (byte) (h5 >>> 24), (byte) (h5 >>> 16), (byte) (h5 >>> 8), 205 | (byte) h5, (byte) (h6 >>> 56), (byte) (h6 >>> 48), 206 | (byte) (h6 >>> 40), (byte) (h6 >>> 32), (byte) (h6 >>> 24), 207 | (byte) (h6 >>> 16), (byte) (h6 >>> 8), (byte) h6, 208 | (byte) (h7 >>> 56), (byte) (h7 >>> 48), (byte) (h7 >>> 40), 209 | (byte) (h7 >>> 32), (byte) (h7 >>> 24), (byte) (h7 >>> 16), 210 | (byte) (h7 >>> 8), (byte) h7 }; 211 | } 212 | 213 | protected void resetContext() { 214 | // magic SHA-512 initialisation constants 215 | h0 = 0x6a09e667f3bcc908L; 216 | h1 = 0xbb67ae8584caa73bL; 217 | h2 = 0x3c6ef372fe94f82bL; 218 | h3 = 0xa54ff53a5f1d36f1L; 219 | h4 = 0x510e527fade682d1L; 220 | h5 = 0x9b05688c2b3e6c1fL; 221 | h6 = 0x1f83d9abfb41bd6bL; 222 | h7 = 0x5be0cd19137e2179L; 223 | } 224 | 225 | public boolean selfTest() { 226 | if (valid == null) { 227 | Sha512 md = new Sha512(); 228 | md.update((byte) 0x61); // a 229 | md.update((byte) 0x62); // b 230 | md.update((byte) 0x63); // c 231 | String result = UtilServices.toString(md.digest()); 232 | valid = Boolean.valueOf(DIGEST0.equals(result)); 233 | } 234 | return valid.booleanValue(); 235 | } 236 | 237 | // SHA specific methods ---------------------------------------------------- 238 | 239 | private static final synchronized long[] sha(long hh0, long hh1, long hh2, 240 | long hh3, long hh4, long hh5, long hh6, long hh7, byte[] in, 241 | int offset) { 242 | long A = hh0; 243 | long B = hh1; 244 | long C = hh2; 245 | long D = hh3; 246 | long E = hh4; 247 | long F = hh5; 248 | long G = hh6; 249 | long H = hh7; 250 | long T, T2; 251 | int r; 252 | 253 | for (r = 0; r < 16; r++) { 254 | w[r] = (long) in[offset++] << 56 255 | | ((long) in[offset++] & 0xFF) << 48 256 | | ((long) in[offset++] & 0xFF) << 40 257 | | ((long) in[offset++] & 0xFF) << 32 258 | | ((long) in[offset++] & 0xFF) << 24 259 | | ((long) in[offset++] & 0xFF) << 16 260 | | ((long) in[offset++] & 0xFF) << 8 261 | | ((long) in[offset++] & 0xFF); 262 | } 263 | for (r = 16; r < 80; r++) { 264 | T = w[r - 2]; 265 | T2 = w[r - 15]; 266 | w[r] = (((T >>> 19) | (T << 45)) ^ ((T >>> 61) | (T << 3)) ^ (T >>> 6)) 267 | + w[r - 7] 268 | + (((T2 >>> 1) | (T2 << 63)) ^ ((T2 >>> 8) | (T2 << 56)) ^ (T2 >>> 7)) 269 | + w[r - 16]; 270 | } 271 | 272 | for (r = 0; r < 80; r++) { 273 | T = H 274 | + (((E >>> 14) | (E << 50)) ^ ((E >>> 18) | (E << 46)) ^ ((E >>> 41) | (E << 23))) 275 | + ((E & F) ^ ((~E) & G)) + k[r] + w[r]; 276 | T2 = (((A >>> 28) | (A << 36)) ^ ((A >>> 34) | (A << 30)) ^ ((A >>> 39) | (A << 25))) 277 | + ((A & B) ^ (A & C) ^ (B & C)); 278 | H = G; 279 | G = F; 280 | F = E; 281 | E = D + T; 282 | D = C; 283 | C = B; 284 | B = A; 285 | A = T + T2; 286 | } 287 | 288 | return new long[] { hh0 + A, hh1 + B, hh2 + C, hh3 + D, hh4 + E, 289 | hh5 + F, hh6 + G, hh7 + H }; 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/TextActivity.java: -------------------------------------------------------------------------------- 1 | /* TextActivity.java -- 2 | Copyright (C) 2010 Christophe Bouyer (Hobby One) 3 | 4 | This file is part of Hash Droid. 5 | 6 | Hash Droid is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | Hash Droid is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Hash Droid. If not, see42 | * A collection of utility methods used throughout this project. 43 | *
44 | */ 45 | public class UtilServices { 46 | 47 | // Constants and variables 48 | // ------------------------------------------------------------------------- 49 | 50 | // Hex charset 51 | private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); 52 | 53 | // Constructor(s) 54 | // ------------------------------------------------------------------------- 55 | 56 | /** 57 | * Trivial constructor to enforce Singleton pattern. 58 | */ 59 | private UtilServices() { 60 | super(); 61 | } 62 | 63 | // Class methods 64 | // ------------------------------------------------------------------------- 65 | 66 | /** 67 | *68 | * Returns a string of hexadecimal digits from a byte array. Each byte is 69 | * converted to 2 hex symbols; zero(es) included. 70 | *
71 | * 72 | *73 | * This method calls the method with same name and three arguments as: 74 | *
75 | * 76 | *77 | * toString(ba, 0, ba.length); 78 | *79 | * 80 | * @param ba the byte array to convert. 81 | * @return a string of hexadecimal characters (two for each byte) 82 | * representing the designated input byte array. 83 | */ 84 | public static String toString(byte[] ba) { 85 | return toString(ba, 0, ba.length); 86 | } 87 | 88 | /** 89 | *
90 | * Returns a string of hexadecimal digits from a byte array, starting at
91 | * offset
and consisting of length
bytes. Each
92 | * byte is converted to 2 hex symbols; zero(es) included.
93 | *