├── Android
└── CryptoDemo
│ ├── .idea
│ ├── compiler.xml
│ ├── gradle.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
│ ├── app
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── comtasoft
│ │ │ └── cryptodemo
│ │ │ └── ExampleInstrumentedTest.kt
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── comtasoft
│ │ │ │ └── cryptodemo
│ │ │ │ └── MainActivity.kt
│ │ ├── jniLibs
│ │ │ ├── arm64-v8a
│ │ │ │ └── librust_crypto.so
│ │ │ ├── armeabi-v7a
│ │ │ │ └── librust_crypto.so
│ │ │ └── x86_64
│ │ │ │ └── librust_crypto.so
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.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-night
│ │ │ └── themes.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── themes.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── comtasoft
│ │ └── cryptodemo
│ │ └── ExampleUnitTest.kt
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── Backend
├── cargo-config.toml
├── cargo-config.toml.template
├── cargo-config.toml.template.new.linux
├── cargo-config.toml.template.new.mac
├── create-ndk-build-info-linux.sh
├── create-ndk-build-info-mac.sh
├── create-ndk-standalone-ndk-r18.sh
├── create-ndk-standalone.sh
├── libs
│ ├── rust-crypto-0.2.41
│ │ ├── CHANGELOG.md
│ │ ├── Cargo.toml
│ │ ├── LICENSE-APACHE
│ │ ├── LICENSE-MIT
│ │ ├── README.md
│ │ ├── appveyor.yml
│ │ ├── build.rs
│ │ ├── examples
│ │ │ └── symmetriccipher.rs
│ │ └── src
│ │ │ ├── aead.rs
│ │ │ ├── aes.rs
│ │ │ ├── aes_gcm.rs
│ │ │ ├── aesni.rs
│ │ │ ├── aesni_helpers.asm
│ │ │ ├── aesni_helpers.c
│ │ │ ├── aessafe.rs
│ │ │ ├── api.rs
│ │ │ ├── bcrypt.rs
│ │ │ ├── bcrypt_pbkdf.rs
│ │ │ ├── blake2b.rs
│ │ │ ├── blake2s.rs
│ │ │ ├── blockmodes.rs
│ │ │ ├── blowfish.rs
│ │ │ ├── buffer.rs
│ │ │ ├── chacha20.rs
│ │ │ ├── chacha20poly1305.rs
│ │ │ ├── cryptoutil.rs
│ │ │ ├── curve25519.rs
│ │ │ ├── digest.rs
│ │ │ ├── ed25519.rs
│ │ │ ├── fortuna.rs
│ │ │ ├── ghash.rs
│ │ │ ├── hc128.rs
│ │ │ ├── hkdf.rs
│ │ │ ├── hmac.rs
│ │ │ ├── lib.rs
│ │ │ ├── mac.rs
│ │ │ ├── md5.rs
│ │ │ ├── pbkdf2.rs
│ │ │ ├── poly1305.rs
│ │ │ ├── rc4.rs
│ │ │ ├── ripemd160.rs
│ │ │ ├── salsa20.rs
│ │ │ ├── scrypt.rs
│ │ │ ├── sha1.rs
│ │ │ ├── sha2.rs
│ │ │ ├── sha3.rs
│ │ │ ├── simd.rs
│ │ │ ├── sosemanuk.rs
│ │ │ ├── step_by.rs
│ │ │ ├── symmetriccipher.rs
│ │ │ ├── util.rs
│ │ │ ├── util_helpers.asm
│ │ │ ├── util_helpers.c
│ │ │ └── whirlpool.rs
│ └── rustc-serialize-0.3.24
│ │ ├── .cargo-ok
│ │ ├── .travis.yml
│ │ ├── Cargo.toml
│ │ ├── LICENSE-APACHE
│ │ ├── LICENSE-MIT
│ │ ├── README.md
│ │ ├── appveyor.yml
│ │ ├── benches
│ │ ├── base64.rs
│ │ ├── hex.rs
│ │ └── json.rs
│ │ └── src
│ │ ├── base64.rs
│ │ ├── collection_impls.rs
│ │ ├── hex.rs
│ │ ├── json.rs
│ │ ├── lib.rs
│ │ └── serialize.rs
└── rust_crypto
│ ├── Cargo.toml
│ └── src
│ ├── lib.rs
│ └── rust_crypto.h
├── Console
└── cscrypto_2.1.2
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ └── main.rs
├── Desktop
├── MainFrame.cpp
├── MainFrame.h
├── Makefile-linux
├── Makefile-mac
├── Makefile-win32
├── Makefile-win64
├── app.cpp
├── app.h
└── res
│ └── app.rc
├── README.md
├── Screenshoots
├── Android.png
├── Linux.png
├── WebAssembly.png
├── Win32.png
├── Windows-UWP.png
├── iOS.png
└── macOS.png
├── UWP
└── CryptoDemo
│ ├── CryptoDemo.sln
│ └── CryptoDemo
│ ├── App.cpp
│ ├── App.h
│ ├── App.idl
│ ├── App.xaml
│ ├── Assets
│ ├── LockScreenLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── StoreLogo.png
│ └── Wide310x150Logo.scale-200.png
│ ├── CryptoDemo.vcxproj
│ ├── CryptoDemo.vcxproj.filters
│ ├── CryptoDemo.vcxproj.user
│ ├── CryptoDemo_TemporaryKey.pfx
│ ├── MainPage.cpp
│ ├── MainPage.h
│ ├── MainPage.idl
│ ├── MainPage.xaml
│ ├── Package.appxmanifest
│ ├── PropertySheet.props
│ ├── build_rust-lib.cmd
│ ├── packages.config
│ ├── pch.cpp
│ ├── pch.h
│ └── readme.txt
├── WebAssembly
└── crypto-demo
│ ├── .appveyor.yml
│ ├── .cargo-ok
│ ├── .travis.yml
│ ├── Cargo.toml
│ ├── LICENSE_APACHE
│ ├── LICENSE_MIT
│ ├── README.md
│ ├── package-lock.json
│ ├── src
│ ├── lib.rs
│ └── utils.rs
│ └── tests
│ └── web.rs
└── iOS
└── CryptoDemo
├── ._CryptoDemo.xcodeproj
├── CryptoDemo.xcodeproj
├── ._project.xcworkspace
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ ├── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── WorkspaceSettings.xcsettings
│ └── xcuserdata
│ │ ├── owner.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ │ └── tungthanhnguyen.xcuserdatad
│ │ ├── UserInterfaceState.xcuserstate
│ │ ├── WorkspaceSettings.xcsettings
│ │ └── xcdebugger
│ │ └── Expressions.xcexplist
├── xcshareddata
│ └── xcschemes
│ │ ├── Debug.xcscheme
│ │ └── Release.xcscheme
└── xcuserdata
│ ├── owner.xcuserdatad
│ └── xcschemes
│ │ └── xcschememanagement.plist
│ └── tungthanhnguyen.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── CryptoDemo.xcscheme
│ └── xcschememanagement.plist
├── CryptoDemo
├── AppDelegate.swift
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── CryptoDemo-Bridging-Header.h
├── Info.plist
├── RustCrypto.h
├── RustCrypto.m
└── ViewController.swift
└── OptimizationProfiles
└── CryptoDemo.profdata
/Android/CryptoDemo/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 30
8 | buildToolsVersion "30.0.3"
9 |
10 | defaultConfig {
11 | applicationId "com.comtasoft.cryptodemo"
12 | minSdkVersion 26
13 | targetSdkVersion 30
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | }
33 | ndkVersion '23.0.7123448 rc1'
34 | }
35 |
36 | dependencies {
37 |
38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
39 | implementation 'androidx.core:core-ktx:1.5.0'
40 | implementation 'androidx.appcompat:appcompat:1.3.0'
41 | implementation 'com.google.android.material:material:1.3.0'
42 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
43 | testImplementation 'junit:junit:4.13.2'
44 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
46 | }
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/androidTest/java/com/comtasoft/cryptodemo/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.comtasoft.cryptodemo
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.comtasoft.cryptodemo", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/java/com/comtasoft/cryptodemo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.comtasoft.cryptodemo
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import android.widget.EditText
6 | import android.widget.TextView
7 | import androidx.appcompat.app.AppCompatActivity
8 |
9 | class MainActivity : AppCompatActivity()
10 | {
11 | private val pubKey = "ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic="
12 | private val priKey = "E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8="
13 |
14 | init
15 | {
16 | System.loadLibrary("rust_crypto")
17 | }
18 |
19 | private external fun RustEncrypt(pubKey: String, message: String): String?
20 | private external fun RustDecrypt(priKey: String, message: String): String?
21 |
22 | private lateinit var edtMess: EditText
23 | private lateinit var lblEncryptedText: TextView
24 | private lateinit var lblDecryptedText: TextView
25 |
26 | override fun onCreate(savedInstanceState: Bundle?)
27 | {
28 | super.onCreate(savedInstanceState)
29 | setContentView(R.layout.activity_main)
30 |
31 | edtMess = findViewById(R.id.edtMess)
32 | lblEncryptedText = findViewById(R.id.lblEncryptedText)
33 | lblDecryptedText = findViewById(R.id.lblDecryptedText)
34 | }
35 |
36 | fun onAction(view: View)
37 | {
38 | val sMess = edtMess.text.toString().trim()
39 | if (sMess.isNotEmpty())
40 | {
41 | val encMess = RustEncrypt(pubKey, sMess)
42 | val decMess = RustDecrypt(priKey, encMess.toString())
43 |
44 | lblEncryptedText.text = encMess
45 | lblDecryptedText.text = decMess
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/jniLibs/arm64-v8a/librust_crypto.so:
--------------------------------------------------------------------------------
1 | ./../../../../../../../Backend/rust_crypto/target/aarch64-linux-android/release/librust_crypto.so
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/jniLibs/armeabi-v7a/librust_crypto.so:
--------------------------------------------------------------------------------
1 | ./../../../../../../../Backend/rust_crypto/target/armv7-linux-androideabi/release/librust_crypto.so
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/jniLibs/x86_64/librust_crypto.so:
--------------------------------------------------------------------------------
1 | ./../../../../../../../Backend/rust_crypto/target/x86_64-linux-android/release/librust_crypto.so
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
32 |
33 |
44 |
45 |
56 |
57 |
66 |
67 |
78 |
79 |
89 |
90 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 | #3F51B5
12 | #303F9F
13 | #FF4081
14 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CryptoDemo
3 | Action
4 | Input Text:
5 | Encrypted Text:
6 | Decrypted Text:
7 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/app/src/test/java/com/comtasoft/cryptodemo/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.comtasoft.cryptodemo
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/Android/CryptoDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = "1.5.10"
4 | repositories {
5 | google()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath "com.android.tools.build:gradle:4.2.1"
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | mavenCentral()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
--------------------------------------------------------------------------------
/Android/CryptoDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
--------------------------------------------------------------------------------
/Android/CryptoDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Android/CryptoDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Android/CryptoDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 18 14:18:55 ICT 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Android/CryptoDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "CryptoDemo"
2 | include ':app'
3 |
--------------------------------------------------------------------------------
/Backend/cargo-config.toml:
--------------------------------------------------------------------------------
1 | [target.aarch64-linux-android]
2 | linker = "/home/tungthanhnguyen/Android/Sdk/ndk/23.0.7123448/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-clang"
3 |
4 | [target.armv7-linux-androideabi]
5 | linker = "/home/tungthanhnguyen/Android/Sdk/ndk/23.0.7123448/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-clang"
6 |
7 | [target.i686-linux-android]
8 | linker = "/home/tungthanhnguyen/Android/Sdk/ndk/23.0.7123448/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-clang"
9 |
10 | [target.x86_64-linux-android]
11 | linker = "/home/tungthanhnguyen/Android/Sdk/ndk/23.0.7123448/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-clang"
12 |
--------------------------------------------------------------------------------
/Backend/cargo-config.toml.template:
--------------------------------------------------------------------------------
1 | [target.aarch64-linux-android]
2 | ar = "$PWD/NDK/arm64/bin/aarch64-linux-android-ar"
3 | linker = "$PWD/NDK/arm64/bin/aarch64-linux-android-clang"
4 |
5 | [target.armv7-linux-androideabi]
6 | ar = "$PWD/NDK/arm/bin/arm-linux-androideabi-ar"
7 | linker = "$PWD/NDK/arm/bin/arm-linux-androideabi-clang"
8 |
9 | [target.i686-linux-android]
10 | ar = "$PWD/NDK/x86/bin/i686-linux-android-ar"
11 | linker = "$PWD/NDK/x86/bin/i686-linux-android-clang"
12 |
--------------------------------------------------------------------------------
/Backend/cargo-config.toml.template.new.linux:
--------------------------------------------------------------------------------
1 | [target.aarch64-linux-android]
2 | linker = "$PWD/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-clang"
3 |
4 | [target.armv7-linux-androideabi]
5 | linker = "$PWD/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-clang"
6 |
7 | [target.i686-linux-android]
8 | linker = "$PWD/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-clang"
9 |
10 | [target.x86_64-linux-android]
11 | linker = "$PWD/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-clang"
12 |
--------------------------------------------------------------------------------
/Backend/cargo-config.toml.template.new.mac:
--------------------------------------------------------------------------------
1 | [target.aarch64-linux-android]
2 | linker = "$PWD/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-clang"
3 |
4 | [target.i686-linux-android]
5 | linker = "$PWD/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android-clang"
6 |
7 | [target.x86_64-linux-android]
8 | linker = "$PWD/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android-clang"
9 |
--------------------------------------------------------------------------------
/Backend/create-ndk-build-info-linux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo 'Creating the build tools and information...'
4 |
5 | BUILD_TOOLS_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
6 | ln -f "$BUILD_TOOLS_PATH/aarch64-linux-android30-clang" "$BUILD_TOOLS_PATH/aarch64-linux-android-clang"
7 | ln -f $BUILD_TOOLS_PATH/armv7a-linux-androideabi30-clang $BUILD_TOOLS_PATH/arm-linux-androideabi-clang
8 | ln -f $BUILD_TOOLS_PATH/i686-linux-android30-clang $BUILD_TOOLS_PATH/i686-linux-android-clang
9 | ln -f $BUILD_TOOLS_PATH/x86_64-linux-android30-clang $BUILD_TOOLS_PATH/x86_64-linux-android-clang
10 |
11 | sed 's|$PWD|'"${ANDROID_NDK_HOME}"'|g' cargo-config.toml.template.new.linux > cargo-config.toml
12 |
--------------------------------------------------------------------------------
/Backend/create-ndk-build-info-mac.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo 'Creating the build tools and information...'
4 |
5 | BUILD_TOOLS_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin"
6 | ln -f "$BUILD_TOOLS_PATH/aarch64-linux-android21-clang" "$BUILD_TOOLS_PATH/aarch64-linux-android-clang"
7 | ln -f $BUILD_TOOLS_PATH/i686-linux-android16-clang $BUILD_TOOLS_PATH/i686-linux-android-clang
8 | ln -f $BUILD_TOOLS_PATH/x86_64-linux-android21-clang $BUILD_TOOLS_PATH/x86_64-linux-android-clang
9 |
10 | sed 's|$PWD|'"${ANDROID_NDK_HOME}"'|g' cargo-config.toml.template.new.mac > cargo-config.toml
11 |
--------------------------------------------------------------------------------
/Backend/create-ndk-standalone-ndk-r18.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -eu
4 |
5 | if [ -d NDK ]; then
6 | printf '\033[33;1mStandalone NDK already exists... Delete the NDK folder to make a new one.\033[0m\n\n'
7 | printf ' $ rm -rf NDK\n'
8 | exit 0
9 | fi
10 |
11 | if [ ! -d "${ANDROID_SDK_ROOT-}" ]; then
12 | ANDROID_SDK_ROOT=$ANDROID_SDK
13 | fi
14 | if [ ! -d "${ANDROID_HOME-}" ]; then
15 | ANDROID_HOME="$ANDROID_SDK_ROOT"
16 | fi
17 | if [ ! -d "${ANDROID_NDK_HOME-}" ]; then
18 | ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"
19 | fi
20 | MAKER="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
21 |
22 | if [ -x "$MAKER" ]; then
23 | echo 'Creating standalone NDK...'
24 | else
25 | printf '\033[91;1mPlease install Android NDK!\033[0m\n\n'
26 | printf ' $ sdkmanager ndk-bundle\n\n'
27 | printf "\033[33;1mnote\033[0m: file \033[34;4m$MAKER\033[0m not found.\n"
28 | printf 'If you have installed the NDK in non-standard location, please define the \033[1m$ANDROID_NDK_HOME\033[0m variable.\n'
29 | exit 1
30 | fi
31 |
32 | NDK_STANDALONE_HOME="$HOME/NDK"
33 | if [ -d "$NDK_STANDALONE_HOME" ]; then
34 | rm -rf "$NDK_STANDALONE_HOME"
35 | fi
36 | mkdir "$NDK_STANDALONE_HOME"
37 |
38 | create_ndk() {
39 | echo "($1)..."
40 | "$MAKER" --api "$2" --arch "$1" --install-dir "$NDK_STANDALONE_HOME/$1"
41 | }
42 |
43 | create_ndk arm64 21
44 | create_ndk arm 16
45 | create_ndk x86 16
46 | create_ndk x86_64 21
47 |
48 | ln -s $ANDROID_NDK_HOME/toolchains/llvm $NDK_STANDALONE_HOME/llvm
49 |
50 | FILES=("$NDK_STANDALONE_HOME/arm/bin/arm-linux-androideabi-g++" "$NDK_STANDALONE_HOME/arm/bin/arm-linux-androideabi-gcc" "$NDK_STANDALONE_HOME/arm64/bin/aarch64-linux-android-g++" "$NDK_STANDALONE_HOME/arm64/bin/aarch64-linux-android-gcc" "$NDK_STANDALONE_HOME/x86/bin/i686-linux-android-g++" "$NDK_STANDALONE_HOME/x86/bin/i686-linux-android-gcc")
51 | for file in "${FILES[@]}"; do
52 | cat "$file" | sed -e 's/\/..\/..\/..\/..\//\/..\/..\//' > "$file".edt
53 | mv "$file".edt "$file"
54 | chmod 775 "$file"
55 | done
56 |
57 | echo 'Updating cargo-config.toml...'
58 |
59 | sed 's|$PWD|'"${HOME}"'|g' cargo-config.toml.template > cargo-config.toml
60 |
61 |
--------------------------------------------------------------------------------
/Backend/create-ndk-standalone.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -eu
4 |
5 | if [ -d NDK ]; then
6 | printf '\033[33;1mStandalone NDK already exists... Delete the NDK folder to make a new one.\033[0m\n\n'
7 | printf ' $ rm -rf NDK\n'
8 | exit 0
9 | fi
10 |
11 | if [ ! -d "${ANDROID_SDK_ROOT-}" ]; then
12 | ANDROID_SDK_ROOT=$ANDROID_SDK
13 | fi
14 | if [ ! -d "${ANDROID_HOME-}" ]; then
15 | ANDROID_HOME="$ANDROID_SDK_ROOT"
16 | fi
17 | if [ ! -d "${ANDROID_NDK_HOME-}" ]; then
18 | ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"
19 | fi
20 | MAKER="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
21 |
22 | if [ -x "$MAKER" ]; then
23 | echo 'Creating standalone NDK...'
24 | else
25 | printf '\033[91;1mPlease install Android NDK!\033[0m\n\n'
26 | printf ' $ sdkmanager ndk-bundle\n\n'
27 | printf "\033[33;1mnote\033[0m: file \033[34;4m$MAKER\033[0m not found.\n"
28 | printf 'If you have installed the NDK in non-standard location, please define the \033[1m$ANDROID_NDK_HOME\033[0m variable.\n'
29 | exit 1
30 | fi
31 |
32 |
33 | mkdir "$HOME/NDK"
34 |
35 | create_ndk() {
36 | echo "($1)..."
37 | "$MAKER" --api "$2" --arch "$1" --install-dir "$HOME/NDK/$1"
38 | }
39 |
40 | create_ndk arm64 21
41 | create_ndk arm 16
42 | create_ndk x86 16
43 | create_ndk x86_64 21
44 |
45 | echo 'Updating cargo-config.toml...'
46 |
47 | sed 's|$PWD|'"${HOME}"'|g' cargo-config.toml.template > cargo-config.toml
48 |
49 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Version v0.2.35 (4/4/2016)
2 | ==========================
3 |
4 | * Improve cross compiling from GCC to msvc.
5 | * Fix BCrypt algorithm when using a cost of 31.
6 | * Improve building on OpenBSD.
7 | * Add implementation of SHA3 digest function.
8 | * Fix errors in Blake2b that could lead to incorrect output. The Blake2b
9 | initialization functions are modified to take parameters by value instead of
10 | by reference, which may break users of the interfaces.
11 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rust-crypto"
3 | version = "0.2.41"
4 | authors = ["The Rust-Crypto Project Developers"]
5 | edition = "2018"
6 | license = "MIT/Apache-2.0"
7 | description = "A (mostly) pure-Rust implementation of various common cryptographic algorithms."
8 | keywords = [ "Crypto", "MD5", "Sha1", "Sha2", "AES" ]
9 | readme = "README.md"
10 | build = "build.rs"
11 |
12 | [lib]
13 | name = "crypto"
14 |
15 | [features]
16 | with-bench = []
17 |
18 | [build-dependencies]
19 | cc = "1.0.68"
20 |
21 | [dependencies]
22 | libc = "0.2.97"
23 | time = "0.2.27"
24 | rand = "0.8.4"
25 | rustc-serialize = { version = "0.3.24", path = "../rustc-serialize-0.3.24" }
26 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2006-2009 Graydon Hoare
2 | Copyright (c) 2009-2013 Mozilla Foundation
3 |
4 | Permission is hereby granted, free of charge, to any
5 | person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the
7 | Software without restriction, including without
8 | limitation the rights to use, copy, modify, merge,
9 | publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software
11 | is furnished to do so, subject to the following
12 | conditions:
13 |
14 | The above copyright notice and this permission notice
15 | shall be included in all copies or substantial portions
16 | of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 | DEALINGS IN THE SOFTWARE.
27 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/README.md:
--------------------------------------------------------------------------------
1 | # Rust-Crypto
2 |
3 | [](https://travis-ci.org/DaGenix/rust-crypto)
4 |
5 | A (mostly) pure-Rust implementation of various common cryptographic algorithms.
6 |
7 | Rust-Crypto seeks to create practical, auditable, pure-Rust implementations of common cryptographic
8 | algorithms with a minimum amount of assembly code where appropriate. The x86-64, x86, and
9 | ARM architectures are supported, although the x86-64 architecture receives the most testing.
10 |
11 | Rust-Crypto targets the current, stable build of Rust.
12 | If you are having issues while using an older version, please try upgrading to the latest stable.
13 |
14 | Rust-Crypto has not been thoroughly
15 | audited for correctness, so any use where security is important is not recommended at this time.
16 |
17 | ## Usage
18 |
19 | To use Rust-Crypto, add the following to your Cargo.toml:
20 |
21 | ```toml
22 | [dependencies]
23 | rust-crypto = "^0.2"
24 | ```
25 |
26 | and the following to your crate root:
27 |
28 | ```rust
29 | extern crate crypto;
30 | ```
31 |
32 | ## Contributions
33 |
34 | Contributions are extremely welcome. The most significant needs are help
35 | adding documentation, implementing new algorithms,
36 | and general cleanup and improvement of the code. By submitting a pull request you are agreeing to
37 | make you work available under the license
38 | terms of the Rust-Crypto project.
39 |
40 | ## License
41 |
42 | Rust-Crypto is dual licensed under the MIT and Apache 2.0 licenses, the same licenses
43 | as the Rust compiler.
44 |
45 | ## Algorithms
46 |
47 | Rust-Crypto already supports a significant number of algorithms and with your help
48 | it will support even more in the future. Currently supported algorithms include:
49 |
50 | * AES
51 | * Bcrypt
52 | * Blake2B
53 | * Blowfish
54 | * ChaCha20
55 | * Curve25519
56 | * ECB, CBC, and CTR block cipher modes
57 | * Ed25519
58 | * Fortuna
59 | * Ghash
60 | * HC128
61 | * HMAC
62 | * MD5
63 | * PBKDF2
64 | * PKCS padding for CBC block cipher mode
65 | * Poly1305
66 | * RC4
67 | * RIPEMD-160
68 | * Salsa20 and XSalsa20
69 | * Scrypt
70 | * Sha1
71 | * Sha2 (All fixed output size variants)
72 | * Sosemanuk
73 | * Whirlpool
74 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/appveyor.yml:
--------------------------------------------------------------------------------
1 | clone_depth: 50
2 | environment:
3 | matrix:
4 | - TARGET: nightly-x86_64-pc-windows-msvc
5 | - TARGET: nightly-i686-pc-windows-msvc
6 | - TARGET: nightly-x86_64-pc-windows-gnu
7 | MSYS_BITS: 64
8 | - TARGET: nightly-i686-pc-windows-gnu
9 | MSYS_BITS: 32
10 | - TARGET: beta-x86_64-pc-windows-msvc
11 | - TARGET: beta-i686-pc-windows-msvc
12 | - TARGET: beta-x86_64-pc-windows-gnu
13 | MSYS_BITS: 64
14 | - TARGET: beta-i686-pc-windows-gnu
15 | MSYS_BITS: 32
16 | - TARGET: 1.8.0-x86_64-pc-windows-msvc
17 | - TARGET: 1.8.0-i686-pc-windows-msvc
18 | - TARGET: 1.8.0-x86_64-pc-windows-gnu
19 | MSYS_BITS: 64
20 | - TARGET: 1.8.0-i686-pc-windows-gnu
21 | MSYS_BITS: 32
22 | - TARGET: 1.7.0-x86_64-pc-windows-msvc
23 | - TARGET: 1.7.0-x86_64-pc-windows-gnu
24 | MSYS_BITS: 64
25 | - TARGET: 1.7.0-i686-pc-windows-gnu
26 | MSYS_BITS: 32
27 | - TARGET: 1.6.0-x86_64-pc-windows-msvc
28 | - TARGET: 1.6.0-x86_64-pc-windows-gnu
29 | MSYS_BITS: 64
30 | - TARGET: 1.6.0-i686-pc-windows-gnu
31 | MSYS_BITS: 32
32 | - TARGET: 1.5.0-x86_64-pc-windows-gnu
33 | MSYS_BITS: 64
34 | - TARGET: 1.5.0-i686-pc-windows-gnu
35 | MSYS_BITS: 32
36 | - TARGET: 1.4.0-x86_64-pc-windows-gnu
37 | MSYS_BITS: 64
38 | - TARGET: 1.4.0-i686-pc-windows-gnu
39 | MSYS_BITS: 32
40 | install:
41 | - git submodule update --init --recursive
42 | - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe" -FileName "rust-install.exe"
43 | - ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
44 | - ps: $env:PATH="$env:PATH;C:\rust\bin"
45 | - if defined MSYS_BITS set PATH=C:\msys64\mingw%MSYS_BITS%\bin;C:\msys64\usr\bin;%PATH%
46 | - rustc -vV
47 | - cargo -vV
48 | build_script:
49 | - cargo build
50 | - cargo package
51 | test_script:
52 | - cargo test
53 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/build.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | extern crate cc;
8 |
9 | use std::env;
10 | use std::path::Path;
11 |
12 | fn main()
13 | {
14 | let target = env::var("TARGET").unwrap();
15 | let host = env::var("HOST").unwrap();
16 | if target.contains("msvc") && host.contains("windows")
17 | {
18 | let mut config = cc::Build::new();
19 | config.file("src/util_helpers.asm");
20 | config.file("src/aesni_helpers.asm");
21 | if target.contains("x86_64")
22 | {
23 | config.define("X64", None);
24 | }
25 | config.compile("lib_rust_crypto_helpers.a")
26 | }
27 | else
28 | {
29 | let mut cfg = cc::Build::new();
30 | cfg.file("src/util_helpers.c");
31 | cfg.file("src/aesni_helpers.c");
32 | if env::var_os("CC").is_none()
33 | {
34 | if host.contains("openbsd")
35 | {
36 | // Use clang on openbsd since there have been reports that
37 | // GCC doesn't like some of the assembly that we use on that
38 | // platform.
39 | cfg.compiler(Path::new("clang"));
40 | }
41 | else
42 | {
43 | if target.contains("android")
44 | {
45 | if target.contains("aarch64") { cfg.compiler(Path::new("aarch64-linux-android-clang")); }
46 | else if target.contains("arm") { cfg.compiler(Path::new("arm-linux-androideabi-clang")); }
47 | else if target.contains("i686") { cfg.compiler(Path::new("i686-linux-android-clang")); }
48 | else if target.contains("x86_64") { cfg.compiler(Path::new("x86_64-linux-android-clang")); }
49 | env::set_var("AR", "llvm-ar");
50 | }
51 | else if target.contains("wasm32")
52 | {
53 | env::set_var("CC", "/mnt/PrivateData/formatlibs/wasi-sdk-12.0/bin/clang");
54 | env::set_var("AR", "/mnt/PrivateData/formatlibs/wasi-sdk-12.0/bin/llvm-ar");
55 | cfg.flag("--target=wasm32-wasi");
56 | cfg.flag("--sysroot=/mnt/PrivateData/formatlibs/wasi-sdk-12.0/share/wasi-sysroot");
57 | }
58 | else
59 | {
60 | cfg.compiler(Path::new("cc"));
61 | }
62 | }
63 | }
64 | cfg.compile("lib_rust_crypto_helpers.a");
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/examples/symmetriccipher.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | extern crate crypto;
8 | extern crate rand;
9 |
10 | use crypto::{ symmetriccipher, buffer, aes, blockmodes };
11 | use crypto::buffer::{ ReadBuffer, WriteBuffer, BufferResult };
12 |
13 | use rand::{ Rng, OsRng };
14 |
15 | // Encrypt a buffer with the given key and iv using
16 | // AES-256/CBC/Pkcs encryption.
17 | fn encrypt(data: &[u8], key: &[u8], iv: &[u8]) -> Result, symmetriccipher::SymmetricCipherError> {
18 |
19 | // Create an encryptor instance of the best performing
20 | // type available for the platform.
21 | let mut encryptor = aes::cbc_encryptor(
22 | aes::KeySize::KeySize256,
23 | key,
24 | iv,
25 | blockmodes::PkcsPadding);
26 |
27 | // Each encryption operation encrypts some data from
28 | // an input buffer into an output buffer. Those buffers
29 | // must be instances of RefReaderBuffer and RefWriteBuffer
30 | // (respectively) which keep track of how much data has been
31 | // read from or written to them.
32 | let mut final_result = Vec::::new();
33 | let mut read_buffer = buffer::RefReadBuffer::new(data);
34 | let mut buffer = [0; 4096];
35 | let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer);
36 |
37 | // Each encryption operation will "make progress". "Making progress"
38 | // is a bit loosely defined, but basically, at the end of each operation
39 | // either BufferUnderflow or BufferOverflow will be returned (unless
40 | // there was an error). If the return value is BufferUnderflow, it means
41 | // that the operation ended while wanting more input data. If the return
42 | // value is BufferOverflow, it means that the operation ended because it
43 | // needed more space to output data. As long as the next call to the encryption
44 | // operation provides the space that was requested (either more input data
45 | // or more output space), the operation is guaranteed to get closer to
46 | // completing the full operation - ie: "make progress".
47 | //
48 | // Here, we pass the data to encrypt to the enryptor along with a fixed-size
49 | // output buffer. The 'true' flag indicates that the end of the data that
50 | // is to be encrypted is included in the input buffer (which is true, since
51 | // the input data includes all the data to encrypt). After each call, we copy
52 | // any output data to our result Vec. If we get a BufferOverflow, we keep
53 | // going in the loop since it means that there is more work to do. We can
54 | // complete as soon as we get a BufferUnderflow since the encryptor is telling
55 | // us that it stopped processing data due to not having any more data in the
56 | // input buffer.
57 | loop {
58 | let result = try!(encryptor.encrypt(&mut read_buffer, &mut write_buffer, true));
59 |
60 | // "write_buffer.take_read_buffer().take_remaining()" means:
61 | // from the writable buffer, create a new readable buffer which
62 | // contains all data that has been written, and then access all
63 | // of that data as a slice.
64 | final_result.extend(write_buffer.take_read_buffer().take_remaining().iter().map(|&i| i));
65 |
66 | match result {
67 | BufferResult::BufferUnderflow => break,
68 | BufferResult::BufferOverflow => { }
69 | }
70 | }
71 |
72 | Ok(final_result)
73 | }
74 |
75 | // Decrypts a buffer with the given key and iv using
76 | // AES-256/CBC/Pkcs encryption.
77 | //
78 | // This function is very similar to encrypt(), so, please reference
79 | // comments in that function. In non-example code, if desired, it is possible to
80 | // share much of the implementation using closures to hide the operation
81 | // being performed. However, such code would make this example less clear.
82 | fn decrypt(encrypted_data: &[u8], key: &[u8], iv: &[u8]) -> Result, symmetriccipher::SymmetricCipherError> {
83 | let mut decryptor = aes::cbc_decryptor(
84 | aes::KeySize::KeySize256,
85 | key,
86 | iv,
87 | blockmodes::PkcsPadding);
88 |
89 | let mut final_result = Vec::::new();
90 | let mut read_buffer = buffer::RefReadBuffer::new(encrypted_data);
91 | let mut buffer = [0; 4096];
92 | let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer);
93 |
94 | loop {
95 | let result = try!(decryptor.decrypt(&mut read_buffer, &mut write_buffer, true));
96 | final_result.extend(write_buffer.take_read_buffer().take_remaining().iter().map(|&i| i));
97 | match result {
98 | BufferResult::BufferUnderflow => break,
99 | BufferResult::BufferOverflow => { }
100 | }
101 | }
102 |
103 | Ok(final_result)
104 | }
105 |
106 | fn main() {
107 | let message = "Hello World!";
108 |
109 | let mut key: [u8; 32] = [0; 32];
110 | let mut iv: [u8; 16] = [0; 16];
111 |
112 | // In a real program, the key and iv may be determined
113 | // using some other mechanism. If a password is to be used
114 | // as a key, an algorithm like PBKDF2, Bcrypt, or Scrypt (all
115 | // supported by Rust-Crypto!) would be a good choice to derive
116 | // a password. For the purposes of this example, the key and
117 | // iv are just random values.
118 | let mut rng = OsRng::new().ok().unwrap();
119 | rng.fill_bytes(&mut key);
120 | rng.fill_bytes(&mut iv);
121 |
122 | let encrypted_data = encrypt(message.as_bytes(), &key, &iv).ok().unwrap();
123 | let decrypted_data = decrypt(&encrypted_data[..], &key, &iv).ok().unwrap();
124 |
125 | assert!(message.as_bytes() == &decrypted_data[..]);
126 | }
127 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/aead.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | pub trait AeadEncryptor {
8 |
9 | fn encrypt(&mut self, input: &[u8], output: &mut [u8], tag: &mut [u8]);
10 | }
11 |
12 | pub trait AeadDecryptor {
13 |
14 | fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool;
15 | }
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/aesni_helpers.asm:
--------------------------------------------------------------------------------
1 | ifndef X64
2 | .686p
3 | .XMM
4 | .model flat, C
5 | endif
6 |
7 | .code
8 |
9 | rust_crypto_aesni_aesimc PROC public
10 | ret
11 | rust_crypto_aesni_aesimc ENDP
12 |
13 | rust_crypto_aesni_setup_working_key_128 PROC public
14 | ret
15 | rust_crypto_aesni_setup_working_key_128 ENDP
16 |
17 | rust_crypto_aesni_setup_working_key_192 PROC public
18 | ret
19 | rust_crypto_aesni_setup_working_key_192 ENDP
20 |
21 | rust_crypto_aesni_setup_working_key_256 PROC public
22 | ret
23 | rust_crypto_aesni_setup_working_key_256 ENDP
24 |
25 | rust_crypto_aesni_setup_working_key_512 PROC public
26 | ret
27 | rust_crypto_aesni_setup_working_key_512 ENDP
28 |
29 | rust_crypto_aesni_setup_working_key_1024 PROC public
30 | ret
31 | rust_crypto_aesni_setup_working_key_1024 ENDP
32 |
33 | rust_crypto_aesni_encrypt_block PROC public
34 | ret
35 | rust_crypto_aesni_encrypt_block ENDP
36 |
37 | rust_crypto_aesni_decrypt_block PROC public
38 | ret
39 | rust_crypto_aesni_decrypt_block ENDP
40 |
41 | end
42 |
43 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/api.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | enum DigestSpec {
8 | Md5,
9 | Sha1,
10 | Sha224,
11 | Sha256,
12 | Sha384,
13 | Sha512,
14 | Blake2b,
15 | Ripemd160,
16 | Whirlpool,
17 | }
18 |
19 | enum MacSpec {
20 | Hmac,
21 | }
22 |
23 | enum BlockModeSpec {
24 | Ebc,
25 | Cbc,
26 | Ctr,
27 | }
28 |
29 | enum BlodeModePaddingSpec {
30 | NoPadding,
31 | Pkcs,
32 | }
33 |
34 | enum SymmetricCipherSpec {
35 | Aes,
36 | Des,
37 | Rc4,
38 | Blowfish,
39 | ChaCha20,
40 | Hc128,
41 | Salsa20,
42 | XSalsa20,
43 | Sosemanuk,
44 | }
45 |
46 | enum KdfSpec {
47 | Pbkdf2,
48 | Bcrypt,
49 | Scrypt,
50 | }
51 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/digest.rs:
--------------------------------------------------------------------------------
1 | // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 | // file at the top-level directory of this distribution and at
3 | // http://rust-lang.org/COPYRIGHT.
4 | //
5 | // Licensed under the Apache License, Version 2.0 or the MIT license
7 | // , at your
8 | // option. This file may not be copied, modified, or distributed
9 | // except according to those terms.
10 |
11 | use std::iter::repeat;
12 |
13 | /**
14 | * The Digest trait specifies an interface common to digest functions, such as SHA-1 and the SHA-2
15 | * family of digest functions.
16 | */
17 | pub trait Digest {
18 | /**
19 | * Provide message data.
20 | *
21 | * # Arguments
22 | *
23 | * * input - A vector of message data
24 | */
25 | fn input(&mut self, input: &[u8]);
26 |
27 | /**
28 | * Retrieve the digest result. This method may be called multiple times.
29 | *
30 | * # Arguments
31 | *
32 | * * out - the vector to hold the result. Must be large enough to contain output_bits().
33 | */
34 | fn result(&mut self, out: &mut [u8]);
35 |
36 | /**
37 | * Reset the digest. This method must be called after result() and before supplying more
38 | * data.
39 | */
40 | fn reset(&mut self);
41 |
42 | /**
43 | * Get the output size in bits.
44 | */
45 | fn output_bits(&self) -> usize;
46 |
47 | /**
48 | * Get the output size in bytes.
49 | */
50 | fn output_bytes(&self) -> usize {
51 | (self.output_bits() + 7) / 8
52 | }
53 |
54 | /**
55 | * Get the block size in bytes.
56 | */
57 | fn block_size(&self) -> usize;
58 |
59 | /**
60 | * Convenience function that feeds a string into a digest.
61 | *
62 | * # Arguments
63 | *
64 | * * `input` The string to feed into the digest
65 | */
66 | fn input_str(&mut self, input: &str) {
67 | self.input(input.as_bytes());
68 | }
69 |
70 | /**
71 | * Convenience function that retrieves the result of a digest as a
72 | * String in hexadecimal format.
73 | */
74 | fn result_str(&mut self) -> String {
75 | use serialize::hex::ToHex;
76 |
77 | let mut buf: Vec = repeat(0).take((self.output_bits()+7)/8).collect();
78 | self.result(&mut buf);
79 | buf[..].to_hex()
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/hmac.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | /*!
8 | * This module implements the Hmac function - a Message Authentication Code using a Digest.
9 | */
10 |
11 | use std::iter::repeat;
12 |
13 | use crate::cryptoutil;
14 | use crate::digest::Digest;
15 | use crate::mac::{Mac, MacResult};
16 |
17 | /**
18 | * The Hmac struct represents an Hmac function - a Message Authentication Code using a Digest.
19 | */
20 | pub struct Hmac {
21 | digest: D,
22 | i_key: Vec,
23 | o_key: Vec,
24 | finished: bool
25 | }
26 |
27 | fn derive_key(key: &mut [u8], mask: u8) {
28 | for elem in key.iter_mut() {
29 | *elem ^= mask;
30 | }
31 | }
32 |
33 | // The key that Hmac processes must be the same as the block size of the underlying Digest. If the
34 | // provided key is smaller than that, we just pad it with zeros. If its larger, we hash it and then
35 | // pad it with zeros.
36 | fn expand_key(digest: &mut D, key: &[u8]) -> Vec {
37 | let bs = digest.block_size();
38 | let mut expanded_key: Vec = repeat(0).take(bs).collect();
39 |
40 | if key.len() <= bs {
41 | cryptoutil::copy_memory(key, &mut expanded_key);
42 | } else {
43 | let output_size = digest.output_bytes();
44 | digest.input(key);
45 | digest.result(&mut expanded_key[..output_size]);
46 | digest.reset();
47 | }
48 | expanded_key
49 | }
50 |
51 | // Hmac uses two keys derived from the provided key - one by xoring every byte with 0x36 and another
52 | // with 0x5c.
53 | fn create_keys(digest: &mut D, key: &[u8]) -> (Vec, Vec) {
54 | let mut i_key = expand_key(digest, key);
55 | let mut o_key = i_key.clone();
56 | derive_key(&mut i_key, 0x36);
57 | derive_key(&mut o_key, 0x5c);
58 | (i_key, o_key)
59 | }
60 |
61 | impl Hmac {
62 | /**
63 | * Create a new Hmac instance.
64 | *
65 | * # Arguments
66 | * * digest - The Digest to use.
67 | * * key - The key to use.
68 | *
69 | */
70 | pub fn new(mut digest: D, key: &[u8]) -> Hmac {
71 | let (i_key, o_key) = create_keys(&mut digest, key);
72 | digest.input(&i_key[..]);
73 | Hmac {
74 | digest: digest,
75 | i_key: i_key,
76 | o_key: o_key,
77 | finished: false
78 | }
79 | }
80 | }
81 |
82 | impl Mac for Hmac {
83 | fn input(&mut self, data: &[u8]) {
84 | assert!(!self.finished);
85 | self.digest.input(data);
86 | }
87 |
88 | fn reset(&mut self) {
89 | self.digest.reset();
90 | self.digest.input(&self.i_key[..]);
91 | self.finished = false;
92 | }
93 |
94 | fn result(&mut self) -> MacResult {
95 | let output_size = self.digest.output_bytes();
96 | let mut code: Vec = repeat(0).take(output_size).collect();
97 |
98 | self.raw_result(&mut code);
99 |
100 | MacResult::new_from_owned(code)
101 | }
102 |
103 | fn raw_result(&mut self, output: &mut [u8]) {
104 | if !self.finished {
105 | self.digest.result(output);
106 |
107 | self.digest.reset();
108 | self.digest.input(&self.o_key[..]);
109 | self.digest.input(output);
110 |
111 | self.finished = true;
112 | }
113 |
114 | self.digest.result(output);
115 | }
116 |
117 | fn output_bytes(&self) -> usize { self.digest.output_bytes() }
118 | }
119 |
120 | #[cfg(test)]
121 | mod test {
122 | use std::iter::repeat;
123 |
124 | use mac::{Mac, MacResult};
125 | use hmac::Hmac;
126 | use digest::Digest;
127 | use md5::Md5;
128 |
129 | struct Test {
130 | key: Vec,
131 | data: Vec,
132 | expected: Vec
133 | }
134 |
135 | // Test vectors from: http://tools.ietf.org/html/rfc2104
136 |
137 | fn tests() -> Vec {
138 | vec![
139 | Test {
140 | key: repeat(0x0bu8).take(16).collect(),
141 | data: b"Hi There".to_vec(),
142 | expected: vec![
143 | 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
144 | 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d ]
145 | },
146 | Test {
147 | key: b"Jefe".to_vec(),
148 | data: b"what do ya want for nothing?".to_vec(),
149 | expected: vec![
150 | 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
151 | 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 ]
152 | },
153 | Test {
154 | key: repeat(0xaau8).take(16).collect(),
155 | data: repeat(0xddu8).take(50).collect(),
156 | expected: vec![
157 | 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
158 | 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 ]
159 | }
160 | ]
161 | }
162 |
163 | #[test]
164 | fn test_hmac_md5() {
165 | let tests = tests();
166 | for t in tests.iter() {
167 | let mut hmac = Hmac::new(Md5::new(), &t.key[..]);
168 |
169 | hmac.input(&t.data[..]);
170 | let result = hmac.result();
171 | let expected = MacResult::new(&t.expected[..]);
172 | assert!(result == expected);
173 |
174 | hmac.reset();
175 |
176 | hmac.input(&t.data[..]);
177 | let result2 = hmac.result();
178 | let expected2 = MacResult::new(&t.expected[..]);
179 | assert!(result2 == expected2);
180 | }
181 | }
182 |
183 | #[test]
184 | fn test_hmac_md5_incremental() {
185 | let tests = tests();
186 | for t in tests.iter() {
187 | let mut hmac = Hmac::new(Md5::new(), &t.key[..]);
188 | for i in 0..t.data.len() {
189 | hmac.input(&t.data[i..i + 1]);
190 | }
191 | let result = hmac.result();
192 | let expected = MacResult::new(&t.expected[..]);
193 | assert!(result == expected);
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | #![cfg_attr(feature = "with-bench", feature(test))]
8 |
9 | extern crate rand;
10 | extern crate rustc_serialize as serialize;
11 | extern crate time;
12 | extern crate libc;
13 |
14 | #[cfg(all(test, feature = "with-bench"))]
15 | extern crate test;
16 |
17 | pub mod aead;
18 | pub mod aes;
19 | pub mod aes_gcm;
20 | pub mod aessafe;
21 | pub mod bcrypt;
22 | pub mod bcrypt_pbkdf;
23 | pub mod blake2b;
24 | pub mod blake2s;
25 | pub mod blockmodes;
26 | pub mod blowfish;
27 | pub mod buffer;
28 | pub mod chacha20;
29 | pub mod chacha20poly1305;
30 | mod cryptoutil;
31 | pub mod curve25519;
32 | pub mod digest;
33 | pub mod ed25519;
34 | pub mod fortuna;
35 | pub mod ghash;
36 | pub mod hc128;
37 | pub mod hmac;
38 | pub mod hkdf;
39 | pub mod mac;
40 | pub mod md5;
41 | pub mod pbkdf2;
42 | pub mod poly1305;
43 | pub mod rc4;
44 | pub mod ripemd160;
45 | pub mod salsa20;
46 | pub mod scrypt;
47 | pub mod sha1;
48 | pub mod sha2;
49 | pub mod sha3;
50 | mod simd;
51 | pub mod sosemanuk;
52 | mod step_by;
53 | pub mod symmetriccipher;
54 | pub mod util;
55 | pub mod whirlpool;
56 |
57 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58 | pub mod aesni;
59 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/mac.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | /*!
8 | * The mac module defines the Message Authentication Code (Mac) trait.
9 | */
10 |
11 | use crate::util::fixed_time_eq;
12 |
13 | /**
14 | * The Mac trait defines methods for a Message Authentication function.
15 | */
16 | pub trait Mac {
17 | /**
18 | * Process input data.
19 | *
20 | * # Arguments
21 | * * data - The input data to process.
22 | *
23 | */
24 | fn input(&mut self, data: &[u8]);
25 |
26 | /**
27 | * Reset the Mac state to begin processing another input stream.
28 | */
29 | fn reset(&mut self);
30 |
31 | /**
32 | * Obtain the result of a Mac computation as a MacResult.
33 | */
34 | fn result(&mut self) -> MacResult;
35 |
36 | /**
37 | * Obtain the result of a Mac computation as [u8]. This method should be used very carefully
38 | * since incorrect use of the Mac code could result in permitting a timing attack which defeats
39 | * the security provided by a Mac function.
40 | */
41 | fn raw_result(&mut self, output: &mut [u8]);
42 |
43 | /**
44 | * Get the size of the Mac code, in bytes.
45 | */
46 | fn output_bytes(&self) -> usize;
47 | }
48 |
49 | /**
50 | * A MacResult wraps a Mac code and provides a safe Eq implementation that runs in fixed time.
51 | */
52 | pub struct MacResult {
53 | code: Vec
54 | }
55 |
56 | impl MacResult {
57 | /**
58 | * Create a new MacResult.
59 | */
60 | pub fn new(code: &[u8]) -> MacResult {
61 | MacResult {
62 | code: code.to_vec()
63 | }
64 | }
65 |
66 | /**
67 | * Create a new MacResult taking ownership of the specified code value.
68 | */
69 | pub fn new_from_owned(code: Vec) -> MacResult {
70 | MacResult {
71 | code: code
72 | }
73 | }
74 |
75 | /**
76 | * Get the code value. Be very careful using this method, since incorrect use of the code value
77 | * may permit timing attacks which defeat the security provided by the Mac function.
78 | */
79 | pub fn code<'s>(&'s self) -> &'s [u8] {
80 | &self.code[..]
81 | }
82 | }
83 |
84 | impl PartialEq for MacResult {
85 | fn eq(&self, x: &MacResult) -> bool {
86 | let lhs = self.code();
87 | let rhs = x.code();
88 | fixed_time_eq(lhs, rhs)
89 | }
90 | }
91 |
92 | impl Eq for MacResult { }
93 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/rc4.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | /*!
8 | * An implementation of the RC4 (also sometimes called ARC4) stream cipher. THIS IMPLEMENTATION IS
9 | * NOT A FIXED TIME IMPLEMENTATION.
10 | */
11 |
12 | use crate::buffer::{BufferResult, RefReadBuffer, RefWriteBuffer};
13 | use crate::symmetriccipher::{Encryptor, Decryptor, SynchronousStreamCipher, SymmetricCipherError};
14 | use crate::cryptoutil::symm_enc_or_dec;
15 |
16 | #[derive(Copy)]
17 | pub struct Rc4 {
18 | i: u8,
19 | j: u8,
20 | state: [u8; 256]
21 | }
22 |
23 | impl Clone for Rc4 { fn clone(&self) -> Rc4 { *self } }
24 |
25 | impl Rc4 {
26 | pub fn new(key: &[u8]) -> Rc4 {
27 | assert!(key.len() >= 1 && key.len() <= 256);
28 | let mut rc4 = Rc4 { i: 0, j: 0, state: [0; 256] };
29 | for (i, x) in rc4.state.iter_mut().enumerate() {
30 | *x = i as u8;
31 | }
32 | let mut j: u8 = 0;
33 | for i in 0..256 {
34 | j = j.wrapping_add(rc4.state[i]).wrapping_add(key[i % key.len()]);
35 | rc4.state.swap(i, j as usize);
36 | }
37 | rc4
38 | }
39 | fn next(&mut self) -> u8 {
40 | self.i = self.i.wrapping_add(1);
41 | self.j = self.j.wrapping_add(self.state[self.i as usize]);
42 | self.state.swap(self.i as usize, self.j as usize);
43 | let k = self.state[(self.state[self.i as usize].wrapping_add(self.state[self.j as usize])) as usize];
44 | k
45 | }
46 | }
47 |
48 | impl SynchronousStreamCipher for Rc4 {
49 | fn process(&mut self, input: &[u8], output: &mut [u8]) {
50 | assert!(input.len() == output.len());
51 | for (x, y) in input.iter().zip(output.iter_mut()) {
52 | *y = *x ^ self.next();
53 | }
54 | }
55 | }
56 |
57 | impl Encryptor for Rc4 {
58 | fn encrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, _: bool)
59 | -> Result {
60 | symm_enc_or_dec(self, input, output)
61 | }
62 | }
63 |
64 | impl Decryptor for Rc4 {
65 | fn decrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, _: bool)
66 | -> Result {
67 | symm_enc_or_dec(self, input, output)
68 | }
69 | }
70 |
71 | #[cfg(test)]
72 | mod test {
73 | use std::iter::repeat;
74 |
75 | use symmetriccipher::SynchronousStreamCipher;
76 | use rc4::Rc4;
77 |
78 | struct Test {
79 | key: &'static str,
80 | input: &'static str,
81 | output: Vec
82 | }
83 |
84 | fn tests() -> Vec {
85 | vec![
86 | Test {
87 | key: "Key",
88 | input: "Plaintext",
89 | output: vec![0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3]
90 | },
91 | Test {
92 | key: "Wiki",
93 | input: "pedia",
94 | output: vec![0x10, 0x21, 0xBF, 0x04, 0x20]
95 | },
96 | Test {
97 | key: "Secret",
98 | input: "Attack at dawn",
99 | output: vec![0x45, 0xA0, 0x1F, 0x64, 0x5F, 0xC3, 0x5B,
100 | 0x38, 0x35, 0x52, 0x54, 0x4B, 0x9B, 0xF5]
101 | }
102 | ]
103 | }
104 |
105 | #[test]
106 | fn wikipedia_tests() {
107 | let tests = tests();
108 | for t in tests.iter() {
109 | let mut rc4 = Rc4::new(t.key.as_bytes());
110 | let mut result: Vec = repeat(0).take(t.output.len()).collect();
111 | rc4.process(t.input.as_bytes(), &mut result);
112 | assert!(result == t.output);
113 | }
114 | }
115 | }
116 |
117 | #[cfg(all(test, feature = "with-bench"))]
118 | mod bench {
119 | use test::Bencher;
120 | use symmetriccipher::SynchronousStreamCipher;
121 | use rc4::Rc4;
122 |
123 | #[bench]
124 | pub fn rc4_10(bh: & mut Bencher) {
125 | let mut rc4 = Rc4::new("key".as_bytes());
126 | let input = [1u8; 10];
127 | let mut output = [0u8; 10];
128 | bh.iter( || {
129 | rc4.process(&input, &mut output);
130 | });
131 | bh.bytes = input.len() as u64;
132 | }
133 |
134 | #[bench]
135 | pub fn rc4_1k(bh: & mut Bencher) {
136 | let mut rc4 = Rc4::new("key".as_bytes());
137 | let input = [1u8; 1024];
138 | let mut output = [0u8; 1024];
139 | bh.iter( || {
140 | rc4.process(&input, &mut output);
141 | });
142 | bh.bytes = input.len() as u64;
143 | }
144 |
145 | #[bench]
146 | pub fn rc4_64k(bh: & mut Bencher) {
147 | let mut rc4 = Rc4::new("key".as_bytes());
148 | let input = [1u8; 65536];
149 | let mut output = [0u8; 65536];
150 | bh.iter( || {
151 | rc4.process(&input, &mut output);
152 | });
153 | bh.bytes = input.len() as u64;
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/simd.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | pub use self::fake::*;
8 |
9 | pub trait SimdExt {
10 | fn simd_eq(self, rhs: Self) -> Self;
11 | }
12 |
13 | impl SimdExt for fake::u32x4 {
14 | fn simd_eq(self, rhs: Self) -> Self {
15 | if self == rhs {
16 | fake::u32x4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff)
17 | } else {
18 | fake::u32x4(0, 0, 0, 0)
19 | }
20 | }
21 | }
22 |
23 | mod fake {
24 | use std::ops::{Add, BitAnd, BitOr, BitXor, Shl, Shr, Sub};
25 |
26 | #[derive(Clone, Copy, PartialEq, Eq)]
27 | #[allow(non_camel_case_types)]
28 | pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
29 |
30 | impl Add for u32x4 {
31 | type Output = u32x4;
32 |
33 | fn add(self, rhs: u32x4) -> u32x4 {
34 | u32x4(
35 | self.0.wrapping_add(rhs.0),
36 | self.1.wrapping_add(rhs.1),
37 | self.2.wrapping_add(rhs.2),
38 | self.3.wrapping_add(rhs.3))
39 | }
40 | }
41 |
42 | impl Sub for u32x4 {
43 | type Output = u32x4;
44 |
45 | fn sub(self, rhs: u32x4) -> u32x4 {
46 | u32x4(
47 | self.0.wrapping_sub(rhs.0),
48 | self.1.wrapping_sub(rhs.1),
49 | self.2.wrapping_sub(rhs.2),
50 | self.3.wrapping_sub(rhs.3))
51 | }
52 | }
53 |
54 | impl BitAnd for u32x4 {
55 | type Output = u32x4;
56 |
57 | fn bitand(self, rhs: u32x4) -> u32x4 {
58 | u32x4(self.0 & rhs.0, self.1 & rhs.1, self.2 & rhs.2, self.3 & rhs.3)
59 | }
60 | }
61 |
62 | impl BitOr for u32x4 {
63 | type Output = u32x4;
64 |
65 | fn bitor(self, rhs: u32x4) -> u32x4 {
66 | u32x4(self.0 | rhs.0, self.1 | rhs.1, self.2 | rhs.2, self.3 | rhs.3)
67 | }
68 | }
69 |
70 | impl BitXor for u32x4 {
71 | type Output = u32x4;
72 |
73 | fn bitxor(self, rhs: u32x4) -> u32x4 {
74 | u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3)
75 | }
76 | }
77 |
78 | impl Shl for u32x4 {
79 | type Output = u32x4;
80 |
81 | fn shl(self, amt: usize) -> u32x4 {
82 | u32x4(self.0 << amt, self.1 << amt, self.2 << amt, self.3 << amt)
83 | }
84 | }
85 |
86 | impl Shl for u32x4 {
87 | type Output = u32x4;
88 |
89 | fn shl(self, rhs: u32x4) -> u32x4 {
90 | u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3)
91 | }
92 | }
93 |
94 | impl Shr for u32x4 {
95 | type Output = u32x4;
96 |
97 | fn shr(self, amt: usize) -> u32x4 {
98 | u32x4(self.0 >> amt, self.1 >> amt, self.2 >> amt, self.3 >> amt)
99 | }
100 | }
101 |
102 | impl Shr for u32x4 {
103 | type Output = u32x4;
104 |
105 | fn shr(self, rhs: u32x4) -> u32x4 {
106 | u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3)
107 | }
108 | }
109 |
110 | #[derive(Clone, Copy)]
111 | #[allow(non_camel_case_types)]
112 | pub struct u64x2(pub u64, pub u64);
113 |
114 | impl Add for u64x2 {
115 | type Output = u64x2;
116 |
117 | fn add(self, rhs: u64x2) -> u64x2 {
118 | u64x2(self.0.wrapping_add(rhs.0), self.1.wrapping_add(rhs.1))
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/step_by.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | /// This module just implements a simple verison of step_by() since
8 | /// the function from the standard library is currently unstable.
9 | /// This should be removed once that function becomes stable.
10 |
11 | use std::ops::{Add, Range};
12 |
13 | #[derive(Clone)]
14 | pub struct StepUp {
15 | next: T,
16 | end: T,
17 | ammount: T
18 | }
19 |
20 | impl Iterator for StepUp where
21 | T: Add + PartialOrd + Copy {
22 | type Item = T;
23 |
24 | #[inline]
25 | fn next(&mut self) -> Option {
26 | if self.next < self.end {
27 | let n = self.next;
28 | self.next = self.next + self.ammount;
29 | Some(n)
30 | } else {
31 | None
32 | }
33 | }
34 | }
35 |
36 | pub trait RangeExt {
37 | fn step_up(self, ammount: T) -> StepUp;
38 | }
39 |
40 | impl RangeExt for Range where
41 | T: Add + PartialOrd + Copy {
42 | fn step_up(self, ammount: T) -> StepUp {
43 | StepUp {
44 | next: self.start,
45 | end: self.end,
46 | ammount: ammount
47 | }
48 | }
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/symmetriccipher.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | use crate::buffer::{BufferResult, RefReadBuffer, RefWriteBuffer};
8 | use crate::cryptoutil::symm_enc_or_dec;
9 |
10 | pub trait BlockEncryptor {
11 | fn block_size(&self) -> usize;
12 | fn encrypt_block(&self, input: &[u8], output: &mut [u8]);
13 | }
14 |
15 | pub trait BlockEncryptorX8 {
16 | fn block_size(&self) -> usize;
17 | fn encrypt_block_x8(&self, input: &[u8], output: &mut [u8]);
18 | }
19 |
20 | pub trait BlockDecryptor {
21 | fn block_size(&self) -> usize;
22 | fn decrypt_block(&self, input: &[u8], output: &mut [u8]);
23 | }
24 |
25 | pub trait BlockDecryptorX8 {
26 | fn block_size(&self) -> usize;
27 | fn decrypt_block_x8(&self, input: &[u8], output: &mut [u8]);
28 | }
29 |
30 | #[derive(Debug, Clone, Copy)]
31 | pub enum SymmetricCipherError {
32 | InvalidLength,
33 | InvalidPadding
34 | }
35 |
36 | pub trait Encryptor {
37 | fn encrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, eof: bool)
38 | -> Result;
39 | }
40 |
41 | pub trait Decryptor {
42 | fn decrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, eof: bool)
43 | -> Result;
44 | }
45 |
46 | pub trait SynchronousStreamCipher {
47 | fn process(&mut self, input: &[u8], output: &mut [u8]);
48 | }
49 |
50 | // TODO - Its a bit unclear to me why this is necessary
51 | impl SynchronousStreamCipher for Box {
52 | fn process(&mut self, input: &[u8], output: &mut [u8]) {
53 | let me = &mut **self;
54 | me.process(input, output);
55 | }
56 | }
57 |
58 | impl Encryptor for Box {
59 | fn encrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, _: bool)
60 | -> Result {
61 | symm_enc_or_dec(self, input, output)
62 | }
63 | }
64 |
65 | impl Decryptor for Box {
66 | fn decrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, _: bool)
67 | -> Result {
68 | symm_enc_or_dec(self, input, output)
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/util.rs:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
8 | extern
9 | {
10 | pub fn rust_crypto_util_supports_aesni() -> u32;
11 | }
12 |
13 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
14 | pub fn supports_aesni() -> bool
15 | {
16 | unsafe
17 | {
18 | rust_crypto_util_supports_aesni() != 0
19 | }
20 | // false
21 | }
22 |
23 | extern
24 | {
25 | pub fn rust_crypto_util_fixed_time_eq_asm(lhsp: *const u8, rhsp: *const u8, count: usize) -> u32;
26 | pub fn rust_crypto_util_secure_memset(dst: *mut u8, val: u8, count: usize);
27 | }
28 |
29 | pub fn secure_memset(dst: &mut [u8], val: u8)
30 | {
31 | unsafe
32 | {
33 | rust_crypto_util_secure_memset(dst.as_mut_ptr(), val, dst.len() as usize);
34 | }
35 | }
36 |
37 | /// Compare two vectors using a fixed number of operations. If the two vectors are not of equal
38 | /// length, the function returns false immediately.
39 | pub fn fixed_time_eq(lhs: &[u8], rhs: &[u8]) -> bool
40 | {
41 | if lhs.len() != rhs.len() { false }
42 | else
43 | {
44 | // let count = lhs.len() as libc::size_t;
45 | // unsafe
46 | // {
47 | // let lhsp = lhs.get_unchecked(0);
48 | // let rhsp = rhs.get_unchecked(0);
49 | // rust_crypto_util_fixed_time_eq_asm(lhsp, rhsp, count) == 0
50 | // }
51 | // Replace with...
52 | lhs.iter().zip(rhs).all(|(a, b)| a == b)
53 | }
54 | }
55 |
56 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 |
58 | pub struct OwnedIv
59 | {
60 | base_iv: [u8; 16],
61 | iv: [u8; 16],
62 | pos: usize,
63 | pp: usize, // pinned pos
64 | rev: bool, // ge or le bytes
65 | mm: bool // min or max
66 | }
67 |
68 | impl OwnedIv
69 | {
70 | pub fn new(iv: &[u8; 16]) -> OwnedIv
71 | {
72 | let mut tmp_base_iv: [u8; 16] = [0; 16];
73 | let mut tmp_iv: [u8; 16] = [0; 16];
74 | tmp_base_iv.clone_from_slice(iv);
75 | tmp_iv.clone_from_slice(iv);
76 | let mut sum: usize = 0;
77 | for item in iv.iter() { sum += *item as usize }
78 | let pp: usize = sum % 9;
79 | OwnedIv { base_iv: tmp_base_iv, iv: tmp_iv, pos: pp, pp: pp, rev: false, mm: true }
80 | }
81 |
82 | fn do_magic(&mut self) -> u64
83 | {
84 | // Reset iv
85 | self.iv[self.pos] = self.base_iv[self.pos];
86 | self.iv[self.pos + 1] = self.base_iv[self.pos + 1];
87 | self.iv[self.pos + 2] = self.base_iv[self.pos + 2];
88 | self.iv[self.pos + 3] = self.base_iv[self.pos + 3];
89 | self.iv[self.pos + 4] = self.base_iv[self.pos + 4];
90 | self.iv[self.pos + 5] = self.base_iv[self.pos + 5];
91 | self.iv[self.pos + 6] = self.base_iv[self.pos + 6];
92 | self.iv[self.pos + 7] = self.base_iv[self.pos + 7];
93 |
94 | if self.rev == false
95 | {
96 | if self.pos > 0
97 | {
98 | self.pos -= 1;
99 | if self.pos == self.pp
100 | {
101 | if self.mm == false
102 | {
103 | self.base_iv.reverse();
104 | self.iv.reverse();
105 | }
106 | self.mm = !self.mm
107 | }
108 | }
109 | else { self.rev = true }
110 | }
111 | else
112 | {
113 | if self.pos < 8 { self.pos += 1 }
114 | else { self.rev = false }
115 | }
116 |
117 | let mut eight_bytes: [u8; 8] = [0; 8];
118 | eight_bytes[0] = self.iv[self.pos];
119 | eight_bytes[1] = self.iv[self.pos + 1];
120 | eight_bytes[2] = self.iv[self.pos + 2];
121 | eight_bytes[3] = self.iv[self.pos + 3];
122 | eight_bytes[4] = self.iv[self.pos + 4];
123 | eight_bytes[5] = self.iv[self.pos + 5];
124 | eight_bytes[6] = self.iv[self.pos + 6];
125 | eight_bytes[7] = self.iv[self.pos + 7];
126 |
127 | if !self.rev { u64::from_le_bytes(eight_bytes) }
128 | else { u64::from_be_bytes(eight_bytes) }
129 | }
130 |
131 | pub fn next_iv(&mut self) -> &[u8; 16]
132 | {
133 | let mut eight_bytes: [u8; 8] = [0; 8];
134 | eight_bytes[0] = self.iv[self.pos];
135 | eight_bytes[1] = self.iv[self.pos + 1];
136 | eight_bytes[2] = self.iv[self.pos + 2];
137 | eight_bytes[3] = self.iv[self.pos + 3];
138 | eight_bytes[4] = self.iv[self.pos + 4];
139 | eight_bytes[5] = self.iv[self.pos + 5];
140 | eight_bytes[6] = self.iv[self.pos + 6];
141 | eight_bytes[7] = self.iv[self.pos + 7];
142 |
143 | let mut tmp: u64;
144 | if self.rev == false { tmp = u64::from_le_bytes(eight_bytes) }
145 | else { tmp = u64::from_be_bytes(eight_bytes) }
146 |
147 | if self.mm { if tmp == u64::MAX - 1 { tmp = self.do_magic() } }
148 | else { if tmp == u64::MIN + 1 { tmp = self.do_magic() } }
149 |
150 | if self.mm { tmp += 1 }
151 | else { tmp -= 1 }
152 |
153 | if !self.rev { eight_bytes = tmp.to_le_bytes() }
154 | else { eight_bytes = tmp.to_be_bytes() }
155 |
156 | self.iv[self.pos] = eight_bytes[0];
157 | self.iv[self.pos + 1] = eight_bytes[1];
158 | self.iv[self.pos + 2] = eight_bytes[2];
159 | self.iv[self.pos + 3] = eight_bytes[3];
160 | self.iv[self.pos + 4] = eight_bytes[4];
161 | self.iv[self.pos + 5] = eight_bytes[5];
162 | self.iv[self.pos + 6] = eight_bytes[6];
163 | self.iv[self.pos + 7] = eight_bytes[7];
164 |
165 | &self.iv
166 | }
167 | }
168 |
169 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
170 |
171 | #[cfg(test)]
172 | mod test {
173 | use util::fixed_time_eq;
174 |
175 | #[test]
176 | pub fn test_fixed_time_eq() {
177 | let a = [0, 1, 2];
178 | let b = [0, 1, 2];
179 | let c = [0, 1, 9];
180 | let d = [9, 1, 2];
181 | let e = [2, 1, 0];
182 | let f = [2, 2, 2];
183 | let g = [0, 0, 0];
184 |
185 | assert!(fixed_time_eq(&a, &a));
186 | assert!(fixed_time_eq(&a, &b));
187 |
188 | assert!(!fixed_time_eq(&a, &c));
189 | assert!(!fixed_time_eq(&a, &d));
190 | assert!(!fixed_time_eq(&a, &e));
191 | assert!(!fixed_time_eq(&a, &f));
192 | assert!(!fixed_time_eq(&a, &g));
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/util_helpers.asm:
--------------------------------------------------------------------------------
1 | ifndef X64
2 | .686p
3 | .XMM
4 | .model flat, C
5 | endif
6 |
7 | .code
8 |
9 | rust_crypto_util_supports_aesni PROC public
10 | ; Return false since the AES-NI function have not been
11 | ; converted to assembly
12 | xor eax, eax
13 | ret
14 | rust_crypto_util_supports_aesni ENDP
15 |
16 | ; The rust_crypto_util_fixed_time_eq_asm for X86-64
17 | ifdef X64
18 | rust_crypto_util_fixed_time_eq_asm PROC public lhs:QWORD, rhs:QWORD, count:QWORD
19 | ; lhs is in RCX
20 | ; rhs is in RDX
21 | ; count is in R8
22 |
23 | ; set the return value initially to 0
24 | xor eax, eax
25 |
26 | test r8, r8
27 | jz DONE
28 |
29 | BEGIN:
30 |
31 | mov r10b, [rcx]
32 | xor r10b, [rdx]
33 | or al, r10b
34 |
35 | inc rcx
36 | inc rdx
37 | dec r8
38 | jnz BEGIN
39 |
40 | DONE:
41 |
42 | ret
43 | rust_crypto_util_fixed_time_eq_asm ENDP
44 | endif
45 |
46 | ; The rust_crypto_util_fixed_time_eq_asm for X86 (32-bit)
47 | ifndef X64
48 | rust_crypto_util_fixed_time_eq_asm PROC public lhs:DWORD, rhs:DWORD, count:DWORD
49 | push ebx
50 | push esi
51 |
52 | mov ecx, lhs
53 | mov edx, rhs
54 | mov esi, count
55 |
56 | xor eax, eax
57 |
58 | test esi, esi
59 | jz DONE
60 |
61 | BEGIN:
62 |
63 | mov bl, [ecx]
64 | xor bl, [edx]
65 | or al, bl
66 |
67 | inc ecx
68 | inc edx
69 | dec esi
70 | jnz BEGIN
71 |
72 | DONE:
73 |
74 | pop esi
75 | pop ebx
76 |
77 | ret
78 | rust_crypto_util_fixed_time_eq_asm ENDP
79 | endif
80 |
81 | ifdef X64
82 | rust_crypto_util_secure_memset PROC public dst:QWORD, val:BYTE, count:QWORD
83 | ; dst is in RCX
84 | ; val is in RDX
85 | ; count is in R8
86 |
87 | test r8, r8
88 | jz DONE
89 |
90 | BEGIN:
91 |
92 | mov [rcx], dl
93 | inc rcx
94 | dec r8
95 | jnz BEGIN
96 |
97 | DONE:
98 |
99 | ret
100 | rust_crypto_util_secure_memset ENDP
101 | endif
102 |
103 | ifndef X64
104 | rust_crypto_util_secure_memset PROC public dst:DWORD, val:BYTE, count:DWORD
105 | mov eax, dst
106 | mov cl, val
107 | mov edx, count
108 |
109 | test edx, edx
110 | jz DONE
111 |
112 | BEGIN:
113 |
114 | mov [eax], cl
115 | inc eax
116 | dec edx
117 | jnz BEGIN
118 |
119 | DONE:
120 |
121 | ret
122 | rust_crypto_util_secure_memset ENDP
123 | endif
124 |
125 | end
126 |
127 |
--------------------------------------------------------------------------------
/Backend/libs/rust-crypto-0.2.41/src/util_helpers.c:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 or the MIT license
3 | // , at your
4 | // option. This file may not be copied, modified, or distributed
5 | // except according to those terms.
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #if defined(__i386__)
12 | uint32_t rust_crypto_util_supports_aesni() {
13 | #ifdef __SSE__
14 | uint32_t flags;
15 | asm(
16 | "pushl %%ebx; \
17 | mov $1, %%eax; cpuid; \
18 | popl %%ebx;"
19 | : "=c" (flags) // output
20 | : // input
21 | : "eax", "edx" // clobbers
22 | );
23 | return flags & 0x02000000;
24 | #else
25 | return 0;
26 | #endif
27 | }
28 | #endif
29 |
30 | #if defined(__x86_64__)
31 | uint32_t rust_crypto_util_supports_aesni() {
32 | #ifdef __SSE__
33 | uint32_t flags;
34 | asm(
35 | "mov $1, %%eax; cpuid;"
36 | : "=c" (flags) // output
37 | : // input
38 | : "eax", "ebx", "edx" // clobbers
39 | );
40 | return flags & 0x02000000;
41 | #else
42 | return 0;
43 | #endif
44 | }
45 | #endif
46 |
47 | #if defined(__i386__) || defined(__x86_64__)
48 | uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) {
49 | if (count == 0) {
50 | return 1;
51 | }
52 | uint8_t result = 0;
53 | asm(
54 | " \
55 | 1: \
56 | \
57 | mov (%1), %%cl; \
58 | xor (%2), %%cl; \
59 | or %%cl, %0; \
60 | \
61 | inc %1; \
62 | inc %2; \
63 | dec %3; \
64 | jnz 1b; \
65 | "
66 | : "+&r" (result), "+&r" (lhsp), "+&r" (rhsp), "+&r" (count) // all input and output
67 | : // input
68 | : "cl", "cc" // clobbers
69 | );
70 |
71 | return result;
72 | }
73 | #endif
74 |
75 | #ifdef __arm__
76 | uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) {
77 | if (count == 0) {
78 | return 1;
79 | }
80 | uint8_t result = 0;
81 | asm(
82 | " \
83 | 1: \
84 | \
85 | ldrb r4, [%1]; \
86 | ldrb r5, [%2]; \
87 | eor r4, r4, r5; \
88 | orr %0, %0, r4; \
89 | \
90 | add %1, %1, #1; \
91 | add %2, %2, #1; \
92 | subs %3, %3, #1; \
93 | bne 1b; \
94 | "
95 | : "+&r" (result), "+&r" (lhsp), "+&r" (rhsp), "+&r" (count) // all input and output
96 | : // input
97 | : "r4", "r5", "cc" // clobbers
98 | );
99 |
100 | return result;
101 | }
102 | #endif
103 |
104 | /*#ifdef __aarch64__
105 | uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) {
106 | if (count == 0) {
107 | return 1;
108 | }
109 | uint8_t result = 0;
110 | asm(
111 | " \
112 | 1: \
113 | \
114 | ldrb w4, [%1]; \
115 | ldrb w5, [%2]; \
116 | eor w4, w4, w5; \
117 | orr %w0, %w0, w4; \
118 | \
119 | add %w1, %w1, #1; \
120 | add %w2, %w2, #1; \
121 | subs %w3, %w3, #1; \
122 | bne 1b; \
123 | "
124 | : "+&r" (result), "+&r" (lhsp), "+&r" (rhsp), "+&r" (count) // all input and output
125 | : // input
126 | : "w4", "w5", "cc" // clobbers
127 | );
128 |
129 | return result;
130 | }
131 | #endif*/
132 |
133 | void rust_crypto_util_secure_memset(uint8_t* dst, uint8_t val, size_t count) {
134 | memset(dst, val, count);
135 | asm volatile("" : : "g" (dst) : "memory");
136 | }
137 |
138 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/.cargo-ok:
--------------------------------------------------------------------------------
1 | ok
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/.travis.yml:
--------------------------------------------------------------------------------
1 | language: rust
2 | rust:
3 | - 1.0.0
4 | - stable
5 | - beta
6 | - nightly
7 | sudo: false
8 | before_script:
9 | - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
10 | script:
11 | - cargo build --verbose
12 | - cargo test --verbose
13 | - cargo doc --no-deps
14 | after_success:
15 | - travis-cargo --only nightly doc-upload
16 | env:
17 | global:
18 | secure: "kJnqqAXRl0C7Afx0c8Y3vA6TAEZsxlasu7eIZMdCbNS4N1+Rwh0jNTa2jy2D3CQCrzW5OCefnkpkPTu8mADrAjedM4p/9X5UXZi0sgg2lzCgfGwrRzitTnyPDkdYidiu4QeC/r0WPC8lYZKHkJXYhF8bZgchB9ypnZ6LAHCcDkA="
19 |
20 |
21 |
22 | notifications:
23 | email:
24 | on_success: never
25 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 |
3 | name = "rustc-serialize"
4 | version = "0.3.24"
5 | authors = ["The Rust Project Developers"]
6 | license = "MIT/Apache-2.0"
7 | readme = "README.md"
8 | repository = "https://github.com/rust-lang/rustc-serialize"
9 | homepage = "https://github.com/rust-lang/rustc-serialize"
10 | documentation = "https://doc.rust-lang.org/rustc-serialize"
11 | description = """
12 | Generic serialization/deserialization support corresponding to the
13 | `derive(RustcEncodable, RustcDecodable)` mode in the compiler. Also includes
14 | support for hex, base64, and json encoding and decoding.
15 | """
16 |
17 | [dev-dependencies]
18 | rand = "0.7.3"
19 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 The Rust Project Developers
2 |
3 | Permission is hereby granted, free of charge, to any
4 | person obtaining a copy of this software and associated
5 | documentation files (the "Software"), to deal in the
6 | Software without restriction, including without
7 | limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software
10 | is furnished to do so, subject to the following
11 | conditions:
12 |
13 | The above copyright notice and this permission notice
14 | shall be included in all copies or substantial portions
15 | of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | DEALINGS IN THE SOFTWARE.
26 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/README.md:
--------------------------------------------------------------------------------
1 | # rustc-serialize
2 |
3 | > **NOTE**: This crate is deprecated in favor of [`serde`]. No new feature
4 | > development will happen in this crate, although bug fixes proposed through PRs
5 | > will still be merged. It is very highly recommended by the Rust Library Team
6 | > that you use [`serde`], not this crate.
7 |
8 | [`serde`]: https://serde.rs
9 |
10 | Serialization and deserialization support provided by the compiler in the form
11 | of `derive(RustcEncodable, RustcDecodable)`.
12 |
13 | [](https://travis-ci.org/rust-lang-nursery/rustc-serialize)
14 | [](https://ci.appveyor.com/project/alexcrichton/rustc-serialize)
15 |
16 | [Documentation](https://doc.rust-lang.org/rustc-serialize)
17 |
18 | ## Usage
19 |
20 | Add this to your `Cargo.toml`:
21 |
22 | ```toml
23 | [dependencies]
24 | rustc-serialize = "0.3"
25 | ```
26 |
27 | and this to your crate root:
28 |
29 | ```rust
30 | extern crate rustc_serialize;
31 | ```
32 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/appveyor.yml:
--------------------------------------------------------------------------------
1 | environment:
2 | matrix:
3 | - TARGET: x86_64-pc-windows-msvc
4 | - TARGET: i686-pc-windows-msvc
5 | - TARGET: i686-pc-windows-gnu
6 | install:
7 | - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.exe"
8 | - rust-nightly-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
9 | - SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
10 | - SET PATH=%PATH%;C:\MinGW\bin
11 | - rustc -V
12 | - cargo -V
13 |
14 | build: false
15 |
16 | test_script:
17 | - cargo test --verbose
18 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/benches/base64.rs:
--------------------------------------------------------------------------------
1 | #![feature(test)]
2 |
3 | extern crate test;
4 | extern crate rustc_serialize;
5 |
6 | use rustc_serialize::base64::{FromBase64, ToBase64, STANDARD};
7 | use test::Bencher;
8 |
9 | #[bench]
10 | fn bench_to_base64(b: &mut Bencher) {
11 | let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
12 | ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
13 | b.iter(|| {
14 | s.as_bytes().to_base64(STANDARD);
15 | });
16 | b.bytes = s.len() as u64;
17 | }
18 |
19 | #[bench]
20 | fn bench_from_base64(b: &mut Bencher) {
21 | let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
22 | ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
23 | let sb = s.as_bytes().to_base64(STANDARD);
24 | b.iter(|| {
25 | sb.from_base64().unwrap();
26 | });
27 | b.bytes = sb.len() as u64;
28 | }
29 |
30 |
31 | #[bench]
32 | fn bench_to_base64_large(b: &mut Bencher) {
33 | let s: Vec<_> = (0..10000).map(|i| ((i as u32 * 12345) % 256) as u8).collect();
34 | b.iter(|| {
35 | s.to_base64(STANDARD);
36 | });
37 | b.bytes = s.len() as u64;
38 | }
39 |
40 | #[bench]
41 | fn bench_from_base64_large(b: &mut Bencher) {
42 | let s: Vec<_> = (0..10000).map(|i| ((i as u32 * 12345) % 256) as u8).collect();
43 | let sb = s.to_base64(STANDARD);
44 | b.iter(|| {
45 | sb.from_base64().unwrap();
46 | });
47 | b.bytes = sb.len() as u64;
48 | }
49 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/benches/hex.rs:
--------------------------------------------------------------------------------
1 | #![feature(test)]
2 |
3 | extern crate test;
4 | extern crate rustc_serialize;
5 |
6 | use test::Bencher;
7 | use rustc_serialize::hex::{FromHex, ToHex};
8 |
9 | #[bench]
10 | fn bench_to_hex(b: &mut Bencher) {
11 | let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
12 | ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
13 | b.iter(|| {
14 | s.as_bytes().to_hex();
15 | });
16 | b.bytes = s.len() as u64;
17 | }
18 |
19 | #[bench]
20 | fn bench_from_hex(b: &mut Bencher) {
21 | let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
22 | ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
23 | let sb = s.as_bytes().to_hex();
24 | b.iter(|| {
25 | sb.from_hex().unwrap();
26 | });
27 | b.bytes = sb.len() as u64;
28 | }
29 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/benches/json.rs:
--------------------------------------------------------------------------------
1 | #![feature(test)]
2 |
3 | extern crate test;
4 | extern crate rustc_serialize;
5 |
6 | use std::string;
7 | use rustc_serialize::json::{Json, Parser};
8 | use test::Bencher;
9 |
10 | #[bench]
11 | fn bench_streaming_small(b: &mut Bencher) {
12 | b.iter( || {
13 | let mut parser = Parser::new(
14 | r#"{
15 | "a": 1.0,
16 | "b": [
17 | true,
18 | "foo\nbar",
19 | { "c": {"d": null} }
20 | ]
21 | }"#.chars()
22 | );
23 | loop {
24 | match parser.next() {
25 | None => return,
26 | _ => {}
27 | }
28 | }
29 | });
30 | }
31 | #[bench]
32 | fn bench_small(b: &mut Bencher) {
33 | b.iter( || {
34 | let _ = Json::from_str(r#"{
35 | "a": 1.0,
36 | "b": [
37 | true,
38 | "foo\nbar",
39 | { "c": {"d": null} }
40 | ]
41 | }"#);
42 | });
43 | }
44 |
45 | #[bench]
46 | fn bench_decode_hex_escape(b: &mut Bencher) {
47 | let mut src = "\"".to_string();
48 | for _ in 0..10 {
49 | src.push_str("\\uF975\\uf9bc\\uF9A0\\uF9C4\\uF975\\uf9bc\\uF9A0\\uF9C4");
50 | }
51 | src.push_str("\"");
52 | b.iter( || {
53 | let _ = Json::from_str(&src);
54 | });
55 | }
56 |
57 | fn big_json() -> string::String {
58 | let mut src = "[\n".to_string();
59 | for _ in 0..500 {
60 | src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
61 | [1,2,3]},"#);
62 | }
63 | src.push_str("{}]");
64 | return src;
65 | }
66 |
67 | #[bench]
68 | fn bench_streaming_large(b: &mut Bencher) {
69 | let src = big_json();
70 | b.iter( || {
71 | let mut parser = Parser::new(src.chars());
72 | loop {
73 | match parser.next() {
74 | None => return,
75 | _ => {}
76 | }
77 | }
78 | });
79 | }
80 | #[bench]
81 | fn bench_large(b: &mut Bencher) {
82 | let src = big_json();
83 | b.iter( || { let _ = Json::from_str(&src); });
84 | }
85 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/src/collection_impls.rs:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 | // file at the top-level directory of this distribution and at
3 | // http://rust-lang.org/COPYRIGHT.
4 | //
5 | // Licensed under the Apache License, Version 2.0 or the MIT license
7 | // , at your
8 | // option. This file may not be copied, modified, or distributed
9 | // except according to those terms.
10 |
11 | //! Implementations of serialization for structures found in libcollections
12 |
13 | use std::hash::Hash;
14 |
15 | use {Decodable, Encodable, Decoder, Encoder, cap_capacity};
16 | use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet};
17 |
18 | impl<
19 | T: Encodable
20 | > Encodable for LinkedList {
21 | fn encode(&self, s: &mut S) -> Result<(), S::Error> {
22 | s.emit_seq(self.len(), |s| {
23 | for (i, e) in self.iter().enumerate() {
24 | s.emit_seq_elt(i, |s| e.encode(s))?;
25 | }
26 | Ok(())
27 | })
28 | }
29 | }
30 |
31 | impl Decodable for LinkedList {
32 | fn decode(d: &mut D) -> Result, D::Error> {
33 | d.read_seq(|d, len| {
34 | let mut list = LinkedList::new();
35 | for i in 0..len {
36 | list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?);
37 | }
38 | Ok(list)
39 | })
40 | }
41 | }
42 |
43 | impl Encodable for VecDeque {
44 | fn encode(&self, s: &mut S) -> Result<(), S::Error> {
45 | s.emit_seq(self.len(), |s| {
46 | for (i, e) in self.iter().enumerate() {
47 | s.emit_seq_elt(i, |s| e.encode(s))?;
48 | }
49 | Ok(())
50 | })
51 | }
52 | }
53 |
54 | impl Decodable for VecDeque {
55 | fn decode(d: &mut D) -> Result, D::Error> {
56 | d.read_seq(|d, len| {
57 | let mut deque: VecDeque = VecDeque::new();
58 | for i in 0..len {
59 | deque.push_back(d.read_seq_elt(i, |d| Decodable::decode(d))?);
60 | }
61 | Ok(deque)
62 | })
63 | }
64 | }
65 |
66 | impl<
67 | K: Encodable + Ord,
68 | V: Encodable
69 | > Encodable for BTreeMap {
70 | fn encode(&self, e: &mut S) -> Result<(), S::Error> {
71 | e.emit_map(self.len(), |e| {
72 | let mut i = 0;
73 | for (key, val) in self.iter() {
74 | e.emit_map_elt_key(i, |e| key.encode(e))?;
75 | e.emit_map_elt_val(i, |e| val.encode(e))?;
76 | i += 1;
77 | }
78 | Ok(())
79 | })
80 | }
81 | }
82 |
83 | impl<
84 | K: Decodable + Ord,
85 | V: Decodable
86 | > Decodable for BTreeMap {
87 | fn decode(d: &mut D) -> Result, D::Error> {
88 | d.read_map(|d, len| {
89 | let mut map = BTreeMap::new();
90 | for i in 0..len {
91 | let key = d.read_map_elt_key(i, |d| Decodable::decode(d))?;
92 | let val = d.read_map_elt_val(i, |d| Decodable::decode(d))?;
93 | map.insert(key, val);
94 | }
95 | Ok(map)
96 | })
97 | }
98 | }
99 |
100 | impl<
101 | T: Encodable + Ord
102 | > Encodable for BTreeSet {
103 | fn encode(&self, s: &mut S) -> Result<(), S::Error> {
104 | s.emit_seq(self.len(), |s| {
105 | let mut i = 0;
106 | for e in self.iter() {
107 | s.emit_seq_elt(i, |s| e.encode(s))?;
108 | i += 1;
109 | }
110 | Ok(())
111 | })
112 | }
113 | }
114 |
115 | impl<
116 | T: Decodable + Ord
117 | > Decodable for BTreeSet {
118 | fn decode(d: &mut D) -> Result, D::Error> {
119 | d.read_seq(|d, len| {
120 | let mut set = BTreeSet::new();
121 | for i in 0..len {
122 | set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))?);
123 | }
124 | Ok(set)
125 | })
126 | }
127 | }
128 |
129 | impl Encodable for HashMap
130 | where K: Encodable + Hash + Eq,
131 | V: Encodable,
132 | {
133 | fn encode(&self, e: &mut E) -> Result<(), E::Error> {
134 | e.emit_map(self.len(), |e| {
135 | let mut i = 0;
136 | for (key, val) in self.iter() {
137 | e.emit_map_elt_key(i, |e| key.encode(e))?;
138 | e.emit_map_elt_val(i, |e| val.encode(e))?;
139 | i += 1;
140 | }
141 | Ok(())
142 | })
143 | }
144 | }
145 |
146 | impl Decodable for HashMap
147 | where K: Decodable + Hash + Eq,
148 | V: Decodable,
149 | {
150 | fn decode(d: &mut D) -> Result, D::Error> {
151 | d.read_map(|d, len| {
152 | let mut map = HashMap::with_capacity(cap_capacity::<(K, V)>(len));
153 | for i in 0..len {
154 | let key = d.read_map_elt_key(i, |d| Decodable::decode(d))?;
155 | let val = d.read_map_elt_val(i, |d| Decodable::decode(d))?;
156 | map.insert(key, val);
157 | }
158 | Ok(map)
159 | })
160 | }
161 | }
162 |
163 | impl Encodable for HashSet where T: Encodable + Hash + Eq {
164 | fn encode(&self, s: &mut E) -> Result<(), E::Error> {
165 | s.emit_seq(self.len(), |s| {
166 | let mut i = 0;
167 | for e in self.iter() {
168 | s.emit_seq_elt(i, |s| e.encode(s))?;
169 | i += 1;
170 | }
171 | Ok(())
172 | })
173 | }
174 | }
175 |
176 | impl Decodable for HashSet where T: Decodable + Hash + Eq, {
177 | fn decode(d: &mut D) -> Result, D::Error> {
178 | d.read_seq(|d, len| {
179 | let mut set = HashSet::with_capacity(cap_capacity::(len));
180 | for i in 0..len {
181 | set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))?);
182 | }
183 | Ok(set)
184 | })
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/Backend/libs/rustc-serialize-0.3.24/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 | // file at the top-level directory of this distribution and at
3 | // http://rust-lang.org/COPYRIGHT.
4 | //
5 | // Licensed under the Apache License, Version 2.0 or the MIT license
7 | // , at your
8 | // option. This file may not be copied, modified, or distributed
9 | // except according to those terms.
10 |
11 | //! Support code for encoding and decoding types.
12 | //!
13 | //! > **NOTE**: This crate is deprecated in favor of [`serde`]. No new feature
14 | //! > development will happen in this crate, although bug fixes proposed through
15 | //! > PRs will still be merged. It is very highly recommended by the Rust
16 | //! > Library Team that you use [`serde`], not this crate.
17 | //!
18 | //! [`serde`]: https://serde.rs
19 | //!
20 | //! # Usage
21 | //!
22 | //! This crate is [on crates.io](https://crates.io/crates/rustc-serialize) and
23 | //! can be used by adding `rustc-serialize` to the dependencies in your
24 | //! project's `Cargo.toml`.
25 | //!
26 | //! ```toml
27 | //! [dependencies]
28 | //! rustc-serialize = "0.3"
29 | //! ```
30 | //!
31 | //! and this to your crate root:
32 | //!
33 | //! ```rust
34 | //! extern crate rustc_serialize;
35 | //! ```
36 |
37 | #![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
38 | #![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
39 |
40 | #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
41 | html_favicon_url = "https://www.rust-lang.org/favicon.ico",
42 | html_root_url = "https://doc.rust-lang.org/rustc-serialize/")]
43 | #![cfg_attr(test, deny(warnings))]
44 | #![allow(trivial_numeric_casts)]
45 | #![cfg_attr(rust_build, feature(staged_api))]
46 | #![cfg_attr(rust_build, staged_api)]
47 | #![cfg_attr(rust_build,
48 | unstable(feature = "rustc_private",
49 | reason = "use the crates.io `rustc-serialize` library instead"))]
50 |
51 | #[cfg(test)] extern crate rand;
52 |
53 | pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
54 | DecoderHelpers, EncoderHelpers};
55 |
56 |
57 | // Limit collections from allocating more than
58 | // 1 MB for calls to `with_capacity`.
59 | fn cap_capacity(given_len: usize) -> usize {
60 | use std::cmp::min;
61 | use std::mem::size_of;
62 | const PRE_ALLOCATE_CAP: usize = 0x100000;
63 |
64 | match size_of::() {
65 | 0 => min(given_len, PRE_ALLOCATE_CAP),
66 | n => min(given_len, PRE_ALLOCATE_CAP / n)
67 | }
68 | }
69 |
70 | mod serialize;
71 | mod collection_impls;
72 |
73 | pub mod base64;
74 | pub mod hex;
75 | pub mod json;
76 |
77 | mod rustc_serialize {
78 | pub use serialize::*;
79 | }
80 |
--------------------------------------------------------------------------------
/Backend/rust_crypto/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rust_crypto"
3 | version = "0.1.3"
4 | authors = ["tungthanhnguyen"]
5 | edition = "2018"
6 | publish = false
7 |
8 | [dependencies]
9 | rand = "0.8.4"
10 | #rand = { version = "0.7.3", features = ["wasm-bindgen"] }
11 | rust-crypto = { version = "0.2.41", path = "../libs/rust-crypto-0.2.41" }
12 | rustc-serialize = { version = "0.3.24", path = "../libs/rustc-serialize-0.3.24" }
13 |
14 | [target.'cfg(target_os="android")'.dependencies]
15 | jni = { version = "0.19.0", default-features = false }
16 |
17 | [lib]
18 | name = "rust_crypto"
19 | crate-type = ["staticlib", "cdylib", "rlib"]
20 |
--------------------------------------------------------------------------------
/Backend/rust_crypto/src/rust_crypto.h:
--------------------------------------------------------------------------------
1 | #ifndef __RUST_CRYPTO_H_
2 | #define __RUST_CRYPTO_H_
3 |
4 | #if __cplusplus
5 | extern "C"
6 | {
7 | #endif
8 |
9 | const char* rust_encrypt(const char* pub_key, const char* msg);
10 | const char* rust_decrypt(const char* pri_key, const char* msg);
11 |
12 | #if __cplusplus
13 | }
14 | #endif
15 |
16 | #endif /* __RUST_CRYPTO_H_ */
17 |
--------------------------------------------------------------------------------
/Console/cscrypto_2.1.2/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "cscrypto"
3 | version = "2.1.2"
4 | authors = ["tungthanhnguyen"]
5 | edition = "2018"
6 |
7 | [profile.release]
8 | opt-level = 3
9 | debug = false
10 | rpath = false
11 | lto = false
12 | debug-assertions = false
13 | codegen-units = 16
14 | panic = 'unwind'
15 | incremental = false
16 | overflow-checks = false
17 |
18 | [dependencies]
19 | alloc-no-stdlib = "2.0.1"
20 | brotli = "3.3.0"
21 | clap = "2.33.3"
22 | num = "0.4.0"
23 | num_cpus = "1.13.0"
24 | rand = "0.8.4"
25 | rust-crypto = { version = "0.2.41", path = "../../Backend/libs/rust-crypto-0.2.41" }
26 | rustc-serialize = { version = "0.3.24", path = "../../Backend/libs/rustc-serialize-0.3.24" }
27 | rust_crypto = { version = "0.1.3", path = "../../Backend/rust_crypto" }
28 |
--------------------------------------------------------------------------------
/Console/cscrypto_2.1.2/README.md:
--------------------------------------------------------------------------------
1 | To build
2 | -----
3 |
4 | ```sh
5 | cargo build --release
6 | ```
7 |
8 | To run
9 | -----
10 |
11 | ```sh
12 | cargo run --release help # to print usage
13 | ```
14 |
--------------------------------------------------------------------------------
/Desktop/MainFrame.cpp:
--------------------------------------------------------------------------------
1 | #include "MainFrame.h"
2 |
3 | #include "../Backend/rust_crypto/src/rust_crypto.h"
4 |
5 | wxBEGIN_EVENT_TABLE(CMainFrame, wxFrame)
6 | EVT_MENU(wxID_EXIT, CMainFrame::OnQuit)
7 | EVT_BUTTON(ID_Action, CMainFrame::OnAction)
8 | wxEND_EVENT_TABLE()
9 |
10 | CMainFrame::CMainFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
11 | : wxFrame(parent, id, title, pos, size, style)
12 | {
13 | m_pubKey = wxString("ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic=");
14 | m_priKey = wxString("E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8=");
15 |
16 | wxMenu* n_pMenuApp = new wxMenu;
17 | n_pMenuApp->Append(wxID_EXIT, wxT("Exit"));
18 |
19 | wxMenuBar* n_pMainMenuBar = new wxMenuBar;
20 | n_pMainMenuBar->Append(n_pMenuApp, wxT("App"));
21 | SetMenuBar(n_pMainMenuBar);
22 |
23 | m_pTxtInputText = new wxTextCtrl(this, wxID_ANY, wxT(""));
24 | m_pBtnAction = new wxButton(this, ID_Action, wxT("Action"));
25 | m_pEncryptedText = new wxTextCtrl(this, ID_Encrypted_Text, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxTE_READONLY | wxTE_MULTILINE | wxTE_CHARWRAP);
26 | m_pDecryptedText = new wxStaticText(this, ID_Decrypted_Text, wxT(""));
27 |
28 | wxBoxSizer* n_pSizer = new wxBoxSizer(wxVERTICAL);
29 | if (n_pSizer != NULL)
30 | {
31 | wxFlexGridSizer* n_pMainSizer = new wxFlexGridSizer(4, 2, 5, 5);
32 | if (n_pMainSizer != NULL)
33 | {
34 | n_pMainSizer->AddGrowableRow(2, 1);
35 | n_pMainSizer->AddGrowableCol(1, 1);
36 |
37 | n_pMainSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Input Text:")), 1, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
38 | n_pMainSizer->Add(m_pTxtInputText, 1, wxEXPAND);
39 |
40 | n_pMainSizer->Add(m_pBtnAction, wxALIGN_RIGHT);
41 | n_pMainSizer->AddStretchSpacer();
42 |
43 | n_pMainSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Encrypted Text:")), 1, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxEXPAND);
44 | n_pMainSizer->Add(m_pEncryptedText, 1, wxEXPAND);
45 |
46 | n_pMainSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Decrypted Text:")), 1, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
47 | n_pMainSizer->Add(m_pDecryptedText, 1, wxEXPAND);
48 |
49 | n_pSizer->Add(n_pMainSizer, 1, wxALL | wxEXPAND, 10);
50 |
51 | SetSizer(n_pSizer);
52 | n_pSizer->SetSizeHints(this);
53 | }
54 | }
55 |
56 | #ifdef __WXGTK__
57 | SetSize(wxSize(480, 300));
58 | SetMinSize(wxSize(480, 300));
59 | #else
60 | SetSize(wxSize(480, GetBestHeight(480)));
61 | SetMinSize(wxSize(480, GetBestHeight(480)));
62 | #endif
63 |
64 | Centre(wxBOTH | wxCENTRE_ON_SCREEN);
65 | }
66 |
67 | CMainFrame::~CMainFrame()
68 | {
69 | }
70 |
71 | void CMainFrame::OnAction(wxCommandEvent& WXUNUSED(evt))
72 | {
73 | wxString n_txtMessage = m_pTxtInputText->GetValue().Trim(false).Trim();
74 | if (!n_txtMessage.IsEmpty())
75 | {
76 | wxString n_txtEncryptedText(rust_encrypt((const char*) m_pubKey.mb_str(wxConvUTF8), (const char*) n_txtMessage.mb_str(wxConvUTF8)), wxConvUTF8);
77 | wxString n_txtDecryptedText(rust_decrypt((const char*) m_priKey.mb_str(wxConvUTF8), (const char*) n_txtEncryptedText.mb_str(wxConvUTF8)), wxConvUTF8);
78 |
79 | m_pEncryptedText->SetValue(n_txtEncryptedText);
80 | m_pDecryptedText->SetLabel(n_txtDecryptedText);
81 | }
82 | else
83 | {
84 | m_pEncryptedText->SetValue(wxT(""));
85 | m_pDecryptedText->SetLabel(wxT(""));
86 | }
87 | }
88 |
89 | void CMainFrame::OnQuit(wxCommandEvent& WXUNUSED(evt))
90 | {
91 | Close(true);
92 | }
93 |
--------------------------------------------------------------------------------
/Desktop/MainFrame.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_FRAME_H_
2 | #define __MAIN_FRAME_H_
3 |
4 | #include
5 | #ifndef WX_PRECOMP
6 | #include
7 | #endif
8 |
9 | #include
10 |
11 | class CMainFrame : public wxFrame
12 | {
13 | enum
14 | {
15 | ID_Action = wxID_HIGHEST + 1,
16 | ID_Encrypted_Text,
17 | ID_Decrypted_Text
18 | };
19 |
20 | public:
21 | CMainFrame(wxWindow* parent, wxWindowID id, const wxString& title,
22 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
23 | long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER);
24 | ~CMainFrame();
25 |
26 | protected:
27 | void OnAction(wxCommandEvent& evt);
28 | void OnQuit(wxCommandEvent& evt);
29 |
30 | private:
31 | wxTextCtrl* m_pTxtInputText;
32 | wxButton* m_pBtnAction;
33 | wxTextCtrl* m_pEncryptedText;
34 | wxStaticText* m_pDecryptedText;
35 |
36 | wxString m_pubKey;
37 | wxString m_priKey;
38 |
39 | wxDECLARE_EVENT_TABLE();
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/Desktop/Makefile-linux:
--------------------------------------------------------------------------------
1 | CXX = g++ -std=gnu++2a
2 |
3 | OBJS_OUTPUT_DIR = ./Objs
4 | APP_OUTPUT_DIR = ./Bin
5 | APP_NAME = app
6 | LIB_RUST_NAME = rust_crypto
7 | LIB_RUST_FILE_NAME = librust_crypto.a
8 | RUST_TARGET = x86_64-unknown-linux-gnu
9 | CORELIB_DIR = ../Backend/$(LIB_RUST_NAME)
10 |
11 | all: CreateOutputDirs MakeApp
12 |
13 | CreateOutputDirs:
14 | @if [ ! -e $(OBJS_OUTPUT_DIR) ]; \
15 | then \
16 | mkdir $(OBJS_OUTPUT_DIR); \
17 | fi \
18 |
19 | @if [ ! -e $(APP_OUTPUT_DIR) ]; \
20 | then \
21 | mkdir $(APP_OUTPUT_DIR); \
22 | fi
23 |
24 | MakeApp: BuildCoreLib $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o
25 | $(CXX) -o $(APP_OUTPUT_DIR)/$(APP_NAME) $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o \
26 | $(CORELIB_DIR)/target/$(RUST_TARGET)/release/$(LIB_RUST_FILE_NAME) `wx-config --libs`
27 |
28 | BuildCoreLib: $(CORELIB_DIR)/src/lib.rs $(CORELIB_DIR)/Cargo.toml
29 | cargo build --target $(RUST_TARGET) --release --manifest-path $(CORELIB_DIR)/Cargo.toml
30 |
31 | $(OBJS_OUTPUT_DIR)/app.o: app.h app.cpp MainFrame.h MainFrame.cpp
32 | $(CXX) `wx-config --cxxflags` -c app.cpp -o $(OBJS_OUTPUT_DIR)/app.o
33 |
34 | $(OBJS_OUTPUT_DIR)/MainFrame.o: MainFrame.h MainFrame.cpp
35 | $(CXX) `wx-config --cxxflags` -c MainFrame.cpp -o $(OBJS_OUTPUT_DIR)/MainFrame.o
36 |
37 | clear:
38 | @if [ -e $(OBJS_OUTPUT_DIR) ]; \
39 | then \
40 | rm -rf $(OBJS_OUTPUT_DIR); \
41 | fi
42 | rm -rf $(CORELIB_DIR)/target/$(RUST_TARGET)
43 |
44 | clean: clear
45 | @if [ -e $(APP_OUTPUT_DIR) ]; \
46 | then \
47 | rm -rf $(APP_OUTPUT_DIR); \
48 | fi
49 |
--------------------------------------------------------------------------------
/Desktop/Makefile-mac:
--------------------------------------------------------------------------------
1 | CXX = clang++ -std=c++2a -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.14 -stdlib=libc++
2 |
3 | OBJS_OUTPUT_DIR = ./Objs
4 | APP_OUTPUT_DIR = ./Bin
5 | APP_NAME = app
6 | TOP_SRC_DIR = ../../../formatlibs/wxWidgets
7 | SRC_DIR = .
8 | LIB_RUST_NAME = rust_crypto
9 | LIB_RUST_FILE_NAME = librust_crypto.a
10 | RUST_TARGET = x86_64-apple-darwin
11 | CORELIB_DIR = ../Backend/$(LIB_RUST_NAME)
12 |
13 | WX_RELEASE = 3.1
14 | WX_VERSION = $(WX_RELEASE).6
15 |
16 | all: CreateOutputDirs MakeApp BuildAppPack
17 |
18 | CreateOutputDirs:
19 | @if [ ! -e $(OBJS_OUTPUT_DIR) ]; \
20 | then \
21 | mkdir $(OBJS_OUTPUT_DIR); \
22 | fi \
23 |
24 | @if [ ! -e $(APP_OUTPUT_DIR) ]; \
25 | then \
26 | mkdir $(APP_OUTPUT_DIR); \
27 | fi
28 |
29 | MakeApp: BuildCoreLib $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o
30 | $(CXX) -o $(APP_OUTPUT_DIR)/$(APP_NAME) $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o \
31 | $(CORELIB_DIR)/target/$(RUST_TARGET)/release/$(LIB_RUST_FILE_NAME) `wx-config --libs`
32 |
33 |
34 |
35 | BuildAppPack: $(TOP_SRC_DIR)/src/osx/carbon/Info.plist.in $(TOP_SRC_DIR)/src/osx/carbon/wxmac.icns
36 | mkdir -p $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/MacOS
37 | mkdir -p $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/Resources
38 |
39 | sed -e "s/IDENTIFIER/`echo $(SRC_DIR) | sed -e 's,\.\./,,g' | sed -e 's,/,.,g'`/" \
40 | -e "s/EXECUTABLE/$(APP_NAME)/" \
41 | -e "s/VERSION/$(WX_VERSION)/" \
42 | $(TOP_SRC_DIR)/src/osx/carbon/Info.plist.in > $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/Info.plist
43 |
44 | /bin/echo "APPL????" > $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/PkgInfo
45 |
46 | ln -f $(APP_OUTPUT_DIR)/$(APP_NAME) $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME)
47 |
48 | cp -f $(TOP_SRC_DIR)/src/osx/carbon/wxmac.icns $(APP_OUTPUT_DIR)/$(APP_NAME).app/Contents/Resources/wxmac.icns
49 |
50 | rm -f $(APP_OUTPUT_DIR)/$(APP_NAME)
51 |
52 |
53 |
54 | BuildCoreLib: $(CORELIB_DIR)/src/lib.rs $(CORELIB_DIR)/Cargo.toml
55 | cargo build --target $(RUST_TARGET) --release --manifest-path $(CORELIB_DIR)/Cargo.toml
56 |
57 | $(OBJS_OUTPUT_DIR)/app.o: app.h app.cpp MainFrame.h MainFrame.cpp
58 | $(CXX) `wx-config --cxxflags` -c app.cpp -o $(OBJS_OUTPUT_DIR)/app.o
59 |
60 | $(OBJS_OUTPUT_DIR)/MainFrame.o: MainFrame.h MainFrame.cpp
61 | $(CXX) `wx-config --cxxflags` -c MainFrame.cpp -o $(OBJS_OUTPUT_DIR)/MainFrame.o
62 |
63 | clear:
64 | @if [ -e $(OBJS_OUTPUT_DIR) ]; \
65 | then \
66 | rm -rf $(OBJS_OUTPUT_DIR); \
67 | fi
68 | rm -rf $(CORELIB_DIR)/target/$(RUST_TARGET)
69 |
70 | clean: clear
71 | @if [ -e $(APP_OUTPUT_DIR) ]; \
72 | then \
73 | rm -rf $(APP_OUTPUT_DIR); \
74 | fi
75 |
--------------------------------------------------------------------------------
/Desktop/Makefile-win32:
--------------------------------------------------------------------------------
1 | CXX = g++ -std=gnu++2a
2 |
3 | OBJS_OUTPUT_DIR = ./Objs
4 | APP_OUTPUT_DIR = ./Bin
5 | APP_NAME = app.exe
6 | LIB_RUST_NAME = rust_crypto
7 | LIB_RUST_FILE_NAME = librust_crypto.a
8 | RUST_TARGET = i686-pc-windows-gnu
9 | CORELIB_DIR = ../Backend/$(LIB_RUST_NAME)
10 |
11 | all: CreateOutputDirs MakeApp
12 |
13 | CreateOutputDirs:
14 | @if [ ! -e $(OBJS_OUTPUT_DIR) ]; \
15 | then \
16 | mkdir $(OBJS_OUTPUT_DIR); \
17 | fi \
18 |
19 | @if [ ! -e $(APP_OUTPUT_DIR) ]; \
20 | then \
21 | mkdir $(APP_OUTPUT_DIR); \
22 | fi
23 |
24 | MakeApp: BuildCoreLib $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o $(OBJS_OUTPUT_DIR)/app_rc.o
25 | $(CXX) -o $(APP_OUTPUT_DIR)/$(APP_NAME) $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o \
26 | $(CORELIB_DIR)/target/$(RUST_TARGET)/release/$(LIB_RUST_FILE_NAME) \
27 | $(OBJS_OUTPUT_DIR)/app_rc.o `wx-config --libs` -lgcc_eh -luserenv -lws2_32 -lbcrypt
28 |
29 | BuildCoreLib: $(CORELIB_DIR)/src/lib.rs $(CORELIB_DIR)/Cargo.toml
30 | cargo build --target $(RUST_TARGET) --release --manifest-path $(CORELIB_DIR)/Cargo.toml
31 |
32 | $(OBJS_OUTPUT_DIR)/app.o: app.h app.cpp MainFrame.h MainFrame.cpp
33 | $(CXX) `wx-config --cxxflags` -c app.cpp -o $(OBJS_OUTPUT_DIR)/app.o
34 |
35 | $(OBJS_OUTPUT_DIR)/MainFrame.o: MainFrame.h MainFrame.cpp
36 | $(CXX) `wx-config --cxxflags` -c MainFrame.cpp -o $(OBJS_OUTPUT_DIR)/MainFrame.o
37 |
38 | $(OBJS_OUTPUT_DIR)/app_rc.o: ./res/app.rc
39 | windres -I ~/../../mingw32/include/wx-3.1 -I . -i ./res/app.rc -o $(OBJS_OUTPUT_DIR)/app_rc.o
40 |
41 | clear:
42 | @if [ -e $(OBJS_OUTPUT_DIR) ]; \
43 | then \
44 | rm -rf $(OBJS_OUTPUT_DIR); \
45 | fi
46 | rm -rf $(CORELIB_DIR)/target/$(RUST_TARGET)
47 |
48 | clean: clear
49 | rm -f $(APP_OUTPUT_DIR)/$(APP_NAME)
50 |
--------------------------------------------------------------------------------
/Desktop/Makefile-win64:
--------------------------------------------------------------------------------
1 | CXX = g++ -std=gnu++2a
2 |
3 | OBJS_OUTPUT_DIR = ./Objs
4 | APP_OUTPUT_DIR = ./Bin
5 | APP_NAME = app.exe
6 | LIB_RUST_NAME = rust_crypto
7 | LIB_RUST_FILE_NAME = librust_crypto.a
8 | RUST_TARGET = x86_64-pc-windows-gnu
9 | CORELIB_DIR = ../Backend/$(LIB_RUST_NAME)
10 |
11 | all: CreateOutputDirs MakeApp
12 |
13 | CreateOutputDirs:
14 | @if [ ! -e $(OBJS_OUTPUT_DIR) ]; \
15 | then \
16 | mkdir $(OBJS_OUTPUT_DIR); \
17 | fi \
18 |
19 | @if [ ! -e $(APP_OUTPUT_DIR) ]; \
20 | then \
21 | mkdir $(APP_OUTPUT_DIR); \
22 | fi
23 |
24 | MakeApp: BuildCoreLib $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o $(OBJS_OUTPUT_DIR)/app_rc.o
25 | $(CXX) -o $(APP_OUTPUT_DIR)/$(APP_NAME) $(OBJS_OUTPUT_DIR)/app.o $(OBJS_OUTPUT_DIR)/MainFrame.o \
26 | $(CORELIB_DIR)/target/$(RUST_TARGET)/release/$(LIB_RUST_FILE_NAME) \
27 | $(OBJS_OUTPUT_DIR)/app_rc.o `wx-config --libs` -lgcc_eh -luserenv -lws2_32 -lbcrypt
28 |
29 | BuildCoreLib: $(CORELIB_DIR)/src/lib.rs $(CORELIB_DIR)/Cargo.toml
30 | cargo build --target $(RUST_TARGET) --release --manifest-path $(CORELIB_DIR)/Cargo.toml
31 |
32 | $(OBJS_OUTPUT_DIR)/app.o: app.h app.cpp MainFrame.h MainFrame.cpp
33 | $(CXX) `wx-config --cxxflags` -c app.cpp -o $(OBJS_OUTPUT_DIR)/app.o
34 |
35 | $(OBJS_OUTPUT_DIR)/MainFrame.o: MainFrame.h MainFrame.cpp
36 | $(CXX) `wx-config --cxxflags` -c MainFrame.cpp -o $(OBJS_OUTPUT_DIR)/MainFrame.o
37 |
38 | $(OBJS_OUTPUT_DIR)/app_rc.o: ./res/app.rc
39 | windres -I ~/../../mingw64/include/wx-3.1 -I . -i ./res/app.rc -o $(OBJS_OUTPUT_DIR)/app_rc.o
40 |
41 | clear:
42 | @if [ -e $(OBJS_OUTPUT_DIR) ]; \
43 | then \
44 | rm -rf $(OBJS_OUTPUT_DIR); \
45 | fi
46 | rm -rf $(CORELIB_DIR)/target/$(RUST_TARGET)
47 |
48 | clean: clear
49 | @if [ -e $(APP_OUTPUT_DIR) ]; \
50 | then \
51 | rm -rf $(APP_OUTPUT_DIR); \
52 | fi
53 |
--------------------------------------------------------------------------------
/Desktop/app.cpp:
--------------------------------------------------------------------------------
1 | #include "app.h"
2 | #include "MainFrame.h"
3 |
4 | wxIMPLEMENT_APP(CCryptoDemoApp);
5 |
6 | bool CCryptoDemoApp::OnInit()
7 | {
8 | if (!wxApp::OnInit()) return false;
9 |
10 | // Create the main application window
11 | CMainFrame *pFrame = new CMainFrame(NULL, wxID_ANY, wxT("Test rust-crypto with wxWidgets"));
12 |
13 | // Show it
14 | pFrame->Show(true);
15 |
16 | // Start the event loop
17 | return true;
18 | }
19 |
--------------------------------------------------------------------------------
/Desktop/app.h:
--------------------------------------------------------------------------------
1 | #ifndef __CRYPTO_DEMO_FRAME_H_
2 | #define __CRYPTO_DEMO_FRAME_H_
3 |
4 | #include
5 | #ifndef WX_PRECOMP
6 | #include
7 | #endif
8 |
9 | class CCryptoDemoApp : public wxApp
10 | {
11 | public:
12 | CCryptoDemoApp() {}
13 | virtual ~CCryptoDemoApp() {}
14 |
15 | virtual bool OnInit();
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/Desktop/res/app.rc:
--------------------------------------------------------------------------------
1 | #include "wx/msw/rcdefs.h"
2 |
3 | // see "about isolated applications" topic in MSDN
4 | #ifdef ISOLATION_AWARE_ENABLED
5 | #define wxMANIFEST_ID 2
6 | #else
7 | #define wxMANIFEST_ID 1
8 | #endif
9 |
10 | #if defined(WX_CPU_AMD64)
11 | wxMANIFEST_ID 24 "wx/msw/amd64.manifest"
12 | #elif defined(WX_CPU_IA64)
13 | wxMANIFEST_ID 24 "wx/msw/ia64.manifest"
14 | #elif defined(WX_CPU_X86)
15 | wxMANIFEST_ID 24 "wx/msw/wx.manifest"
16 | #endif
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Rust-crypto_ios_android (was supported for arm64)
2 | ================
3 |
4 |
5 |
6 | Example project for building a library for iOS + Android in Rust. macOS is
7 | required for iOS development.
8 |
9 | * ✓ Rust 1.52.1
10 | * ✓ Android 8.0 – 10.0+ (API 26 – 30)
11 | * ✓ Swift 5.2
12 | * ✓ iOS 12 – 14.5
13 |
14 | *Note: The purpose of this project is not to create a pure Rust app, but rather
15 | use Rust as a shared native component between the mobile platforms.*
16 |
17 | Setup
18 | -----
19 |
20 | 1. Install the common build tools like C compiler and linker. On macOS, get
21 | Xcode, and install the command line tools.
22 |
23 | ```sh
24 | xcode-select --install
25 | ```
26 |
27 | 2. Get Android NDK. We recommend installing it via Android Studio or
28 | `sdkmanager`:
29 |
30 | ```sh
31 | sdkmanager --verbose ndk-bundle
32 | ```
33 |
34 | Otherwise, please define the environment variable `ANDROID_NDK_HOME` to the
35 | path of the current version of Android NDK.
36 |
37 | ```sh
38 | export ANDROID_NDK_HOME='/usr/local/opt/android-ndk/android-ndk-r21d/'
39 | ```
40 |
41 | 3. Create the build information for NDK.
42 |
43 | ```sh
44 | # Linux.
45 | ./create-ndk-build-info-linux.sh
46 |
47 | # Mac.
48 | ./create-ndk-build-info-mac.sh
49 | ```
50 |
51 | 4. Add the NDK to search path:
52 |
53 | ```sh
54 | # Linux.
55 | export PATH="$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
56 |
57 | # Mac.
58 | export PATH="$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin"
59 | ```
60 |
61 | 5. Download [rustup](https://www.rustup.rs/). We will use this to setup Rust for
62 | cross-compiling.
63 |
64 | ```sh
65 | curl https://sh.rustup.rs -sSf | sh
66 | ```
67 |
68 | 6. Download targets for iOS and Android.
69 |
70 | ```sh
71 | # iOS.
72 | rustup target add aarch64-apple-ios x86_64-apple-ios
73 |
74 | # Android.
75 | rustup target add armv7-linux-androideabi aarch64-linux-android x86_64-linux-android
76 | ```
77 |
78 | 7. Copy the content of `cargo-config.toml` (consists of linker information of
79 | the Android targets) to `~/.cargo/config`
80 |
81 | ```sh
82 | cat cargo-config.toml >> ~/.cargo/config
83 | ```
84 |
85 | 8. Install cargo-lipo to generate the iOS universal library.
86 |
87 | ```sh
88 | cargo install cargo-lipo
89 | ```
90 |
91 | Creating the libraries
92 | ----------------------
93 |
94 | You use use the `iOS/`, `Android/` projects as an example. (Note that the sample itself
95 | does not contain proper error checking.)
96 |
97 | 1. Write the library and expose a C interface. See [the FFI chapter in the Rust
98 | Book](http://doc.rust-lang.org/book/ffi.html) for an introduction.
99 |
100 | 2. Expose the Java interface with JNI when `target_os="android"`.
101 |
102 | 3. Build the libraries.
103 |
104 | ```sh
105 | cd Backend/rust_crypto
106 |
107 | # iOS.
108 | # Integrated into Xcode project.
109 |
110 | # Android.
111 | cargo build --target armv7-linux-androideabi --release
112 | cargo build --target aarch64-linux-android --release
113 | cargo build --target x86_64-linux-android --release
114 | ```
115 |
116 | 4. Build the Xcode project.
117 |
118 | Using Xcode 12.4 (MacOS Catalina)
119 |
120 | When you create an Xcode project yourself, note the following points:
121 | * Add a new `Run Script` phase to your `Build Phases`. Place it before `Compile Sources`. Add something like the following to the script:
122 |
123 | ```sh
124 | export PATH="$HOME/.cargo/bin:$PATH"
125 |
126 | LIB_RUST_NAME=rust_crypto
127 | CORELIB_DIR=../../Backend/$LIB_RUST_NAME
128 |
129 | # --xcode-integ determines --release and --targets from XCode's env vars.
130 | # Depending your setup, specify the rustup toolchain explicitly.
131 | cargo lipo --xcode-integ --manifest-path ../../Backend/rust_crypto/Cargo.toml
132 |
133 | if [ $CONFIGURATION == "Release" ]
134 | then
135 | cp $CORELIB_DIR/target/universal/release/librust_crypto.a $CORELIB_DIR/target/universal
136 | else
137 | cp $CORELIB_DIR/target/universal/debug/librust_crypto.a $CORELIB_DIR/target/universal
138 | fi
139 | ```
140 | * Build the project once, then update the `Link Binary with Libraries` phase: Click the `+`, then choose `Add Other...`. Navigate to `Backend/rust_crypto/target/universal` and select file `librust_crypto.a`.
141 | * You need to link to `libresolv.tbd`.
142 | * Go back to your `Build Settings` and add `Library Search Paths` for `Debug` and `Release`, pointing to `../../Backend/rust_crypto/target/universal`.
143 | * Add the C header `rust_crypto.h` to allow using the Rust functions from C.
144 | * Note that `cargo-lipo` does not generate bitcode yet. You must set
145 | `ENABLE_BITCODE` to `NO`. (See also )
146 |
147 | 5. Build the Android project.
148 |
149 | Using Android Studio 4.2.1
150 |
151 | When you create an Android Studio project yourself, note the following
152 | points:
153 |
154 | * Copy or link the `*.so` into the corresponding `src/main/jniLibs` folders:
155 |
156 | Copy from Rust | Copy to Android
157 | ---|---
158 | `target/armv7-linux-androideabi/release/librust_crypto.so` | `src/main/jniLibs/armeabi-v7a/librust_crypto.so`
159 | `target/aarch64-linux-android/release/librust_crypto.so` | `src/main/jniLibs/arm64-v8a/librust_crypto.so`
160 | `target/x86_64-linux-android/release/librust_crypto.so` | `src/main/jniLibs/x86_64/librust_crypto.so`
161 |
162 | * Don't forget to ensure the JNI glue between Rust and Java are compatible.
163 |
--------------------------------------------------------------------------------
/Screenshoots/Android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/Android.png
--------------------------------------------------------------------------------
/Screenshoots/Linux.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/Linux.png
--------------------------------------------------------------------------------
/Screenshoots/WebAssembly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/WebAssembly.png
--------------------------------------------------------------------------------
/Screenshoots/Win32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/Win32.png
--------------------------------------------------------------------------------
/Screenshoots/Windows-UWP.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/Windows-UWP.png
--------------------------------------------------------------------------------
/Screenshoots/iOS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/iOS.png
--------------------------------------------------------------------------------
/Screenshoots/macOS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/Screenshoots/macOS.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29215.179
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CryptoDemo", "CryptoDemo\CryptoDemo.vcxproj", "{FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|ARM = Release|ARM
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|ARM.ActiveCfg = Debug|ARM
19 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|ARM.Build.0 = Debug|ARM
20 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|ARM.Deploy.0 = Debug|ARM
21 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x64.ActiveCfg = Debug|x64
22 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x64.Build.0 = Debug|x64
23 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x64.Deploy.0 = Debug|x64
24 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x86.ActiveCfg = Debug|Win32
25 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x86.Build.0 = Debug|Win32
26 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Debug|x86.Deploy.0 = Debug|Win32
27 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|ARM.ActiveCfg = Release|ARM
28 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|ARM.Build.0 = Release|ARM
29 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|ARM.Deploy.0 = Release|ARM
30 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x64.ActiveCfg = Release|x64
31 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x64.Build.0 = Release|x64
32 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x64.Deploy.0 = Release|x64
33 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x86.ActiveCfg = Release|Win32
34 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x86.Build.0 = Release|Win32
35 | {FB0BD9C3-BFAE-4425-AF38-C37BC0FD98B2}.Release|x86.Deploy.0 = Release|Win32
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {046232CB-29AA-4C10-9AA0-EFCAE6B9AA6D}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/App.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 |
3 | #include "App.h"
4 | #include "MainPage.h"
5 |
6 | using namespace winrt;
7 | using namespace Windows::ApplicationModel;
8 | using namespace Windows::ApplicationModel::Activation;
9 | using namespace Windows::Foundation;
10 | using namespace Windows::UI::Xaml;
11 | using namespace Windows::UI::Xaml::Controls;
12 | using namespace Windows::UI::Xaml::Navigation;
13 | using namespace CryptoDemo;
14 | using namespace CryptoDemo::implementation;
15 |
16 | ///
17 | /// Initializes the singleton application object. This is the first line of authored code
18 | /// executed, and as such is the logical equivalent of main() or WinMain().
19 | ///
20 | App::App()
21 | {
22 | InitializeComponent();
23 | Suspending({ this, &App::OnSuspending });
24 |
25 | #if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
26 | UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
27 | {
28 | if (IsDebuggerPresent())
29 | {
30 | auto errorMessage = e.Message();
31 | __debugbreak();
32 | }
33 | });
34 | #endif
35 | }
36 |
37 | ///
38 | /// Invoked when the application is launched normally by the end user. Other entry points
39 | /// will be used such as when the application is launched to open a specific file.
40 | ///
41 | /// Details about the launch request and process.
42 | void App::OnLaunched(LaunchActivatedEventArgs const& e)
43 | {
44 | Frame rootFrame{ nullptr };
45 | auto content = Window::Current().Content();
46 | if (content)
47 | {
48 | rootFrame = content.try_as();
49 | }
50 |
51 | // Do not repeat app initialization when the Window already has content,
52 | // just ensure that the window is active
53 | if (rootFrame == nullptr)
54 | {
55 | // Create a Frame to act as the navigation context and associate it with
56 | // a SuspensionManager key
57 | rootFrame = Frame();
58 |
59 | rootFrame.NavigationFailed({ this, &App::OnNavigationFailed });
60 |
61 | if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated)
62 | {
63 | // Restore the saved session state only when appropriate, scheduling the
64 | // final launch steps after the restore is complete
65 | }
66 |
67 | if (e.PrelaunchActivated() == false)
68 | {
69 | if (rootFrame.Content() == nullptr)
70 | {
71 | // When the navigation stack isn't restored navigate to the first page,
72 | // configuring the new page by passing required information as a navigation
73 | // parameter
74 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments()));
75 | }
76 | // Place the frame in the current Window
77 | Window::Current().Content(rootFrame);
78 | // Ensure the current window is active
79 | Window::Current().Activate();
80 | }
81 | }
82 | else
83 | {
84 | if (e.PrelaunchActivated() == false)
85 | {
86 | if (rootFrame.Content() == nullptr)
87 | {
88 | // When the navigation stack isn't restored navigate to the first page,
89 | // configuring the new page by passing required information as a navigation
90 | // parameter
91 | rootFrame.Navigate(xaml_typename(), box_value(e.Arguments()));
92 | }
93 | // Ensure the current window is active
94 | Window::Current().Activate();
95 | }
96 | }
97 | }
98 |
99 | ///
100 | /// Invoked when application execution is being suspended. Application state is saved
101 | /// without knowing whether the application will be terminated or resumed with the contents
102 | /// of memory still intact.
103 | ///
104 | /// The source of the suspend request.
105 | /// Details about the suspend request.
106 | void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e)
107 | {
108 | // Save application state and stop any background activity
109 | }
110 |
111 | ///
112 | /// Invoked when Navigation to a certain page fails
113 | ///
114 | /// The Frame which failed navigation
115 | /// Details about the navigation failure
116 | void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e)
117 | {
118 | throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name);
119 | }
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/App.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "App.xaml.g.h"
3 |
4 | namespace winrt::CryptoDemo::implementation
5 | {
6 | struct App : AppT
7 | {
8 | App();
9 |
10 | void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&);
11 | void OnSuspending(IInspectable const&, Windows::ApplicationModel::SuspendingEventArgs const&);
12 | void OnNavigationFailed(IInspectable const&, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&);
13 | };
14 | }
15 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/App.idl:
--------------------------------------------------------------------------------
1 | namespace CryptoDemo
2 | {
3 | }
4 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/CryptoDemo.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | Assets
26 |
27 |
28 | Assets
29 |
30 |
31 | Assets
32 |
33 |
34 | Assets
35 |
36 |
37 | Assets
38 |
39 |
40 | Assets
41 |
42 |
43 | Assets
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | {e48dc53e-40b1-40cb-970a-f89935452892}
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/CryptoDemo.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | UWPRemoteDebugger
5 |
6 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/CryptoDemo_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/UWP/CryptoDemo/CryptoDemo/CryptoDemo_TemporaryKey.pfx
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/MainPage.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 | #include "MainPage.h"
3 | #include "MainPage.g.cpp"
4 |
5 | using namespace std;
6 | using namespace winrt;
7 | using namespace Windows::UI::Xaml;
8 |
9 | #include "..\..\..\Backend\rust_crypto\src\rust_crypto.h"
10 |
11 | std::string make_string(const std::wstring& wstring)
12 | {
13 | auto wideData = wstring.c_str();
14 | int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wideData, -1, nullptr, 0, NULL, NULL);
15 | auto utf8 = std::make_unique(bufferSize);
16 | if (0 == WideCharToMultiByte(CP_UTF8, 0, wideData, -1, utf8.get(), bufferSize, NULL, NULL))
17 | throw std::exception("Can't convert string to UTF8");
18 |
19 | return std::string(utf8.get());
20 | }
21 |
22 | std::wstring make_wstring(const std::string& string)
23 | {
24 | auto utf8Data = string.c_str();
25 | int bufferSize = MultiByteToWideChar(CP_UTF8, 0, utf8Data, -1, nullptr, 0);
26 | auto wide = std::make_unique(bufferSize);
27 | if (0 == MultiByteToWideChar(CP_UTF8, 0, utf8Data, -1, wide.get(), bufferSize))
28 | throw std::exception("Can't convert string to Unicode");
29 |
30 | return std::wstring(wide.get());
31 | }
32 |
33 | winrt::hstring trim_string(const winrt::hstring& string)
34 | {
35 | if (!string.empty())
36 | {
37 | //convert to wstring
38 | std::wstring classicString(string.data());
39 |
40 | //trimming
41 | classicString.erase(0, classicString.find_first_not_of(' '));
42 | classicString.erase(classicString.find_last_not_of(' ') + 1);
43 |
44 | //convert to Platform::String
45 | return winrt::hstring(classicString.c_str());
46 | }
47 | return string;
48 | }
49 |
50 | namespace winrt::CryptoDemo::implementation
51 | {
52 | MainPage::MainPage()
53 | {
54 | InitializeComponent();
55 |
56 | m_pubKey = L"ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic=";
57 | m_priKey = L"E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8=";
58 | }
59 |
60 | int32_t MainPage::MyProperty()
61 | {
62 | throw hresult_not_implemented();
63 | }
64 |
65 | void MainPage::MyProperty(int32_t /* value */)
66 | {
67 | throw hresult_not_implemented();
68 | }
69 |
70 | void MainPage::BtnAction_Click(IInspectable const& /* sender */, RoutedEventArgs const& /* args */)
71 | {
72 | hstring n_inputText = trim_string(txtInputText().Text());
73 | if (!n_inputText.empty())
74 | {
75 | wstring ws_inputText{ n_inputText };
76 |
77 | string s_pubKey = make_string(m_pubKey);
78 | string s_priKey = make_string(m_priKey);
79 | string s_inputText = make_string(ws_inputText);
80 |
81 | string s_encryptedText{ rust_encrypt(s_pubKey.c_str(), s_inputText.c_str()) };
82 | string s_decryptedText{ rust_decrypt(s_priKey.c_str(), s_encryptedText.c_str()) };
83 |
84 | wstring n_encryptedText = make_wstring(s_encryptedText);
85 | wstring n_decryptedText = make_wstring(s_decryptedText);
86 |
87 | txtEncryptedText().Text(n_encryptedText);
88 | txtDecryptedText().Text(n_decryptedText);
89 | }
90 | else
91 | {
92 | txtEncryptedText().Text(L"");
93 | txtDecryptedText().Text(L"");
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/MainPage.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "MainPage.g.h"
4 |
5 | #include
6 |
7 | using namespace std;
8 | using namespace winrt;
9 |
10 | namespace winrt::CryptoDemo::implementation
11 | {
12 | struct MainPage : MainPageT
13 | {
14 | wstring m_pubKey, m_priKey;
15 |
16 | MainPage();
17 |
18 | int32_t MyProperty();
19 | void MyProperty(int32_t value);
20 |
21 | void BtnAction_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
22 | };
23 | }
24 |
25 | namespace winrt::CryptoDemo::factory_implementation
26 | {
27 | struct MainPage : MainPageT
28 | {
29 | };
30 | }
31 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/MainPage.idl:
--------------------------------------------------------------------------------
1 | namespace CryptoDemo
2 | {
3 | [default_interface]
4 | runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
5 | {
6 | MainPage();
7 | Int32 MyProperty;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 | CryptoDemo
10 | tungthanhnguyen
11 | Assets\StoreLogo.png
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/PropertySheet.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/build_rust-lib.cmd:
--------------------------------------------------------------------------------
1 | rem @echo off
2 |
3 | rem i686 x86_64 aarch64
4 | SET BUILD_ARCH=%1
5 |
6 | rem debug release
7 | SET BUILD_TYPE=%2
8 |
9 | SET LIB_RUST_NAME=rust_crypto
10 | SET RUST_TARGET=%BUILD_ARCH%-pc-windows-msvc
11 | SET CORELIB_DIR=..\..\..\Backend\%LIB_RUST_NAME%
12 | SET CARGO_COMMAND=%USERPROFILE%\.cargo\bin\cargo.exe
13 |
14 | IF %BUILD_TYPE% == debug (
15 | %CARGO_COMMAND% build --target %RUST_TARGET% --manifest-path %CORELIB_DIR%\Cargo.toml
16 | ) ELSE (
17 | %CARGO_COMMAND% build --target %RUST_TARGET% --%BUILD_TYPE% --manifest-path %CORELIB_DIR%\Cargo.toml
18 | )
19 |
20 | copy %CORELIB_DIR%\target\%RUST_TARGET%\%BUILD_TYPE%\%LIB_RUST_NAME%.lib %CORELIB_DIR%\target
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/pch.cpp:
--------------------------------------------------------------------------------
1 | #include "pch.h"
2 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/pch.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
--------------------------------------------------------------------------------
/UWP/CryptoDemo/CryptoDemo/readme.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | C++/WinRT CryptoDemo Project Overview
3 | ========================================================================
4 |
5 | This project demonstrates how to get started writing XAML apps directly
6 | with standard C++, using the C++/WinRT SDK component and XAML compiler
7 | support to generate implementation headers from interface (IDL) files.
8 | These headers can then be used to implement the local Windows Runtime
9 | classes referenced in the app's XAML pages.
10 |
11 | Steps:
12 | 1. Create an interface (IDL) file to define any local Windows Runtime
13 | classes referenced in the app's XAML pages.
14 | 2. Build the project once to generate implementation templates under
15 | the "Generated Files" folder, as well as skeleton class definitions
16 | under "Generated Files\sources".
17 | 3. Use the skeleton class definitions for reference to implement your
18 | Windows Runtime classes.
19 |
20 | ========================================================================
21 | Learn more about C++/WinRT here:
22 | http://aka.ms/cppwinrt/
23 | ========================================================================
24 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/.appveyor.yml:
--------------------------------------------------------------------------------
1 | install:
2 | - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
3 | - if not defined RUSTFLAGS rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
4 | - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
5 | - rustc -V
6 | - cargo -V
7 |
8 | build: false
9 |
10 | test_script:
11 | - cargo test --locked
12 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/.cargo-ok:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/WebAssembly/crypto-demo/.cargo-ok
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/.travis.yml:
--------------------------------------------------------------------------------
1 | language: rust
2 | sudo: false
3 |
4 | cache: cargo
5 |
6 | matrix:
7 | include:
8 |
9 | # Builds with wasm-pack.
10 | - rust: beta
11 | env: RUST_BACKTRACE=1
12 | addons:
13 | firefox: latest
14 | chrome: stable
15 | before_script:
16 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
17 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
18 | - cargo install-update -a
19 | - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
20 | script:
21 | - cargo generate --git . --name testing
22 | # Having a broken Cargo.toml (in that it has curlies in fields) anywhere
23 | # in any of our parent dirs is problematic.
24 | - mv Cargo.toml Cargo.toml.tmpl
25 | - cd testing
26 | - wasm-pack build
27 | - wasm-pack test --chrome --firefox --headless
28 |
29 | # Builds on nightly.
30 | - rust: nightly
31 | env: RUST_BACKTRACE=1
32 | before_script:
33 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
34 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
35 | - cargo install-update -a
36 | - rustup target add wasm32-unknown-unknown
37 | script:
38 | - cargo generate --git . --name testing
39 | - mv Cargo.toml Cargo.toml.tmpl
40 | - cd testing
41 | - cargo check
42 | - cargo check --target wasm32-unknown-unknown
43 | - cargo check --no-default-features
44 | - cargo check --target wasm32-unknown-unknown --no-default-features
45 | - cargo check --no-default-features --features console_error_panic_hook
46 | - cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
47 | - cargo check --no-default-features --features "console_error_panic_hook wee_alloc"
48 | - cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc"
49 |
50 | # Builds on beta.
51 | - rust: beta
52 | env: RUST_BACKTRACE=1
53 | before_script:
54 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
55 | - (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate)
56 | - cargo install-update -a
57 | - rustup target add wasm32-unknown-unknown
58 | script:
59 | - cargo generate --git . --name testing
60 | - mv Cargo.toml Cargo.toml.tmpl
61 | - cd testing
62 | - cargo check
63 | - cargo check --target wasm32-unknown-unknown
64 | - cargo check --no-default-features
65 | - cargo check --target wasm32-unknown-unknown --no-default-features
66 | - cargo check --no-default-features --features console_error_panic_hook
67 | - cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook
68 | # Note: no enabling the `wee_alloc` feature here because it requires
69 | # nightly for now.
70 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "crypto-demo"
3 | version = "0.1.0"
4 | authors = ["tungthanhnguyen"]
5 | edition = "2018"
6 |
7 | [lib]
8 | crate-type = ["cdylib", "rlib"]
9 |
10 | [features]
11 | default = ["console_error_panic_hook"]
12 |
13 | [build-dependencies]
14 | rust_crypto = { version = "0.1.3", path = "../../Backend/rust_crypto" }
15 |
16 | [dependencies]
17 | wasm-bindgen = "0.2.74"
18 | rust_crypto = { version = "0.1.3", path = "../../Backend/rust_crypto" }
19 | rustc-serialize = { version = "0.3.24", path = "../../Backend/libs/rustc-serialize-0.3.24" }
20 |
21 | # The `console_error_panic_hook` crate provides better debugging of panics by
22 | # logging them with `console.error`. This is great for development, but requires
23 | # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
24 | # code size when deploying.
25 | console_error_panic_hook = { version = "0.1.6", optional = true }
26 |
27 | # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
28 | # compared to the default allocator's ~10K. It is slower than the default
29 | # allocator, however.
30 | #
31 | # Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
32 | wee_alloc = { version = "0.4.5", optional = true }
33 |
34 | # [dependencies.wasm-opt]
35 | # wasm-opt = false
36 |
37 | getrandom = { version = "0.2", features = ["js"] }
38 |
39 | [dependencies.web-sys]
40 | version = "0.3.51"
41 | features = ["console"]
42 |
43 | [dev-dependencies]
44 | wasm-bindgen-test = "0.3.24"
45 |
46 | [profile.release]
47 | # Tell `rustc` to optimize for small code size.
48 | opt-level = "s"
49 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/LICENSE_MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2018 tungthanhnguyen
2 |
3 | Permission is hereby granted, free of charge, to any
4 | person obtaining a copy of this software and associated
5 | documentation files (the "Software"), to deal in the
6 | Software without restriction, including without
7 | limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software
10 | is furnished to do so, subject to the following
11 | conditions:
12 |
13 | The above copyright notice and this permission notice
14 | shall be included in all copies or substantial portions
15 | of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 | DEALINGS IN THE SOFTWARE.
26 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/README.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | ## About
21 |
22 | [**📚 Read this template tutorial! 📚**][template-docs]
23 |
24 | This template is designed for compiling Rust libraries into WebAssembly and
25 | publishing the resulting package to NPM.
26 |
27 | Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
28 | templates and usages of `wasm-pack`.
29 |
30 | [tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
31 | [template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
32 |
33 | ## 🚴 Usage
34 |
35 | ### 🐑 Use `cargo generate` to Clone this Template
36 |
37 | [Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
38 |
39 | ```
40 | cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
41 | cd my-project
42 | ```
43 |
44 | ### 🛠️ Build with `wasm-pack build`
45 |
46 | ```
47 | wasm-pack build
48 | ```
49 |
50 | ### 🔬 Test in Headless Browsers with `wasm-pack test`
51 |
52 | ```
53 | wasm-pack test --headless --firefox
54 | ```
55 |
56 | ### 🎁 Publish to NPM with `wasm-pack publish`
57 |
58 | ```
59 | wasm-pack publish
60 | ```
61 |
62 | ## 🔋 Batteries Included
63 |
64 | * [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
65 | between WebAssembly and JavaScript.
66 | * [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
67 | for logging panic messages to the developer console.
68 | * [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
69 | for small code size.
70 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crypto-demo",
3 | "lockfileVersion": 2,
4 | "requires": true,
5 | "packages": {}
6 | }
7 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/src/lib.rs:
--------------------------------------------------------------------------------
1 | extern crate rust_crypto;
2 | extern crate rustc_serialize;
3 | extern crate web_sys;
4 |
5 | mod utils;
6 |
7 | use std::vec::Vec;
8 |
9 | use wasm_bindgen::prelude::*;
10 |
11 | use rustc_serialize::base64::{FromBase64, ToBase64, STANDARD};
12 |
13 | use rust_crypto::{encrypt_buf, decrypt_buf};
14 |
15 | // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
16 | // allocator.
17 | #[cfg(feature = "wee_alloc")]
18 | #[global_allocator]
19 | static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
20 |
21 | // A macro to provide `println!(..)`-style syntax for `console.log` logging.
22 | macro_rules! log
23 | {
24 | ( $( $t:tt )* ) =>
25 | {
26 | web_sys::console::log_1(&format!( $( $t )* ).into());
27 | }
28 | }
29 |
30 | #[wasm_bindgen(js_name = "encrypt")]
31 | pub fn wasm_encrypt(pub_key: String, msg: String) -> String
32 | {
33 | // utils::set_panic_hook();
34 |
35 | let mut arr = [0u8; 32]; // temp buffer
36 | let public_key: &[u8; 32] = match pub_key.trim().from_base64()
37 | {
38 | Ok(m) =>
39 | {
40 | if m.len() != 32
41 | {
42 | // let e_str = format!("Public key size is wrong");
43 | // log!("{}", e_str);
44 | return String::new()
45 | }
46 | arr.copy_from_slice(&m);
47 | &arr
48 | },
49 | Err(why) =>
50 | {
51 | // let e_str = format!("Public key is wrong\n For reason: {}", why);
52 | // log!("{}", e_str);
53 | return String::new()
54 | }
55 | };
56 |
57 | let enc_dat: Vec = match encrypt_buf(&public_key, msg.as_bytes())
58 | {
59 | Ok(d) => d,
60 | Err(_) =>
61 | {
62 | // let e_str = format!("Couldn't encrypt a buffer");
63 | // log!("{}", e_str);
64 | return String::new()
65 | }
66 | };
67 |
68 | String::from(enc_dat.as_slice().to_base64(STANDARD))
69 | }
70 |
71 | #[wasm_bindgen(js_name = "decrypt")]
72 | pub fn wasm_decrypt(pri_key: String, msg: String) -> String
73 | {
74 | // utils::set_panic_hook();
75 |
76 | let mut arr = [0u8; 32]; // temp buff
77 | let private_key: &[u8; 32] = match pri_key.trim().from_base64()
78 | {
79 | Ok(m) =>
80 | {
81 | if m.len() != 32
82 | {
83 | // let e_str = format!("Private key size is wrong");
84 | // log!("{}", e_str);
85 | return String::new()
86 | }
87 | arr.copy_from_slice(&m);
88 | &arr
89 | },
90 | Err(why) =>
91 | {
92 | // let e_str = format!("Private key is wrong\n For reason: {}", why);
93 | // log!("{}", e_str);
94 | return String::new()
95 | }
96 | };
97 |
98 | let recv_msg: Vec = match msg.as_bytes().from_base64()
99 | {
100 | Ok(r) => r,
101 | Err(_) =>
102 | {
103 | // let e_str = format!("Invalid Base64 string");
104 | // log!("{}", e_str);
105 | return String::new()
106 | }
107 | };
108 |
109 | let dec_dat: Vec = match decrypt_buf(&private_key, &recv_msg)
110 | {
111 | Ok(d) => d,
112 | Err(_) =>
113 | {
114 | // let e_str = format!("Couldn't decrypt data");
115 | // log!("{}", e_str);
116 | return String::new()
117 | }
118 | };
119 |
120 | String::from_utf8(dec_dat).unwrap()
121 | }
122 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/src/utils.rs:
--------------------------------------------------------------------------------
1 | pub fn set_panic_hook() {
2 | // When the `console_error_panic_hook` feature is enabled, we can call the
3 | // `set_panic_hook` function at least once during initialization, and then
4 | // we will get better error messages if our code ever panics.
5 | //
6 | // For more details see
7 | // https://github.com/rustwasm/console_error_panic_hook#readme
8 | #[cfg(feature = "console_error_panic_hook")]
9 | console_error_panic_hook::set_once();
10 | }
11 |
--------------------------------------------------------------------------------
/WebAssembly/crypto-demo/tests/web.rs:
--------------------------------------------------------------------------------
1 | //! Test suite for the Web and headless browsers.
2 |
3 | #![cfg(target_arch = "wasm32")]
4 |
5 | extern crate wasm_bindgen_test;
6 | use wasm_bindgen_test::*;
7 |
8 | wasm_bindgen_test_configure!(run_in_browser);
9 |
10 | #[wasm_bindgen_test]
11 | fn pass() {
12 | assert_eq!(1 + 1, 2);
13 | }
14 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/._CryptoDemo.xcodeproj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/._CryptoDemo.xcodeproj
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/._project.xcworkspace:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/._project.xcworkspace
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/owner.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/owner.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | BuildLocationStyle
6 | UseAppPreferences
7 | CustomBuildLocationType
8 | RelativeToDerivedData
9 | DerivedDataLocationStyle
10 | Default
11 | EnabledFullIndexStoreVisibility
12 |
13 | IssueFilterStyle
14 | ShowActiveSchemeOnly
15 | LiveSourceIssuesEnabled
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/project.xcworkspace/xcuserdata/tungthanhnguyen.xcuserdatad/xcdebugger/Expressions.xcexplist:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
8 |
10 |
11 |
12 |
13 |
15 |
16 |
18 |
19 |
21 |
22 |
23 |
24 |
26 |
27 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
45 |
51 |
52 |
53 |
54 |
60 |
62 |
68 |
69 |
70 |
71 |
73 |
74 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcshareddata/xcschemes/Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
48 |
50 |
56 |
57 |
58 |
59 |
65 |
67 |
73 |
74 |
75 |
76 |
78 |
79 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/owner.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Debug.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 1
11 |
12 | Release.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 0
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | 8FA604D51EF5204700D6B7EF
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcschemes/CryptoDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo.xcodeproj/xcuserdata/tungthanhnguyen.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | CryptoDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | Release.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 1
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | 8FA604D51EF5204700D6B7EF
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // CryptoDemo
4 | //
5 | // Created by Tung Thanh Nguyen on 6/17/17.
6 | // Copyright © 2017 Comtasoft. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | }
88 | ],
89 | "info" : {
90 | "version" : 1,
91 | "author" : "xcode"
92 | }
93 | }
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/CryptoDemo-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Use this file to import your target's public headers that you would like to expose to Swift.
3 | //
4 |
5 | //
6 | // CryptoDemo-Bridging-Header.h
7 | // CryptoDemo
8 | //
9 | // Created by Tung Thanh Nguyen on 6/17/17.
10 | // Copyright © 2017 Comtasoft. All rights reserved.
11 | //
12 |
13 | #ifndef CryptoDemo_Bridging_Header_h
14 | #define CryptoDemo_Bridging_Header_h
15 |
16 | #import
17 |
18 | #include "RustCrypto.h"
19 |
20 | #endif /* CryptoDemo_Bridging_Header_h */
21 |
22 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/RustCrypto.h:
--------------------------------------------------------------------------------
1 | //
2 | // RustCrypto.h
3 | // CryptoDemo
4 | //
5 | // Created by Tung Thanh Nguyen on 6/17/17.
6 | // Copyright © 2017 Comtasoft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #include "rust_crypto.h"
12 |
13 | @interface RustCrypto : NSObject
14 |
15 | - (instancetype) init;
16 |
17 | - (NSString*) encrypt:(NSString*) pubKey rawMessage:(NSString*) message;
18 | - (NSString*) decrypt:(NSString*) priKey encryptedMessage:(NSString*) message;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/RustCrypto.m:
--------------------------------------------------------------------------------
1 | //
2 | // RustCrypto.m
3 | // CryptoDemo
4 | //
5 | // Created by Tung Thanh Nguyen on 6/17/17.
6 | // Copyright © 2017 Comtasoft. All rights reserved.
7 | //
8 |
9 | #import "RustCrypto.h"
10 |
11 | @implementation RustCrypto
12 |
13 | - (instancetype) init
14 | {
15 | self = [super init];
16 | return self;
17 | }
18 |
19 | - (NSString*) encrypt:(NSString*) pubKey rawMessage:(NSString*) message
20 | {
21 | const char* result = (const char *) rust_encrypt([pubKey UTF8String], [message UTF8String]);
22 | return [[NSString alloc] initWithCString:result encoding:NSUTF8StringEncoding];
23 | }
24 |
25 | - (NSString*) decrypt:(NSString*) priKey encryptedMessage:(NSString*) message
26 | {
27 | const char* result = rust_decrypt([priKey UTF8String], [message UTF8String]);
28 | return [[NSString alloc] initWithCString:result encoding:NSUTF8StringEncoding];
29 | }
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/CryptoDemo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // CryptoDemo
4 | //
5 | // Created by Tung Thanh Nguyen on 6/17/17.
6 | // Copyright © 2017 Comtasoft. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController
12 | {
13 | @IBOutlet var message: UITextField!
14 | @IBOutlet var lblEncryptedText: UILabel!
15 | @IBOutlet var lblDecryptedText: UILabel!
16 |
17 | let crypto = RustCrypto()!
18 |
19 | let pubKey = "ij2bL9WP9+R27/8VjjxVWoba4o3IbTpOme0o28Hjwic="
20 | let priKey = "E3B3Q3TglEQKg+w7CBkQ8XmrqemJ4fYGkTzWPSMUhW8="
21 |
22 | override func viewDidLoad()
23 | {
24 | super.viewDidLoad()
25 | // Do any additional setup after loading the view, typically from a nib.
26 | }
27 |
28 | override func didReceiveMemoryWarning()
29 | {
30 | super.didReceiveMemoryWarning()
31 | // Dispose of any resources that can be recreated.
32 | }
33 |
34 | @IBAction func action(_ sender: UIButton)
35 | {
36 | if !(message.text?.isEmpty)! && !(message.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty)!
37 | {
38 | let c = crypto.encrypt(pubKey, rawMessage: message.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines))
39 | let d = crypto.decrypt(priKey, encryptedMessage: c)
40 |
41 | lblEncryptedText.text = c
42 | lblDecryptedText.text = d
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/iOS/CryptoDemo/OptimizationProfiles/CryptoDemo.profdata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tungthanhnguyen/Rust-crypto_ios_android/e9d7536094e252242948818269b7e1d60a830990/iOS/CryptoDemo/OptimizationProfiles/CryptoDemo.profdata
--------------------------------------------------------------------------------