├── .gitignore ├── .idea ├── dictionaries │ └── cpf.xml ├── gradle.xml ├── kotlinc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── base ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── cpf │ │ └── baseproject │ │ ├── base │ │ ├── BaseActivity.kt │ │ ├── BaseFragment.kt │ │ ├── BaseModel.kt │ │ ├── BasePresenter.kt │ │ └── ILifeObserver.kt │ │ ├── bean │ │ └── JsonMessage.kt │ │ ├── util │ │ ├── Async.kt │ │ ├── Base64.kt │ │ ├── File.kt │ │ ├── Fuel.kt │ │ ├── JsonCache.kt │ │ ├── Log.kt │ │ ├── Notice.kt │ │ ├── ObjectIO.kt │ │ ├── SHA256.kt │ │ ├── SeekBar.kt │ │ ├── SharedPreference.kt │ │ ├── Sqlite.kt │ │ ├── Text.kt │ │ └── WebView.kt │ │ └── widget │ │ ├── RefreshLayout.kt │ │ ├── SwipeBackLayout.kt │ │ └── TextChangeListener.kt │ └── res │ ├── anim │ ├── slide_center_to_down.xml │ ├── slide_center_to_up.xml │ ├── slide_down_to_center.xml │ └── slide_up_to_center.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── xmrminer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── cpf │ ├── cryptonight │ └── Miner.kt │ └── xmrminer │ ├── HexUtil.java │ ├── Job.kt │ ├── JobTest.kt │ ├── MainActivity.kt │ ├── MinerEventListener.kt │ ├── MinerManager.kt │ ├── MinerMsgListener.kt │ └── MinerService.kt ├── jni ├── CMakeLists.txt ├── compat │ └── compat.h ├── crypto │ ├── aesb.c │ ├── c_blake256.c │ ├── c_blake256.h │ ├── c_groestl.c │ ├── c_groestl.h │ ├── c_jh.c │ ├── c_jh.h │ ├── c_keccak.c │ ├── c_keccak.h │ ├── c_skein.c │ ├── c_skein.h │ ├── groestl_tables.h │ ├── hash-ops.h │ ├── hash.c │ ├── hash.h │ ├── int-util.h │ ├── oaes_config.h │ ├── oaes_lib.c │ ├── oaes_lib.h │ ├── skein_port.h │ └── sph_types.h ├── cryptonight.c └── cryptonight_jni.c └── res ├── layout └── activity_main.xml ├── mipmap-hdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-mdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxxhdpi ├── ic_launcher.png └── ic_launcher_round.png └── values ├── colors.xml ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/dictionaries/cpf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | algorism 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CryptoNightMiner 2 | Android mining software based on cryptonight algorithm 3 | -------------------------------------------------------------------------------- /base/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /base/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | ext.fuel_version = '1.12.0' 6 | 7 | android { 8 | compileSdkVersion 26 9 | defaultConfig { 10 | minSdkVersion 17 11 | targetSdkVersion 26 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled true 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 25 | implementation "com.android.support:appcompat-v7:$android_support_version" 26 | api "com.android.support:design:$android_support_version" 27 | /** 28 | * fuel网络框架 29 | */ 30 | api "com.github.kittinunf.fuel:fuel-android:$fuel_version" 31 | //for Android 32 | // api "com.github.kittinunf.fuel:fuel-livedata:$fuel_version" //for LiveData support 33 | // api "com.github.kittinunf.fuel:fuel-rxjava:$fuel_version" //for RxJava support 34 | api "com.github.kittinunf.fuel:fuel-gson:$fuel_version" 35 | api 'android.arch.lifecycle:extensions:1.0.0' 36 | 37 | } 38 | -------------------------------------------------------------------------------- /base/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------------------- 2 | -renamesourcefileattribute SourceFile 3 | -keepparameternames #【是否保留方法内参数命名】外壳暂时不加,影响开发者理解,但可以减小约1KB 4 | -optimizationpasses 5 #【优化轮数】,外壳不需要加,增加包大小 5 | #-dontusemixedcaseclassnames #【混淆时不会产生形形色色的类名】,不会影响包大小 6 | -dontskipnonpubliclibraryclasses #【指定不去忽略非公共的库类】,不会影响包大小 7 | -dontskipnonpubliclibraryclassmembers 8 | -dontpreverify #【不预校验】,需要打开,减少包大小,android不需预校验 9 | -dontoptimize 10 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* #【优化】,外壳可不加,加上包大小略微变大 11 | #-------------------------------------------基本不用动区域-------------------------------------------- 12 | #---------------------------------基本指令区---------------------------------- 13 | -verbose 14 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod,*Annotation* 15 | #---------------------------------------------------------------------------- 16 | 17 | #---------------------------------默认保留区--------------------------------- 18 | -keep public class * extends android.app.Activity 19 | -keep public class * extends android.app.Application 20 | -keep public class * extends android.app.Service 21 | -keep public class * extends android.content.BroadcastReceiver 22 | -keep public class * extends android.content.ContentProvider 23 | -keep public class * extends android.app.backup.BackupAgentHelper 24 | -keep public class * extends android.preference.Preference 25 | -keep public class * extends android.view.View 26 | -keep public class com.android.vending.licensing.ILicensingService 27 | 28 | -keepclasseswithmembernames class * { 29 | native ; 30 | } 31 | -keepclassmembers class * extends android.app.Activity{ 32 | public void *(android.view.View); 33 | } 34 | -keepclassmembers enum * { 35 | public static **[] values(); 36 | public static ** valueOf(java.lang.String); 37 | } 38 | -keep public class * extends android.view.View{ 39 | *** get*(); 40 | void set*(***); 41 | public (android.content.Context); 42 | public (android.content.Context, android.util.AttributeSet); 43 | public (android.content.Context, android.util.AttributeSet, int); 44 | } 45 | -keepclasseswithmembers class * { 46 | public (android.content.Context, android.util.AttributeSet); 47 | public (android.content.Context, android.util.AttributeSet, int); 48 | } 49 | -keep class * implements android.os.Parcelable { 50 | public static final android.os.Parcelable$Creator *; 51 | } 52 | -keepclassmembers class * implements java.io.Serializable { 53 | static final long serialVersionUID; 54 | private static final java.io.ObjectStreamField[] serialPersistentFields; 55 | private void writeObject(java.io.ObjectOutputStream); 56 | private void readObject(java.io.ObjectInputStream); 57 | java.lang.Object writeReplace(); 58 | java.lang.Object readResolve(); 59 | } 60 | -keep class **.R$* { 61 | *; 62 | } 63 | -keepclassmembers class * { 64 | void *(**On*Event); 65 | } 66 | 67 | #---------------------------------------------------------------------------- 68 | 69 | #---------------------------------webview------------------------------------ 70 | -keepclassmembers class fqcn.of.javascript.interface.for.Webview { 71 | public *; 72 | } 73 | -keepclassmembers class * extends android.webkit.WebViewClient { 74 | public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); 75 | public boolean *(android.webkit.WebView, java.lang.String); 76 | } 77 | -keepclassmembers class * extends android.webkit.WebViewClient { 78 | public void *(android.webkit.WebView, jav.lang.String); 79 | } 80 | #---------------------------------------------------------------------------- 81 | #--------------------------------------------------------------------------------------------------- 82 | #自定义组件不被混淆 83 | -keep public class * extends android.view.View { 84 | public (android.content.Context); 85 | public (android.content.Context, android.util.AttributeSet); 86 | public (android.content.Context, android.util.AttributeSet, int); 87 | public void set*(...); 88 | } 89 | #保持注解继承类不混淆 90 | -keep class * extends java.lang.annotation.Annotation {*;} 91 | #-------------------------------------------定制化区域---------------------------------------------- 92 | 93 | -dontwarn kotlin.** 94 | -dontwarn android.** 95 | -dontwarn org.** 96 | -dontwarn com.github.** 97 | -dontwarn com.google.** 98 | -keep class kotlin.**{*;} 99 | -keep class android.**{*;} 100 | -keep class org.**{*;} 101 | -keep class com.github.**{*;} 102 | -keep class com.google.**{*;} 103 | 104 | #---------------------------------1.实体类--------------------------------- 105 | 106 | 107 | 108 | #------------------------------------------------------------------------- 109 | 110 | #---------------------------------2.第三方包------------------------------- 111 | 112 | -keep class com.alibaba.**{*;} 113 | -dontwarn com.alibaba.** 114 | 115 | #------------------------------------------------------------------------- 116 | 117 | #---------------------------------3.与js互相调用的类------------------------ 118 | 119 | 120 | 121 | #------------------------------------------------------------------------- 122 | 123 | #---------------------------------4.反射相关的类和方法----------------------- -------------------------------------------------------------------------------- /base/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.cpf.baseproject.base 4 | 5 | import android.os.Bundle 6 | import android.support.v7.app.AppCompatActivity 7 | import android.support.v7.widget.LinearLayoutCompat 8 | import android.view.LayoutInflater 9 | import android.view.View 10 | import android.view.Window 11 | import android.widget.ImageView 12 | import android.widget.RelativeLayout 13 | import com.cpf.baseproject.R 14 | import com.cpf.baseproject.widget.SwipeBackLayout 15 | 16 | abstract class BaseActivity : AppCompatActivity() { 17 | 18 | private var mLoadResource = false 19 | private var mPresenter: BasePresenter? = null 20 | private var swipeBackLayout: SwipeBackLayout? = null 21 | 22 | override fun onCreate(savedInstanceState: Bundle?) { 23 | super.onCreate(savedInstanceState) 24 | if (canSwipeBack()) { 25 | setContentView(getContainer()) 26 | swipeBackLayout!!.addView(createView()) 27 | } else { 28 | if (initActionBarLayout() > 0) { 29 | setContentView(createView()) 30 | } else { 31 | setContentView(initLayout()) 32 | } 33 | } 34 | mLoadResource = true 35 | mPresenter = createPresenter() 36 | mPresenter?.attach(this) 37 | mPresenter?.getLifeObserver()?.onCreate() 38 | } 39 | 40 | 41 | override fun onStart() { 42 | super.onStart() 43 | mPresenter?.getLifeObserver()?.onStart() 44 | if (mLoadResource) { 45 | mLoadResource = false 46 | initView() 47 | initEvent() 48 | initData() 49 | } 50 | } 51 | 52 | private fun getContainer(): View { 53 | val container = RelativeLayout(this) 54 | swipeBackLayout = SwipeBackLayout(this) 55 | swipeBackLayout!!.setDragEdge(SwipeBackLayout.DragEdge.LEFT) 56 | val ivShadow = ImageView(this) 57 | ivShadow.setBackgroundColor(resources.getColor(R.color.swipe_back_bg)) 58 | val params = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT) 59 | container.addView(ivShadow, params) 60 | container.addView(swipeBackLayout) 61 | swipeBackLayout!!.setOnSwipeBackListener(object : SwipeBackLayout.SwipeBackListener { 62 | override fun onViewPositionChanged(fractionAnchor: Float, fractionScreen: Float) { 63 | ivShadow.alpha = 1 - fractionScreen 64 | } 65 | }) 66 | return container 67 | } 68 | 69 | open fun createView(): View { 70 | val mRootView = LinearLayoutCompat(this) 71 | mRootView.setBackgroundColor(resources.getColor(R.color.md_white_1000)) 72 | mRootView.orientation = LinearLayoutCompat.VERTICAL 73 | if (initActionBarLayout() > 0) { 74 | requestWindowFeature(Window.FEATURE_NO_TITLE) 75 | mRootView.addView(LayoutInflater.from(this).inflate(initActionBarLayout(), mRootView, false)) 76 | } 77 | if (initLayout() > 0) { 78 | mRootView.addView(LayoutInflater.from(this).inflate(initLayout(), mRootView, false)) 79 | } 80 | return mRootView 81 | } 82 | 83 | abstract fun canSwipeBack(): Boolean 84 | 85 | abstract fun initActionBarLayout(): Int 86 | 87 | abstract fun initLayout(): Int 88 | 89 | abstract fun initView() 90 | 91 | abstract fun initEvent() 92 | 93 | abstract fun initData() 94 | 95 | open fun createPresenter(): BasePresenter? { 96 | return null 97 | } 98 | 99 | override fun onResume() { 100 | super.onResume() 101 | mPresenter?.getLifeObserver()?.onResume() 102 | } 103 | 104 | override fun onPause() { 105 | super.onPause() 106 | mPresenter?.getLifeObserver()?.onPause() 107 | } 108 | 109 | override fun onStop() { 110 | super.onStop() 111 | mPresenter?.getLifeObserver()?.onStop() 112 | } 113 | 114 | override fun onDestroy() { 115 | super.onDestroy() 116 | mPresenter?.getLifeObserver()?.onDestroy() 117 | mPresenter?.detach() 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/base/BaseFragment.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.base 4 | 5 | import android.app.Activity 6 | import android.os.Bundle 7 | import android.support.v4.app.Fragment 8 | import android.view.LayoutInflater 9 | import android.view.View 10 | import android.view.ViewGroup 11 | 12 | abstract class BaseFragment : Fragment() { 13 | 14 | private var mPresenter: BasePresenter? = null 15 | 16 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 17 | inflater.inflate(initLayout(), container, false) 18 | 19 | abstract fun initLayout(): Int 20 | 21 | abstract fun initView() 22 | 23 | abstract fun initEvent() 24 | 25 | abstract fun initData() 26 | 27 | override fun onActivityCreated(savedInstanceState: Bundle?) { 28 | super.onActivityCreated(savedInstanceState) 29 | mPresenter = createPresenter() 30 | mPresenter?.attach(context) 31 | mPresenter?.getLifeObserver()?.onCreate() 32 | initView() 33 | initEvent() 34 | initData() 35 | } 36 | 37 | fun getCurrActivity(): T { 38 | @Suppress("UNCHECKED_CAST") 39 | return activity as T 40 | } 41 | 42 | open fun createPresenter(): BasePresenter? { 43 | return null 44 | } 45 | 46 | override fun onStart() { 47 | super.onStart() 48 | mPresenter?.getLifeObserver()?.onStart() 49 | } 50 | 51 | override fun onResume() { 52 | super.onResume() 53 | mPresenter?.getLifeObserver()?.onResume() 54 | } 55 | 56 | override fun onPause() { 57 | super.onPause() 58 | mPresenter?.getLifeObserver()?.onPause() 59 | } 60 | 61 | override fun onStop() { 62 | super.onStop() 63 | mPresenter?.getLifeObserver()?.onStop() 64 | } 65 | 66 | override fun onDestroyView() { 67 | super.onDestroyView() 68 | mPresenter?.getLifeObserver()?.onDestroy() 69 | mPresenter?.detach() 70 | } 71 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/base/BaseModel.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.base 2 | 3 | import android.content.Context 4 | 5 | 6 | abstract class BaseModel(context: Context) { 7 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/base/BasePresenter.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.base 2 | 3 | import android.content.Context 4 | 5 | @Suppress("unused") 6 | abstract class BasePresenter { 7 | 8 | var mContext: Context? = null 9 | 10 | open fun attach(context: Context) { 11 | this.mContext = context 12 | } 13 | 14 | open fun detach() { 15 | mContext = null 16 | } 17 | 18 | abstract fun getLifeObserver(): ILifeObserver? 19 | 20 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/base/ILifeObserver.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.base 2 | 3 | /** 4 | * Created by cpf on 2017/12/8. 5 | */ 6 | interface ILifeObserver { 7 | 8 | fun onCreate() 9 | 10 | fun onStart() 11 | 12 | fun onResume() 13 | 14 | fun onPause() 15 | 16 | fun onStop() 17 | 18 | fun onDestroy() 19 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/bean/JsonMessage.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.bean 2 | 3 | data class JsonMessage(val code: Int, val msg: String, val data: Any) -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Async.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import android.os.Handler 6 | import java.util.concurrent.ExecutorService 7 | import java.util.concurrent.Executors 8 | 9 | /** 10 | * 全局线程池 11 | */ 12 | var threadService: ExecutorService = Executors.newCachedThreadPool() 13 | /** 14 | * 单任务线程池 15 | */ 16 | var singleThreadService: ExecutorService = Executors.newSingleThreadExecutor() 17 | /** 18 | * 全局handler 19 | */ 20 | val handler = Handler() 21 | 22 | /** 23 | * 启动异步任务 24 | */ 25 | fun async(block: () -> Unit) { 26 | threadService.execute { 27 | block() 28 | } 29 | } 30 | 31 | /** 32 | * ui线程任务 33 | */ 34 | fun ui(block: () -> Unit) { 35 | handler.post { 36 | block() 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Base64.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import android.util.Base64 6 | 7 | 8 | // 加密 9 | fun getBase64(str: String): String { 10 | var result = "" 11 | try { 12 | result = String(Base64.encode(str.toByteArray(), Base64.DEFAULT)) 13 | } catch (e: Exception) { 14 | e.printStackTrace() 15 | } 16 | return result 17 | } 18 | 19 | // 解密 20 | fun getFromBase64(str: String): String { 21 | var result = "" 22 | try { 23 | result = String(Base64.decode(str, Base64.DEFAULT)) 24 | } catch (e: Exception) { 25 | e.printStackTrace() 26 | } 27 | return result 28 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/File.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.content.Context 4 | import java.io.File 5 | import java.io.FileOutputStream 6 | 7 | fun copyFilesFromAssets(context: Context, assetsPath: String, savePath: String) { 8 | try { 9 | val fileNames = context.assets.list(assetsPath)// 获取assets目录下的所有文件及目录名 10 | if (fileNames.isNotEmpty()) {// 如果是目录 11 | val file = File(savePath) 12 | file.mkdirs()// 如果文件夹不存在,则递归 13 | for (fileName in fileNames) { 14 | copyFilesFromAssets(context, assetsPath + "/" + fileName, 15 | savePath + "/" + fileName) 16 | } 17 | } else {// 如果是文件 18 | val inputStream = context.assets.open(assetsPath) 19 | val fos = FileOutputStream(File(savePath)) 20 | val buffer = ByteArray(1024) 21 | var byteCount = inputStream.read(buffer) 22 | while (byteCount != -1) {// 循环从输入流读取 23 | // buffer字节 24 | fos.write(buffer, 0, byteCount)// 将读取的输入流写入到输出流 25 | byteCount = inputStream.read(buffer) 26 | } 27 | fos.flush()// 刷新缓冲区 28 | inputStream.close() 29 | fos.close() 30 | } 31 | } catch (e: Exception) { 32 | e.printStackTrace() 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Fuel.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.content.Context 4 | import com.cpf.baseproject.R 5 | import com.cpf.baseproject.bean.JsonMessage 6 | import com.github.kittinunf.fuel.core.Request 7 | import com.github.kittinunf.result.failure 8 | import com.github.kittinunf.result.success 9 | 10 | /** 11 | * Created by cpf on 2017/12/11. 12 | * Fuel扩展 13 | */ 14 | 15 | fun Request.responseString(context: Context, success: (jsonMessage: JsonMessage) -> Unit, failure: () -> Unit) { 16 | responseString { _, _, result -> 17 | result.success { 18 | logPrint(result.get()) 19 | var jsonMessage: JsonMessage? = null 20 | try { 21 | jsonMessage = gson.fromJson(result.get(), JsonMessage::class.java) 22 | } catch (e: Exception) { 23 | e.printStackTrace() 24 | } 25 | if (jsonMessage != null) { 26 | success(jsonMessage) 27 | } else { 28 | failure() 29 | toast(context, context.getString(R.string.data_parse_exception)) 30 | } 31 | } 32 | result.failure { 33 | failure() 34 | toast(context, context.getString(R.string.net_connect_timeout)) 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/JsonCache.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import android.content.Context 6 | import com.google.gson.Gson 7 | 8 | val gson = Gson() 9 | 10 | fun put(context: Context, key: String, value: Any) { 11 | putString(context, key, getBase64(gson.toJson(value))) 12 | } 13 | 14 | fun get(context: Context, key: String, clazz: Class): T? { 15 | return try { 16 | gson.fromJson(getFromBase64(getSharedPref(context).getString(key, "")), clazz) 17 | } catch (e: Exception) { 18 | e.printStackTrace() 19 | null 20 | } 21 | } 22 | 23 | 24 | inline fun getList(context: Context, key: String): List? { 25 | return try { 26 | gson.fromJson(getFromBase64(getSharedPref(context).getString(key, "")), emptyArray().javaClass).toList() 27 | } catch (e: Exception) { 28 | e.printStackTrace() 29 | null 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Log.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.util.Log 4 | import com.cpf.baseproject.BuildConfig 5 | 6 | /** 7 | *log输出 8 | */ 9 | 10 | fun logPrint(any: Any?) { 11 | 12 | if (any != null && BuildConfig.DEBUG) { 13 | Log.e("APP", any.toString()) 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Notice.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.content.Context 4 | import android.support.design.widget.Snackbar 5 | import android.text.TextUtils 6 | import android.view.View 7 | import android.widget.Toast 8 | 9 | /** 10 | * toast 11 | */ 12 | fun toast(context: Context, string: String) { 13 | Toast.makeText(context.applicationContext, string, Toast.LENGTH_SHORT).show() 14 | } 15 | 16 | fun toast(context: Context, strInt: Int) { 17 | toast(context, context.getString(strInt)) 18 | } 19 | 20 | /** 21 | * md中的底部通知 22 | */ 23 | fun snackBar(view: View, string: String, type: Int) { 24 | snackBar(view, string, type, null, null) 25 | } 26 | 27 | fun snackBar(view: View, string: String, type: Int, actionStr: String?, clickListener: View.OnClickListener?) { 28 | val snackBar = Snackbar.make(view, string, type) 29 | if (!TextUtils.isEmpty(actionStr) || clickListener != null) { 30 | snackBar.setAction(actionStr, clickListener) 31 | } 32 | snackBar.show() 33 | } 34 | 35 | fun snackBar(view: View, strInt: Int, type: Int) { 36 | snackBar(view, view.context.getString(strInt), type, null, null) 37 | } 38 | 39 | fun snackBar(view: View, strInt: Int, type: Int, actionStr: String?, clickListener: View.OnClickListener?) { 40 | snackBar(view, view.context.getString(strInt), type, actionStr, clickListener) 41 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/ObjectIO.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import android.content.Context 6 | import android.util.Base64 7 | import java.io.* 8 | 9 | @Suppress("UNCHECKED_CAST") 10 | fun getObjectByIO(context: Context, key: String): T? { 11 | return try { 12 | val file = context.filesDir 13 | val fis = FileInputStream(File(file, key)) 14 | val bytes = ByteArray(fis.available()) 15 | fis.read(bytes) 16 | val byteIS = ByteArrayInputStream(Base64.decode(bytes, Base64.DEFAULT)) 17 | val ois = ObjectInputStream(byteIS) 18 | val t: T = ois.readObject() as T 19 | ois.close() 20 | byteIS.close() 21 | fis.close() 22 | t 23 | } catch (e: Exception) { 24 | e.printStackTrace() 25 | null 26 | } 27 | } 28 | 29 | fun putObjectByIO(context: Context, key: String, serializable: Serializable): Boolean { 30 | try { 31 | val file = context.filesDir 32 | val fos = FileOutputStream(File(file, key)) 33 | val byteOS = ByteArrayOutputStream() 34 | val oos = ObjectOutputStream(byteOS) 35 | oos.writeObject(serializable) 36 | oos.flush() 37 | oos.close() 38 | fos.write(Base64.encode(byteOS.toByteArray(), Base64.DEFAULT)) 39 | fos.flush() 40 | fos.close() 41 | byteOS.close() 42 | } catch (e: Exception) { 43 | e.printStackTrace() 44 | return false 45 | } 46 | return true 47 | } 48 | 49 | 50 | @Suppress("UNCHECKED_CAST") 51 | fun getObjectByString(content: String): T? { 52 | return try { 53 | val byteIS = ByteArrayInputStream(Base64.decode(content.toByteArray(Charsets.ISO_8859_1), Base64.DEFAULT)) 54 | val ois = ObjectInputStream(byteIS) 55 | val t: T = ois.readObject() as T 56 | ois.close() 57 | byteIS.close() 58 | t 59 | } catch (e: Exception) { 60 | e.printStackTrace() 61 | null 62 | } 63 | } 64 | 65 | fun getStringByObject(any: Any): String { 66 | return try { 67 | val byteOS = ByteArrayOutputStream() 68 | val oos = ObjectOutputStream(byteOS) 69 | oos.writeObject(any) 70 | oos.flush() 71 | oos.close() 72 | byteOS.close() 73 | Base64.encode(byteOS.toByteArray(), Base64.DEFAULT).toString(Charsets.ISO_8859_1) 74 | } catch (e: Exception) { 75 | e.printStackTrace() 76 | "" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/SHA256.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import java.io.UnsupportedEncodingException 6 | import java.security.MessageDigest 7 | import java.security.NoSuchAlgorithmException 8 | import kotlin.experimental.and 9 | 10 | 11 | /** 12 | * 利用java原生的摘要实现SHA256加密 13 | * 14 | * @param str 加密后的报文 15 | * @return 16 | */ 17 | fun sha256(str: String): String { 18 | val messageDigest: MessageDigest 19 | var encodeStr = "" 20 | try { 21 | messageDigest = MessageDigest.getInstance("SHA-256") 22 | messageDigest.update(str.toByteArray(charset("UTF-8"))) 23 | encodeStr = byte2Hex(messageDigest.digest()) 24 | } catch (e: NoSuchAlgorithmException) { 25 | e.printStackTrace() 26 | } catch (e: UnsupportedEncodingException) { 27 | e.printStackTrace() 28 | } 29 | 30 | return encodeStr 31 | } 32 | 33 | /** 34 | * 将byte转为16进制 35 | * 36 | * @param bytes 37 | * @return 38 | */ 39 | private fun byte2Hex(bytes: ByteArray): String { 40 | val stringBuffer = StringBuffer() 41 | var temp: String? 42 | for (i in bytes.indices) { 43 | temp = Integer.toHexString((bytes[i] and 0xFF.toByte()).toInt()) 44 | if (temp!!.length == 1) { 45 | //1得到一位的进行补0操作 46 | stringBuffer.append("0") 47 | } 48 | stringBuffer.append(temp) 49 | } 50 | return stringBuffer.toString() 51 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/SeekBar.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.widget.SeekBar 4 | 5 | /** 6 | * Created by cpf on 2017/12/19. 7 | * SeekBar 8 | */ 9 | fun SeekBar.setOnSeekBarChangeAfterListener(block: (progress: Int) -> Unit) { 10 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 11 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 12 | 13 | } 14 | 15 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 16 | 17 | } 18 | 19 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 20 | block(seekBar!!.progress) 21 | } 22 | 23 | }) 24 | } 25 | 26 | fun SeekBar.setOnSeekBarChangeBeforeListener(block: (progress: Int) -> Unit) { 27 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 28 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 29 | 30 | } 31 | 32 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 33 | block(seekBar!!.progress) 34 | } 35 | 36 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 37 | 38 | } 39 | 40 | }) 41 | } 42 | 43 | fun SeekBar.setOnSeekBarChangeListener(change: (progress: Int) -> Unit, stop: (progress: Int) -> Unit) { 44 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 45 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 46 | if (fromUser) { 47 | change(progress) 48 | } 49 | } 50 | 51 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 52 | } 53 | 54 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 55 | stop(seekBar!!.progress) 56 | } 57 | 58 | }) 59 | } 60 | 61 | fun SeekBar.setOnSeekBarChangeListener(change: (progress: Int) -> Unit, start: (progress: Int) -> Unit, stop: (progress: Int) -> Unit) { 62 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 63 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 64 | if (fromUser) { 65 | change(progress) 66 | } 67 | } 68 | 69 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 70 | start(seekBar!!.progress) 71 | } 72 | 73 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 74 | stop(seekBar!!.progress) 75 | } 76 | 77 | }) 78 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/SharedPreference.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.content.Context 4 | import android.content.SharedPreferences 5 | 6 | /** 7 | * SharedPreferences 8 | */ 9 | fun getSharedPref(context: Context): SharedPreferences = 10 | context.getSharedPreferences("APP", Context.MODE_PRIVATE) 11 | 12 | fun putInt(context: Context, key: String, value: Int) { 13 | getSharedPref(context).edit().putInt(key, value).apply() 14 | } 15 | 16 | fun putString(context: Context, key: String, value: String) { 17 | getSharedPref(context).edit().putString(key, value).apply() 18 | } 19 | 20 | fun putBoolean(context: Context, key: String, value: Boolean) { 21 | getSharedPref(context).edit().putBoolean(key, value).apply() 22 | } 23 | 24 | fun putFloat(context: Context, key: String, value: Float) { 25 | getSharedPref(context).edit().putFloat(key, value).apply() 26 | } 27 | 28 | fun putLong(context: Context, key: String, value: Long) { 29 | getSharedPref(context).edit().putLong(key, value).apply() 30 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Sqlite.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.util 4 | 5 | import android.content.Context 6 | import android.database.Cursor 7 | import android.database.sqlite.SQLiteDatabase 8 | import android.support.annotation.NonNull 9 | 10 | enum class EncodeMode { 11 | Serializable, 12 | JSON 13 | } 14 | 15 | private var mEncodeMode = EncodeMode.JSON 16 | 17 | fun initSQLiteEncodeMode(@NonNull encodeMode: EncodeMode) { 18 | mEncodeMode = encodeMode 19 | } 20 | 21 | fun getDatabase(context: Context): SQLiteDatabase = 22 | context.openOrCreateDatabase("App.db", Context.MODE_PRIVATE, null) 23 | 24 | /** 25 | * 处理加密 26 | */ 27 | private fun handleEncode(str: String): String = getBase64(str) 28 | 29 | 30 | /** 31 | * 处理解密 32 | */ 33 | private fun handleDecode(str: String): String = getFromBase64(str) 34 | 35 | 36 | /** 37 | * 创建表,如果存在则不会创建 38 | */ 39 | fun createTableIfNotExist(context: Context, clazz: Class): Boolean { 40 | try { 41 | val db = getDatabase(context) 42 | val sql = StringBuffer() 43 | sql.append("create table if not exists `${clazz.simpleName}`(" + 44 | "`_id` integer primary key autoincrement,`") 45 | val fields = clazz.declaredFields 46 | for (field in fields) { 47 | if (field.name != "serialVersionUID" && !field.name.contains("$")) { 48 | field.isAccessible = true 49 | val value = field.type 50 | when (value) { 51 | String::class.java -> { 52 | sql.append(field.name + "` TEXT,`") 53 | } 54 | Char::class.java -> { 55 | sql.append(field.name + "` TEXT,`") 56 | } 57 | Boolean::class.java -> { 58 | sql.append(field.name + "` INTEGER,`") 59 | } 60 | Int::class.java -> { 61 | sql.append(field.name + "` INTEGER,`") 62 | } 63 | Short::class.java -> { 64 | sql.append(field.name + "` INTEGER,`") 65 | } 66 | Byte::class.java -> { 67 | sql.append(field.name + "` INTEGER,`") 68 | } 69 | Long::class.java -> { 70 | sql.append(field.name + "` BIGINT,`") 71 | } 72 | Float::class.java -> { 73 | sql.append(field.name + "` REAL,`") 74 | } 75 | Double::class.java -> { 76 | sql.append(field.name + "` REAL,`") 77 | } 78 | else -> { 79 | sql.append(field.name + "` TEXT,`") 80 | } 81 | } 82 | } 83 | } 84 | sql.delete(sql.length - 2, sql.length) 85 | sql.append(");") 86 | logPrint(sql.toString()) 87 | db.execSQL(sql.toString()) 88 | db.close() 89 | } catch (e: Exception) { 90 | e.printStackTrace() 91 | return false 92 | } 93 | return true 94 | } 95 | 96 | /** 97 | * 增 98 | */ 99 | fun insert(context: Context, any: Any): Boolean { 100 | try { 101 | when (any) { 102 | is Collection<*> -> any.forEach { 103 | if (it != null) { 104 | insert(context, it) 105 | } 106 | } 107 | is Array<*> -> any.forEach { 108 | if (it != null) { 109 | insert(context, it) 110 | } 111 | } 112 | else -> { 113 | val db = getDatabase(context) 114 | val fields = any.javaClass.declaredFields 115 | val sql = StringBuffer().append("insert into `${any.javaClass.simpleName}`(") 116 | for (field in fields) { 117 | if (field.name != "serialVersionUID" && !field.name.contains("$")) { 118 | field.isAccessible = true 119 | if (field.get(any) != null) { 120 | sql.append("`").append(field.name).append("`,") 121 | } 122 | } 123 | } 124 | sql.deleteCharAt(sql.length - 1) 125 | sql.append(") values(") 126 | for (field in fields) { 127 | if (field.name != "serialVersionUID" && !field.name.contains("$")) { 128 | field.isAccessible = true 129 | var value = field.get(any) 130 | if (value != null) { 131 | when (value) { 132 | is String -> { 133 | value = handleEncode(value) 134 | } 135 | is Char -> { 136 | } 137 | is Boolean -> { 138 | value = if (value) 1 else 0 139 | } 140 | is Int -> { 141 | } 142 | is Short -> { 143 | } 144 | is Byte -> { 145 | } 146 | is Long -> { 147 | } 148 | is Float -> { 149 | } 150 | is Double -> { 151 | } 152 | else -> { 153 | value = if (mEncodeMode == EncodeMode.Serializable) { 154 | getStringByObject(value) 155 | } else { 156 | handleEncode(gson.toJson(value)) 157 | } 158 | } 159 | } 160 | sql.append("'").append(value).append("'").append(",") 161 | } 162 | } 163 | } 164 | 165 | sql.deleteCharAt(sql.length - 1) 166 | sql.append(");") 167 | logPrint(sql) 168 | db.execSQL(sql.toString()) 169 | db.close() 170 | } 171 | } 172 | } catch (e: Exception) { 173 | e.printStackTrace() 174 | return false 175 | } 176 | return true 177 | } 178 | 179 | /** 180 | * 增 181 | */ 182 | fun insert(context: Context, sql: String, args: Array?): Boolean { 183 | try { 184 | val db = getDatabase(context) 185 | if (args != null) { 186 | db.execSQL(sql, args) 187 | } else { 188 | db.execSQL(sql) 189 | } 190 | db.close() 191 | } catch (e: Exception) { 192 | e.printStackTrace() 193 | return false 194 | } 195 | return true 196 | } 197 | 198 | /** 199 | * 删 200 | */ 201 | fun delete(context: Context, sql: String, args: Array?): Boolean = insert(context, sql, args) 202 | 203 | /** 204 | * 改 205 | */ 206 | fun update(context: Context, sql: String, args: Array?): Boolean = insert(context, sql, args) 207 | 208 | /** 209 | * 判断是否存在 210 | */ 211 | fun exist(context: Context, sql: String, args: Array?): Boolean? { 212 | val result: Boolean? 213 | try { 214 | val db = getDatabase(context) 215 | val cursor = db.rawQuery(sql, args) 216 | result = cursor.moveToFirst() 217 | cursor.close() 218 | db.close() 219 | } catch (e: Exception) { 220 | e.printStackTrace() 221 | return null 222 | } 223 | return result 224 | } 225 | 226 | /** 227 | * 查询 228 | * 返回第一条数据 229 | */ 230 | fun rawQuerySingle(context: Context, sql: String, args: Array?, clazz: Class): T? { 231 | var t: T? = null 232 | try { 233 | val db = getDatabase(context) 234 | val cursor = db.rawQuery(sql, args) 235 | if (cursor.moveToFirst()) { 236 | t = handleValue(clazz, cursor) 237 | } 238 | cursor.close() 239 | db.close() 240 | } catch (e: Exception) { 241 | e.printStackTrace() 242 | return null 243 | } 244 | return t 245 | } 246 | 247 | /** 248 | * 查询 249 | */ 250 | fun rawQuery(context: Context, sql: String, args: Array?, clazz: Class): List? { 251 | val list = arrayListOf() 252 | try { 253 | val db = getDatabase(context) 254 | val cursor = db.rawQuery(sql, args) 255 | while (cursor.moveToNext()) { 256 | val t = handleValue(clazz, cursor) 257 | if (t != null) { 258 | list.add(t) 259 | } 260 | } 261 | cursor.close() 262 | db.close() 263 | } catch (e: Exception) { 264 | e.printStackTrace() 265 | return null 266 | } 267 | return list 268 | } 269 | 270 | /** 271 | * 查询 272 | * 返回查询的所有数据 273 | */ 274 | fun rawQueryAll(context: Context, clazz: Class): List? { 275 | val list = arrayListOf() 276 | try { 277 | val db = getDatabase(context) 278 | val cursor = db.rawQuery("select * from ${clazz.simpleName}", null) 279 | while (cursor.moveToNext()) { 280 | val t = handleValue(clazz, cursor) 281 | if (t != null) { 282 | list.add(t) 283 | } 284 | } 285 | cursor.close() 286 | db.close() 287 | } catch (e: Exception) { 288 | e.printStackTrace() 289 | return null 290 | } 291 | return list 292 | } 293 | 294 | 295 | fun handleValue(clazz: Class, cursor: Cursor): T? { 296 | try { 297 | val t: T = clazz.newInstance() 298 | val fields = clazz.declaredFields 299 | for (field in fields) { 300 | if (field.name != "serialVersionUID" && !field.name.contains("$")) { 301 | field.isAccessible = true 302 | val value = field.type 303 | when (value) { 304 | String::class.java -> { 305 | field.set(t, handleDecode(cursor.getString(cursor.getColumnIndex(field.name)))) 306 | } 307 | Char::class.java -> { 308 | field.set(t, cursor.getString(cursor.getColumnIndex(field.name))) 309 | } 310 | Boolean::class.java -> { 311 | field.set(t, cursor.getInt(cursor.getColumnIndex(field.name)) == 1) 312 | } 313 | Int::class.java -> { 314 | field.set(t, cursor.getInt(cursor.getColumnIndex(field.name))) 315 | } 316 | Short::class.java -> { 317 | field.set(t, cursor.getShort(cursor.getColumnIndex(field.name))) 318 | } 319 | Byte::class.java -> { 320 | field.set(t, cursor.getInt(cursor.getColumnIndex(field.name))) 321 | } 322 | Long::class.java -> { 323 | field.set(t, cursor.getLong(cursor.getColumnIndex(field.name))) 324 | } 325 | Float::class.java -> { 326 | field.set(t, cursor.getFloat(cursor.getColumnIndex(field.name))) 327 | } 328 | Double::class.java -> { 329 | field.set(t, cursor.getDouble(cursor.getColumnIndex(field.name))) 330 | } 331 | else -> { 332 | val str = cursor.getString(cursor.getColumnIndex(field.name)) 333 | if (str != null) { 334 | if (mEncodeMode == EncodeMode.Serializable) { 335 | field.set(t, getObjectByString(str)) 336 | } else { 337 | field.set(t, gson.fromJson(handleDecode(str), field.type)) 338 | } 339 | } 340 | } 341 | } 342 | } 343 | } 344 | return t 345 | } catch (e: Exception) { 346 | e.printStackTrace() 347 | } 348 | return null 349 | } 350 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/Text.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.text.Editable 4 | import android.widget.EditText 5 | import com.cpf.baseproject.widget.TextChangeListener 6 | 7 | /** 8 | * edittext扩展 9 | */ 10 | fun EditText.addTextChangedListener(block: () -> Unit) { 11 | addTextChangedListener(object : TextChangeListener() { 12 | override fun afterTextChanged(s: Editable?) { 13 | block() 14 | } 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/util/WebView.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.util 2 | 3 | import android.os.Build 4 | import android.support.annotation.RequiresApi 5 | import android.webkit.WebView 6 | 7 | /** 8 | * Created by cpf on 2017/12/16. 9 | * webView扩展 10 | */ 11 | @RequiresApi(Build.VERSION_CODES.KITKAT) 12 | fun WebView.execJS(jsString: String) { 13 | logPrint(jsString) 14 | evaluateJavascript("javascript:" + jsString, null) 15 | } 16 | 17 | @RequiresApi(Build.VERSION_CODES.KITKAT) 18 | fun WebView.execJS(jsString: String, block: (result: String) -> Unit) { 19 | evaluateJavascript("javascript:" + jsString, { 20 | block(it) 21 | }) 22 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/widget/RefreshLayout.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.baseproject.widget 4 | 5 | import android.content.Context 6 | import android.support.v4.widget.SwipeRefreshLayout 7 | import android.util.AttributeSet 8 | import android.view.MotionEvent 9 | import android.view.ViewConfiguration 10 | 11 | /** 12 | * Created by cpf on 2017/12/14. 13 | * 自定义SwipeRefreshLayout控件,解决左右滑动冲突问题 14 | */ 15 | class RefreshLayout : SwipeRefreshLayout { 16 | 17 | private var mStartX = 0f 18 | private var mStartY = 0f 19 | private var mIsDrag = false//是否拖动中 20 | 21 | private var mTouchSlop = 0 22 | 23 | constructor(context: Context?) : super(context, null) 24 | 25 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { 26 | mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop 27 | } 28 | 29 | override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { 30 | 31 | when (ev.action) { 32 | 33 | MotionEvent.ACTION_DOWN -> { 34 | mStartX = ev.x 35 | mStartY = ev.y 36 | mIsDrag = false 37 | } 38 | 39 | MotionEvent.ACTION_MOVE -> { 40 | 41 | // 如果viewpager正在拖拽中,那么不拦截它的事件,直接return false; 42 | if (mIsDrag) { 43 | return false 44 | } 45 | //获取当前手的位置 46 | 47 | val endY = ev.y 48 | val endX = ev.x 49 | val distanceX = Math.abs(endX - mStartX) 50 | val distanceY = Math.abs(endY - mStartY) 51 | if (distanceX > mTouchSlop && distanceX > distanceY) { 52 | mIsDrag = true 53 | return false 54 | } 55 | mIsDrag = false 56 | } 57 | 58 | MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> mIsDrag = false 59 | } 60 | 61 | 62 | return super.onInterceptTouchEvent(ev) 63 | } 64 | } -------------------------------------------------------------------------------- /base/src/main/java/com/cpf/baseproject/widget/TextChangeListener.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.baseproject.widget 2 | 3 | import android.text.Editable 4 | import android.text.TextWatcher 5 | 6 | abstract class TextChangeListener : TextWatcher { 7 | 8 | abstract override fun afterTextChanged(s: Editable?) 9 | 10 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { 11 | } 12 | 13 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /base/src/main/res/anim/slide_center_to_down.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | -------------------------------------------------------------------------------- /base/src/main/res/anim/slide_center_to_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | -------------------------------------------------------------------------------- /base/src/main/res/anim/slide_down_to_center.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | -------------------------------------------------------------------------------- /base/src/main/res/anim/slide_up_to_center.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /base/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #8f000000 5 | 7 | 8 | 9 | #FFEBEE 10 | #FFCDD2 11 | #EF9A9A 12 | #E57373 13 | #EF5350 14 | #F44336 15 | #E53935 16 | #D32F2F 17 | #C62828 18 | #B71C1C 19 | #FF8A80 20 | #FF5252 21 | #FF1744 22 | #D50000 23 | 24 | 25 | #FCE4EC 26 | #F8BBD0 27 | #F48FB1 28 | #F06292 29 | #EC407A 30 | #E91E63 31 | #D81B60 32 | #C2185B 33 | #AD1457 34 | #880E4F 35 | #FF80AB 36 | #FF4081 37 | #F50057 38 | #C51162 39 | 40 | 41 | #F3E5F5 42 | #E1BEE7 43 | #CE93D8 44 | #BA68C8 45 | #AB47BC 46 | #9C27B0 47 | #8E24AA 48 | #7B1FA2 49 | #6A1B9A 50 | #4A148C 51 | #EA80FC 52 | #E040FB 53 | #D500F9 54 | #AA00FF 55 | 56 | 57 | #EDE7F6 58 | #D1C4E9 59 | #B39DDB 60 | #9575CD 61 | #7E57C2 62 | #673AB7 63 | #5E35B1 64 | #512DA8 65 | #4527A0 66 | #311B92 67 | #B388FF 68 | #7C4DFF 69 | #651FFF 70 | #6200EA 71 | 72 | 73 | #E8EAF6 74 | #C5CAE9 75 | #9FA8DA 76 | #7986CB 77 | #5C6BC0 78 | #3F51B5 79 | #3949AB 80 | #303F9F 81 | #283593 82 | #1A237E 83 | #8C9EFF 84 | #536DFE 85 | #3D5AFE 86 | #304FFE 87 | 88 | 89 | #E3F2FD 90 | #BBDEFB 91 | #90CAF9 92 | #64B5F6 93 | #42A5F5 94 | #2196F3 95 | #1E88E5 96 | #1976D2 97 | #1565C0 98 | #0D47A1 99 | #82B1FF 100 | #448AFF 101 | #2979FF 102 | #2962FF 103 | 104 | 105 | #E1F5FE 106 | #B3E5FC 107 | #81D4fA 108 | #4fC3F7 109 | #29B6FC 110 | #03A9F4 111 | #039BE5 112 | #0288D1 113 | #0277BD 114 | #01579B 115 | #80D8FF 116 | #40C4FF 117 | #00B0FF 118 | #0091EA 119 | 120 | 121 | #E0F7FA 122 | #B2EBF2 123 | #80DEEA 124 | #4DD0E1 125 | #26C6DA 126 | #00BCD4 127 | #00ACC1 128 | #0097A7 129 | #00838F 130 | #006064 131 | #84FFFF 132 | #18FFFF 133 | #00E5FF 134 | #00B8D4 135 | 136 | 137 | #E0F2F1 138 | #B2DFDB 139 | #80CBC4 140 | #4DB6AC 141 | #26A69A 142 | #009688 143 | #00897B 144 | #00796B 145 | #00695C 146 | #004D40 147 | #A7FFEB 148 | #64FFDA 149 | #1DE9B6 150 | #00BFA5 151 | 152 | 153 | #E8F5E9 154 | #C8E6C9 155 | #A5D6A7 156 | #81C784 157 | #66BB6A 158 | #4CAF50 159 | #43A047 160 | #388E3C 161 | #2E7D32 162 | #1B5E20 163 | #B9F6CA 164 | #69F0AE 165 | #00E676 166 | #00C853 167 | 168 | 169 | #F1F8E9 170 | #DCEDC8 171 | #C5E1A5 172 | #AED581 173 | #9CCC65 174 | #8BC34A 175 | #7CB342 176 | #689F38 177 | #558B2F 178 | #33691E 179 | #CCFF90 180 | #B2FF59 181 | #76FF03 182 | #64DD17 183 | 184 | 185 | #F9FBE7 186 | #F0F4C3 187 | #E6EE9C 188 | #DCE775 189 | #D4E157 190 | #CDDC39 191 | #C0CA33 192 | #A4B42B 193 | #9E9D24 194 | #827717 195 | #F4FF81 196 | #EEFF41 197 | #C6FF00 198 | #AEEA00 199 | 200 | 201 | #FFFDE7 202 | #FFF9C4 203 | #FFF590 204 | #FFF176 205 | #FFEE58 206 | #FFEB3B 207 | #FDD835 208 | #FBC02D 209 | #F9A825 210 | #F57F17 211 | #FFFF82 212 | #FFFF00 213 | #FFEA00 214 | #FFD600 215 | 216 | 217 | #FFF8E1 218 | #FFECB3 219 | #FFE082 220 | #FFD54F 221 | #FFCA28 222 | #FFC107 223 | #FFB300 224 | #FFA000 225 | #FF8F00 226 | #FF6F00 227 | #FFE57F 228 | #FFD740 229 | #FFC400 230 | #FFAB00 231 | 232 | 233 | #FFF3E0 234 | #FFE0B2 235 | #FFCC80 236 | #FFB74D 237 | #FFA726 238 | #FF9800 239 | #FB8C00 240 | #F57C00 241 | #EF6C00 242 | #E65100 243 | #FFD180 244 | #FFAB40 245 | #FF9100 246 | #FF6D00 247 | 248 | 249 | #FBE9A7 250 | #FFCCBC 251 | #FFAB91 252 | #FF8A65 253 | #FF7043 254 | #FF5722 255 | #F4511E 256 | #E64A19 257 | #D84315 258 | #BF360C 259 | #FF9E80 260 | #FF6E40 261 | #FF3D00 262 | #DD2600 263 | 264 | 265 | #EFEBE9 266 | #D7CCC8 267 | #BCAAA4 268 | #A1887F 269 | #8D6E63 270 | #795548 271 | #6D4C41 272 | #5D4037 273 | #4E342E 274 | #3E2723 275 | 276 | 277 | #FAFAFA 278 | #F5F5F5 279 | #EEEEEE 280 | #E0E0E0 281 | #BDBDBD 282 | #9E9E9E 283 | #757575 284 | #616161 285 | #424242 286 | #212121 287 | #000000 288 | #ffffff 289 | 290 | 291 | #ECEFF1 292 | #CFD8DC 293 | #B0BBC5 294 | #90A4AE 295 | #78909C 296 | #607D8B 297 | #546E7A 298 | #455A64 299 | #37474F 300 | #263238 301 | 302 | -------------------------------------------------------------------------------- /base/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0123456789qwertyuioplkjhgfdsazxcvbnm 4 | 网络连接超时 5 | 数据解析异常 6 | -------------------------------------------------------------------------------- /base/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | ext.kotlin_version = '1.2.20' 6 | ext.android_support_version = '26.1.0' 7 | 8 | repositories { 9 | google() 10 | jcenter() 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.0.1' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | 16 | // NOTE: Do not place your application dependencies here; they belong 17 | // in the individual module build.gradle files 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | google() 24 | jcenter() 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | android.useDeprecatedNdk=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Dec 26 15:22:56 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':base', ':xmrminer' 2 | -------------------------------------------------------------------------------- /xmrminer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /release 3 | -------------------------------------------------------------------------------- /xmrminer/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | android { 5 | compileSdkVersion 26 6 | 7 | defaultConfig { 8 | applicationId "com.cpf.xmrminer" 9 | minSdkVersion 19 10 | targetSdkVersion 26 11 | versionCode 1 12 | versionName "1.0" 13 | externalNativeBuild { 14 | cmake { 15 | cppFlags "-std=c++11 -frtti -fexceptions" 16 | } 17 | } 18 | ndk { 19 | // 设置支持的 SO 库构架 20 | abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64' 21 | } 22 | } 23 | 24 | // sourceSets { 25 | // main { 26 | // jniLibs.srcDirs = ['libs'] 27 | // } 28 | // } 29 | 30 | buildTypes { 31 | release { 32 | minifyEnabled true 33 | shrinkResources true 34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 35 | } 36 | } 37 | externalNativeBuild { 38 | cmake { 39 | path "src/main/jni/CMakeLists.txt" 40 | } 41 | } 42 | } 43 | 44 | dependencies { 45 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 46 | implementation 'com.android.support:appcompat-v7:26.1.0' 47 | implementation project(':base') 48 | } 49 | -------------------------------------------------------------------------------- /xmrminer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------------------- 2 | -renamesourcefileattribute SourceFile 3 | -keepparameternames #【是否保留方法内参数命名】外壳暂时不加,影响开发者理解,但可以减小约1KB 4 | -optimizationpasses 5 #【优化轮数】,外壳不需要加,增加包大小 5 | #-dontusemixedcaseclassnames #【混淆时不会产生形形色色的类名】,不会影响包大小 6 | -dontskipnonpubliclibraryclasses #【指定不去忽略非公共的库类】,不会影响包大小 7 | -dontskipnonpubliclibraryclassmembers 8 | -dontpreverify #【不预校验】,需要打开,减少包大小,android不需预校验 9 | -dontoptimize 10 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* #【优化】,外壳可不加,加上包大小略微变大 11 | #-------------------------------------------基本不用动区域-------------------------------------------- 12 | #---------------------------------基本指令区---------------------------------- 13 | -verbose 14 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod,*Annotation* 15 | #---------------------------------------------------------------------------- 16 | 17 | #---------------------------------默认保留区--------------------------------- 18 | -keep public class * extends android.app.Activity 19 | -keep public class * extends android.app.Application 20 | -keep public class * extends android.app.Service 21 | -keep public class * extends android.content.BroadcastReceiver 22 | -keep public class * extends android.content.ContentProvider 23 | -keep public class * extends android.app.backup.BackupAgentHelper 24 | -keep public class * extends android.preference.Preference 25 | -keep public class * extends android.view.View 26 | -keep public class com.android.vending.licensing.ILicensingService 27 | 28 | -keepclasseswithmembernames class * { 29 | native ; 30 | } 31 | -keepclassmembers class * extends android.app.Activity{ 32 | public void *(android.view.View); 33 | } 34 | -keepclassmembers enum * { 35 | public static **[] values(); 36 | public static ** valueOf(java.lang.String); 37 | } 38 | -keep public class * extends android.view.View{ 39 | *** get*(); 40 | void set*(***); 41 | public (android.content.Context); 42 | public (android.content.Context, android.util.AttributeSet); 43 | public (android.content.Context, android.util.AttributeSet, int); 44 | } 45 | -keepclasseswithmembers class * { 46 | public (android.content.Context, android.util.AttributeSet); 47 | public (android.content.Context, android.util.AttributeSet, int); 48 | } 49 | -keep class * implements android.os.Parcelable { 50 | public static final android.os.Parcelable$Creator *; 51 | } 52 | -keepclassmembers class * implements java.io.Serializable { 53 | static final long serialVersionUID; 54 | private static final java.io.ObjectStreamField[] serialPersistentFields; 55 | private void writeObject(java.io.ObjectOutputStream); 56 | private void readObject(java.io.ObjectInputStream); 57 | java.lang.Object writeReplace(); 58 | java.lang.Object readResolve(); 59 | } 60 | -keep class **.R$* { 61 | *; 62 | } 63 | -keepclassmembers class * { 64 | void *(**On*Event); 65 | } 66 | 67 | #---------------------------------------------------------------------------- 68 | 69 | #---------------------------------webview------------------------------------ 70 | -keepclassmembers class fqcn.of.javascript.interface.for.Webview { 71 | public *; 72 | } 73 | -keepclassmembers class * extends android.webkit.WebViewClient { 74 | public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); 75 | public boolean *(android.webkit.WebView, java.lang.String); 76 | } 77 | -keepclassmembers class * extends android.webkit.WebViewClient { 78 | public void *(android.webkit.WebView, jav.lang.String); 79 | } 80 | #---------------------------------------------------------------------------- 81 | #--------------------------------------------------------------------------------------------------- 82 | #自定义组件不被混淆 83 | -keep public class * extends android.view.View { 84 | public (android.content.Context); 85 | public (android.content.Context, android.util.AttributeSet); 86 | public (android.content.Context, android.util.AttributeSet, int); 87 | public void set*(...); 88 | } 89 | #保持注解继承类不混淆 90 | -keep class * extends java.lang.annotation.Annotation {*;} 91 | #-------------------------------------------定制化区域---------------------------------------------- 92 | 93 | -dontwarn kotlin.** 94 | -dontwarn android.** 95 | -dontwarn org.** 96 | -dontwarn com.github.** 97 | -dontwarn com.google.** 98 | -keep class kotlin.**{*;} 99 | -keep class android.**{*;} 100 | -keep class org.**{*;} 101 | -keep class com.github.**{*;} 102 | -keep class com.google.**{*;} 103 | 104 | #---------------------------------1.实体类--------------------------------- 105 | 106 | -dontwarn com.cpf.cryptonight.** 107 | -keep class com.cpf.cryptonight.**{*;} 108 | 109 | #------------------------------------------------------------------------- 110 | 111 | #---------------------------------2.第三方包------------------------------- 112 | 113 | -keep class com.alibaba.**{*;} 114 | -dontwarn com.alibaba.** 115 | 116 | #------------------------------------------------------------------------- 117 | 118 | #---------------------------------3.与js互相调用的类------------------------ 119 | 120 | 121 | 122 | #------------------------------------------------------------------------- 123 | 124 | #---------------------------------4.反射相关的类和方法----------------------- -------------------------------------------------------------------------------- /xmrminer/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/cryptonight/Miner.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.cryptonight 2 | 3 | /** 4 | * Created by cpf on 2017/12/28. 5 | * Miner 6 | */ 7 | object Miner { 8 | 9 | init { 10 | System.loadLibrary("CryptoNight") 11 | } 12 | 13 | external fun fastHash(input: ByteArray, output: ByteArray) 14 | 15 | } -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/HexUtil.java: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer; 2 | 3 | /** 4 | * Created by cpf on 2018/1/17. 5 | */ 6 | 7 | public class HexUtil { 8 | 9 | private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); 10 | 11 | public static int fromHexChar(char paramChar) { 12 | if ((paramChar >= '0') && (paramChar <= '9')) { 13 | paramChar -= 48; 14 | } 15 | if ((paramChar >= 'A') && (paramChar <= 'F')) { 16 | paramChar = (char) (paramChar - 'A' + 10); 17 | } else { 18 | paramChar = (char) (paramChar - 'a' + 10); 19 | } 20 | return paramChar; 21 | } 22 | 23 | public static byte[] fromHexString(String paramString) { 24 | if ((paramString.length() & 0x1) != 0) { 25 | throw new RuntimeException("Invalid hex string"); 26 | } 27 | byte[] arrayOfByte = new byte[paramString.length() / 2]; 28 | for (int i = 0; i < paramString.length() / 2; i++) { 29 | arrayOfByte[i] = ((byte) (fromHexChar(paramString.charAt(i * 2)) << 4 | fromHexChar(paramString.charAt(i * 2 + 1)))); 30 | } 31 | return arrayOfByte; 32 | } 33 | 34 | public static String toHexString(byte[] paramArrayOfByte) { 35 | char[] arrayOfChar = new char[paramArrayOfByte.length * 2]; 36 | for (int i = 0; i < paramArrayOfByte.length; i++) { 37 | int j = paramArrayOfByte[i] & 0xFF; 38 | arrayOfChar[(i * 2)] = hexArray[(j >>> 4)]; 39 | arrayOfChar[(i * 2 + 1)] = hexArray[(j & 0xF)]; 40 | } 41 | return new String(arrayOfChar); 42 | } 43 | 44 | /** 45 | * Transform a byte array into a it's hexadecimal representation 46 | */ 47 | public static String hexlify(byte[] bytes) { 48 | char[] hexChars = new char[bytes.length * 2]; 49 | for (int j = 0; j < bytes.length; j++) { 50 | int v = bytes[j] & 0xFF; 51 | hexChars[j * 2] = hexArray[v >>> 4]; 52 | hexChars[j * 2 + 1] = hexArray[v & 0x0F]; 53 | } 54 | String ret = new String(hexChars); 55 | return ret; 56 | } 57 | 58 | /** 59 | * Transform a string of hexadecimal chars into a byte array 60 | */ 61 | public static byte[] unhexlify(String argbuf) { 62 | int arglen = argbuf.length(); 63 | if (arglen % 2 != 0) 64 | throw new RuntimeException("Odd-length string"); 65 | 66 | byte[] retbuf = new byte[arglen / 2]; 67 | 68 | for (int i = 0; i < arglen; i += 2) { 69 | int top = Character.digit(argbuf.charAt(i), 16); 70 | int bot = Character.digit(argbuf.charAt(i + 1), 16); 71 | if (top == -1 || bot == -1) 72 | throw new RuntimeException("Non-hexadecimal digit found"); 73 | retbuf[i / 2] = (byte) ((top << 4) + bot); 74 | } 75 | return retbuf; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/Job.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | import com.cpf.baseproject.util.logPrint 4 | import com.cpf.cryptonight.Miner 5 | import org.json.JSONObject 6 | 7 | /** 8 | * Created by cpf on 2017/12/28. 9 | * Job 10 | */ 11 | class Job(private val miner: MinerManager, 12 | private val start: Int, 13 | private val space: Int, 14 | private val jobBean: JobBean) : Runnable { 15 | 16 | override fun run() { 17 | val blobByte = HexUtil.unhexlify(jobBean.blob) 18 | var nonce = start 19 | val nonceByte = ByteArray(4) 20 | val result = ByteArray(32) 21 | while (nonce < 0x7fffffff) { 22 | if (!miner.isRunning) return 23 | if (miner.mJobID != jobBean.jobId) return 24 | blobByte[39] = nonce.toByte() 25 | blobByte[40] = (nonce shr 8).toByte() 26 | blobByte[41] = (nonce shr 16).toByte() 27 | blobByte[42] = (nonce shr 24).toByte() 28 | Miner.fastHash(blobByte, result) 29 | val resultStr = HexUtil.hexlify(result) 30 | val rs = resultStr.substring(resultStr.length - jobBean.target.length) 31 | var byteArray = HexUtil.unhexlify(rs) 32 | byteArray = miner.byteArraySort(byteArray) 33 | val str = HexUtil.hexlify(byteArray) 34 | val tarL = str.toLong(16) 35 | if (tarL < jobBean.target.toLong(16)) { 36 | logPrint("submit____id${miner.mId}___thread${start}_____${jobBean.target}_____${str}_____$resultStr") 37 | nonceByte[0] = nonce.toByte() 38 | nonceByte[1] = (nonce shr 8).toByte() 39 | nonceByte[2] = (nonce shr 16).toByte() 40 | nonceByte[3] = (nonce shr 24).toByte() 41 | send(HexUtil.hexlify(nonceByte), resultStr) 42 | } 43 | nonce += space 44 | miner.mHashCount++ 45 | if (miner.mSpeed < 1f) { 46 | try { 47 | Thread.sleep((miner.mSleepTime * (1 - miner.mSpeed)).toLong()) 48 | } catch (e: Exception) { 49 | } 50 | } 51 | } 52 | } 53 | 54 | private fun send(nonceHex: String, tar: String) { 55 | val jsonObj = JSONObject() 56 | jsonObj.put("id", miner.mId++) 57 | jsonObj.put("method", "submit") 58 | jsonObj.put("jsonrpc", "2.0") 59 | val json = JSONObject() 60 | json.put("id", jobBean.id) 61 | json.put("job_id", jobBean.jobId) 62 | json.put("nonce", nonceHex) 63 | json.put("result", tar) 64 | jsonObj.put("params", json) 65 | miner.mPrintWrite?.println(jsonObj.toString()) 66 | miner.mPrintWrite?.flush() 67 | } 68 | 69 | class JobBean { 70 | var blob: String = "" 71 | var target: String = "" 72 | var jobId: String = "" 73 | var id: String = "" 74 | } 75 | } -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/JobTest.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.cpf.xmrminer 4 | 5 | import com.cpf.baseproject.util.logPrint 6 | import com.cpf.cryptonight.Miner 7 | 8 | /** 9 | * Created by cpf on 2017/12/28. 10 | * Job 11 | */ 12 | class JobTest(private val miner: MinerManager, 13 | private val start: Int, 14 | private val jobBean: Job.JobBean, 15 | private val block: () -> Unit) : Runnable { 16 | 17 | override fun run() { 18 | val startTime = System.currentTimeMillis() 19 | val blobByte = HexUtil.unhexlify(jobBean.blob) 20 | val nonce = start 21 | ByteArray(4) 22 | val result = ByteArray(32) 23 | blobByte[39] = nonce.toByte() 24 | blobByte[40] = (nonce shr 8).toByte() 25 | blobByte[41] = (nonce shr 16).toByte() 26 | blobByte[42] = (nonce shr 24).toByte() 27 | Miner.fastHash(blobByte, result) 28 | val resultStr = HexUtil.hexlify(result) 29 | val rs = resultStr.substring(resultStr.length - jobBean.target.length) 30 | var byteArray = HexUtil.unhexlify(rs) 31 | byteArray = miner.byteArraySort(byteArray) 32 | val str = HexUtil.hexlify(byteArray) 33 | str.toLong(16) 34 | miner.mSleepTime = System.currentTimeMillis() - startTime 35 | logPrint("Execution algorithm time-consuming ${miner.mSleepTime}") 36 | block() 37 | } 38 | } -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | import android.text.method.ScrollingMovementMethod 4 | import com.cpf.baseproject.base.BaseActivity 5 | import com.cpf.baseproject.util.addTextChangedListener 6 | import com.cpf.baseproject.util.setOnSeekBarChangeListener 7 | import com.cpf.baseproject.util.ui 8 | import kotlinx.android.synthetic.main.activity_main.* 9 | import java.io.File 10 | import java.io.FileFilter 11 | import java.util.* 12 | import java.util.regex.Pattern 13 | 14 | 15 | /** 16 | * Created by cpf on 2017/12/28. 17 | */ 18 | class MainActivity : BaseActivity() { 19 | 20 | private var miner = MinerManager() 21 | private var maxThread = 1 22 | private var timer: Timer? = null 23 | 24 | override fun canSwipeBack(): Boolean = false 25 | 26 | override fun initActionBarLayout(): Int = 0 27 | 28 | override fun initLayout(): Int = R.layout.activity_main 29 | 30 | override fun initView() { 31 | 32 | } 33 | 34 | override fun initEvent() { 35 | miner.setMinerEventListener(object : MinerEventListener { 36 | override fun start() { 37 | ui { 38 | run.text = stopStr 39 | url.isEnabled = false 40 | user.isEnabled = false 41 | pwd.isEnabled = false 42 | startTimer() 43 | } 44 | } 45 | 46 | override fun stop() { 47 | ui { 48 | run.text = runStr 49 | url.isEnabled = true 50 | user.isEnabled = true 51 | pwd.isEnabled = true 52 | stopTimer() 53 | } 54 | } 55 | 56 | override fun error() { 57 | 58 | } 59 | 60 | }) 61 | content.movementMethod = ScrollingMovementMethod.getInstance() 62 | miner.setMinerMsgListener(object : MinerMsgListener { 63 | override fun message(msg: String) { 64 | ui { 65 | refreshLogView(msg + "\n") 66 | } 67 | } 68 | }) 69 | 70 | run.setOnClickListener { 71 | changeStatus() 72 | } 73 | speedSeekBar.setOnSeekBarChangeListener({ 74 | speedText.text = ((it + 1) * 10).toString().plus("%") 75 | }, { 76 | miner.mSpeed = (it + 1) / 10f 77 | }) 78 | threadSeekBar.setOnSeekBarChangeListener({ 79 | threadText.text = (it + 1).toString() 80 | }, { 81 | miner.mThreadNum = it + 1 82 | }) 83 | url.addTextChangedListener { 84 | if (!url.text.isNullOrEmpty()) { 85 | urlLayout.isErrorEnabled = false 86 | } 87 | } 88 | user.addTextChangedListener { 89 | if (!user.text.isNullOrEmpty()) { 90 | userLayout.isErrorEnabled = false 91 | } 92 | } 93 | pwd.addTextChangedListener { 94 | if (!pwd.text.isNullOrEmpty()) { 95 | pwdLayout.isErrorEnabled = false 96 | } 97 | } 98 | } 99 | 100 | fun refreshLogView(msg: String) { 101 | content.append(msg) 102 | val offset = content.lineCount * content.lineHeight 103 | if (offset > content.height) { 104 | content.scrollTo(0, offset - content.height) 105 | } 106 | } 107 | 108 | private var runStr: String? = null 109 | private var stopStr: String? = null 110 | 111 | private fun changeStatus() { 112 | if (runStr == null) { 113 | runStr = getString(R.string.run) 114 | } 115 | if (stopStr == null) { 116 | stopStr = getString(R.string.stop) 117 | } 118 | if (url.text.isNullOrEmpty()) { 119 | urlLayout.error = getString(R.string.url_tip) 120 | return 121 | } 122 | if (user.text.isNullOrEmpty()) { 123 | userLayout.error = getString(R.string.user_tip) 124 | return 125 | } 126 | if (pwd.text.isNullOrEmpty()) { 127 | pwdLayout.error = getString(R.string.pwd_tip) 128 | return 129 | } 130 | if (run.text == runStr) { 131 | miner.mThreadNum = threadText.text.toString().toInt() 132 | miner.mSpeed = (speedSeekBar.progress + 1) / 10f 133 | miner.startMiner(url.text.toString(), user.text.toString(), pwd.text.toString()) 134 | } else { 135 | miner.stopMiner() 136 | } 137 | } 138 | 139 | private fun startTimer() { 140 | if (timer != null) { 141 | timer!!.cancel() 142 | timer = null 143 | } 144 | timer = Timer() 145 | timer!!.scheduleAtFixedRate(object : TimerTask() { 146 | var tempHash = 0L 147 | override fun run() { 148 | ui { 149 | hash.text = formatHash((miner.mHashCount - tempHash) / 3) 150 | total.text = formatHash(miner.mHashCount) 151 | accepted.text = miner.mShareCount.toString() 152 | tempHash = miner.mHashCount 153 | } 154 | } 155 | 156 | }, 1000, 3000) 157 | } 158 | 159 | private fun formatHash(count: Long): String { 160 | return when { 161 | count < 1000f -> { 162 | count.toString() 163 | } 164 | count >= 1000f -> { 165 | (count / 1000f).toString() + "K" 166 | } 167 | count >= 1000f * 1000f -> { 168 | (count / 1000f * 1000f).toString() + "M" 169 | } 170 | count >= 1000f * 1000f * 1000f -> { 171 | (count / 1000f * 1000f * 1000f).toString() + "G" 172 | } 173 | else -> { 174 | (count / 1000f * 1000f * 1000f).toString() + "G" 175 | } 176 | } 177 | } 178 | 179 | override fun onDestroy() { 180 | super.onDestroy() 181 | miner.stopMiner() 182 | } 183 | 184 | private fun stopTimer() { 185 | timer?.cancel() 186 | timer = null 187 | } 188 | 189 | override fun initData() { 190 | maxThread = getNumCores() 191 | threadSeekBar.max = maxThread - 1 192 | threadSeekBar.progress = maxThread - 1 193 | threadText.text = maxThread.toString() 194 | } 195 | 196 | private fun getNumCores(): Int { 197 | class CpuFilter : FileFilter { 198 | override fun accept(pathname: File): Boolean = Pattern.matches(getString(R.string.cpu_match), pathname.name) 199 | } 200 | return try { 201 | val dir = File("/sys/devices/system/cpu/") 202 | val files = dir.listFiles(CpuFilter()) 203 | files.size 204 | } catch (e: Exception) { 205 | 1 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/MinerEventListener.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | /** 4 | * Created by cpf on 2018/1/9. 5 | * miner listener 6 | */ 7 | interface MinerEventListener { 8 | 9 | fun start() 10 | 11 | fun stop() 12 | 13 | fun error() 14 | 15 | } -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/MinerManager.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | import com.cpf.baseproject.util.async 4 | import com.cpf.baseproject.util.logPrint 5 | import org.json.JSONObject 6 | import java.io.PrintWriter 7 | import java.net.Socket 8 | import java.util.* 9 | import java.util.concurrent.ExecutorService 10 | import java.util.concurrent.Executors 11 | 12 | /** 13 | * Created by cpf on 2017/12/28. 14 | * MinerManager 15 | */ 16 | class MinerManager { 17 | 18 | var mId = 0 19 | private var mSocket: Socket? = null 20 | var mPrintWrite: PrintWriter? = null 21 | private var mScanner: Scanner? = null 22 | private var mEvent: MinerEventListener? = null 23 | private var mMsg: MinerMsgListener? = null 24 | var isRunning = false 25 | private var mThreadPool: ExecutorService? = null 26 | private var mUrl: String = "" 27 | private var mUser: String = "" 28 | private var mPWD: String = "x" 29 | var mThreadNum = 1 30 | var mSpeed = 0.9f 31 | var mShareCount = 0L 32 | var mHashCount = 0L 33 | private var mSubID = "" 34 | var mJobID = "" 35 | var mSleepTime = 0L 36 | 37 | fun byteArraySort(byteArray: ByteArray): ByteArray { 38 | val temp = ByteArray(byteArray.size) 39 | for (i in 0 until byteArray.size) { 40 | temp[i] = byteArray[byteArray.size - 1 - i] 41 | } 42 | return temp 43 | } 44 | 45 | private fun connect() { 46 | try { 47 | mMsg?.message("connect...") 48 | val strArray = mUrl.split(":") 49 | logPrint(strArray[0] + ":" + strArray[1]) 50 | mSocket = Socket(strArray[0], strArray[1].toInt()) 51 | mPrintWrite = PrintWriter(mSocket?.getOutputStream()) 52 | mScanner = Scanner(mSocket?.getInputStream()) 53 | val jsonObj = JSONObject() 54 | jsonObj.put("login", mUser) 55 | jsonObj.put("pass", mPWD) 56 | val json = JSONObject() 57 | json.put("id", mId++) 58 | json.put("method", "login") 59 | json.put("params", jsonObj) 60 | mPrintWrite?.println(json.toString()) 61 | mPrintWrite?.flush() 62 | mMsg?.message("Pool connection is successful") 63 | } catch (e: Exception) { 64 | e.printStackTrace() 65 | mEvent?.error() 66 | mMsg?.message("connection is failure") 67 | } 68 | if (mSocket != null && mSocket!!.isConnected) { 69 | start() 70 | } 71 | } 72 | 73 | private fun handleJob(jobBean: Job.JobBean) { 74 | synchronized(MinerManager::class) { 75 | if (mSleepTime == 0L) { 76 | logPrint("Hash algorithm error") 77 | stopMiner() 78 | } 79 | mMsg?.message("Received job") 80 | var difficulty = 0 81 | try { 82 | val byteArray = HexUtil.unhexlify(jobBean.target) 83 | val sortArray = byteArraySort(byteArray) 84 | val str = HexUtil.hexlify(sortArray) 85 | val targetL = str.toLong(16) 86 | jobBean.target = str 87 | difficulty = (Int.MAX_VALUE / targetL).toInt() 88 | } catch (e: Exception) { 89 | e.printStackTrace() 90 | mMsg?.message("Difficulty calculation error") 91 | } 92 | if (difficulty > 0) { 93 | mMsg?.message("The current difficulty is $difficulty") 94 | for (i in 0 until mThreadNum) { 95 | mThreadPool?.execute(Job(this, i, mThreadNum, jobBean)) 96 | } 97 | } 98 | } 99 | } 100 | 101 | private fun start() { 102 | mEvent?.start() 103 | mMsg?.message("Thread:$mThreadNum") 104 | mMsg?.message("Speed:${mSpeed * 100}%") 105 | isRunning = true 106 | mThreadPool = Executors.newFixedThreadPool(mThreadNum) 107 | while (isRunning && mSocket!!.isConnected) { 108 | if (mScanner == null) return 109 | var result: String? = null 110 | try { 111 | result = mScanner!!.nextLine() 112 | logPrint(result) 113 | } catch (e: Exception) { 114 | 115 | } 116 | if (!isRunning || result == null) return 117 | var json: JSONObject? = null 118 | try { 119 | json = JSONObject(result) 120 | } catch (e: Exception) { 121 | e.printStackTrace() 122 | mEvent?.error() 123 | mMsg?.message("Json parsing error") 124 | } 125 | if (json != null) { 126 | when { 127 | json.has("method") -> { 128 | when { 129 | json.getString("method") == "job" -> { 130 | //job 131 | val params = json.getJSONObject("params") 132 | val jobBean = Job.JobBean() 133 | jobBean.jobId = params.getString("job_id") 134 | jobBean.blob = params.getString("blob") 135 | jobBean.target = params.getString("target") 136 | mJobID = jobBean.jobId 137 | jobBean.id = mSubID 138 | handleJob(jobBean) 139 | } 140 | } 141 | } 142 | json.has("result") && !json.isNull("result") && json.isNull("error") -> { 143 | val resultObject = json.getJSONObject("result") 144 | when { 145 | resultObject.has("job") -> { 146 | //job 147 | val job = resultObject.getJSONObject("job") 148 | val jobBean = Job.JobBean() 149 | jobBean.jobId = job.getString("job_id") 150 | jobBean.blob = job.getString("blob") 151 | jobBean.target = job.getString("target") 152 | jobBean.id = resultObject.getString("id") 153 | mSubID = jobBean.id 154 | mJobID = jobBean.jobId 155 | if (mSleepTime == 0L) { 156 | async { 157 | try { 158 | val byteArray = HexUtil.unhexlify(jobBean.target) 159 | val sortArray = byteArraySort(byteArray) 160 | val str = HexUtil.hexlify(sortArray) 161 | val jobBeanTest = Job.JobBean() 162 | jobBeanTest.jobId = jobBean.jobId 163 | jobBeanTest.target = str 164 | jobBeanTest.blob = jobBean.blob 165 | jobBeanTest.id = jobBean.id 166 | JobTest(this, 0, jobBeanTest, { 167 | handleJob(jobBean) 168 | }).run() 169 | } catch (e: Exception) { 170 | e.printStackTrace() 171 | mSleepTime = 0 172 | } 173 | } 174 | } 175 | } 176 | resultObject.has("status") -> { 177 | if (resultObject.getString("status") == "OK") { 178 | mShareCount++ 179 | } 180 | } 181 | } 182 | } 183 | json.has("error") -> { 184 | val error = json.getJSONObject("error") 185 | logPrint(error.toString()) 186 | when { 187 | error.getString("message").contains("Incorrect") -> { 188 | mMsg?.message("Submit error") 189 | } 190 | error.getString("message").contains("Invalid") -> { 191 | mMsg?.message("Submit is invalid") 192 | } 193 | } 194 | } 195 | else -> { 196 | mMsg?.message("Unknown json") 197 | logPrint(result) 198 | } 199 | } 200 | } 201 | } 202 | if (isRunning) { 203 | mMsg?.message("Abnormal network, try to reconnect") 204 | connect() 205 | } else { 206 | mEvent?.stop() 207 | } 208 | } 209 | 210 | fun startMiner(url: String, user: String, pwd: String) { 211 | if (!url.contains(":")) { 212 | mMsg?.message("url is invalid") 213 | return 214 | } 215 | mUrl = url 216 | mUser = user 217 | mPWD = pwd 218 | async { 219 | connect() 220 | } 221 | } 222 | 223 | fun stopMiner() { 224 | mEvent?.stop() 225 | mMsg?.message("Mining stop") 226 | isRunning = false 227 | try { 228 | mThreadPool?.shutdownNow() 229 | } catch (e: Exception) { 230 | } 231 | mThreadPool = null 232 | mPrintWrite?.close() 233 | mScanner?.close() 234 | mSocket?.close() 235 | mPrintWrite = null 236 | mScanner = null 237 | mSocket = null 238 | } 239 | 240 | 241 | fun setMinerEventListener(event: MinerEventListener) { 242 | this.mEvent = event 243 | } 244 | 245 | fun setMinerMsgListener(msg: MinerMsgListener) { 246 | this.mMsg = msg 247 | } 248 | 249 | } 250 | -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/MinerMsgListener.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | /** 4 | * Created by cpf on 2018/1/15. 5 | */ 6 | interface MinerMsgListener { 7 | fun message(msg: String) 8 | } -------------------------------------------------------------------------------- /xmrminer/src/main/java/com/cpf/xmrminer/MinerService.kt: -------------------------------------------------------------------------------- 1 | package com.cpf.xmrminer 2 | 3 | import android.app.Service 4 | import android.content.Intent 5 | import android.os.Binder 6 | import android.os.IBinder 7 | 8 | class MinerService : Service() { 9 | 10 | override fun onBind(intent: Intent): IBinder? { 11 | return MinerBinder() 12 | } 13 | 14 | inner class MinerBinder : Binder() { 15 | fun getService(): MinerService { 16 | return this@MinerService 17 | } 18 | } 19 | 20 | fun startMiner(){ 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project (CryptoNight) 3 | 4 | include_directories( 5 | crypto/ 6 | ) 7 | 8 | set (HEADER_FILES 9 | crypto/c_blake256.h 10 | crypto/c_groestl.h 11 | crypto/c_jh.h 12 | crypto/c_keccak.h 13 | crypto/c_skein.h 14 | crypto/hash.h 15 | crypto/oaes_lib.h 16 | 17 | crypto/groestl_tables.h 18 | crypto/hash-ops.h 19 | crypto/int-util.h 20 | crypto/oaes_config.h 21 | crypto/skein_port.h 22 | crypto/sph_types.h 23 | 24 | compat/compat.h 25 | ) 26 | 27 | set (SOURCE_FILES 28 | cryptonight.c 29 | cryptonight_jni.c 30 | crypto/aesb.c 31 | crypto/c_blake256.c 32 | crypto/c_groestl.c 33 | crypto/c_jh.c 34 | crypto/c_keccak.c 35 | crypto/c_skein.c 36 | crypto/hash.c 37 | crypto/oaes_lib.c 38 | ) 39 | 40 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 41 | 42 | add_library(CryptoNight SHARED 43 | ${HEADER_FILES} 44 | ${SOURCE_FILES}) -------------------------------------------------------------------------------- /xmrminer/src/main/jni/compat/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | #include 8 | 9 | #ifndef localtime_r 10 | #define localtime_r(src, dst) localtime_s(dst, src) 11 | #endif 12 | 13 | #define sleep(secs) Sleep((secs) * 1000) 14 | 15 | enum { 16 | PRIO_PROCESS = 0, 17 | }; 18 | 19 | extern int opt_priority; 20 | static __inline int setpriority(int which, int who, int prio) 21 | { 22 | switch (opt_priority) { 23 | case 5: 24 | prio = THREAD_PRIORITY_TIME_CRITICAL; 25 | break; 26 | case 4: 27 | prio = THREAD_PRIORITY_HIGHEST; 28 | break; 29 | case 3: 30 | prio = THREAD_PRIORITY_ABOVE_NORMAL; 31 | break; 32 | case 2: 33 | prio = THREAD_PRIORITY_NORMAL; 34 | break; 35 | case 1: 36 | prio = THREAD_PRIORITY_BELOW_NORMAL; 37 | break; 38 | case 0: 39 | default: 40 | prio = THREAD_PRIORITY_IDLE; 41 | } 42 | return -!SetThreadPriority(GetCurrentThread(), prio); 43 | } 44 | 45 | #ifdef _MSC_VER 46 | //#define snprintf(...) _snprintf(__VA_ARGS__) 47 | #define strdup(...) _strdup(__VA_ARGS__) 48 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) 49 | #define strcasecmp(x,y) _stricmp(x,y) 50 | #define __func__ __FUNCTION__ 51 | #define __thread __declspec(thread) 52 | #define _ALIGN(x) __declspec(align(x)) 53 | typedef int ssize_t; 54 | 55 | __inline int msver(void) { 56 | switch (_MSC_VER) { 57 | case 1500: return 2008; 58 | case 1600: return 2010; 59 | case 1700: return 2012; 60 | case 1800: return 2013; 61 | case 1900: return 2015; 62 | default: return (_MSC_VER/100); 63 | } 64 | } 65 | 66 | #include 67 | // This static var is made to be compatible with linux/mingw (no free on string result) 68 | // This is not thread safe but we only use that once on process start 69 | static char dirname_buffer[_MAX_PATH] = { 0 }; 70 | static __inline char * dirname(char *file) { 71 | char drive[_MAX_DRIVE] = { 0 }; 72 | char dir[_MAX_DIR] = { 0 }; 73 | char fname[_MAX_FNAME], ext[_MAX_EXT]; 74 | _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); 75 | if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') { 76 | dir[strlen(dir) - 1] = '\0'; 77 | } 78 | sprintf(dirname_buffer, "%s%s", drive, dir); 79 | return &dirname_buffer[0]; 80 | } 81 | #endif 82 | 83 | #endif /* WIN32 */ 84 | 85 | #ifndef _MSC_VER 86 | #define _ALIGN(x) __attribute__ ((aligned(x))) 87 | #endif 88 | 89 | #undef unlikely 90 | #undef likely 91 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 92 | #define unlikely(expr) (__builtin_expect(!!(expr), 0)) 93 | #define likely(expr) (__builtin_expect(!!(expr), 1)) 94 | #else 95 | #define unlikely(expr) (expr) 96 | #define likely(expr) (expr) 97 | #endif 98 | 99 | #ifndef WIN32 100 | #define MAX_PATH PATH_MAX 101 | #endif 102 | 103 | #endif /* __COMPAT_H__ */ 104 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/aesb.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #include 22 | 23 | #if defined(__cplusplus) 24 | extern "C" 25 | { 26 | #endif 27 | 28 | #define TABLE_ALIGN 32 29 | #define WPOLY 0x011b 30 | #define N_COLS 4 31 | #define AES_BLOCK_SIZE 16 32 | #define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2)) 33 | 34 | #if defined(_MSC_VER) 35 | #define ALIGN __declspec(align(TABLE_ALIGN)) 36 | #elif defined(__GNUC__) 37 | #define ALIGN __attribute__ ((aligned(16))) 38 | #else 39 | #define ALIGN 40 | #endif 41 | 42 | #define rf1(r,c) (r) 43 | #define word_in(x,c) (*((uint32_t*)(x)+(c))) 44 | #define word_out(x,c,v) (*((uint32_t*)(x)+(c)) = (v)) 45 | 46 | #define s(x,c) x[c] 47 | #define si(y,x,c) (s(y,c) = word_in(x, c)) 48 | #define so(y,x,c) word_out(y, c, s(x,c)) 49 | #define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3) 50 | #define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) 51 | #define round(y,x,k) \ 52 | y[0] = (k)[0] ^ (t_fn[0][x[0] & 0xff] ^ t_fn[1][(x[1] >> 8) & 0xff] ^ t_fn[2][(x[2] >> 16) & 0xff] ^ t_fn[3][x[3] >> 24]); \ 53 | y[1] = (k)[1] ^ (t_fn[0][x[1] & 0xff] ^ t_fn[1][(x[2] >> 8) & 0xff] ^ t_fn[2][(x[3] >> 16) & 0xff] ^ t_fn[3][x[0] >> 24]); \ 54 | y[2] = (k)[2] ^ (t_fn[0][x[2] & 0xff] ^ t_fn[1][(x[3] >> 8) & 0xff] ^ t_fn[2][(x[0] >> 16) & 0xff] ^ t_fn[3][x[1] >> 24]); \ 55 | y[3] = (k)[3] ^ (t_fn[0][x[3] & 0xff] ^ t_fn[1][(x[0] >> 8) & 0xff] ^ t_fn[2][(x[1] >> 16) & 0xff] ^ t_fn[3][x[2] >> 24]); 56 | #define to_byte(x) ((x) & 0xff) 57 | #define bval(x,n) to_byte((x) >> (8 * (n))) 58 | 59 | #define fwd_var(x,r,c)\ 60 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 61 | : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ 62 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 63 | : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) 64 | 65 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c)) 66 | 67 | #define sb_data(w) {\ 68 | w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ 69 | w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ 70 | w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ 71 | w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ 72 | w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ 73 | w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ 74 | w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ 75 | w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ 76 | w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ 77 | w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ 78 | w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ 79 | w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ 80 | w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ 81 | w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ 82 | w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ 83 | w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ 84 | w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ 85 | w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ 86 | w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ 87 | w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ 88 | w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ 89 | w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ 90 | w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ 91 | w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ 92 | w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ 93 | w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ 94 | w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ 95 | w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ 96 | w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ 97 | w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ 98 | w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ 99 | w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } 100 | 101 | #define rc_data(w) {\ 102 | w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\ 103 | w(0x1b), w(0x36) } 104 | 105 | #define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \ 106 | ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0)) 107 | 108 | #define h0(x) (x) 109 | #define w0(p) bytes2word(p, 0, 0, 0) 110 | #define w1(p) bytes2word(0, p, 0, 0) 111 | #define w2(p) bytes2word(0, 0, p, 0) 112 | #define w3(p) bytes2word(0, 0, 0, p) 113 | 114 | #define u0(p) bytes2word(f2(p), p, p, f3(p)) 115 | #define u1(p) bytes2word(f3(p), f2(p), p, p) 116 | #define u2(p) bytes2word(p, f3(p), f2(p), p) 117 | #define u3(p) bytes2word(p, p, f3(p), f2(p)) 118 | 119 | #define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) 120 | #define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) 121 | #define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) 122 | #define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) 123 | 124 | #define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) 125 | #define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) 126 | #define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY)) 127 | #define f3(x) (f2(x) ^ x) 128 | #define f9(x) (f8(x) ^ x) 129 | #define fb(x) (f8(x) ^ f2(x) ^ x) 130 | #define fd(x) (f8(x) ^ f4(x) ^ x) 131 | #define fe(x) (f8(x) ^ f4(x) ^ f2(x)) 132 | 133 | #define t_dec(m,n) t_##m##n 134 | #define t_set(m,n) t_##m##n 135 | #define t_use(m,n) t_##m##n 136 | 137 | #define d_4(t,n,b,e,f,g,h) ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) } 138 | 139 | #define four_tables(x,tab,vf,rf,c) \ 140 | (tab[0][bval(vf(x,0,c),rf(0,c))] \ 141 | ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ 142 | ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ 143 | ^ tab[3][bval(vf(x,3,c),rf(3,c))]) 144 | 145 | d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3); 146 | 147 | void aesb_single_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey) 148 | { 149 | round(((uint32_t*) out), ((uint32_t*) in), ((uint32_t*) expandedKey)); 150 | } 151 | 152 | void aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey) 153 | { 154 | uint32_t b1[4]; 155 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey)); 156 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 1 * N_COLS); 157 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 2 * N_COLS); 158 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 3 * N_COLS); 159 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 4 * N_COLS); 160 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 5 * N_COLS); 161 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 6 * N_COLS); 162 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 7 * N_COLS); 163 | round(b1, ((uint32_t*) val), ((const uint32_t *) expandedKey) + 8 * N_COLS); 164 | round(((uint32_t*) val), b1, ((const uint32_t *) expandedKey) + 9 * N_COLS); 165 | } 166 | 167 | 168 | #if defined(__cplusplus) 169 | } 170 | #endif 171 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_blake256.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The blake256_* and blake224_* functions are largely copied from 3 | * blake256_light.c and blake224_light.c from the BLAKE website: 4 | * 5 | * http://131002.net/blake/ 6 | * 7 | * The hmac_* functions implement HMAC-BLAKE-256 and HMAC-BLAKE-224. 8 | * HMAC is specified by RFC 2104. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "c_blake256.h" 15 | 16 | #define U8TO32(p) \ 17 | (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ 18 | ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) )) 19 | #define U32TO8(p, v) \ 20 | (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ 21 | (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); 22 | 23 | const uint8_t sigma[][16] = { 24 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}, 25 | {14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3}, 26 | {11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4}, 27 | { 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8}, 28 | { 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13}, 29 | { 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9}, 30 | {12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11}, 31 | {13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10}, 32 | { 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5}, 33 | {10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0}, 34 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}, 35 | {14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3}, 36 | {11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4}, 37 | { 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8} 38 | }; 39 | 40 | const uint32_t cst[16] = { 41 | 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 42 | 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, 43 | 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 44 | 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917 45 | }; 46 | 47 | static const uint8_t padding[] = { 48 | 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 49 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 50 | }; 51 | 52 | 53 | void blake256_compress(state *S, const uint8_t *block) { 54 | uint32_t v[16], m[16], i; 55 | 56 | #define ROT(x,n) (((x)<<(32-n))|((x)>>(n))) 57 | #define G(a,b,c,d,e) \ 58 | v[a] += (m[sigma[i][e]] ^ cst[sigma[i][e+1]]) + v[b]; \ 59 | v[d] = ROT(v[d] ^ v[a],16); \ 60 | v[c] += v[d]; \ 61 | v[b] = ROT(v[b] ^ v[c],12); \ 62 | v[a] += (m[sigma[i][e+1]] ^ cst[sigma[i][e]])+v[b]; \ 63 | v[d] = ROT(v[d] ^ v[a], 8); \ 64 | v[c] += v[d]; \ 65 | v[b] = ROT(v[b] ^ v[c], 7); 66 | 67 | for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4); 68 | for (i = 0; i < 8; ++i) v[i] = S->h[i]; 69 | v[ 8] = S->s[0] ^ 0x243F6A88; 70 | v[ 9] = S->s[1] ^ 0x85A308D3; 71 | v[10] = S->s[2] ^ 0x13198A2E; 72 | v[11] = S->s[3] ^ 0x03707344; 73 | v[12] = 0xA4093822; 74 | v[13] = 0x299F31D0; 75 | v[14] = 0x082EFA98; 76 | v[15] = 0xEC4E6C89; 77 | 78 | if (S->nullt == 0) { 79 | v[12] ^= S->t[0]; 80 | v[13] ^= S->t[0]; 81 | v[14] ^= S->t[1]; 82 | v[15] ^= S->t[1]; 83 | } 84 | 85 | for (i = 0; i < 14; ++i) { 86 | G(0, 4, 8, 12, 0); 87 | G(1, 5, 9, 13, 2); 88 | G(2, 6, 10, 14, 4); 89 | G(3, 7, 11, 15, 6); 90 | G(3, 4, 9, 14, 14); 91 | G(2, 7, 8, 13, 12); 92 | G(0, 5, 10, 15, 8); 93 | G(1, 6, 11, 12, 10); 94 | } 95 | 96 | for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i]; 97 | for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4]; 98 | } 99 | 100 | void blake256_init(state *S) { 101 | S->h[0] = 0x6A09E667; 102 | S->h[1] = 0xBB67AE85; 103 | S->h[2] = 0x3C6EF372; 104 | S->h[3] = 0xA54FF53A; 105 | S->h[4] = 0x510E527F; 106 | S->h[5] = 0x9B05688C; 107 | S->h[6] = 0x1F83D9AB; 108 | S->h[7] = 0x5BE0CD19; 109 | S->t[0] = S->t[1] = S->buflen = S->nullt = 0; 110 | S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0; 111 | } 112 | 113 | void blake224_init(state *S) { 114 | S->h[0] = 0xC1059ED8; 115 | S->h[1] = 0x367CD507; 116 | S->h[2] = 0x3070DD17; 117 | S->h[3] = 0xF70E5939; 118 | S->h[4] = 0xFFC00B31; 119 | S->h[5] = 0x68581511; 120 | S->h[6] = 0x64F98FA7; 121 | S->h[7] = 0xBEFA4FA4; 122 | S->t[0] = S->t[1] = S->buflen = S->nullt = 0; 123 | S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0; 124 | } 125 | 126 | // datalen = number of bits 127 | void blake256_update(state *S, const uint8_t *data, uint64_t datalen) { 128 | int left = S->buflen >> 3; 129 | int fill = 64 - left; 130 | 131 | if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) { 132 | memcpy((void *) (S->buf + left), (void *) data, fill); 133 | S->t[0] += 512; 134 | if (S->t[0] == 0) S->t[1]++; 135 | blake256_compress(S, S->buf); 136 | data += fill; 137 | datalen -= (fill << 3); 138 | left = 0; 139 | } 140 | 141 | while (datalen >= 512) { 142 | S->t[0] += 512; 143 | if (S->t[0] == 0) S->t[1]++; 144 | blake256_compress(S, data); 145 | data += 64; 146 | datalen -= 512; 147 | } 148 | 149 | if (datalen > 0) { 150 | memcpy((void *) (S->buf + left), (void *) data, (size_t) (datalen >> 3)); 151 | S->buflen = (left << 3) + (int) datalen; 152 | } else { 153 | S->buflen = 0; 154 | } 155 | } 156 | 157 | // datalen = number of bits 158 | void blake224_update(state *S, const uint8_t *data, uint64_t datalen) { 159 | blake256_update(S, data, datalen); 160 | } 161 | 162 | void blake256_final_h(state *S, uint8_t *digest, uint8_t pa, uint8_t pb) { 163 | uint8_t msglen[8]; 164 | uint32_t lo = S->t[0] + S->buflen, hi = S->t[1]; 165 | if (lo < (unsigned) S->buflen) hi++; 166 | U32TO8(msglen + 0, hi); 167 | U32TO8(msglen + 4, lo); 168 | 169 | if (S->buflen == 440) { /* one padding byte */ 170 | S->t[0] -= 8; 171 | blake256_update(S, &pa, 8); 172 | } else { 173 | if (S->buflen < 440) { /* enough space to fill the block */ 174 | if (S->buflen == 0) S->nullt = 1; 175 | S->t[0] -= 440 - S->buflen; 176 | blake256_update(S, padding, 440 - S->buflen); 177 | } else { /* need 2 compressions */ 178 | S->t[0] -= 512 - S->buflen; 179 | blake256_update(S, padding, 512 - S->buflen); 180 | S->t[0] -= 440; 181 | blake256_update(S, padding + 1, 440); 182 | S->nullt = 1; 183 | } 184 | blake256_update(S, &pb, 8); 185 | S->t[0] -= 8; 186 | } 187 | S->t[0] -= 64; 188 | blake256_update(S, msglen, 64); 189 | 190 | U32TO8(digest + 0, S->h[0]); 191 | U32TO8(digest + 4, S->h[1]); 192 | U32TO8(digest + 8, S->h[2]); 193 | U32TO8(digest + 12, S->h[3]); 194 | U32TO8(digest + 16, S->h[4]); 195 | U32TO8(digest + 20, S->h[5]); 196 | U32TO8(digest + 24, S->h[6]); 197 | U32TO8(digest + 28, S->h[7]); 198 | } 199 | 200 | void blake256_final(state *S, uint8_t *digest) { 201 | blake256_final_h(S, digest, 0x81, 0x01); 202 | } 203 | 204 | void blake224_final(state *S, uint8_t *digest) { 205 | blake256_final_h(S, digest, 0x80, 0x00); 206 | } 207 | 208 | // inlen = number of bytes 209 | void blake256_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) { 210 | state S; 211 | blake256_init(&S); 212 | blake256_update(&S, in, inlen * 8); 213 | blake256_final(&S, out); 214 | } 215 | 216 | // inlen = number of bytes 217 | void blake224_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) { 218 | state S; 219 | blake224_init(&S); 220 | blake224_update(&S, in, inlen * 8); 221 | blake224_final(&S, out); 222 | } 223 | 224 | // keylen = number of bytes 225 | void hmac_blake256_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) { 226 | const uint8_t *key = _key; 227 | uint8_t keyhash[32]; 228 | uint8_t pad[64]; 229 | uint64_t i; 230 | 231 | if (keylen > 64) { 232 | blake256_hash(keyhash, key, keylen); 233 | key = keyhash; 234 | keylen = 32; 235 | } 236 | 237 | blake256_init(&S->inner); 238 | memset(pad, 0x36, 64); 239 | for (i = 0; i < keylen; ++i) { 240 | pad[i] ^= key[i]; 241 | } 242 | blake256_update(&S->inner, pad, 512); 243 | 244 | blake256_init(&S->outer); 245 | memset(pad, 0x5c, 64); 246 | for (i = 0; i < keylen; ++i) { 247 | pad[i] ^= key[i]; 248 | } 249 | blake256_update(&S->outer, pad, 512); 250 | 251 | memset(keyhash, 0, 32); 252 | } 253 | 254 | // keylen = number of bytes 255 | void hmac_blake224_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) { 256 | const uint8_t *key = _key; 257 | uint8_t keyhash[32]; 258 | uint8_t pad[64]; 259 | uint64_t i; 260 | 261 | if (keylen > 64) { 262 | blake256_hash(keyhash, key, keylen); 263 | key = keyhash; 264 | keylen = 28; 265 | } 266 | 267 | blake224_init(&S->inner); 268 | memset(pad, 0x36, 64); 269 | for (i = 0; i < keylen; ++i) { 270 | pad[i] ^= key[i]; 271 | } 272 | blake224_update(&S->inner, pad, 512); 273 | 274 | blake224_init(&S->outer); 275 | memset(pad, 0x5c, 64); 276 | for (i = 0; i < keylen; ++i) { 277 | pad[i] ^= key[i]; 278 | } 279 | blake224_update(&S->outer, pad, 512); 280 | 281 | memset(keyhash, 0, 32); 282 | } 283 | 284 | // datalen = number of bits 285 | void hmac_blake256_update(hmac_state *S, const uint8_t *data, uint64_t datalen) { 286 | // update the inner state 287 | blake256_update(&S->inner, data, datalen); 288 | } 289 | 290 | // datalen = number of bits 291 | void hmac_blake224_update(hmac_state *S, const uint8_t *data, uint64_t datalen) { 292 | // update the inner state 293 | blake224_update(&S->inner, data, datalen); 294 | } 295 | 296 | void hmac_blake256_final(hmac_state *S, uint8_t *digest) { 297 | uint8_t ihash[32]; 298 | blake256_final(&S->inner, ihash); 299 | blake256_update(&S->outer, ihash, 256); 300 | blake256_final(&S->outer, digest); 301 | memset(ihash, 0, 32); 302 | } 303 | 304 | void hmac_blake224_final(hmac_state *S, uint8_t *digest) { 305 | uint8_t ihash[32]; 306 | blake224_final(&S->inner, ihash); 307 | blake224_update(&S->outer, ihash, 224); 308 | blake224_final(&S->outer, digest); 309 | memset(ihash, 0, 32); 310 | } 311 | 312 | // keylen = number of bytes; inlen = number of bytes 313 | void hmac_blake256_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) { 314 | hmac_state S; 315 | hmac_blake256_init(&S, key, keylen); 316 | hmac_blake256_update(&S, in, inlen * 8); 317 | hmac_blake256_final(&S, out); 318 | } 319 | 320 | // keylen = number of bytes; inlen = number of bytes 321 | void hmac_blake224_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) { 322 | hmac_state S; 323 | hmac_blake224_init(&S, key, keylen); 324 | hmac_blake224_update(&S, in, inlen * 8); 325 | hmac_blake224_final(&S, out); 326 | } 327 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_blake256.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLAKE256_H_ 2 | #define _BLAKE256_H_ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint32_t h[8], s[4], t[2]; 8 | int buflen, nullt; 9 | uint8_t buf[64]; 10 | } state; 11 | 12 | typedef struct { 13 | state inner; 14 | state outer; 15 | } hmac_state; 16 | 17 | void blake256_init(state *); 18 | void blake224_init(state *); 19 | 20 | void blake256_update(state *, const uint8_t *, uint64_t); 21 | void blake224_update(state *, const uint8_t *, uint64_t); 22 | 23 | void blake256_final(state *, uint8_t *); 24 | void blake224_final(state *, uint8_t *); 25 | 26 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 27 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 28 | 29 | /* HMAC functions: */ 30 | 31 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 32 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 33 | 34 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 35 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 36 | 37 | void hmac_blake256_final(hmac_state *, uint8_t *); 38 | void hmac_blake224_final(hmac_state *, uint8_t *); 39 | 40 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 41 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 42 | 43 | #endif /* _BLAKE256_H_ */ 44 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_groestl.c: -------------------------------------------------------------------------------- 1 | /* hash.c April 2012 2 | * Groestl ANSI C code optimised for 32-bit machines 3 | * Author: Thomas Krinninger 4 | * 5 | * This work is based on the implementation of 6 | * Soeren S. Thomsen and Krystian Matusiewicz 7 | * 8 | * 9 | */ 10 | 11 | #include "c_groestl.h" 12 | #include "groestl_tables.h" 13 | 14 | #define P_TYPE 0 15 | #define Q_TYPE 1 16 | 17 | const uint8_t shift_Values[2][8] = {{0,1,2,3,4,5,6,7},{1,3,5,7,0,2,4,6}}; 18 | 19 | const uint8_t indices_cyclic[15] = {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6}; 20 | 21 | 22 | #define ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) {temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \ 23 | v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \ 24 | v1 = temp_var;} 25 | 26 | 27 | #define COLUMN(x,y,i,c0,c1,c2,c3,c4,c5,c6,c7,tv1,tv2,tu,tl,t) \ 28 | tu = T[2*(uint32_t)x[4*c0+0]]; \ 29 | tl = T[2*(uint32_t)x[4*c0+0]+1]; \ 30 | tv1 = T[2*(uint32_t)x[4*c1+1]]; \ 31 | tv2 = T[2*(uint32_t)x[4*c1+1]+1]; \ 32 | ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ 33 | tu ^= tv1; \ 34 | tl ^= tv2; \ 35 | tv1 = T[2*(uint32_t)x[4*c2+2]]; \ 36 | tv2 = T[2*(uint32_t)x[4*c2+2]+1]; \ 37 | ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ 38 | tu ^= tv1; \ 39 | tl ^= tv2; \ 40 | tv1 = T[2*(uint32_t)x[4*c3+3]]; \ 41 | tv2 = T[2*(uint32_t)x[4*c3+3]+1]; \ 42 | ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ 43 | tu ^= tv1; \ 44 | tl ^= tv2; \ 45 | tl ^= T[2*(uint32_t)x[4*c4+0]]; \ 46 | tu ^= T[2*(uint32_t)x[4*c4+0]+1]; \ 47 | tv1 = T[2*(uint32_t)x[4*c5+1]]; \ 48 | tv2 = T[2*(uint32_t)x[4*c5+1]+1]; \ 49 | ROTATE_COLUMN_DOWN(tv1,tv2,1,t) \ 50 | tl ^= tv1; \ 51 | tu ^= tv2; \ 52 | tv1 = T[2*(uint32_t)x[4*c6+2]]; \ 53 | tv2 = T[2*(uint32_t)x[4*c6+2]+1]; \ 54 | ROTATE_COLUMN_DOWN(tv1,tv2,2,t) \ 55 | tl ^= tv1; \ 56 | tu ^= tv2; \ 57 | tv1 = T[2*(uint32_t)x[4*c7+3]]; \ 58 | tv2 = T[2*(uint32_t)x[4*c7+3]+1]; \ 59 | ROTATE_COLUMN_DOWN(tv1,tv2,3,t) \ 60 | tl ^= tv1; \ 61 | tu ^= tv2; \ 62 | y[i] = tu; \ 63 | y[i+1] = tl; 64 | 65 | 66 | /* compute one round of P (short variants) */ 67 | static void RND512P(uint8_t *x, uint32_t *y, uint32_t r) { 68 | uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; 69 | uint32_t* x32 = (uint32_t*)x; 70 | x32[ 0] ^= 0x00000000^r; 71 | x32[ 2] ^= 0x00000010^r; 72 | x32[ 4] ^= 0x00000020^r; 73 | x32[ 6] ^= 0x00000030^r; 74 | x32[ 8] ^= 0x00000040^r; 75 | x32[10] ^= 0x00000050^r; 76 | x32[12] ^= 0x00000060^r; 77 | x32[14] ^= 0x00000070^r; 78 | COLUMN(x,y, 0, 0, 2, 4, 6, 9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 79 | COLUMN(x,y, 2, 2, 4, 6, 8, 11, 13, 15, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 80 | COLUMN(x,y, 4, 4, 6, 8, 10, 13, 15, 1, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 81 | COLUMN(x,y, 6, 6, 8, 10, 12, 15, 1, 3, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 82 | COLUMN(x,y, 8, 8, 10, 12, 14, 1, 3, 5, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 83 | COLUMN(x,y,10, 10, 12, 14, 0, 3, 5, 7, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 84 | COLUMN(x,y,12, 12, 14, 0, 2, 5, 7, 9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 85 | COLUMN(x,y,14, 14, 0, 2, 4, 7, 9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 86 | } 87 | 88 | /* compute one round of Q (short variants) */ 89 | static void RND512Q(uint8_t *x, uint32_t *y, uint32_t r) { 90 | uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp; 91 | uint32_t* x32 = (uint32_t*)x; 92 | x32[ 0] = ~x32[ 0]; 93 | x32[ 1] ^= 0xffffffff^r; 94 | x32[ 2] = ~x32[ 2]; 95 | x32[ 3] ^= 0xefffffff^r; 96 | x32[ 4] = ~x32[ 4]; 97 | x32[ 5] ^= 0xdfffffff^r; 98 | x32[ 6] = ~x32[ 6]; 99 | x32[ 7] ^= 0xcfffffff^r; 100 | x32[ 8] = ~x32[ 8]; 101 | x32[ 9] ^= 0xbfffffff^r; 102 | x32[10] = ~x32[10]; 103 | x32[11] ^= 0xafffffff^r; 104 | x32[12] = ~x32[12]; 105 | x32[13] ^= 0x9fffffff^r; 106 | x32[14] = ~x32[14]; 107 | x32[15] ^= 0x8fffffff^r; 108 | COLUMN(x,y, 0, 2, 6, 10, 14, 1, 5, 9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 109 | COLUMN(x,y, 2, 4, 8, 12, 0, 3, 7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 110 | COLUMN(x,y, 4, 6, 10, 14, 2, 5, 9, 13, 1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 111 | COLUMN(x,y, 6, 8, 12, 0, 4, 7, 11, 15, 3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 112 | COLUMN(x,y, 8, 10, 14, 2, 6, 9, 13, 1, 5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 113 | COLUMN(x,y,10, 12, 0, 4, 8, 11, 15, 3, 7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 114 | COLUMN(x,y,12, 14, 2, 6, 10, 13, 1, 5, 9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 115 | COLUMN(x,y,14, 0, 4, 8, 12, 15, 3, 7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp); 116 | } 117 | 118 | /* compute compression function (short variants) */ 119 | static void F512(uint32_t *h, const uint32_t *m) { 120 | int i; 121 | uint32_t Ptmp[2*COLS512]; 122 | uint32_t Qtmp[2*COLS512]; 123 | uint32_t y[2*COLS512]; 124 | uint32_t z[2*COLS512]; 125 | 126 | for (i = 0; i < 2*COLS512; i++) { 127 | z[i] = m[i]; 128 | Ptmp[i] = h[i]^m[i]; 129 | } 130 | 131 | /* compute Q(m) */ 132 | RND512Q((uint8_t*)z, y, 0x00000000); 133 | RND512Q((uint8_t*)y, z, 0x01000000); 134 | RND512Q((uint8_t*)z, y, 0x02000000); 135 | RND512Q((uint8_t*)y, z, 0x03000000); 136 | RND512Q((uint8_t*)z, y, 0x04000000); 137 | RND512Q((uint8_t*)y, z, 0x05000000); 138 | RND512Q((uint8_t*)z, y, 0x06000000); 139 | RND512Q((uint8_t*)y, z, 0x07000000); 140 | RND512Q((uint8_t*)z, y, 0x08000000); 141 | RND512Q((uint8_t*)y, Qtmp, 0x09000000); 142 | 143 | /* compute P(h+m) */ 144 | RND512P((uint8_t*)Ptmp, y, 0x00000000); 145 | RND512P((uint8_t*)y, z, 0x00000001); 146 | RND512P((uint8_t*)z, y, 0x00000002); 147 | RND512P((uint8_t*)y, z, 0x00000003); 148 | RND512P((uint8_t*)z, y, 0x00000004); 149 | RND512P((uint8_t*)y, z, 0x00000005); 150 | RND512P((uint8_t*)z, y, 0x00000006); 151 | RND512P((uint8_t*)y, z, 0x00000007); 152 | RND512P((uint8_t*)z, y, 0x00000008); 153 | RND512P((uint8_t*)y, Ptmp, 0x00000009); 154 | 155 | /* compute P(h+m) + Q(m) + h */ 156 | for (i = 0; i < 2*COLS512; i++) { 157 | h[i] ^= Ptmp[i]^Qtmp[i]; 158 | } 159 | } 160 | 161 | 162 | /* digest up to msglen bytes of input (full blocks only) */ 163 | static void Transform(groestlHashState *ctx, 164 | const uint8_t *input, 165 | int msglen) { 166 | 167 | /* digest message, one block at a time */ 168 | for (; msglen >= SIZE512; 169 | msglen -= SIZE512, input += SIZE512) { 170 | F512(ctx->chaining,(uint32_t*)input); 171 | 172 | /* increment block counter */ 173 | ctx->block_counter1++; 174 | if (ctx->block_counter1 == 0) ctx->block_counter2++; 175 | } 176 | } 177 | 178 | /* given state h, do h <- P(h)+h */ 179 | static void OutputTransformation(groestlHashState *ctx) { 180 | int j; 181 | uint32_t temp[2*COLS512]; 182 | uint32_t y[2*COLS512]; 183 | uint32_t z[2*COLS512]; 184 | 185 | 186 | 187 | for (j = 0; j < 2*COLS512; j++) { 188 | temp[j] = ctx->chaining[j]; 189 | } 190 | RND512P((uint8_t*)temp, y, 0x00000000); 191 | RND512P((uint8_t*)y, z, 0x00000001); 192 | RND512P((uint8_t*)z, y, 0x00000002); 193 | RND512P((uint8_t*)y, z, 0x00000003); 194 | RND512P((uint8_t*)z, y, 0x00000004); 195 | RND512P((uint8_t*)y, z, 0x00000005); 196 | RND512P((uint8_t*)z, y, 0x00000006); 197 | RND512P((uint8_t*)y, z, 0x00000007); 198 | RND512P((uint8_t*)z, y, 0x00000008); 199 | RND512P((uint8_t*)y, temp, 0x00000009); 200 | for (j = 0; j < 2*COLS512; j++) { 201 | ctx->chaining[j] ^= temp[j]; 202 | } 203 | } 204 | 205 | /* initialise context */ 206 | static void Init(groestlHashState* ctx) { 207 | int i = 0; 208 | /* allocate memory for state and data buffer */ 209 | 210 | for(;i<(SIZE512/sizeof(uint32_t));i++) 211 | { 212 | ctx->chaining[i] = 0; 213 | } 214 | 215 | /* set initial value */ 216 | ctx->chaining[2*COLS512-1] = u32BIG((uint32_t)HASH_BIT_LEN); 217 | 218 | /* set other variables */ 219 | ctx->buf_ptr = 0; 220 | ctx->block_counter1 = 0; 221 | ctx->block_counter2 = 0; 222 | ctx->bits_in_last_byte = 0; 223 | } 224 | 225 | /* update state with databitlen bits of input */ 226 | static void Update(groestlHashState* ctx, 227 | const BitSequence* input, 228 | DataLength databitlen) { 229 | int index = 0; 230 | int msglen = (int)(databitlen/8); 231 | int rem = (int)(databitlen%8); 232 | 233 | /* if the buffer contains data that has not yet been digested, first 234 | add data to buffer until full */ 235 | if (ctx->buf_ptr) { 236 | while (ctx->buf_ptr < SIZE512 && index < msglen) { 237 | ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; 238 | } 239 | if (ctx->buf_ptr < SIZE512) { 240 | /* buffer still not full, return */ 241 | if (rem) { 242 | ctx->bits_in_last_byte = rem; 243 | ctx->buffer[(int)ctx->buf_ptr++] = input[index]; 244 | } 245 | return; 246 | } 247 | 248 | /* digest buffer */ 249 | ctx->buf_ptr = 0; 250 | Transform(ctx, ctx->buffer, SIZE512); 251 | } 252 | 253 | /* digest bulk of message */ 254 | Transform(ctx, input+index, msglen-index); 255 | index += ((msglen-index)/SIZE512)*SIZE512; 256 | 257 | /* store remaining data in buffer */ 258 | while (index < msglen) { 259 | ctx->buffer[(int)ctx->buf_ptr++] = input[index++]; 260 | } 261 | 262 | /* if non-integral number of bytes have been supplied, store 263 | remaining bits in last byte, together with information about 264 | number of bits */ 265 | if (rem) { 266 | ctx->bits_in_last_byte = rem; 267 | ctx->buffer[(int)ctx->buf_ptr++] = input[index]; 268 | } 269 | } 270 | 271 | #define BILB ctx->bits_in_last_byte 272 | 273 | /* finalise: process remaining data (including padding), perform 274 | output transformation, and write hash result to 'output' */ 275 | static void Final(groestlHashState* ctx, 276 | BitSequence* output) { 277 | int i, j = 0, hashbytelen = HASH_BIT_LEN/8; 278 | uint8_t *s = (BitSequence*)ctx->chaining; 279 | 280 | /* pad with '1'-bit and first few '0'-bits */ 281 | if (BILB) { 282 | ctx->buffer[(int)ctx->buf_ptr-1] &= ((1<buffer[(int)ctx->buf_ptr-1] ^= 0x1<<(7-BILB); 284 | BILB = 0; 285 | } 286 | else ctx->buffer[(int)ctx->buf_ptr++] = 0x80; 287 | 288 | /* pad with '0'-bits */ 289 | if (ctx->buf_ptr > SIZE512-LENGTHFIELDLEN) { 290 | /* padding requires two blocks */ 291 | while (ctx->buf_ptr < SIZE512) { 292 | ctx->buffer[(int)ctx->buf_ptr++] = 0; 293 | } 294 | /* digest first padding block */ 295 | Transform(ctx, ctx->buffer, SIZE512); 296 | ctx->buf_ptr = 0; 297 | } 298 | while (ctx->buf_ptr < SIZE512-LENGTHFIELDLEN) { 299 | ctx->buffer[(int)ctx->buf_ptr++] = 0; 300 | } 301 | 302 | /* length padding */ 303 | ctx->block_counter1++; 304 | if (ctx->block_counter1 == 0) ctx->block_counter2++; 305 | ctx->buf_ptr = SIZE512; 306 | 307 | while (ctx->buf_ptr > SIZE512-(int)sizeof(uint32_t)) { 308 | ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter1; 309 | ctx->block_counter1 >>= 8; 310 | } 311 | while (ctx->buf_ptr > SIZE512-LENGTHFIELDLEN) { 312 | ctx->buffer[(int)--ctx->buf_ptr] = (uint8_t)ctx->block_counter2; 313 | ctx->block_counter2 >>= 8; 314 | } 315 | /* digest final padding block */ 316 | Transform(ctx, ctx->buffer, SIZE512); 317 | /* perform output transformation */ 318 | OutputTransformation(ctx); 319 | 320 | /* store hash result in output */ 321 | for (i = SIZE512-hashbytelen; i < SIZE512; i++,j++) { 322 | output[j] = s[i]; 323 | } 324 | 325 | /* zeroise relevant variables and deallocate memory */ 326 | for (i = 0; i < COLS512; i++) { 327 | ctx->chaining[i] = 0; 328 | } 329 | for (i = 0; i < SIZE512; i++) { 330 | ctx->buffer[i] = 0; 331 | } 332 | } 333 | 334 | /* hash bit sequence */ 335 | void groestl(const BitSequence* data, 336 | DataLength databitlen, 337 | BitSequence* hashval) { 338 | 339 | groestlHashState context; 340 | 341 | /* initialise */ 342 | Init(&context); 343 | 344 | 345 | /* process message */ 346 | Update(&context, data, databitlen); 347 | 348 | /* finalise */ 349 | Final(&context, hashval); 350 | } 351 | /* 352 | static int crypto_hash(unsigned char *out, 353 | const unsigned char *in, 354 | unsigned long long len) 355 | { 356 | groestl(in, 8*len, out); 357 | return 0; 358 | } 359 | 360 | */ 361 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_groestl.h: -------------------------------------------------------------------------------- 1 | #ifndef __hash_h 2 | #define __hash_h 3 | /* 4 | #include "crypto_uint8.h" 5 | #include "crypto_uint32.h" 6 | #include "crypto_uint64.h" 7 | #include "crypto_hash.h" 8 | 9 | typedef crypto_uint8 uint8_t; 10 | typedef crypto_uint32 uint32_t; 11 | typedef crypto_uint64 uint64_t; 12 | */ 13 | #include 14 | 15 | #include "hash.h" 16 | 17 | /* some sizes (number of bytes) */ 18 | #define ROWS 8 19 | #define LENGTHFIELDLEN ROWS 20 | #define COLS512 8 21 | 22 | #define SIZE512 (ROWS*COLS512) 23 | 24 | #define ROUNDS512 10 25 | #define HASH_BIT_LEN 256 26 | 27 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 28 | 29 | 30 | #define li_32(h) 0x##h##u 31 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 32 | #define u32BIG(a) \ 33 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 34 | (ROTL32(a,24) & li_32(FF00FF00))) 35 | 36 | 37 | /* NIST API begin */ 38 | typedef struct { 39 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 40 | uint32_t block_counter1, 41 | block_counter2; /* message block counter(s) */ 42 | BitSequence buffer[SIZE512]; /* data buffer */ 43 | int buf_ptr; /* data buffer pointer */ 44 | int bits_in_last_byte; /* no. of message bits in last byte of 45 | data buffer */ 46 | } groestlHashState; 47 | 48 | /*void Init(hashState*); 49 | void Update(hashState*, const BitSequence*, DataLength); 50 | void Final(hashState*, BitSequence*); */ 51 | void groestl(const BitSequence*, DataLength, BitSequence*); 52 | /* NIST API end */ 53 | 54 | /* 55 | int crypto_hash(unsigned char *out, 56 | const unsigned char *in, 57 | unsigned long long len); 58 | */ 59 | 60 | #endif /* __hash_h */ 61 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_jh.h: -------------------------------------------------------------------------------- 1 | /*This program gives the 64-bit optimized bitslice implementation of JH using ANSI C 2 | 3 | -------------------------------- 4 | Performance 5 | 6 | Microprocessor: Intel CORE 2 processor (Core 2 Duo Mobile T6600 2.2GHz) 7 | Operating System: 64-bit Ubuntu 10.04 (Linux kernel 2.6.32-22-generic) 8 | Speed for long message: 9 | 1) 45.8 cycles/byte compiler: Intel C++ Compiler 11.1 compilation option: icc -O2 10 | 2) 56.8 cycles/byte compiler: gcc 4.4.3 compilation option: gcc -O3 11 | 12 | -------------------------------- 13 | Last Modified: January 16, 2011 14 | */ 15 | #pragma once 16 | 17 | #include "hash.h" 18 | 19 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 20 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_keccak.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include "hash-ops.h" 6 | #include "c_keccak.h" 7 | 8 | const uint64_t keccakf_rndc[24] = 9 | { 10 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 11 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 12 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 13 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 14 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 15 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 16 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 17 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 18 | }; 19 | 20 | const int keccakf_rotc[24] = 21 | { 22 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 23 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 24 | }; 25 | 26 | const int keccakf_piln[24] = 27 | { 28 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 29 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 30 | }; 31 | 32 | // update the state with given number of rounds 33 | 34 | void keccakf(uint64_t st[25], int rounds) 35 | { 36 | int i, j, round; 37 | uint64_t t, bc[5]; 38 | 39 | for (round = 0; round < rounds; ++round) { 40 | 41 | // Theta 42 | bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 43 | bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 44 | bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22]; 45 | bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23]; 46 | bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24]; 47 | 48 | for (i = 0; i < 5; ++i) { 49 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 50 | st[i ] ^= t; 51 | st[i + 5] ^= t; 52 | st[i + 10] ^= t; 53 | st[i + 15] ^= t; 54 | st[i + 20] ^= t; 55 | } 56 | 57 | // Rho Pi 58 | t = st[1]; 59 | for (i = 0; i < 24; ++i) { 60 | bc[0] = st[keccakf_piln[i]]; 61 | st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]); 62 | t = bc[0]; 63 | } 64 | 65 | // Chi 66 | for (j = 0; j < 25; j += 5) { 67 | bc[0] = st[j ]; 68 | bc[1] = st[j + 1]; 69 | bc[2] = st[j + 2]; 70 | bc[3] = st[j + 3]; 71 | bc[4] = st[j + 4]; 72 | st[j ] ^= (~bc[1]) & bc[2]; 73 | st[j + 1] ^= (~bc[2]) & bc[3]; 74 | st[j + 2] ^= (~bc[3]) & bc[4]; 75 | st[j + 3] ^= (~bc[4]) & bc[0]; 76 | st[j + 4] ^= (~bc[0]) & bc[1]; 77 | } 78 | 79 | // Iota 80 | st[0] ^= keccakf_rndc[round]; 81 | } 82 | } 83 | 84 | // compute a keccak hash (md) of given byte length from "in" 85 | typedef uint64_t state_t[25]; 86 | 87 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) 88 | { 89 | state_t st; 90 | uint8_t temp[144]; 91 | int i, rsiz, rsizw; 92 | 93 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 94 | rsizw = rsiz / 8; 95 | 96 | memset(st, 0, sizeof(st)); 97 | 98 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 99 | for (i = 0; i < rsizw; i++) 100 | st[i] ^= ((uint64_t *) in)[i]; 101 | keccakf(st, KECCAK_ROUNDS); 102 | } 103 | 104 | // last block and padding 105 | memcpy(temp, in, inlen); 106 | temp[inlen++] = 1; 107 | memset(temp + inlen, 0, rsiz - inlen); 108 | temp[rsiz - 1] |= 0x80; 109 | 110 | for (i = 0; i < rsizw; i++) 111 | st[i] ^= ((uint64_t *) temp)[i]; 112 | 113 | keccakf(st, KECCAK_ROUNDS); 114 | 115 | memcpy(md, st, mdlen); 116 | 117 | return 0; 118 | } 119 | 120 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md) 121 | { 122 | keccak(in, inlen, md, sizeof(state_t)); 123 | } 124 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/c_skein.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_H_ 2 | #define _SKEIN_H_ 1 3 | /************************************************************************** 4 | ** 5 | ** Interface declarations and internal definitions for Skein hashing. 6 | ** 7 | ** Source code author: Doug Whiting, 2008. 8 | ** 9 | ** This algorithm and source code is released to the public domain. 10 | ** 11 | *************************************************************************** 12 | ** 13 | ** The following compile-time switches may be defined to control some 14 | ** tradeoffs between speed, code size, error checking, and security. 15 | ** 16 | ** The "default" note explains what happens when the switch is not defined. 17 | ** 18 | ** SKEIN_DEBUG -- make callouts from inside Skein code 19 | ** to examine/display intermediate values. 20 | ** [default: no callouts (no overhead)] 21 | ** 22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 23 | ** code. If not defined, most error checking 24 | ** is disabled (for performance). Otherwise, 25 | ** the switch value is interpreted as: 26 | ** 0: use assert() to flag errors 27 | ** 1: return SKEIN_FAIL to flag errors 28 | ** 29 | ***************************************************************************/ 30 | #include "skein_port.h" /* get platform-specific definitions */ 31 | 32 | typedef enum 33 | { 34 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */ 35 | SKEIN_FAIL = 1, 36 | SKEIN_BAD_HASHLEN = 2 37 | } 38 | SkeinHashReturn; 39 | 40 | typedef size_t SkeinDataLength; /* bit count type */ 41 | typedef u08b_t SkeinBitSequence; /* bit stream type */ 42 | 43 | /* "all-in-one" call */ 44 | SkeinHashReturn skein_hash(int hashbitlen, const SkeinBitSequence *data, 45 | SkeinDataLength databitlen, SkeinBitSequence *hashval); 46 | 47 | #endif /* ifndef _SKEIN_H_ */ 48 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/groestl_tables.h: -------------------------------------------------------------------------------- 1 | #ifndef __tables_h 2 | #define __tables_h 3 | 4 | 5 | const uint32_t T[512] = {0xa5f432c6, 0xc6a597f4, 0x84976ff8, 0xf884eb97, 0x99b05eee, 0xee99c7b0, 0x8d8c7af6, 0xf68df78c, 0xd17e8ff, 0xff0de517, 0xbddc0ad6, 0xd6bdb7dc, 0xb1c816de, 0xdeb1a7c8, 0x54fc6d91, 0x915439fc 6 | , 0x50f09060, 0x6050c0f0, 0x3050702, 0x2030405, 0xa9e02ece, 0xcea987e0, 0x7d87d156, 0x567dac87, 0x192bcce7, 0xe719d52b, 0x62a613b5, 0xb56271a6, 0xe6317c4d, 0x4de69a31, 0x9ab559ec, 0xec9ac3b5 7 | , 0x45cf408f, 0x8f4505cf, 0x9dbca31f, 0x1f9d3ebc, 0x40c04989, 0x894009c0, 0x879268fa, 0xfa87ef92, 0x153fd0ef, 0xef15c53f, 0xeb2694b2, 0xb2eb7f26, 0xc940ce8e, 0x8ec90740, 0xb1de6fb, 0xfb0bed1d 8 | , 0xec2f6e41, 0x41ec822f, 0x67a91ab3, 0xb3677da9, 0xfd1c435f, 0x5ffdbe1c, 0xea256045, 0x45ea8a25, 0xbfdaf923, 0x23bf46da, 0xf7025153, 0x53f7a602, 0x96a145e4, 0xe496d3a1, 0x5bed769b, 0x9b5b2ded 9 | , 0xc25d2875, 0x75c2ea5d, 0x1c24c5e1, 0xe11cd924, 0xaee9d43d, 0x3dae7ae9, 0x6abef24c, 0x4c6a98be, 0x5aee826c, 0x6c5ad8ee, 0x41c3bd7e, 0x7e41fcc3, 0x206f3f5, 0xf502f106, 0x4fd15283, 0x834f1dd1 10 | , 0x5ce48c68, 0x685cd0e4, 0xf4075651, 0x51f4a207, 0x345c8dd1, 0xd134b95c, 0x818e1f9, 0xf908e918, 0x93ae4ce2, 0xe293dfae, 0x73953eab, 0xab734d95, 0x53f59762, 0x6253c4f5, 0x3f416b2a, 0x2a3f5441 11 | , 0xc141c08, 0x80c1014, 0x52f66395, 0x955231f6, 0x65afe946, 0x46658caf, 0x5ee27f9d, 0x9d5e21e2, 0x28784830, 0x30286078, 0xa1f8cf37, 0x37a16ef8, 0xf111b0a, 0xa0f1411, 0xb5c4eb2f, 0x2fb55ec4 12 | , 0x91b150e, 0xe091c1b, 0x365a7e24, 0x2436485a, 0x9bb6ad1b, 0x1b9b36b6, 0x3d4798df, 0xdf3da547, 0x266aa7cd, 0xcd26816a, 0x69bbf54e, 0x4e699cbb, 0xcd4c337f, 0x7fcdfe4c, 0x9fba50ea, 0xea9fcfba 13 | , 0x1b2d3f12, 0x121b242d, 0x9eb9a41d, 0x1d9e3ab9, 0x749cc458, 0x5874b09c, 0x2e724634, 0x342e6872, 0x2d774136, 0x362d6c77, 0xb2cd11dc, 0xdcb2a3cd, 0xee299db4, 0xb4ee7329, 0xfb164d5b, 0x5bfbb616 14 | , 0xf601a5a4, 0xa4f65301, 0x4dd7a176, 0x764decd7, 0x61a314b7, 0xb76175a3, 0xce49347d, 0x7dcefa49, 0x7b8ddf52, 0x527ba48d, 0x3e429fdd, 0xdd3ea142, 0x7193cd5e, 0x5e71bc93, 0x97a2b113, 0x139726a2 15 | , 0xf504a2a6, 0xa6f55704, 0x68b801b9, 0xb96869b8, 0x0, 0x0, 0x2c74b5c1, 0xc12c9974, 0x60a0e040, 0x406080a0, 0x1f21c2e3, 0xe31fdd21, 0xc8433a79, 0x79c8f243, 0xed2c9ab6, 0xb6ed772c 16 | , 0xbed90dd4, 0xd4beb3d9, 0x46ca478d, 0x8d4601ca, 0xd9701767, 0x67d9ce70, 0x4bddaf72, 0x724be4dd, 0xde79ed94, 0x94de3379, 0xd467ff98, 0x98d42b67, 0xe82393b0, 0xb0e87b23, 0x4ade5b85, 0x854a11de 17 | , 0x6bbd06bb, 0xbb6b6dbd, 0x2a7ebbc5, 0xc52a917e, 0xe5347b4f, 0x4fe59e34, 0x163ad7ed, 0xed16c13a, 0xc554d286, 0x86c51754, 0xd762f89a, 0x9ad72f62, 0x55ff9966, 0x6655ccff, 0x94a7b611, 0x119422a7 18 | , 0xcf4ac08a, 0x8acf0f4a, 0x1030d9e9, 0xe910c930, 0x60a0e04, 0x406080a, 0x819866fe, 0xfe81e798, 0xf00baba0, 0xa0f05b0b, 0x44ccb478, 0x7844f0cc, 0xbad5f025, 0x25ba4ad5, 0xe33e754b, 0x4be3963e 19 | , 0xf30eaca2, 0xa2f35f0e, 0xfe19445d, 0x5dfeba19, 0xc05bdb80, 0x80c01b5b, 0x8a858005, 0x58a0a85, 0xadecd33f, 0x3fad7eec, 0xbcdffe21, 0x21bc42df, 0x48d8a870, 0x7048e0d8, 0x40cfdf1, 0xf104f90c 20 | , 0xdf7a1963, 0x63dfc67a, 0xc1582f77, 0x77c1ee58, 0x759f30af, 0xaf75459f, 0x63a5e742, 0x426384a5, 0x30507020, 0x20304050, 0x1a2ecbe5, 0xe51ad12e, 0xe12effd, 0xfd0ee112, 0x6db708bf, 0xbf6d65b7 21 | , 0x4cd45581, 0x814c19d4, 0x143c2418, 0x1814303c, 0x355f7926, 0x26354c5f, 0x2f71b2c3, 0xc32f9d71, 0xe13886be, 0xbee16738, 0xa2fdc835, 0x35a26afd, 0xcc4fc788, 0x88cc0b4f, 0x394b652e, 0x2e395c4b 22 | , 0x57f96a93, 0x93573df9, 0xf20d5855, 0x55f2aa0d, 0x829d61fc, 0xfc82e39d, 0x47c9b37a, 0x7a47f4c9, 0xacef27c8, 0xc8ac8bef, 0xe73288ba, 0xbae76f32, 0x2b7d4f32, 0x322b647d, 0x95a442e6, 0xe695d7a4 23 | , 0xa0fb3bc0, 0xc0a09bfb, 0x98b3aa19, 0x199832b3, 0xd168f69e, 0x9ed12768, 0x7f8122a3, 0xa37f5d81, 0x66aaee44, 0x446688aa, 0x7e82d654, 0x547ea882, 0xabe6dd3b, 0x3bab76e6, 0x839e950b, 0xb83169e 24 | , 0xca45c98c, 0x8cca0345, 0x297bbcc7, 0xc729957b, 0xd36e056b, 0x6bd3d66e, 0x3c446c28, 0x283c5044, 0x798b2ca7, 0xa779558b, 0xe23d81bc, 0xbce2633d, 0x1d273116, 0x161d2c27, 0x769a37ad, 0xad76419a 25 | , 0x3b4d96db, 0xdb3bad4d, 0x56fa9e64, 0x6456c8fa, 0x4ed2a674, 0x744ee8d2, 0x1e223614, 0x141e2822, 0xdb76e492, 0x92db3f76, 0xa1e120c, 0xc0a181e, 0x6cb4fc48, 0x486c90b4, 0xe4378fb8, 0xb8e46b37 26 | , 0x5de7789f, 0x9f5d25e7, 0x6eb20fbd, 0xbd6e61b2, 0xef2a6943, 0x43ef862a, 0xa6f135c4, 0xc4a693f1, 0xa8e3da39, 0x39a872e3, 0xa4f7c631, 0x31a462f7, 0x37598ad3, 0xd337bd59, 0x8b8674f2, 0xf28bff86 27 | , 0x325683d5, 0xd532b156, 0x43c54e8b, 0x8b430dc5, 0x59eb856e, 0x6e59dceb, 0xb7c218da, 0xdab7afc2, 0x8c8f8e01, 0x18c028f, 0x64ac1db1, 0xb16479ac, 0xd26df19c, 0x9cd2236d, 0xe03b7249, 0x49e0923b 28 | , 0xb4c71fd8, 0xd8b4abc7, 0xfa15b9ac, 0xacfa4315, 0x709faf3, 0xf307fd09, 0x256fa0cf, 0xcf25856f, 0xafea20ca, 0xcaaf8fea, 0x8e897df4, 0xf48ef389, 0xe9206747, 0x47e98e20, 0x18283810, 0x10182028 29 | , 0xd5640b6f, 0x6fd5de64, 0x888373f0, 0xf088fb83, 0x6fb1fb4a, 0x4a6f94b1, 0x7296ca5c, 0x5c72b896, 0x246c5438, 0x3824706c, 0xf1085f57, 0x57f1ae08, 0xc7522173, 0x73c7e652, 0x51f36497, 0x975135f3 30 | , 0x2365aecb, 0xcb238d65, 0x7c8425a1, 0xa17c5984, 0x9cbf57e8, 0xe89ccbbf, 0x21635d3e, 0x3e217c63, 0xdd7cea96, 0x96dd377c, 0xdc7f1e61, 0x61dcc27f, 0x86919c0d, 0xd861a91, 0x85949b0f, 0xf851e94 31 | , 0x90ab4be0, 0xe090dbab, 0x42c6ba7c, 0x7c42f8c6, 0xc4572671, 0x71c4e257, 0xaae529cc, 0xccaa83e5, 0xd873e390, 0x90d83b73, 0x50f0906, 0x6050c0f, 0x103f4f7, 0xf701f503, 0x12362a1c, 0x1c123836 32 | , 0xa3fe3cc2, 0xc2a39ffe, 0x5fe18b6a, 0x6a5fd4e1, 0xf910beae, 0xaef94710, 0xd06b0269, 0x69d0d26b, 0x91a8bf17, 0x17912ea8, 0x58e87199, 0x995829e8, 0x2769533a, 0x3a277469, 0xb9d0f727, 0x27b94ed0 33 | , 0x384891d9, 0xd938a948, 0x1335deeb, 0xeb13cd35, 0xb3cee52b, 0x2bb356ce, 0x33557722, 0x22334455, 0xbbd604d2, 0xd2bbbfd6, 0x709039a9, 0xa9704990, 0x89808707, 0x7890e80, 0xa7f2c133, 0x33a766f2 34 | , 0xb6c1ec2d, 0x2db65ac1, 0x22665a3c, 0x3c227866, 0x92adb815, 0x15922aad, 0x2060a9c9, 0xc9208960, 0x49db5c87, 0x874915db, 0xff1ab0aa, 0xaaff4f1a, 0x7888d850, 0x5078a088, 0x7a8e2ba5, 0xa57a518e 35 | , 0x8f8a8903, 0x38f068a, 0xf8134a59, 0x59f8b213, 0x809b9209, 0x980129b, 0x1739231a, 0x1a173439, 0xda751065, 0x65daca75, 0x315384d7, 0xd731b553, 0xc651d584, 0x84c61351, 0xb8d303d0, 0xd0b8bbd3 36 | , 0xc35edc82, 0x82c31f5e, 0xb0cbe229, 0x29b052cb, 0x7799c35a, 0x5a77b499, 0x11332d1e, 0x1e113c33, 0xcb463d7b, 0x7bcbf646, 0xfc1fb7a8, 0xa8fc4b1f, 0xd6610c6d, 0x6dd6da61, 0x3a4e622c, 0x2c3a584e}; 37 | 38 | #endif /* __tables_h */ 39 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #if !defined(__cplusplus) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "int-util.h" 15 | 16 | #if 0 17 | static inline void *padd(void *p, size_t i) { 18 | return (char *) p + i; 19 | } 20 | 21 | static inline const void *cpadd(const void *p, size_t i) { 22 | return (const char *) p + i; 23 | } 24 | 25 | static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { 26 | if (sizeof(size_t) == 4) { 27 | *(uint32_t*) padd(buffer, bufsize - 4) = swap32be(length); 28 | } else { 29 | *(uint64_t*) padd(buffer, bufsize - 8) = swap64be(length); 30 | } 31 | } 32 | #endif 33 | 34 | #pragma pack(push, 1) 35 | union hash_state { 36 | uint8_t b[200]; 37 | uint64_t w[25]; 38 | }; 39 | #pragma pack(pop) 40 | 41 | void hash_permutation(union hash_state *state); 42 | void hash_process(union hash_state *state, const uint8_t *buf, int count); 43 | 44 | #endif 45 | 46 | enum { 47 | HASH_SIZE = 32, 48 | HASH_DATA_AREA = 136 49 | }; 50 | 51 | void cn_fast_hash(const void *data, int len, char *hash); 52 | void cn_slow_hash(const void *data, size_t length, char *hash); 53 | 54 | void hash_extra_blake(const void *data, size_t length, char *hash); 55 | void hash_extra_groestl(const void *data, size_t length, char *hash); 56 | void hash_extra_jh(const void *data, size_t length, char *hash); 57 | void hash_extra_skein(const void *data, size_t length, char *hash); 58 | 59 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash); 60 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "hash-ops.h" 10 | #include "c_keccak.h" 11 | 12 | void hash_permutation(union hash_state *state) { 13 | keccakf((uint64_t*)state, 24); 14 | } 15 | 16 | void hash_process(union hash_state *state, const uint8_t *buf, int count) { 17 | keccak1600(buf, count, (uint8_t*)state); 18 | } 19 | 20 | void cn_fast_hash(const void *data, int len, char *hash) { 21 | union hash_state state; 22 | hash_process(&state, data, len); 23 | memcpy(hash, &state, HASH_SIZE); 24 | } 25 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef unsigned char BitSequence; 4 | typedef unsigned long long DataLength; 5 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 6 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/int-util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | #ifndef INT_UTILS_H_ 7 | #define INT_UTILS_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #ifndef _MSC_VER 14 | #include 15 | #else 16 | #define inline __inline 17 | #endif 18 | 19 | #ifndef LITTLE_ENDIAN 20 | #define LITTLE_ENDIAN 0x1234 21 | #define BIG_ENDIAN 0x4321 22 | #endif 23 | 24 | #if !defined(BYTE_ORDER) && (defined(__LITTLE_ENDIAN__) || defined(__arm__) || defined(WIN32)) 25 | #define BYTE_ORDER LITTLE_ENDIAN 26 | #endif 27 | 28 | #if defined(WIN32) 29 | #include 30 | 31 | static inline uint32_t rol32(uint32_t x, int r) { 32 | return _rotl(x, r); 33 | } 34 | 35 | static inline uint64_t rol64(uint64_t x, int r) { 36 | return _rotl64(x, r); 37 | } 38 | 39 | #else 40 | 41 | static inline uint32_t rol32(uint32_t x, int r) { 42 | return (x << (r & 31)) | (x >> (-r & 31)); 43 | } 44 | 45 | static inline uint64_t rol64(uint64_t x, int r) { 46 | return (x << (r & 63)) | (x >> (-r & 63)); 47 | } 48 | 49 | #endif 50 | 51 | static inline uint64_t hi_dword(uint64_t val) { 52 | return val >> 32; 53 | } 54 | 55 | static inline uint64_t lo_dword(uint64_t val) { 56 | return val & 0xFFFFFFFF; 57 | } 58 | 59 | static inline uint64_t div_with_reminder(uint64_t dividend, uint32_t divisor, uint32_t* remainder) { 60 | dividend |= ((uint64_t)*remainder) << 32; 61 | *remainder = dividend % divisor; 62 | return dividend / divisor; 63 | } 64 | 65 | // Long division with 2^32 base 66 | static inline uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uint32_t divisor, uint64_t* quotient_hi, uint64_t* quotient_lo) { 67 | uint64_t dividend_dwords[4]; 68 | uint32_t remainder = 0; 69 | 70 | dividend_dwords[3] = hi_dword(dividend_hi); 71 | dividend_dwords[2] = lo_dword(dividend_hi); 72 | dividend_dwords[1] = hi_dword(dividend_lo); 73 | dividend_dwords[0] = lo_dword(dividend_lo); 74 | 75 | *quotient_hi = div_with_reminder(dividend_dwords[3], divisor, &remainder) << 32; 76 | *quotient_hi |= div_with_reminder(dividend_dwords[2], divisor, &remainder); 77 | *quotient_lo = div_with_reminder(dividend_dwords[1], divisor, &remainder) << 32; 78 | *quotient_lo |= div_with_reminder(dividend_dwords[0], divisor, &remainder); 79 | 80 | return remainder; 81 | } 82 | 83 | #define IDENT32(x) ((uint32_t) (x)) 84 | #define IDENT64(x) ((uint64_t) (x)) 85 | 86 | #define SWAP32(x) ((((uint32_t) (x) & 0x000000ff) << 24) | \ 87 | (((uint32_t) (x) & 0x0000ff00) << 8) | \ 88 | (((uint32_t) (x) & 0x00ff0000) >> 8) | \ 89 | (((uint32_t) (x) & 0xff000000) >> 24)) 90 | #define SWAP64(x) ((((uint64_t) (x) & 0x00000000000000ff) << 56) | \ 91 | (((uint64_t) (x) & 0x000000000000ff00) << 40) | \ 92 | (((uint64_t) (x) & 0x0000000000ff0000) << 24) | \ 93 | (((uint64_t) (x) & 0x00000000ff000000) << 8) | \ 94 | (((uint64_t) (x) & 0x000000ff00000000) >> 8) | \ 95 | (((uint64_t) (x) & 0x0000ff0000000000) >> 24) | \ 96 | (((uint64_t) (x) & 0x00ff000000000000) >> 40) | \ 97 | (((uint64_t) (x) & 0xff00000000000000) >> 56)) 98 | 99 | static inline uint32_t ident32(uint32_t x) { return x; } 100 | static inline uint64_t ident64(uint64_t x) { return x; } 101 | 102 | static inline uint32_t swap32(uint32_t x) { 103 | x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8); 104 | return (x << 16) | (x >> 16); 105 | } 106 | static inline uint64_t swap64(uint64_t x) { 107 | x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8); 108 | x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16); 109 | return (x << 32) | (x >> 32); 110 | } 111 | 112 | #if defined(__GNUC__) 113 | #define UNUSED __attribute__((unused)) 114 | #else 115 | #define UNUSED 116 | #endif 117 | static inline void mem_inplace_ident(void *mem UNUSED, size_t n UNUSED) { } 118 | #undef UNUSED 119 | 120 | static inline void mem_inplace_swap32(void *mem, size_t n) { 121 | size_t i; 122 | for (i = 0; i < n; i++) { 123 | ((uint32_t *) mem)[i] = swap32(((const uint32_t *) mem)[i]); 124 | } 125 | } 126 | static inline void mem_inplace_swap64(void *mem, size_t n) { 127 | size_t i; 128 | for (i = 0; i < n; i++) { 129 | ((uint64_t *) mem)[i] = swap64(((const uint64_t *) mem)[i]); 130 | } 131 | } 132 | 133 | static inline void memcpy_ident32(void *dst, const void *src, size_t n) { 134 | memcpy(dst, src, 4 * n); 135 | } 136 | static inline void memcpy_ident64(void *dst, const void *src, size_t n) { 137 | memcpy(dst, src, 8 * n); 138 | } 139 | 140 | static inline void memcpy_swap32(void *dst, const void *src, size_t n) { 141 | size_t i; 142 | for (i = 0; i < n; i++) { 143 | ((uint32_t *) dst)[i] = swap32(((const uint32_t *) src)[i]); 144 | } 145 | } 146 | static inline void memcpy_swap64(void *dst, const void *src, size_t n) { 147 | size_t i; 148 | for (i = 0; i < n; i++) { 149 | ((uint64_t *) dst)[i] = swap64(((const uint64_t *) src)[i]); 150 | } 151 | } 152 | 153 | #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) 154 | static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled"); 155 | #endif 156 | 157 | #if BYTE_ORDER == LITTLE_ENDIAN 158 | #define SWAP32LE IDENT32 159 | #define SWAP32BE SWAP32 160 | #define swap32le ident32 161 | #define swap32be swap32 162 | #define mem_inplace_swap32le mem_inplace_ident 163 | #define mem_inplace_swap32be mem_inplace_swap32 164 | #define memcpy_swap32le memcpy_ident32 165 | #define memcpy_swap32be memcpy_swap32 166 | #define SWAP64LE IDENT64 167 | #define SWAP64BE SWAP64 168 | #define swap64le ident64 169 | #define swap64be swap64 170 | #define mem_inplace_swap64le mem_inplace_ident 171 | #define mem_inplace_swap64be mem_inplace_swap64 172 | #define memcpy_swap64le memcpy_ident64 173 | #define memcpy_swap64be memcpy_swap64 174 | #endif 175 | 176 | #if BYTE_ORDER == BIG_ENDIAN 177 | #define SWAP32BE IDENT32 178 | #define SWAP32LE SWAP32 179 | #define swap32be ident32 180 | #define swap32le swap32 181 | #define mem_inplace_swap32be mem_inplace_ident 182 | #define mem_inplace_swap32le mem_inplace_swap32 183 | #define memcpy_swap32be memcpy_ident32 184 | #define memcpy_swap32le memcpy_swap32 185 | #define SWAP64BE IDENT64 186 | #define SWAP64LE SWAP64 187 | #define swap64be ident64 188 | #define swap64le swap64 189 | #define mem_inplace_swap64be mem_inplace_ident 190 | #define mem_inplace_swap64le mem_inplace_swap64 191 | #define memcpy_swap64be memcpy_ident64 192 | #define memcpy_swap64le memcpy_swap64 193 | #endif 194 | 195 | #endif /* INT_UTILS_H_ */ 196 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/oaes_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_LIB_H 32 | #define _OAES_LIB_H 33 | 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #ifdef _WIN32 41 | # ifdef OAES_SHARED 42 | # ifdef oaes_lib_EXPORTS 43 | # define OAES_API __declspec(dllexport) 44 | # else 45 | # define OAES_API __declspec(dllimport) 46 | # endif 47 | # else 48 | # define OAES_API 49 | # endif 50 | #else 51 | # define OAES_API 52 | #endif // WIN32 53 | 54 | #define OAES_VERSION "0.8.1" 55 | #define OAES_BLOCK_SIZE 16 56 | 57 | typedef void OAES_CTX; 58 | 59 | typedef enum 60 | { 61 | OAES_RET_FIRST = 0, 62 | OAES_RET_SUCCESS = 0, 63 | OAES_RET_UNKNOWN, 64 | OAES_RET_ARG1, 65 | OAES_RET_ARG2, 66 | OAES_RET_ARG3, 67 | OAES_RET_ARG4, 68 | OAES_RET_ARG5, 69 | OAES_RET_NOKEY, 70 | OAES_RET_MEM, 71 | OAES_RET_BUF, 72 | OAES_RET_HEADER, 73 | OAES_RET_COUNT 74 | } OAES_RET; 75 | 76 | /* 77 | * oaes_set_option() takes one of these values for its [option] parameter 78 | * some options accept either an optional or a required [value] parameter 79 | */ 80 | // no option 81 | #define OAES_OPTION_NONE 0 82 | // enable ECB mode, disable CBC mode 83 | #define OAES_OPTION_ECB 1 84 | // enable CBC mode, disable ECB mode 85 | // value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify 86 | // the value of the initialization vector, iv 87 | #define OAES_OPTION_CBC 2 88 | 89 | #ifdef OAES_DEBUG 90 | typedef int ( * oaes_step_cb ) ( 91 | const uint8_t state[OAES_BLOCK_SIZE], 92 | const char * step_name, 93 | int step_count, 94 | void * user_data ); 95 | // enable state stepping mode 96 | // value is required, must pass oaes_step_cb to receive the state at each step 97 | #define OAES_OPTION_STEP_ON 4 98 | // disable state stepping mode 99 | #define OAES_OPTION_STEP_OFF 8 100 | #endif // OAES_DEBUG 101 | 102 | typedef uint16_t OAES_OPTION; 103 | 104 | typedef struct _oaes_key 105 | { 106 | size_t data_len; 107 | uint8_t *data; 108 | size_t exp_data_len; 109 | uint8_t *exp_data; 110 | size_t num_keys; 111 | size_t key_base; 112 | } oaes_key; 113 | 114 | typedef struct _oaes_ctx 115 | { 116 | #ifdef OAES_HAVE_ISAAC 117 | randctx * rctx; 118 | #endif // OAES_HAVE_ISAAC 119 | 120 | #ifdef OAES_DEBUG 121 | oaes_step_cb step_cb; 122 | #endif // OAES_DEBUG 123 | 124 | oaes_key * key; 125 | OAES_OPTION options; 126 | uint8_t iv[OAES_BLOCK_SIZE]; 127 | } oaes_ctx; 128 | /* 129 | * // usage: 130 | * 131 | * OAES_CTX * ctx = oaes_alloc(); 132 | * . 133 | * . 134 | * . 135 | * { 136 | * oaes_gen_key_xxx( ctx ); 137 | * { 138 | * oaes_key_export( ctx, _buf, &_buf_len ); 139 | * // or 140 | * oaes_key_export_data( ctx, _buf, &_buf_len );\ 141 | * } 142 | * } 143 | * // or 144 | * { 145 | * oaes_key_import( ctx, _buf, _buf_len ); 146 | * // or 147 | * oaes_key_import_data( ctx, _buf, _buf_len ); 148 | * } 149 | * . 150 | * . 151 | * . 152 | * oaes_encrypt( ctx, m, m_len, c, &c_len ); 153 | * . 154 | * . 155 | * . 156 | * oaes_decrypt( ctx, c, c_len, m, &m_len ); 157 | * . 158 | * . 159 | * . 160 | * oaes_free( &ctx ); 161 | */ 162 | 163 | OAES_API OAES_CTX * oaes_alloc(void); 164 | 165 | OAES_API OAES_RET oaes_free( OAES_CTX ** ctx ); 166 | 167 | OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx, 168 | OAES_OPTION option, const void * value ); 169 | 170 | OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx ); 171 | 172 | OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx ); 173 | 174 | OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx ); 175 | 176 | // export key with header information 177 | // set data == NULL to get the required data_len 178 | OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx, 179 | uint8_t * data, size_t * data_len ); 180 | 181 | // directly export the data from key 182 | // set data == NULL to get the required data_len 183 | OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx, 184 | uint8_t * data, size_t * data_len ); 185 | 186 | // import key with header information 187 | OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx, 188 | const uint8_t * data, size_t data_len ); 189 | 190 | // directly import data into key 191 | OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx, 192 | const uint8_t * data, size_t data_len ); 193 | 194 | // set c == NULL to get the required c_len 195 | OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx, 196 | const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len ); 197 | 198 | // set m == NULL to get the required m_len 199 | OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx, 200 | const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len ); 201 | 202 | // set buf == NULL to get the required buf_len 203 | OAES_API OAES_RET oaes_sprintf( 204 | char * buf, size_t * buf_len, const uint8_t * data, size_t data_len ); 205 | 206 | OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c ); 207 | 208 | OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c ); 209 | 210 | #ifdef __cplusplus 211 | } 212 | #endif 213 | 214 | #endif // _OAES_LIB_H 215 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/crypto/skein_port.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_PORT_H_ 2 | #define _SKEIN_PORT_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifndef RETURN_VALUES 8 | # define RETURN_VALUES 9 | # if defined( DLL_EXPORT ) 10 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 11 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 12 | # define INT_RETURN __declspec( dllexport ) int __stdcall 13 | # elif defined( __GNUC__ ) 14 | # define VOID_RETURN __declspec( __dllexport__ ) void 15 | # define INT_RETURN __declspec( __dllexport__ ) int 16 | # else 17 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 18 | # endif 19 | # elif defined( DLL_IMPORT ) 20 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 21 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 22 | # define INT_RETURN __declspec( dllimport ) int __stdcall 23 | # elif defined( __GNUC__ ) 24 | # define VOID_RETURN __declspec( __dllimport__ ) void 25 | # define INT_RETURN __declspec( __dllimport__ ) int 26 | # else 27 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 28 | # endif 29 | # elif defined( __WATCOMC__ ) 30 | # define VOID_RETURN void __cdecl 31 | # define INT_RETURN int __cdecl 32 | # else 33 | # define VOID_RETURN void 34 | # define INT_RETURN int 35 | # endif 36 | #endif 37 | 38 | /* These defines are used to declare buffers in a way that allows 39 | faster operations on longer variables to be used. In all these 40 | defines 'size' must be a power of 2 and >= 8 41 | 42 | dec_unit_type(size,x) declares a variable 'x' of length 43 | 'size' bits 44 | 45 | dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' 46 | bytes defined as an array of variables 47 | each of 'size' bits (bsize must be a 48 | multiple of size / 8) 49 | 50 | ptr_cast(x,size) casts a pointer to a pointer to a 51 | varaiable of length 'size' bits 52 | */ 53 | 54 | #define ui_type(size) uint##size##_t 55 | #define dec_unit_type(size,x) typedef ui_type(size) x 56 | #define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)] 57 | #define ptr_cast(x,size) ((ui_type(size)*)(x)) 58 | 59 | typedef unsigned int uint_t; /* native unsigned integer */ 60 | typedef uint8_t u08b_t; /* 8-bit unsigned integer */ 61 | typedef uint64_t u64b_t; /* 64-bit unsigned integer */ 62 | 63 | #ifndef RotL_64 64 | #define RotL_64(x,N) (((x) << (N)) | ((x) >> (64-(N)))) 65 | #endif 66 | 67 | /* 68 | * Skein is "natively" little-endian (unlike SHA-xxx), for optimal 69 | * performance on x86 CPUs. The Skein code requires the following 70 | * definitions for dealing with endianness: 71 | * 72 | * SKEIN_NEED_SWAP: 0 for little-endian, 1 for big-endian 73 | * Skein_Put64_LSB_First 74 | * Skein_Get64_LSB_First 75 | * Skein_Swap64 76 | * 77 | * If SKEIN_NEED_SWAP is defined at compile time, it is used here 78 | * along with the portable versions of Put64/Get64/Swap64, which 79 | * are slow in general. 80 | * 81 | * Otherwise, an "auto-detect" of endianness is attempted below. 82 | * If the default handling doesn't work well, the user may insert 83 | * platform-specific code instead (e.g., for big-endian CPUs). 84 | * 85 | */ 86 | #ifndef SKEIN_NEED_SWAP /* compile-time "override" for endianness? */ 87 | 88 | 89 | #include "int-util.h" 90 | 91 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 92 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 93 | 94 | #if BYTE_ORDER == LITTLE_ENDIAN 95 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 96 | #endif 97 | 98 | #if BYTE_ORDER == BIG_ENDIAN 99 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 100 | #endif 101 | 102 | /* special handler for IA64, which may be either endianness (?) */ 103 | /* here we assume little-endian, but this may need to be changed */ 104 | #if defined(__ia64) || defined(__ia64__) || defined(_M_IA64) 105 | # define PLATFORM_MUST_ALIGN (1) 106 | #ifndef PLATFORM_BYTE_ORDER 107 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 108 | #endif 109 | #endif 110 | 111 | #ifndef PLATFORM_MUST_ALIGN 112 | # define PLATFORM_MUST_ALIGN (0) 113 | #endif 114 | 115 | 116 | #if PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN 117 | /* here for big-endian CPUs */ 118 | #define SKEIN_NEED_SWAP (1) 119 | #elif PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN 120 | /* here for x86 and x86-64 CPUs (and other detected little-endian CPUs) */ 121 | #define SKEIN_NEED_SWAP (0) 122 | #if PLATFORM_MUST_ALIGN == 0 /* ok to use "fast" versions? */ 123 | #define Skein_Put64_LSB_First(dst08,src64,bCnt) memcpy(dst08,src64,bCnt) 124 | #define Skein_Get64_LSB_First(dst64,src08,wCnt) memcpy(dst64,src08,8*(wCnt)) 125 | #endif 126 | #else 127 | #error "Skein needs endianness setting!" 128 | #endif 129 | 130 | #endif /* ifndef SKEIN_NEED_SWAP */ 131 | 132 | /* 133 | ****************************************************************** 134 | * Provide any definitions still needed. 135 | ****************************************************************** 136 | */ 137 | #ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */ 138 | #if SKEIN_NEED_SWAP 139 | #define Skein_Swap64(w64) \ 140 | ( (( ((u64b_t)(w64)) & 0xFF) << 56) | \ 141 | (((((u64b_t)(w64)) >> 8) & 0xFF) << 48) | \ 142 | (((((u64b_t)(w64)) >>16) & 0xFF) << 40) | \ 143 | (((((u64b_t)(w64)) >>24) & 0xFF) << 32) | \ 144 | (((((u64b_t)(w64)) >>32) & 0xFF) << 24) | \ 145 | (((((u64b_t)(w64)) >>40) & 0xFF) << 16) | \ 146 | (((((u64b_t)(w64)) >>48) & 0xFF) << 8) | \ 147 | (((((u64b_t)(w64)) >>56) & 0xFF) ) ) 148 | #else 149 | #define Skein_Swap64(w64) (w64) 150 | #endif 151 | #endif /* ifndef Skein_Swap64 */ 152 | 153 | 154 | #ifndef Skein_Put64_LSB_First 155 | void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt) 156 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 157 | { /* this version is fully portable (big-endian or little-endian), but slow */ 158 | size_t n; 159 | 160 | for (n=0;n>3] >> (8*(n&7))); 162 | } 163 | #else 164 | ; /* output only the function prototype */ 165 | #endif 166 | #endif /* ifndef Skein_Put64_LSB_First */ 167 | 168 | 169 | #ifndef Skein_Get64_LSB_First 170 | void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt) 171 | #ifdef SKEIN_PORT_CODE /* instantiate the function code here? */ 172 | { /* this version is fully portable (big-endian or little-endian), but slow */ 173 | size_t n; 174 | 175 | for (n=0;n<8*wCnt;n+=8) 176 | dst[n/8] = (((u64b_t) src[n ]) ) + 177 | (((u64b_t) src[n+1]) << 8) + 178 | (((u64b_t) src[n+2]) << 16) + 179 | (((u64b_t) src[n+3]) << 24) + 180 | (((u64b_t) src[n+4]) << 32) + 181 | (((u64b_t) src[n+5]) << 40) + 182 | (((u64b_t) src[n+6]) << 48) + 183 | (((u64b_t) src[n+7]) << 56) ; 184 | } 185 | #else 186 | ; /* output only the function prototype */ 187 | #endif 188 | #endif /* ifndef Skein_Get64_LSB_First */ 189 | 190 | #endif /* ifndef _SKEIN_PORT_H_ */ 191 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/cryptonight.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | // Modified for CPUminer by Lucas Jones 6 | #include 7 | #include 8 | #include 9 | //#include 10 | 11 | #ifdef STDC_HEADERS 12 | # include 13 | # include 14 | #else 15 | # ifdef HAVE_STDLIB_H 16 | # include 17 | # endif 18 | #endif 19 | 20 | #ifdef HAVE_ALLOCA_H 21 | # include 22 | #elif !defined alloca 23 | # ifdef __GNUC__ 24 | # define alloca __builtin_alloca 25 | # elif defined _AIX 26 | # define alloca __alloca 27 | # elif defined _MSC_VER 28 | # include 29 | # define alloca _alloca 30 | # elif !defined HAVE_ALLOCA 31 | # ifdef __cplusplus 32 | extern "C" 33 | # endif 34 | void *alloca (size_t); 35 | # endif 36 | #endif 37 | 38 | #ifdef HAVE_SYSLOG_H 39 | #include 40 | #define LOG_BLUE 0x10 /* unique value */ 41 | #else 42 | enum { 43 | LOG_ERR, 44 | LOG_WARNING, 45 | LOG_NOTICE, 46 | LOG_INFO, 47 | LOG_DEBUG, 48 | /* custom notices */ 49 | LOG_BLUE = 0x10, 50 | }; 51 | #endif 52 | 53 | #include "compat/compat.h" 54 | 55 | #ifndef ARRAY_SIZE 56 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 57 | #endif 58 | 59 | static inline bool is_windows(void) { 60 | #ifdef WIN32 61 | return 1; 62 | #else 63 | return 0; 64 | #endif 65 | } 66 | 67 | #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) 68 | #define WANT_BUILTIN_BSWAP 69 | #else 70 | #define bswap_32(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) \ 71 | | (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu)) 72 | #endif 73 | 74 | static inline uint32_t swab32(uint32_t v) { 75 | #ifdef WANT_BUILTIN_BSWAP 76 | return __builtin_bswap32(v); 77 | #else 78 | return bswap_32(v); 79 | #endif 80 | } 81 | 82 | #ifdef HAVE_SYS_ENDIAN_H 83 | #include 84 | #endif 85 | 86 | typedef unsigned char uchar; 87 | 88 | #if !HAVE_DECL_BE32DEC 89 | 90 | static inline uint32_t be32dec(const void *pp) { 91 | const uint8_t *p = (uint8_t const *) pp; 92 | return ((uint32_t) (p[3]) + ((uint32_t) (p[2]) << 8) + 93 | ((uint32_t) (p[1]) << 16) + ((uint32_t) (p[0]) << 24)); 94 | } 95 | 96 | #endif 97 | 98 | #if !HAVE_DECL_LE32DEC 99 | 100 | static inline uint32_t le32dec(const void *pp) { 101 | const uint8_t *p = (uint8_t const *) pp; 102 | return ((uint32_t) (p[0]) + ((uint32_t) (p[1]) << 8) + 103 | ((uint32_t) (p[2]) << 16) + ((uint32_t) (p[3]) << 24)); 104 | } 105 | 106 | #endif 107 | 108 | #if !HAVE_DECL_BE32ENC 109 | 110 | static inline void be32enc(void *pp, uint32_t x) { 111 | uint8_t *p = (uint8_t *) pp; 112 | p[3] = x & 0xff; 113 | p[2] = (x >> 8) & 0xff; 114 | p[1] = (x >> 16) & 0xff; 115 | p[0] = (x >> 24) & 0xff; 116 | } 117 | 118 | #endif 119 | 120 | #if !HAVE_DECL_LE32ENC 121 | 122 | static inline void le32enc(void *pp, uint32_t x) { 123 | uint8_t *p = (uint8_t *) pp; 124 | p[0] = x & 0xff; 125 | p[1] = (x >> 8) & 0xff; 126 | p[2] = (x >> 16) & 0xff; 127 | p[3] = (x >> 24) & 0xff; 128 | } 129 | 130 | #endif 131 | 132 | #if !HAVE_DECL_LE16DEC 133 | 134 | static inline uint16_t le16dec(const void *pp) { 135 | const uint8_t *p = (uint8_t const *) pp; 136 | return ((uint16_t) (p[0]) + ((uint16_t) (p[1]) << 8)); 137 | } 138 | 139 | #endif 140 | 141 | #if !HAVE_DECL_LE16ENC 142 | 143 | static inline void le16enc(void *pp, uint16_t x) { 144 | uint8_t *p = (uint8_t *) pp; 145 | p[0] = x & 0xff; 146 | p[1] = (x >> 8) & 0xff; 147 | } 148 | 149 | #endif 150 | 151 | #if JANSSON_MAJOR_VERSION >= 2 152 | #define JSON_LOADS(str, err_ptr) json_loads(str, 0, err_ptr) 153 | #define JSON_LOADF(path, err_ptr) json_load_file(path, 0, err_ptr) 154 | #else 155 | #define JSON_LOADS(str, err_ptr) json_loads(str, err_ptr) 156 | #define JSON_LOADF(path, err_ptr) json_load_file(path, err_ptr) 157 | #endif 158 | 159 | void sha256_init(uint32_t *state); 160 | 161 | void sha256_transform(uint32_t *state, const uint32_t *block, int swap); 162 | 163 | void sha256d(unsigned char *hash, const unsigned char *data, int len); 164 | 165 | #ifdef USE_ASM 166 | #if defined(__ARM_NEON__) || defined(__i386__) || defined(__x86_64__) 167 | #define HAVE_SHA256_4WAY 1 168 | int sha256_use_4way(); 169 | void sha256_init_4way(uint32_t *state); 170 | void sha256_transform_4way(uint32_t *state, const uint32_t *block, int swap); 171 | #endif 172 | #if defined(__x86_64__) && defined(USE_AVX2) 173 | #define HAVE_SHA256_8WAY 1 174 | int sha256_use_8way(); 175 | void sha256_init_8way(uint32_t *state); 176 | void sha256_transform_8way(uint32_t *state, const uint32_t *block, int swap); 177 | #endif 178 | #endif 179 | 180 | #if defined(__arm__) || defined(_MSC_VER) 181 | #ifndef NOASM 182 | #define NOASM 183 | #endif 184 | #endif 185 | 186 | #include "crypto/oaes_lib.h" 187 | #include "crypto/c_keccak.h" 188 | #include "crypto/c_groestl.h" 189 | #include "crypto/c_blake256.h" 190 | #include "crypto/c_jh.h" 191 | #include "crypto/c_skein.h" 192 | #include "crypto/int-util.h" 193 | #include "crypto/hash-ops.h" 194 | 195 | #if USE_INT128 196 | 197 | #if __GNUC__ == 4 && __GNUC_MINOR__ >= 4 && __GNUC_MINOR__ < 6 198 | typedef unsigned int uint128_t __attribute__ ((__mode__ (TI))); 199 | #elif defined (_MSC_VER) 200 | /* only for mingw64 on windows */ 201 | #undef USE_INT128 202 | #define USE_INT128 (0) 203 | #else 204 | typedef __uint128_t uint128_t; 205 | #endif 206 | 207 | #endif 208 | 209 | #define LITE 0 210 | #if LITE /* cryptonight-light */ 211 | #define MEMORY (1 << 20) 212 | #define ITER (1 << 19) 213 | #else 214 | #define MEMORY (1 << 21) /* 2 MiB */ 215 | #define ITER (1 << 20) 216 | #endif 217 | 218 | #define AES_BLOCK_SIZE 16 219 | #define AES_KEY_SIZE 32 /*16*/ 220 | #define INIT_SIZE_BLK 8 221 | #define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) 222 | 223 | #pragma pack(push, 1) 224 | union cn_slow_hash_state { 225 | union hash_state hs; 226 | struct { 227 | uint8_t k[64]; 228 | uint8_t init[INIT_SIZE_BYTE]; 229 | }; 230 | }; 231 | #pragma pack(pop) 232 | 233 | static void do_blake_hash(const void *input, size_t len, char *output) { 234 | blake256_hash((uint8_t *) output, input, len); 235 | } 236 | 237 | static void do_groestl_hash(const void *input, size_t len, char *output) { 238 | groestl(input, len * 8, (uint8_t *) output); 239 | } 240 | 241 | static void do_jh_hash(const void *input, size_t len, char *output) { 242 | int r = jh_hash(HASH_SIZE * 8, input, 8 * len, (uint8_t *) output); 243 | assert(likely(SUCCESS == r)); 244 | } 245 | 246 | static void do_skein_hash(const void *input, size_t len, char *output) { 247 | int r = skein_hash(8 * HASH_SIZE, input, 8 * len, (uint8_t *) output); 248 | assert(likely(SKEIN_SUCCESS == r)); 249 | } 250 | 251 | extern int aesb_single_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey); 252 | 253 | extern int aesb_pseudo_round_mut(uint8_t *val, uint8_t *expandedKey); 254 | 255 | static uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t *product_hi) { 256 | // multiplier = ab = a * 2^32 + b 257 | // multiplicand = cd = c * 2^32 + d 258 | // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d 259 | uint64_t a = hi_dword(multiplier); 260 | uint64_t b = lo_dword(multiplier); 261 | uint64_t c = hi_dword(multiplicand); 262 | uint64_t d = lo_dword(multiplicand); 263 | 264 | uint64_t ac = a * c; 265 | uint64_t ad = a * d; 266 | uint64_t bc = b * c; 267 | uint64_t bd = b * d; 268 | 269 | uint64_t adbc = ad + bc; 270 | uint64_t adbc_carry = adbc < ad ? 1 : 0; 271 | 272 | // multiplier * multiplicand = product_hi * 2^64 + product_lo 273 | uint64_t product_lo = bd + (adbc << 32); 274 | uint64_t product_lo_carry = product_lo < bd ? 1 : 0; 275 | *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry; 276 | assert(ac <= *product_hi); 277 | 278 | return product_lo; 279 | } 280 | 281 | static void (*const extra_hashes[4])(const void *, size_t, char *) = { 282 | do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash 283 | }; 284 | 285 | 286 | static inline size_t e2i(const uint8_t *a) { 287 | #if !LITE 288 | return ((uint32_t *) a)[0] & 0x1FFFF0; 289 | #else 290 | return ((uint32_t *)a)[0] & 0xFFFF0; 291 | #endif 292 | } 293 | 294 | static inline void mul_sum_xor_dst(const uint8_t *a, uint8_t *c, uint8_t *dst) { 295 | uint64_t hi, lo = mul128(((uint64_t *) a)[0], ((uint64_t *) dst)[0], &hi) + ((uint64_t *) c)[1]; 296 | hi += ((uint64_t *) c)[0]; 297 | 298 | ((uint64_t *) c)[0] = ((uint64_t *) dst)[0] ^ hi; 299 | ((uint64_t *) c)[1] = ((uint64_t *) dst)[1] ^ lo; 300 | ((uint64_t *) dst)[0] = hi; 301 | ((uint64_t *) dst)[1] = lo; 302 | } 303 | 304 | static inline void xor_blocks(uint8_t *a, const uint8_t *b) { 305 | #if USE_INT128 306 | *((uint128_t*) a) ^= *((uint128_t*) b); 307 | #else 308 | ((uint64_t *) a)[0] ^= ((uint64_t *) b)[0]; 309 | ((uint64_t *) a)[1] ^= ((uint64_t *) b)[1]; 310 | #endif 311 | } 312 | 313 | static inline void xor_blocks_dst(const uint8_t *a, const uint8_t *b, uint8_t *dst) { 314 | #if USE_INT128 315 | *((uint128_t*) dst) = *((uint128_t*) a) ^ *((uint128_t*) b); 316 | #else 317 | ((uint64_t *) dst)[0] = ((uint64_t *) a)[0] ^ ((uint64_t *) b)[0]; 318 | ((uint64_t *) dst)[1] = ((uint64_t *) a)[1] ^ ((uint64_t *) b)[1]; 319 | #endif 320 | } 321 | 322 | struct cryptonight_ctx { 323 | uint8_t _ALIGN(16) long_state[MEMORY]; 324 | union cn_slow_hash_state state; 325 | uint8_t _ALIGN(16) text[INIT_SIZE_BYTE]; 326 | uint8_t _ALIGN(16) a[AES_BLOCK_SIZE]; 327 | uint8_t _ALIGN(16) b[AES_BLOCK_SIZE]; 328 | uint8_t _ALIGN(16) c[AES_BLOCK_SIZE]; 329 | oaes_ctx *aes_ctx; 330 | }; 331 | 332 | static void cryptonight_hash_ctx(void *output, const void *input, int len, struct cryptonight_ctx *ctx) { 333 | hash_process(&ctx->state.hs, (const uint8_t *) input, len); 334 | ctx->aes_ctx = (oaes_ctx *) oaes_alloc(); 335 | size_t i, j; 336 | memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); 337 | 338 | oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE); 339 | for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) { 340 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 0], ctx->aes_ctx->key->exp_data); 341 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 1], ctx->aes_ctx->key->exp_data); 342 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 2], ctx->aes_ctx->key->exp_data); 343 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 3], ctx->aes_ctx->key->exp_data); 344 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 4], ctx->aes_ctx->key->exp_data); 345 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 5], ctx->aes_ctx->key->exp_data); 346 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 6], ctx->aes_ctx->key->exp_data); 347 | aesb_pseudo_round_mut(&ctx->text[AES_BLOCK_SIZE * 7], ctx->aes_ctx->key->exp_data); 348 | memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE); 349 | } 350 | 351 | xor_blocks_dst(&ctx->state.k[0], &ctx->state.k[32], ctx->a); 352 | xor_blocks_dst(&ctx->state.k[16], &ctx->state.k[48], ctx->b); 353 | 354 | for (i = 0; likely(i < ITER / 4); ++i) { 355 | /* Dependency chain: address -> read value ------+ 356 | * written value <-+ hard function (AES or MUL) <+ 357 | * next address <-+ 358 | */ 359 | /* Iteration 1 */ 360 | j = e2i(ctx->a); 361 | aesb_single_round(&ctx->long_state[j], ctx->c, ctx->a); 362 | xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]); 363 | /* Iteration 2 */ 364 | mul_sum_xor_dst(ctx->c, ctx->a, &ctx->long_state[e2i(ctx->c)]); 365 | /* Iteration 3 */ 366 | j = e2i(ctx->a); 367 | aesb_single_round(&ctx->long_state[j], ctx->b, ctx->a); 368 | xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 369 | /* Iteration 4 */ 370 | mul_sum_xor_dst(ctx->b, ctx->a, &ctx->long_state[e2i(ctx->b)]); 371 | } 372 | 373 | memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE); 374 | oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE); 375 | for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE) { 376 | xor_blocks(&ctx->text[0 * AES_BLOCK_SIZE], &ctx->long_state[i + 0 * AES_BLOCK_SIZE]); 377 | aesb_pseudo_round_mut(&ctx->text[0 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 378 | xor_blocks(&ctx->text[1 * AES_BLOCK_SIZE], &ctx->long_state[i + 1 * AES_BLOCK_SIZE]); 379 | aesb_pseudo_round_mut(&ctx->text[1 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 380 | xor_blocks(&ctx->text[2 * AES_BLOCK_SIZE], &ctx->long_state[i + 2 * AES_BLOCK_SIZE]); 381 | aesb_pseudo_round_mut(&ctx->text[2 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 382 | xor_blocks(&ctx->text[3 * AES_BLOCK_SIZE], &ctx->long_state[i + 3 * AES_BLOCK_SIZE]); 383 | aesb_pseudo_round_mut(&ctx->text[3 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 384 | xor_blocks(&ctx->text[4 * AES_BLOCK_SIZE], &ctx->long_state[i + 4 * AES_BLOCK_SIZE]); 385 | aesb_pseudo_round_mut(&ctx->text[4 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 386 | xor_blocks(&ctx->text[5 * AES_BLOCK_SIZE], &ctx->long_state[i + 5 * AES_BLOCK_SIZE]); 387 | aesb_pseudo_round_mut(&ctx->text[5 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 388 | xor_blocks(&ctx->text[6 * AES_BLOCK_SIZE], &ctx->long_state[i + 6 * AES_BLOCK_SIZE]); 389 | aesb_pseudo_round_mut(&ctx->text[6 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 390 | xor_blocks(&ctx->text[7 * AES_BLOCK_SIZE], &ctx->long_state[i + 7 * AES_BLOCK_SIZE]); 391 | aesb_pseudo_round_mut(&ctx->text[7 * AES_BLOCK_SIZE], ctx->aes_ctx->key->exp_data); 392 | } 393 | memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE); 394 | hash_permutation(&ctx->state.hs); 395 | /*memcpy(hash, &state, 32);*/ 396 | extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, output); 397 | oaes_free((OAES_CTX **) &ctx->aes_ctx); 398 | } 399 | 400 | 401 | static void cryptonight_hash(void *output, void *input, int len) { 402 | struct cryptonight_ctx *ctx = (struct cryptonight_ctx *) malloc(sizeof(struct cryptonight_ctx)); 403 | 404 | cryptonight_hash_ctx(output, input, len, ctx); 405 | 406 | free(ctx); 407 | } 408 | 409 | -------------------------------------------------------------------------------- /xmrminer/src/main/jni/cryptonight_jni.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cryptonight.c" 3 | 4 | JNIEXPORT void 5 | JNICALL Java_com_cpf_cryptonight_Miner_fastHash(JNIEnv *env, jobject j, jbyteArray input, 6 | jbyteArray output) { 7 | 8 | unsigned char *inputBuffer = (unsigned char *) (*env)->GetByteArrayElements(env, input, NULL); 9 | unsigned char *outputBuffer = (unsigned char *) (*env)->GetByteArrayElements(env, output, NULL); 10 | 11 | jsize inputSize = (*env)->GetArrayLength(env, input); 12 | // jsize outputSize = (*env)->GetArrayLength(env, output); 13 | 14 | cryptonight_hash(outputBuffer, inputBuffer, inputSize); 15 | 16 | (*env)->ReleaseByteArrayElements(env, input, (jbyte *) inputBuffer, JNI_ABORT); 17 | (*env)->ReleaseByteArrayElements(env, output, (jbyte *) outputBuffer, JNI_COMMIT); 18 | } -------------------------------------------------------------------------------- /xmrminer/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 | 25 | 26 | 31 | 32 | 39 | 40 | 41 | 42 | 47 | 48 | 55 | 56 | 57 | 58 | 63 | 64 | 69 | 70 | 74 | 75 | 80 | 81 | 88 | 89 | 90 | 91 | 96 | 97 | 102 | 103 | 107 | 108 | 115 | 116 | 123 | 124 | 125 | 126 | 131 | 132 | 136 | 137 | 147 | 148 | 152 | 153 | 163 | 164 | 168 | 169 | 179 | 180 | 181 | 188 | 189 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p2svn/CryptoNightMiner/7e65e2bd7fb4d8bc01a77c9a5f6494e8ac98c7c9/xmrminer/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xmrminer/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /xmrminer/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | XMRMiner 3 | Wallet address 4 | Thread 5 | Speed 6 | Run 7 | Stop 8 | Hashes/S 9 | Total 10 | 90% 11 | Accepted 12 | cpu[0-9] 13 | 14 | URL can not be empty 15 | User/Wallet address can not be empty 16 | Password can not be empty 17 | 18 | 19 | -------------------------------------------------------------------------------- /xmrminer/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | --------------------------------------------------------------------------------