├── .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 | Privacy Policy 7 | 8 | 9 | 10 | Privacy Policy 11 |

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 |
42 |

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 | 54 |
55 |

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 | 94 |

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 |
123 |

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 |
135 | 136 |

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 | 4 | 5 | 11 | 12 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/BaseHash.java: -------------------------------------------------------------------------------- 1 | /* BaseHash.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 | * 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, see . 18 | */ 19 | 20 | package com.hobbyone.HashDroid; 21 | 22 | import android.app.Activity; 23 | import android.graphics.Color; 24 | import android.os.Bundle; 25 | import android.text.Editable; 26 | import android.view.View; 27 | import android.view.View.OnClickListener; 28 | import android.widget.Button; 29 | import android.widget.EditText; 30 | import android.widget.TextView; 31 | 32 | public class CompareActivity extends Activity { 33 | 34 | private EditText mEditText1 = null; 35 | private EditText mEditText2 = null; 36 | private Button mCompareButton = null; 37 | private Button mClearButton1 = null; 38 | private Button mClearButton2 = null; 39 | private TextView mResultTV = null; 40 | 41 | /** 42 | * Called when the activity is first created. 43 | */ 44 | @Override 45 | public void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.compare); 48 | 49 | mEditText1 = (EditText) findViewById(R.id.edit_txt1); 50 | mClearButton1 = (Button) findViewById(R.id.ClearButton1); 51 | mEditText2 = (EditText) findViewById(R.id.edit_txt2); 52 | mClearButton2 = (Button) findViewById(R.id.ClearButton2); 53 | mCompareButton = (Button) findViewById(R.id.CompareButton); 54 | mResultTV = (TextView) findViewById(R.id.label_result); 55 | 56 | mCompareButton.setOnClickListener(new OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | // Perform action on clicks 60 | Editable InputEdit1 = mEditText1.getText(); 61 | String sInputText1 = InputEdit1.toString(); 62 | Editable InputEdit2 = mEditText2.getText(); 63 | String sInputText2 = InputEdit2.toString(); 64 | if (sInputText1 != null && sInputText2 != null) { 65 | String sText = ""; 66 | int IsIdentical = sInputText1 67 | .compareToIgnoreCase(sInputText2); 68 | if (IsIdentical == 0) { 69 | sText = getString(R.string.IdenticalHashes); 70 | mResultTV.setTextColor(Color.GREEN); 71 | } else { 72 | sText = getString(R.string.DifferentHashes); 73 | mResultTV.setTextColor(Color.RED); 74 | } 75 | if (mResultTV != null) 76 | mResultTV.setText(sText); 77 | } 78 | } 79 | }); 80 | 81 | mClearButton1.setOnClickListener(new OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | // Perform action on clicks 85 | mEditText1.setText(""); 86 | mResultTV.setText(""); 87 | } 88 | }); 89 | 90 | mClearButton2.setOnClickListener(new OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | // Perform action on clicks 94 | mEditText2.setText(""); 95 | mResultTV.setText(""); 96 | } 97 | }); 98 | } 99 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/FileActivity.java: -------------------------------------------------------------------------------- 1 | /* FileActivity.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, see . 18 | */ 19 | 20 | package com.hobbyone.HashDroid; 21 | 22 | import android.app.Activity; 23 | import android.app.ProgressDialog; 24 | import android.content.ActivityNotFoundException; 25 | import android.content.Intent; 26 | import android.content.res.Resources; 27 | import android.database.Cursor; 28 | import android.net.Uri; 29 | import android.os.Bundle; 30 | import android.os.Handler; 31 | import android.os.Message; 32 | import android.provider.OpenableColumns; 33 | import android.text.ClipboardManager; 34 | import android.view.View; 35 | import android.view.View.OnClickListener; 36 | import android.widget.AdapterView; 37 | import android.widget.AdapterView.OnItemSelectedListener; 38 | import android.widget.ArrayAdapter; 39 | import android.widget.Button; 40 | import android.widget.CheckBox; 41 | import android.widget.Spinner; 42 | import android.widget.TextView; 43 | import android.widget.Toast; 44 | 45 | import java.io.File; 46 | import java.io.FileNotFoundException; 47 | import java.io.InputStream; 48 | 49 | public class FileActivity extends Activity implements Runnable { 50 | private Button mSelectFileButton = null; 51 | private CheckBox mCheckBox = null; 52 | private Button mGenerateButton = null; 53 | private Button mCopyButton = null; 54 | private Spinner mSpinner = null; 55 | private TextView mResultTV = null; 56 | private String msFileSize = ""; 57 | private String msHash = ""; 58 | private String[] mFunctions; 59 | private ClipboardManager mClipboard = null; 60 | private final int SELECT_FILE_REQUEST = 0; 61 | private HashFunctionOperator mHashOpe = null; 62 | private ProgressDialog mProgressDialog = null; 63 | private int miItePos = -1; 64 | private Uri mSelectedFileUri = null; 65 | 66 | /** 67 | * Called when the activity is first created. 68 | */ 69 | @Override 70 | public void onCreate(Bundle savedInstanceState) { 71 | super.onCreate(savedInstanceState); 72 | setContentView(R.layout.file); 73 | 74 | mSelectFileButton = (Button) findViewById(R.id.SelectFileButton); 75 | mGenerateButton = (Button) findViewById(R.id.GenerateButton); 76 | mSpinner = (Spinner) findViewById(R.id.spinner); 77 | mResultTV = (TextView) findViewById(R.id.label_result); 78 | mCopyButton = (Button) findViewById(R.id.CopyButton); 79 | mClipboard = (ClipboardManager) getSystemService("clipboard"); 80 | mFunctions = getResources().getStringArray(R.array.Algo_Array); 81 | mCheckBox = (CheckBox) findViewById(R.id.UpperCaseCB); 82 | 83 | ArrayAdapter adapter = ArrayAdapter.createFromResource( 84 | this, R.array.Algo_Array, android.R.layout.simple_spinner_item); 85 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 86 | mSpinner.setAdapter(adapter); 87 | mSpinner.setSelection(5); // MD5 by default 88 | 89 | mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { 90 | @Override 91 | public void onItemSelected(AdapterView parentView, 92 | View selectedItemView, int position, long id) { 93 | // your code here 94 | // Hide the copy button 95 | if (!msHash.equals("")) 96 | mCopyButton.setVisibility(View.INVISIBLE); 97 | // Clean the result text view 98 | if (mResultTV != null) 99 | mResultTV.setText(""); 100 | } 101 | 102 | @Override 103 | public void onNothingSelected(AdapterView parentView) { 104 | // your code here 105 | } 106 | }); 107 | 108 | mSelectFileButton.setOnClickListener(new OnClickListener() { 109 | @Override 110 | public void onClick(View v) { 111 | try { 112 | Intent openExplorerIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 113 | if (null != openExplorerIntent) { 114 | openExplorerIntent.addCategory(Intent.CATEGORY_OPENABLE); 115 | openExplorerIntent.setType("*/*"); 116 | startActivityForResult(Intent.createChooser(openExplorerIntent, "Select a file"), SELECT_FILE_REQUEST); 117 | } 118 | } catch (ActivityNotFoundException e) { 119 | } 120 | } 121 | }); 122 | 123 | mGenerateButton.setOnClickListener(new OnClickListener() { 124 | @Override 125 | public void onClick(View v) { 126 | // Perform action on clicks 127 | if (null != mSelectedFileUri) { 128 | miItePos = mSpinner.getSelectedItemPosition(); 129 | File fileToHash = new File(mSelectedFileUri.getPath()); 130 | if (fileToHash != null) 131 | ComputeAndDisplayHash(); 132 | else { 133 | String sWrongFile = getString(R.string.wrong_file); 134 | if (mResultTV != null) 135 | mResultTV.setText(sWrongFile); 136 | if (mCopyButton != null) 137 | mCopyButton.setVisibility(View.INVISIBLE); 138 | } 139 | } 140 | } 141 | }); 142 | 143 | mCopyButton.setOnClickListener(new OnClickListener() { 144 | @Override 145 | public void onClick(View v) { 146 | // Perform action on clicks 147 | if (mClipboard != null) { 148 | mClipboard.setText(msHash); 149 | String sCopied = getString(R.string.copied); 150 | Toast.makeText(FileActivity.this, sCopied, 151 | Toast.LENGTH_SHORT).show(); 152 | } 153 | } 154 | }); 155 | 156 | mCheckBox.setChecked(false); // lower case by default 157 | mCheckBox.setOnClickListener(new OnClickListener() { 158 | @Override 159 | public void onClick(View v) { 160 | // Perform action on clicks 161 | if (!msHash.equals("")) { 162 | // A hash value has already been calculated, 163 | // just convert it to lower or upper case 164 | String OldHash = msHash; 165 | if (mCheckBox.isChecked()) { 166 | msHash = OldHash.toUpperCase(); 167 | } else { 168 | msHash = OldHash.toLowerCase(); 169 | } 170 | if (mResultTV != null) { 171 | String sResult = mResultTV.getText().toString(); 172 | sResult = sResult.replaceAll(OldHash, msHash); 173 | mResultTV.setText(sResult); 174 | } 175 | } 176 | } 177 | }); 178 | } 179 | 180 | @Override 181 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 182 | if (requestCode == SELECT_FILE_REQUEST && resultCode == RESULT_OK) { 183 | if (data != null) { 184 | mSelectedFileUri = data.getData(); //The uri with the location of the file 185 | if (null != mSelectedFileUri) { 186 | Cursor cursor = getContentResolver().query(mSelectedFileUri, null, null, null, null); 187 | if (cursor != null && cursor.moveToFirst()) { 188 | String ret = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); 189 | mSelectFileButton.setText(ret); 190 | } 191 | } 192 | } 193 | } 194 | } 195 | 196 | private void ComputeAndDisplayHash() { 197 | if (mHashOpe == null) 198 | mHashOpe = new HashFunctionOperator(); 199 | String sAlgo = ""; 200 | if (miItePos == 0) 201 | sAlgo = "Adler-32"; 202 | else if (miItePos == 1) 203 | sAlgo = "CRC-32"; 204 | else if (miItePos == 2) 205 | sAlgo = "Haval"; 206 | else if (miItePos == 3) 207 | sAlgo = "md2"; 208 | else if (miItePos == 4) 209 | sAlgo = "md4"; 210 | else if (miItePos == 5) 211 | sAlgo = "md5"; 212 | else if (miItePos == 6) 213 | sAlgo = "ripemd-128"; 214 | else if (miItePos == 7) 215 | sAlgo = "ripemd-160"; 216 | else if (miItePos == 8) 217 | sAlgo = "sha-1"; 218 | else if (miItePos == 9) 219 | sAlgo = "sha-256"; 220 | else if (miItePos == 10) 221 | sAlgo = "sha-384"; 222 | else if (miItePos == 11) 223 | sAlgo = "sha-512"; 224 | else if (miItePos == 12) 225 | sAlgo = "tiger"; 226 | else if (miItePos == 13) 227 | sAlgo = "whirlpool"; 228 | mHashOpe.SetAlgorithm(sAlgo); 229 | 230 | String sCalculating = getString(R.string.Calculating); 231 | mProgressDialog = ProgressDialog.show(FileActivity.this, "", 232 | sCalculating, true); 233 | 234 | Thread thread = new Thread(this); 235 | thread.start(); 236 | } 237 | 238 | @Override 239 | // Call when the thread is started 240 | public void run() { 241 | msHash = ""; 242 | msFileSize = ""; 243 | 244 | if (null != mSelectedFileUri) { 245 | if (mHashOpe != null) { 246 | InputStream inputStream = null; 247 | try { 248 | inputStream = getContentResolver().openInputStream(mSelectedFileUri); 249 | 250 | } catch (FileNotFoundException e1) { 251 | } 252 | if (null != inputStream) { 253 | msHash = mHashOpe.FileToHash(inputStream); 254 | } 255 | } 256 | 257 | Cursor cursor = getContentResolver().query(mSelectedFileUri, null, null, null, null); 258 | if (cursor != null && cursor.moveToFirst()) { 259 | int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); 260 | msFileSize = FileSizeDisplay(cursor.getLong(sizeIndex), false); 261 | } 262 | } 263 | handler.sendEmptyMessage(0); 264 | } 265 | 266 | private String FileSizeDisplay(long lbytes, boolean bSI) { 267 | int unit = bSI ? 1000 : 1024; 268 | if (lbytes < unit) 269 | return lbytes + " B"; 270 | int exp = (int) (Math.log(lbytes) / Math.log(unit)); 271 | String pre = (bSI ? "kMGTPE" : "KMGTPE").charAt(exp - 1) 272 | + (bSI ? "" : "i"); 273 | return String.format("%.2f %sB", lbytes / Math.pow(unit, exp), pre); 274 | } 275 | 276 | // This method is called when the computation is over 277 | private Handler handler = new Handler() { 278 | @Override 279 | public void handleMessage(Message msg) { 280 | // Hide the progress dialog 281 | if (mProgressDialog != null) 282 | mProgressDialog.dismiss(); 283 | if (null != mSelectedFileUri) { 284 | File fileToHash = new File(mSelectedFileUri.getPath()); 285 | if (fileToHash != null) { 286 | Resources res = getResources(); 287 | String fileName = ""; 288 | Cursor cursor = getContentResolver().query(mSelectedFileUri, null, null, null, null); 289 | if (cursor != null && cursor.moveToFirst()) { 290 | fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); 291 | } 292 | String sFileNameTitle = String 293 | .format(res.getString(R.string.FileName), 294 | fileName); 295 | String sFileSizeTitle = String.format( 296 | res.getString(R.string.FileSize), msFileSize); 297 | String sFileHashTitle = ""; 298 | if (!msHash.equals("")) { 299 | if (mCheckBox != null) { 300 | if (mCheckBox.isChecked()) { 301 | msHash = msHash.toUpperCase(); 302 | } else { 303 | msHash = msHash.toLowerCase(); 304 | } 305 | } 306 | String Function = ""; 307 | if (miItePos >= 0) 308 | Function = mFunctions[miItePos]; 309 | sFileHashTitle = String.format( 310 | res.getString(R.string.Hash), Function, msHash); 311 | // Show the copy button 312 | if (mCopyButton != null) 313 | mCopyButton.setVisibility(View.VISIBLE); 314 | } else { 315 | sFileHashTitle = String.format( 316 | res.getString(R.string.unable_to_calculate), 317 | fileToHash.getName()); 318 | // Hide the copy button 319 | if (mCopyButton != null) 320 | mCopyButton.setVisibility(View.INVISIBLE); 321 | } 322 | 323 | if (mResultTV != null) 324 | mResultTV.setText(sFileNameTitle + sFileSizeTitle + sFileHashTitle); 325 | } 326 | } 327 | } 328 | }; 329 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/HashFactory.java: -------------------------------------------------------------------------------- 1 | /* HashFactory.java -- 2 | Copyright (C) 2001, 2002, 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 | * 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, see . 18 | */ 19 | 20 | package com.hobbyone.HashDroid; 21 | 22 | import java.io.InputStream; 23 | import java.io.FileNotFoundException; 24 | import java.io.IOException; 25 | import java.util.zip.Adler32; 26 | import java.util.zip.CRC32; 27 | import java.util.zip.Checksum; 28 | 29 | public class HashFunctionOperator { 30 | private String _sAlgo = "md5"; 31 | 32 | public void SetAlgorithm(String sAlgo) { 33 | _sAlgo = sAlgo; 34 | } 35 | 36 | private String PrependValue(String iStr, int NbDigits) { 37 | String sReturnedStr = iStr; 38 | while (sReturnedStr.length() < NbDigits) 39 | sReturnedStr = "0" + sReturnedStr; 40 | return sReturnedStr; 41 | } 42 | 43 | private String CreateHashString(byte messageDigest[]) { 44 | StringBuffer hexString = new StringBuffer(); 45 | for (int i = 0; i < messageDigest.length; i++) { 46 | String h = Integer.toHexString(0xFF & messageDigest[i]); 47 | String StrComplete = PrependValue(h, 2); 48 | hexString.append(StrComplete); 49 | } 50 | return hexString.toString(); 51 | } 52 | 53 | public String StringToHash(String s) { 54 | String sReturnedStr = ""; 55 | if (_sAlgo.equals("CRC-32") || _sAlgo.equals("Adler-32")) { 56 | long value = 0; 57 | Checksum checksumv = null; 58 | if (_sAlgo.equals("CRC-32")) { 59 | CRC32 crc32v = new CRC32(); 60 | crc32v.update(s.getBytes()); 61 | checksumv = crc32v; 62 | } else if (_sAlgo.equals("Adler-32")) { 63 | Adler32 adler32v = new Adler32(); 64 | adler32v.update(s.getBytes()); 65 | checksumv = adler32v; 66 | } 67 | if (checksumv != null) { 68 | value = checksumv.getValue(); 69 | String StrHex = Long.toHexString(value); 70 | sReturnedStr = PrependValue(StrHex, 8); // 32 bits (8 digits in 71 | // hexadecimal) 72 | } 73 | } else { 74 | IMessageDigest MessageDig = HashFactory.getInstance(_sAlgo); 75 | if (MessageDig != null) { 76 | byte[] in = s.getBytes(); 77 | MessageDig.update(in, 0, in.length); 78 | byte messageDigest[] = MessageDig.digest(); 79 | sReturnedStr = CreateHashString(messageDigest); 80 | } 81 | } 82 | 83 | return sReturnedStr; 84 | } 85 | 86 | public String FileToHash(InputStream inputstream) { 87 | String sReturnedStr = ""; 88 | if (null != inputstream) { 89 | if (_sAlgo.equals("CRC-32") || _sAlgo.equals("Adler-32")) { 90 | try { 91 | byte[] databytes = new byte[1024]; 92 | int nread = 0; 93 | long value = 0; 94 | Checksum checksumv = null; 95 | if (_sAlgo.equals("CRC-32")) { 96 | CRC32 crc32v = new CRC32(); 97 | checksumv = crc32v; 98 | } else if (_sAlgo.equals("Adler-32")) { 99 | Adler32 adler32v = new Adler32(); 100 | checksumv = adler32v; 101 | } 102 | if (checksumv != null) { 103 | while ((nread = inputstream.read(databytes)) > 0) { 104 | checksumv.update(databytes, 0, nread); 105 | } 106 | value = checksumv.getValue(); 107 | String StrHex = Long.toHexString(value); 108 | sReturnedStr = PrependValue(StrHex, 8); // 32 bits (8 digits 109 | // in hexadecimal) 110 | } 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } 114 | } else { 115 | try { 116 | IMessageDigest MessageDig = HashFactory.getInstance(_sAlgo); 117 | if (MessageDig != null) { 118 | byte[] databytes = new byte[1024]; 119 | int nread = 0; 120 | while ((nread = inputstream.read(databytes)) != -1) { 121 | MessageDig.update(databytes, 0, nread); 122 | } 123 | byte messageDigest[] = MessageDig.digest(); 124 | sReturnedStr = CreateHashString(messageDigest); 125 | } 126 | } catch (FileNotFoundException e) { 127 | e.printStackTrace(); 128 | } catch (IOException e) { 129 | e.printStackTrace(); 130 | } 131 | } 132 | } 133 | 134 | return sReturnedStr; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/IMessageDigest.java: -------------------------------------------------------------------------------- 1 | /* IMessageDigest.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 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 | *
    55 | *
  1. The MD2 Message-Digest 56 | * Algorithm.
    57 | * B. Kaliski.
  2. 58 | *
  3. The RFC ERRATA PAGE 59 | * under section RFC 1319.
  4. 60 | *
61 | */ 62 | public class MD2 extends BaseHash { 63 | 64 | // Constants and variables 65 | // ------------------------------------------------------------------------- 66 | 67 | /** 68 | * An MD2 message digest is always 128-bits long, or 16 bytes. 69 | */ 70 | private static final int DIGEST_LENGTH = 16; 71 | 72 | /** 73 | * The MD2 algorithm operates on 128-bit blocks, or 16 bytes. 74 | */ 75 | private static final int BLOCK_LENGTH = 16; 76 | 77 | /** 78 | * 256 byte "random" permutation of the digits of pi. 79 | */ 80 | private static final byte[] PI = {41, 46, 67, -55, -94, -40, 124, 1, 61, 81 | 54, 84, -95, -20, -16, 6, 19, 98, -89, 5, -13, -64, -57, 115, -116, 82 | -104, -109, 43, -39, -68, 76, -126, -54, 30, -101, 87, 60, -3, -44, 83 | -32, 22, 103, 66, 111, 24, -118, 23, -27, 18, -66, 78, -60, -42, 84 | -38, -98, -34, 73, -96, -5, -11, -114, -69, 47, -18, 122, -87, 104, 85 | 121, -111, 21, -78, 7, 63, -108, -62, 16, -119, 11, 34, 95, 33, 86 | -128, 127, 93, -102, 90, -112, 50, 39, 53, 62, -52, -25, -65, -9, 87 | -105, 3, -1, 25, 48, -77, 72, -91, -75, -47, -41, 94, -110, 42, 88 | -84, 86, -86, -58, 79, -72, 56, -46, -106, -92, 125, -74, 118, -4, 89 | 107, -30, -100, 116, 4, -15, 69, -99, 112, 89, 100, 113, -121, 32, 90 | -122, 91, -49, 101, -26, 45, -88, 2, 27, 96, 37, -83, -82, -80, 91 | -71, -10, 28, 70, 97, 105, 52, 64, 126, 15, 85, 71, -93, 35, -35, 92 | 81, -81, 58, -61, 92, -7, -50, -70, -59, -22, 38, 44, 83, 13, 110, 93 | -123, 40, -124, 9, -45, -33, -51, -12, 65, -127, 77, 82, 106, -36, 94 | 55, -56, 108, -63, -85, -6, 36, -31, 123, 8, 12, -67, -79, 74, 120, 95 | -120, -107, -117, -29, 99, -24, 109, -23, -53, -43, -2, 59, 0, 29, 96 | 57, -14, -17, -73, 14, 102, 88, -48, -28, -90, 119, 114, -8, -21, 97 | 117, 75, 10, 49, 68, 80, -76, -113, -19, 31, 26, -37, -103, -115, 98 | 51, -97, 17, -125, 20}; 99 | 100 | /** 101 | * The output of this message digest when no data has been input. 102 | */ 103 | private static final String DIGEST0 = "8350E5A3E24C153DF2275C9F80692773"; 104 | 105 | /** 106 | * caches the result of the correctness test, once executed. 107 | */ 108 | private static Boolean valid; 109 | 110 | /** 111 | * The checksum computed so far. 112 | */ 113 | private byte[] checksum; 114 | 115 | /** 116 | * Work array needed by encrypt method. First 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 | *

198 | * 199 | * @return the bytes to pad the remaining bytes in the buffer before 200 | * completing a hash operation. 201 | */ 202 | protected byte[] padBuffer() { 203 | int length = BLOCK_LENGTH - (int) (count % BLOCK_LENGTH); 204 | if (length == 0) { 205 | length = BLOCK_LENGTH; 206 | } 207 | byte[] pad = new byte[length]; 208 | for (int i = 0; i < length; i++) { 209 | pad[i] = (byte) length; 210 | } 211 | return pad; 212 | } 213 | 214 | /** 215 | *

216 | * Adds BLOCK_LENGTH bytes to the running digest. 217 | *

218 | * 219 | * @param in the byte array to take the 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 | *
    56 | *
  1. The MD4 Message-Digest 57 | * Algorithm.
    58 | * R. Rivest.
  2. 59 | *
60 | * 61 | * @author Casey Marshall (rsdio@metastatic.org) 62 | */ 63 | public class MD4 extends BaseHash { 64 | 65 | // Constants and variables 66 | // ------------------------------------------------------------------------- 67 | 68 | /** 69 | * An MD4 message digest is always 128-bits long, or 16 bytes. 70 | */ 71 | private static final int DIGEST_LENGTH = 16; 72 | 73 | /** 74 | * The MD4 algorithm operates on 512-bit blocks, or 64 bytes. 75 | */ 76 | private static final int BLOCK_LENGTH = 64; 77 | 78 | private static final int A = 0x67452301; 79 | 80 | private static final int B = 0xefcdab89; 81 | 82 | private static final int C = 0x98badcfe; 83 | 84 | private static final int D = 0x10325476; 85 | 86 | /** 87 | * The output of this message digest when no data has been input. 88 | */ 89 | private static final String DIGEST0 = "31D6CFE0D16AE931B73C59D7E0C089C0"; 90 | 91 | /** 92 | * caches the result of the correctness test, once executed. 93 | */ 94 | private static Boolean valid; 95 | 96 | private int a, b, c, d; 97 | 98 | // Constructor(s) 99 | // ------------------------------------------------------------------------- 100 | 101 | /** 102 | *

103 | * Public constructor. Initializes the chaining variables, sets the byte 104 | * count to 0, and creates a new block of 512 105 | * bits. 106 | *

107 | */ 108 | public MD4() { 109 | super("md4", DIGEST_LENGTH, BLOCK_LENGTH); 110 | } 111 | 112 | /** 113 | *

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 | *
    54 | *
  1. The MD5 Message- Digest 55 | * Algorithm.
    56 | * R. Rivest.
  2. 57 | *
58 | */ 59 | public class MD5 extends BaseHash { 60 | 61 | // Constants and variables 62 | // ------------------------------------------------------------------------- 63 | 64 | private static final int BLOCK_SIZE = 64; // inner block size in bytes 65 | 66 | private static final String DIGEST0 = "D41D8CD98F00B204E9800998ECF8427E"; 67 | 68 | /** 69 | * caches the result of the correctness test, once executed. 70 | */ 71 | private static Boolean valid; 72 | 73 | /** 74 | * 128-bit interim result. 75 | */ 76 | private int h0, h1, h2, h3; 77 | 78 | // Constructor(s) 79 | // ------------------------------------------------------------------------- 80 | 81 | /** 82 | * Trivial 0-arguments constructor. 83 | */ 84 | public MD5() { 85 | super("md5", 16, BLOCK_SIZE); 86 | } 87 | 88 | /** 89 | *

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, see . 18 | */ 19 | 20 | package com.hobbyone.HashDroid; 21 | 22 | import android.app.AlertDialog; 23 | import android.app.TabActivity; 24 | import android.content.DialogInterface; 25 | import android.content.Intent; 26 | import android.content.pm.PackageInfo; 27 | import android.content.pm.PackageManager; 28 | import android.content.res.Resources; 29 | import android.graphics.PixelFormat; 30 | import android.net.Uri; 31 | import android.os.Bundle; 32 | import android.util.Log; 33 | import android.view.LayoutInflater; 34 | import android.view.Menu; 35 | import android.view.MenuItem; 36 | import android.view.View; 37 | import android.view.ViewGroup; 38 | import android.view.WindowManager; 39 | import android.widget.TabHost; 40 | import android.widget.TextView; 41 | 42 | public class MainActivity extends TabActivity { 43 | 44 | /** 45 | * Called when the activity is first created. 46 | */ 47 | @Override 48 | public void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.main); 51 | 52 | Resources res = getResources(); // Resource object to get Drawables 53 | TabHost tabHost = getTabHost(); // The activity TabHost 54 | TabHost.TabSpec spec; // Reusable TabSpec for each tab 55 | Intent intent; // Reusable Intent for each tab 56 | 57 | String sTextTabTitle = getString(R.string.tab_text); 58 | // Create an Intent to launch an Activity for the tab (to be reused) 59 | intent = new Intent().setClass(this, TextActivity.class); 60 | // Initialize a TabSpec for each tab and add it to the TabHost 61 | spec = tabHost 62 | .newTabSpec("text") 63 | .setIndicator(sTextTabTitle, 64 | res.getDrawable(R.drawable.ic_tab_text)) 65 | .setContent(intent); 66 | tabHost.addTab(spec); 67 | 68 | // Do the same for the other tabs 69 | String sFileTabTitle = getString(R.string.tab_file); 70 | intent = new Intent().setClass(this, FileActivity.class); 71 | spec = tabHost 72 | .newTabSpec("file") 73 | .setIndicator(sFileTabTitle, 74 | res.getDrawable(R.drawable.ic_tab_file)) 75 | .setContent(intent); 76 | tabHost.addTab(spec); 77 | 78 | intent = new Intent().setClass(this, CompareActivity.class); 79 | String sCompareTabTitle = getString(R.string.tab_compare); 80 | spec = tabHost 81 | .newTabSpec("compare") 82 | .setIndicator(sCompareTabTitle, 83 | res.getDrawable(R.drawable.ic_tab_compare)) 84 | .setContent(intent); 85 | tabHost.addTab(spec); 86 | 87 | tabHost.setCurrentTab(0); 88 | 89 | // methods called to get a smoother gradient background on all devices 90 | //getWindow().setFormat(PixelFormat.RGBA_8888); 91 | // especially for Donut 1.6 92 | //getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); 93 | } 94 | 95 | @Override 96 | public boolean onCreateOptionsMenu(Menu menu) { 97 | getMenuInflater().inflate(R.menu.menu_list, menu); 98 | return true; 99 | } 100 | 101 | @Override 102 | public boolean onOptionsItemSelected(MenuItem item) { 103 | int id = item.getItemId(); 104 | switch (id) { 105 | case R.id.menu_help: 106 | LayoutInflater help_inflater = getLayoutInflater(); 107 | View HelpView = help_inflater.inflate(R.layout.help, 108 | (ViewGroup) findViewById(R.id.help_layout_root)); 109 | 110 | new AlertDialog.Builder(this) 111 | .setIcon(0) 112 | .setTitle(getString(R.string.label_menu_help)) 113 | .setView(HelpView) 114 | .setPositiveButton(getString(R.string.Close_but), 115 | new DialogInterface.OnClickListener() { 116 | 117 | @Override 118 | public void onClick(DialogInterface dialog, 119 | int which) { 120 | // TODO Auto-generated method stub 121 | } 122 | }).show(); 123 | break; 124 | case R.id.menu_rateit: 125 | Intent intent = new Intent(Intent.ACTION_VIEW); 126 | intent.setData(Uri 127 | .parse("market://details?id=" + getPackageName())); 128 | startActivity(intent); 129 | break; 130 | case R.id.menu_about: 131 | LayoutInflater about_inflater = getLayoutInflater(); 132 | View AboutView = about_inflater.inflate(R.layout.about, 133 | (ViewGroup) findViewById(R.id.about_layout_root)); 134 | 135 | TextView vVersion = (TextView) AboutView 136 | .findViewById(R.id.about_version); 137 | String sVersion = vVersion.getText().toString(); 138 | vVersion.setText(sVersion + " " + getSoftwareVersion()); 139 | 140 | new AlertDialog.Builder(this) 141 | .setIcon(0) 142 | .setTitle(getString(R.string.label_menu_about)) 143 | .setView(AboutView) 144 | .setPositiveButton(getString(R.string.Close_but), 145 | new DialogInterface.OnClickListener() { 146 | 147 | @Override 148 | public void onClick(DialogInterface dialog, 149 | int which) { 150 | // TODO Auto-generated method stub 151 | } 152 | }).show(); 153 | break; 154 | default: 155 | break; 156 | } 157 | return true; 158 | } 159 | 160 | private String getSoftwareVersion() { 161 | String sRetString = ""; 162 | try { 163 | PackageInfo packageInfo = getPackageManager().getPackageInfo( 164 | getPackageName(), 0); 165 | sRetString = packageInfo.versionName; 166 | } catch (PackageManager.NameNotFoundException e) { 167 | Log.e("AboutActivity", "Package name not found", e); 168 | } 169 | ; 170 | return sRetString; 171 | } 172 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/RipeMD128.java: -------------------------------------------------------------------------------- 1 | /* RipeMD128.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-128 is a 128-bit message digest. 43 | *

44 | * 45 | *

46 | * References: 47 | *

48 | * 49 | *
    50 | *
  1. 51 | * RIPEMD160: A Strengthened Version of RIPEMD.
    52 | * Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
  2. 53 | *
54 | */ 55 | public class RipeMD128 extends BaseHash { 56 | 57 | // Constants and variables 58 | // ------------------------------------------------------------------------- 59 | 60 | private static final int BLOCK_SIZE = 64; // inner block size in bytes 61 | 62 | private static final String DIGEST0 = "CDF26213A150DC3ECB610F18F6B38B46"; 63 | 64 | /** 65 | * Constants for the transform method. 66 | */ 67 | // selection of message word 68 | private static final int[] R = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 69 | 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 70 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 71 | 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2}; 72 | 73 | private static final int[] Rp = {5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 74 | 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 75 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 76 | 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14}; 77 | 78 | // amount for rotate left (rol) 79 | private static final int[] S = {11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 80 | 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 81 | 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 82 | 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12}; 83 | 84 | private static final int[] Sp = {8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 85 | 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 86 | 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 87 | 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8}; 88 | 89 | /** 90 | * caches the result of the correctness test, once executed. 91 | */ 92 | private static Boolean valid; 93 | 94 | /** 95 | * 128-bit h0, h1, h2, h3 (interim result) 96 | */ 97 | private int h0, h1, h2, h3; 98 | 99 | /** 100 | * 512 bits work buffer = 16 x 32-bit words 101 | */ 102 | private int[] X = new int[16]; 103 | 104 | // Constructor(s) 105 | // ------------------------------------------------------------------------- 106 | 107 | /** 108 | * Trivial 0-arguments constructor. 109 | */ 110 | public RipeMD128() { 111 | super("ripemd-128", 16, BLOCK_SIZE); 112 | } 113 | 114 | /** 115 | *

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 | *
    50 | *
  1. 51 | * RIPEMD160: A Strengthened Version of RIPEMD.
    52 | * Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
  2. 53 | *
54 | */ 55 | public class RipeMD160 extends BaseHash { 56 | 57 | // Constants and variables 58 | // ------------------------------------------------------------------------- 59 | 60 | private static final int BLOCK_SIZE = 64; // inner block size in bytes 61 | 62 | private static final String DIGEST0 = "9C1185A5C5E9FC54612808977EE8F548B2258D31"; 63 | 64 | // selection of message word 65 | private static final int[] R = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 66 | 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 67 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 68 | 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 69 | 14, 1, 3, 8, 11, 6, 15, 13}; 70 | 71 | private static final int[] Rp = {5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 72 | 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 73 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 74 | 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 75 | 7, 6, 2, 13, 14, 0, 3, 9, 11}; 76 | 77 | // amount for rotate left (rol) 78 | private static final int[] S = {11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 79 | 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 80 | 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 81 | 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 82 | 13, 12, 5, 12, 13, 14, 11, 8, 5, 6}; 83 | 84 | private static final int[] Sp = {8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 85 | 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 86 | 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 87 | 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 88 | 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11}; 89 | 90 | /** 91 | * caches the result of the correctness test, once executed. 92 | */ 93 | private static Boolean valid; 94 | 95 | /** 96 | * 160-bit h0, h1, h2, h3, h4 (interim result) 97 | */ 98 | private int h0, h1, h2, h3, h4; 99 | 100 | /** 101 | * 512 bits work buffer = 16 x 32-bit words 102 | */ 103 | private int[] X = new int[16]; 104 | 105 | // Constructor(s) 106 | // ------------------------------------------------------------------------- 107 | 108 | /** 109 | * Trivial 0-arguments constructor. 110 | */ 111 | public RipeMD160() { 112 | super("ripemd-160", 20, BLOCK_SIZE); 113 | } 114 | 115 | /** 116 | *

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 | *
    65 | *
  1. SECURE HASH 66 | * STANDARD
    67 | * Federal Information, Processing Standards Publication 180-1, 1995 April 17.
  2. 68 | *
69 | */ 70 | public class Sha160 extends BaseHash { 71 | 72 | // Constants and variables 73 | // ------------------------------------------------------------------------- 74 | 75 | private static final int BLOCK_SIZE = 64; // inner block size in bytes 76 | 77 | private static final String DIGEST0 = "A9993E364706816ABA3E25717850C26C9CD0D89D"; 78 | 79 | private static final int[] w = new int[80]; 80 | 81 | /** 82 | * caches the result of the correctness test, once executed. 83 | */ 84 | private static Boolean valid; 85 | 86 | /** 87 | * 160-bit interim result. 88 | */ 89 | private int h0, h1, h2, h3, h4; 90 | 91 | // Constructor(s) 92 | // ------------------------------------------------------------------------- 93 | 94 | /** 95 | * Trivial 0-arguments constructor. 96 | */ 97 | public Sha160() { 98 | super("sha-160", 20, BLOCK_SIZE); 99 | } 100 | 101 | /** 102 | *

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 | *
    49 | *
  1. Descriptions of SHA-256, SHA-384, and SHA-512,
  2. 52 | *
  3. http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
  4. 53 | *
54 | */ 55 | public class Sha256 extends BaseHash { 56 | 57 | // Constants and variables 58 | // ------------------------------------------------------------------------- 59 | private static final int[] k = {0x428a2f98, 0x71374491, 0xb5c0fbcf, 60 | 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 61 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 62 | 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 63 | 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 64 | 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 65 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 66 | 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 67 | 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 68 | 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 69 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 70 | 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 71 | 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 72 | 0xc67178f2}; 73 | 74 | private static final int BLOCK_SIZE = 64; // inner block size in bytes 75 | 76 | private static final String DIGEST0 = "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"; 77 | 78 | private static final int[] w = new int[64]; 79 | 80 | /** 81 | * caches the result of the correctness test, once executed. 82 | */ 83 | private static Boolean valid; 84 | 85 | /** 86 | * 256-bit interim result. 87 | */ 88 | private int h0, h1, h2, h3, h4, h5, h6, h7; 89 | 90 | // Constructor(s) 91 | // ------------------------------------------------------------------------- 92 | 93 | /** 94 | * Trivial 0-arguments constructor. 95 | */ 96 | public Sha256() { 97 | super("sha-256", 32, BLOCK_SIZE); 98 | } 99 | 100 | /** 101 | *

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 | *
    49 | *
  1. Descriptions of SHA-256, SHA-384, and SHA-512,
  2. 52 | *
  3. http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
  4. 53 | *
54 | */ 55 | public class Sha384 extends BaseHash { 56 | 57 | // Constants and variables 58 | // ------------------------------------------------------------------------- 59 | 60 | private static final long[] k = {0x428a2f98d728ae22L, 0x7137449123ef65cdL, 61 | 0xb5c0fbcfec4d3b2fL, 0xe9b5dba58189dbbcL, 0x3956c25bf348b538L, 62 | 0x59f111f1b605d019L, 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L, 63 | 0xd807aa98a3030242L, 0x12835b0145706fbeL, 0x243185be4ee4b28cL, 64 | 0x550c7dc3d5ffb4e2L, 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L, 65 | 0x9bdc06a725c71235L, 0xc19bf174cf692694L, 0xe49b69c19ef14ad2L, 66 | 0xefbe4786384f25e3L, 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L, 67 | 0x2de92c6f592b0275L, 0x4a7484aa6ea6e483L, 0x5cb0a9dcbd41fbd4L, 68 | 0x76f988da831153b5L, 0x983e5152ee66dfabL, 0xa831c66d2db43210L, 69 | 0xb00327c898fb213fL, 0xbf597fc7beef0ee4L, 0xc6e00bf33da88fc2L, 70 | 0xd5a79147930aa725L, 0x06ca6351e003826fL, 0x142929670a0e6e70L, 71 | 0x27b70a8546d22ffcL, 0x2e1b21385c26c926L, 0x4d2c6dfc5ac42aedL, 72 | 0x53380d139d95b3dfL, 0x650a73548baf63deL, 0x766a0abb3c77b2a8L, 73 | 0x81c2c92e47edaee6L, 0x92722c851482353bL, 0xa2bfe8a14cf10364L, 74 | 0xa81a664bbc423001L, 0xc24b8b70d0f89791L, 0xc76c51a30654be30L, 75 | 0xd192e819d6ef5218L, 0xd69906245565a910L, 0xf40e35855771202aL, 76 | 0x106aa07032bbd1b8L, 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L, 77 | 0x2748774cdf8eeb99L, 0x34b0bcb5e19b48a8L, 0x391c0cb3c5c95a63L, 78 | 0x4ed8aa4ae3418acbL, 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L, 79 | 0x748f82ee5defb2fcL, 0x78a5636f43172f60L, 0x84c87814a1f0ab72L, 80 | 0x8cc702081a6439ecL, 0x90befffa23631e28L, 0xa4506cebde82bde9L, 81 | 0xbef9a3f7b2c67915L, 0xc67178f2e372532bL, 0xca273eceea26619cL, 82 | 0xd186b8c721c0c207L, 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L, 83 | 0x06f067aa72176fbaL, 0x0a637dc5a2c898a6L, 0x113f9804bef90daeL, 84 | 0x1b710b35131c471bL, 0x28db77f523047d84L, 0x32caab7b40c72493L, 85 | 0x3c9ebe0a15c9bebcL, 0x431d67c49c100d4cL, 0x4cc5d4becb3e42b6L, 86 | 0x597f299cfc657e2aL, 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L}; 87 | 88 | private static final int BLOCK_SIZE = 128; // inner block size in bytes 89 | 90 | private static final String DIGEST0 = "CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED" 91 | + "8086072BA1E7CC2358BAECA134C825A7"; 92 | 93 | private static final long[] w = new long[80]; 94 | 95 | /** 96 | * caches the result of the correctness test, once executed. 97 | */ 98 | private static Boolean valid; 99 | 100 | /** 101 | * 512-bit interim result. 102 | */ 103 | private long h0, h1, h2, h3, h4, h5, h6, h7; 104 | 105 | // Constructor(s) 106 | // ------------------------------------------------------------------------- 107 | 108 | /** 109 | * Trivial 0-arguments constructor. 110 | */ 111 | public Sha384() { 112 | super("sha-384", 48, BLOCK_SIZE); 113 | } 114 | 115 | /** 116 | *

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 | *
    49 | *
  1. Descriptions of SHA-256, SHA-384, and SHA-512,
  2. 52 | *
  3. http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
  4. 53 | *
54 | */ 55 | public class Sha512 extends BaseHash { 56 | 57 | // Constants and variables 58 | // ------------------------------------------------------------------------- 59 | 60 | private static final long[] k = { 0x428a2f98d728ae22L, 0x7137449123ef65cdL, 61 | 0xb5c0fbcfec4d3b2fL, 0xe9b5dba58189dbbcL, 0x3956c25bf348b538L, 62 | 0x59f111f1b605d019L, 0x923f82a4af194f9bL, 0xab1c5ed5da6d8118L, 63 | 0xd807aa98a3030242L, 0x12835b0145706fbeL, 0x243185be4ee4b28cL, 64 | 0x550c7dc3d5ffb4e2L, 0x72be5d74f27b896fL, 0x80deb1fe3b1696b1L, 65 | 0x9bdc06a725c71235L, 0xc19bf174cf692694L, 0xe49b69c19ef14ad2L, 66 | 0xefbe4786384f25e3L, 0x0fc19dc68b8cd5b5L, 0x240ca1cc77ac9c65L, 67 | 0x2de92c6f592b0275L, 0x4a7484aa6ea6e483L, 0x5cb0a9dcbd41fbd4L, 68 | 0x76f988da831153b5L, 0x983e5152ee66dfabL, 0xa831c66d2db43210L, 69 | 0xb00327c898fb213fL, 0xbf597fc7beef0ee4L, 0xc6e00bf33da88fc2L, 70 | 0xd5a79147930aa725L, 0x06ca6351e003826fL, 0x142929670a0e6e70L, 71 | 0x27b70a8546d22ffcL, 0x2e1b21385c26c926L, 0x4d2c6dfc5ac42aedL, 72 | 0x53380d139d95b3dfL, 0x650a73548baf63deL, 0x766a0abb3c77b2a8L, 73 | 0x81c2c92e47edaee6L, 0x92722c851482353bL, 0xa2bfe8a14cf10364L, 74 | 0xa81a664bbc423001L, 0xc24b8b70d0f89791L, 0xc76c51a30654be30L, 75 | 0xd192e819d6ef5218L, 0xd69906245565a910L, 0xf40e35855771202aL, 76 | 0x106aa07032bbd1b8L, 0x19a4c116b8d2d0c8L, 0x1e376c085141ab53L, 77 | 0x2748774cdf8eeb99L, 0x34b0bcb5e19b48a8L, 0x391c0cb3c5c95a63L, 78 | 0x4ed8aa4ae3418acbL, 0x5b9cca4f7763e373L, 0x682e6ff3d6b2b8a3L, 79 | 0x748f82ee5defb2fcL, 0x78a5636f43172f60L, 0x84c87814a1f0ab72L, 80 | 0x8cc702081a6439ecL, 0x90befffa23631e28L, 0xa4506cebde82bde9L, 81 | 0xbef9a3f7b2c67915L, 0xc67178f2e372532bL, 0xca273eceea26619cL, 82 | 0xd186b8c721c0c207L, 0xeada7dd6cde0eb1eL, 0xf57d4f7fee6ed178L, 83 | 0x06f067aa72176fbaL, 0x0a637dc5a2c898a6L, 0x113f9804bef90daeL, 84 | 0x1b710b35131c471bL, 0x28db77f523047d84L, 0x32caab7b40c72493L, 85 | 0x3c9ebe0a15c9bebcL, 0x431d67c49c100d4cL, 0x4cc5d4becb3e42b6L, 86 | 0x597f299cfc657e2aL, 0x5fcb6fab3ad6faecL, 0x6c44198c4a475817L }; 87 | 88 | private static final int BLOCK_SIZE = 128; // inner block size in bytes 89 | 90 | private static final String DIGEST0 = "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A" 91 | + "2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F"; 92 | 93 | private static final long[] w = new long[80]; 94 | 95 | /** caches the result of the correctness test, once executed. */ 96 | private static Boolean valid; 97 | 98 | /** 512-bit interim result. */ 99 | private long h0, h1, h2, h3, h4, h5, h6, h7; 100 | 101 | // Constructor(s) 102 | // ------------------------------------------------------------------------- 103 | 104 | /** Trivial 0-arguments constructor. */ 105 | public Sha512() { 106 | super("sha-512", 64, BLOCK_SIZE); 107 | } 108 | 109 | /** 110 | *

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, see . 18 | */ 19 | 20 | package com.hobbyone.HashDroid; 21 | 22 | import android.app.Activity; 23 | import android.app.ProgressDialog; 24 | import android.content.res.Resources; 25 | import android.os.Bundle; 26 | import android.os.Handler; 27 | import android.os.Message; 28 | import android.text.ClipboardManager; 29 | import android.text.Editable; 30 | import android.view.View; 31 | import android.view.View.OnClickListener; 32 | import android.widget.AdapterView; 33 | import android.widget.AdapterView.OnItemSelectedListener; 34 | import android.widget.ArrayAdapter; 35 | import android.widget.Button; 36 | import android.widget.CheckBox; 37 | import android.widget.EditText; 38 | import android.widget.Spinner; 39 | import android.widget.TextView; 40 | import android.widget.Toast; 41 | 42 | public class TextActivity extends Activity implements Runnable { 43 | private EditText mEditText = null; 44 | private CheckBox mCheckBox = null; 45 | private Button mClearButton = null; 46 | private Button mGenerateButton = null; 47 | private Button mCopyButton = null; 48 | private Spinner mSpinner = null; 49 | private TextView mResultTV = null; 50 | private ClipboardManager mClipboard = null; 51 | private String msHash = ""; 52 | private String msToHash = ""; 53 | private String[] mFunctions; 54 | private HashFunctionOperator mHashOpe = null; 55 | private ProgressDialog mProgressDialog = null; 56 | private int miItePos = -1; 57 | 58 | /** 59 | * Called when the activity is first created. 60 | */ 61 | @Override 62 | public void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.text); 65 | 66 | mEditText = (EditText) findViewById(R.id.edittext); 67 | mClearButton = (Button) findViewById(R.id.ClearButton); 68 | mGenerateButton = (Button) findViewById(R.id.GenerateButton); 69 | mSpinner = (Spinner) findViewById(R.id.spinner); 70 | mResultTV = (TextView) findViewById(R.id.label_result); 71 | mCopyButton = (Button) findViewById(R.id.CopyButton); 72 | mClipboard = (ClipboardManager) getSystemService("clipboard"); 73 | mFunctions = getResources().getStringArray(R.array.Algo_Array); 74 | mCheckBox = (CheckBox) findViewById(R.id.UpperCaseCB); 75 | 76 | ArrayAdapter adapter = ArrayAdapter.createFromResource( 77 | this, R.array.Algo_Array, android.R.layout.simple_spinner_item); 78 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 79 | mSpinner.setAdapter(adapter); 80 | mSpinner.setSelection(5); // MD5 by default 81 | mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { 82 | @Override 83 | public void onItemSelected(AdapterView parentView, 84 | View selectedItemView, int position, long id) { 85 | // your code here 86 | // Hide the copy button 87 | if (!msHash.equals("")) 88 | mCopyButton.setVisibility(View.INVISIBLE); 89 | // Clean the result text view 90 | if (mResultTV != null) 91 | mResultTV.setText(""); 92 | } 93 | 94 | @Override 95 | public void onNothingSelected(AdapterView parentView) { 96 | // your code here 97 | } 98 | }); 99 | 100 | mClearButton.setOnClickListener(new OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | // Perform action on clicks 104 | mEditText.setText(""); 105 | if (mResultTV != null) 106 | mResultTV.setText(""); 107 | msHash = ""; 108 | if (mCopyButton != null) 109 | mCopyButton.setVisibility(View.INVISIBLE); 110 | } 111 | }); 112 | 113 | mGenerateButton.setOnClickListener(new OnClickListener() { 114 | @Override 115 | public void onClick(View v) { 116 | // Perform action on clicks 117 | miItePos = mSpinner.getSelectedItemPosition(); 118 | Editable InputEdit = mEditText.getText(); 119 | msToHash = InputEdit.toString(); 120 | ComputeAndDisplayHash(); 121 | } 122 | }); 123 | 124 | mCopyButton.setOnClickListener(new OnClickListener() { 125 | @Override 126 | public void onClick(View v) { 127 | // Perform action on clicks 128 | if (mClipboard != null) { 129 | mClipboard.setText(msHash); 130 | String sCopied = getString(R.string.copied); 131 | Toast.makeText(TextActivity.this, sCopied, 132 | Toast.LENGTH_SHORT).show(); 133 | } 134 | } 135 | }); 136 | 137 | mCheckBox.setChecked(false); // lower case by default 138 | mCheckBox.setOnClickListener(new OnClickListener() { 139 | @Override 140 | public void onClick(View v) { 141 | // Perform action on clicks 142 | if (!msHash.equals("")) { 143 | // A hash value has already been calculated, 144 | // just convert it to lower or upper case 145 | String OldHash = msHash; 146 | if (mCheckBox.isChecked()) { 147 | msHash = OldHash.toUpperCase(); 148 | } else { 149 | msHash = OldHash.toLowerCase(); 150 | } 151 | if (mResultTV != null) { 152 | String sResult = mResultTV.getText().toString(); 153 | sResult = sResult.replaceAll(OldHash, msHash); 154 | mResultTV.setText(sResult); 155 | } 156 | } 157 | } 158 | }); 159 | 160 | } 161 | 162 | private void ComputeAndDisplayHash() { 163 | if (mHashOpe == null) 164 | mHashOpe = new HashFunctionOperator(); 165 | String sAlgo = ""; 166 | if (miItePos == 0) 167 | sAlgo = "Adler-32"; 168 | else if (miItePos == 1) 169 | sAlgo = "CRC-32"; 170 | else if (miItePos == 2) 171 | sAlgo = "haval"; 172 | else if (miItePos == 3) 173 | sAlgo = "md2"; 174 | else if (miItePos == 4) 175 | sAlgo = "md4"; 176 | else if (miItePos == 5) 177 | sAlgo = "md5"; 178 | else if (miItePos == 6) 179 | sAlgo = "ripemd-128"; 180 | else if (miItePos == 7) 181 | sAlgo = "ripemd-160"; 182 | else if (miItePos == 8) 183 | sAlgo = "sha-1"; 184 | else if (miItePos == 9) 185 | sAlgo = "sha-256"; 186 | else if (miItePos == 10) 187 | sAlgo = "sha-384"; 188 | else if (miItePos == 11) 189 | sAlgo = "sha-512"; 190 | else if (miItePos == 12) 191 | sAlgo = "tiger"; 192 | else if (miItePos == 13) 193 | sAlgo = "whirlpool"; 194 | mHashOpe.SetAlgorithm(sAlgo); 195 | 196 | String sCalculating = getString(R.string.Calculating); 197 | mProgressDialog = ProgressDialog.show(TextActivity.this, "", 198 | sCalculating, true); 199 | 200 | Thread thread = new Thread(this); 201 | thread.start(); 202 | } 203 | 204 | @Override 205 | // Call when the thread is started 206 | public void run() { 207 | msHash = ""; 208 | if (mHashOpe != null) 209 | msHash = mHashOpe.StringToHash(msToHash); 210 | handler.sendEmptyMessage(0); 211 | } 212 | 213 | // This method is called when the computation is over 214 | private Handler handler = new Handler() { 215 | @Override 216 | public void handleMessage(Message msg) { 217 | // Hide the progress dialog 218 | if (mProgressDialog != null) 219 | mProgressDialog.dismiss(); 220 | 221 | Resources res = getResources(); 222 | String sTextTitle = String.format(res.getString(R.string.Text), 223 | msToHash); 224 | String sTextHashTitle = ""; 225 | if (!msHash.equals("")) { 226 | if (mCheckBox != null) { 227 | if (mCheckBox.isChecked()) { 228 | msHash = msHash.toUpperCase(); 229 | } else { 230 | msHash = msHash.toLowerCase(); 231 | } 232 | } 233 | String Function = ""; 234 | if (miItePos >= 0) 235 | Function = mFunctions[miItePos]; 236 | sTextHashTitle = String.format(res.getString(R.string.Hash), 237 | Function, msHash); 238 | // Show the copy button 239 | if (mCopyButton != null) 240 | mCopyButton.setVisibility(View.VISIBLE); 241 | } else { 242 | sTextHashTitle = String.format( 243 | res.getString(R.string.unable_to_calculate), msToHash); 244 | // Hide the copy button 245 | if (mCopyButton != null) 246 | mCopyButton.setVisibility(View.INVISIBLE); 247 | } 248 | 249 | if (mResultTV != null) 250 | mResultTV.setText(sTextTitle + sTextHashTitle); 251 | } 252 | }; 253 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hobbyone/HashDroid/UtilServices.java: -------------------------------------------------------------------------------- 1 | /* UtilServices.java -- various utility routines. 2 | Copyright (C) 2001, 2002, 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 | * 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 | *

94 | * 95 | * @param ba the byte array to convert. 96 | * @param offset the index from which to start considering the bytes to 97 | * convert. 98 | * @param length the count of bytes, starting from the designated offset to 99 | * convert. 100 | * @return a string of hexadecimal characters (two for each byte) 101 | * representing the designated input byte sub-array. 102 | */ 103 | public static final String toString(byte[] ba, int offset, int length) { 104 | char[] buf = new char[length * 2]; 105 | for (int i = 0, j = 0, k; i < length; ) { 106 | k = ba[offset + i++]; 107 | buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; 108 | buf[j++] = HEX_DIGITS[k & 0x0F]; 109 | } 110 | return new String(buf); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/custom_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_menu_about.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_menu_help.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_rateit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_menu_rateit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_compare.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_compare_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_compare_grey.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_compare_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_compare_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_file.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_file_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_file_grey.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_file_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_file_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_text_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_text_grey.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tab_text_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HobbyOneDroid/HashDroid/18153d96a27742fa9ed075ff44178f2f532496e5/app/src/main/res/drawable/ic_tab_text_white.png -------------------------------------------------------------------------------- /app/src/main/res/layout/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 22 | 23 | 31 | 32 | 41 | 42 | 52 | 53 | 64 | 65 | 76 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /app/src/main/res/layout/compare.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 18 | 19 | 23 | 24 |