init commit

This commit is contained in:
JohnE 2017-01-18 18:01:28 -08:00
commit e9dea379c8
84 changed files with 1132 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.gradle
.idea
**/*.iml
local.properties
build
*~
.externalNativeBuild
libwebp
.DS_Store

122
app/build.gradle Normal file
View File

@ -0,0 +1,122 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId 'xyz.nc.android.wc'
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
// ndk default settings for this build
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
// set these default settings
externalNativeBuild {
arguments '-DANDROID_TOOLCHAIN=clang'
//arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static', '-DANDROID_PLATFORM=android-21'
//arguments '-DANDROID_TOOLCHAIN=gcc', '-DANDROID_STL=c++_static', '-DANDROID_PLATFORM=android-22'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// this block links Gradle to the CMake (or ndk-build)
externalNativeBuild {
// cmake build configuration
cmake {
// relative path to CMake build script
path 'src/main/cpp/CMakeLists.txt'
// Passes optional arguments to CMake.
//arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"
// Sets optional flags for the C compiler.
//cFlags "-D_EXAMPLE_C_FLAG1", "-D_EXAMPLE_C_FLAG2"
// Sets a flag to enable format macro constants for the C++ compiler.
//cppFlags "-D__STDC_FORMAT_MACROS"
}
}
sourceSets {
main {
// let gradle pack the shared library into apk
//jniLibs.srcDirs = ['../wolfssl/dist']
//jniLibs.srcDirs = ['../dist/gperf/lib']
}
}
productFlavors {
demo {
// different build settings
externalNativeBuild {
// ...
// targets "native-lib-demo"
}
}
paid {
externalNativeBuild {
// ..
// targets "native-lib-paid"
}
}
// in the future, ndk.abiFilter might also work
// arm7 {
// ndk {
// abiFilter 'armeabi-v7a'
// }
// }
// arm8 {
// ndk {
// abiFilters 'arm64-v8a'
// }
// }
// arm {
// ndk {
// abiFilter 'armeabi'
// }
// }
// x86 {
// ndk {
// abiFilter 'x86'
// }
// }
// x86_64 {
// ndk {
// abiFilter 'x86_64'
// }
// }
// mips {
// ndk {
// abiFilters 'mips', 'mips64'
// }
// }
// all {
// ndk {
// abiFilters 'mips', 'mips64', 'x86', 'x86_64'
// }
// }
} // productFlavors
} // android
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}

17
app/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/gfan/dev/sdk_current/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,49 @@
#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required(VERSION 3.4.1)
# configure import libs
# set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)
add_library(lib_gmath STATIC IMPORTED)
set_target_properties(lib_gmath PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gmath/lib/${ANDROID_ABI}/libgmath.a)
# shared lib will also be tucked into APK and sent to target
# refer to app/build.gradle, jniLibs section for that purpose.
# ${ANDROID_ABI} is handy for our purpose here. Probably this ${ANDROID_ABI} is
# the most valuable thing of this sample, the rest are pretty much normal cmake
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
# build application's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(hello-libs SHARED
hello-libs.cpp)
target_include_directories(hello-libs PRIVATE
${distribution_DIR}/gmath/include
${distribution_DIR}/gperf/include)
target_link_libraries(hello-libs
android
lib_gmath
lib_gperf
log)

View File

@ -0,0 +1,250 @@
/* com_wolfssl_wolfcrypt_RSA.c
*
* Copyright (C) 2006-2016 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include "com_wolfssl_wolfcrypt_RSA.h"
#include <stdio.h>
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doSign
(JNIEnv* jenv, jobject jcl, jobject in, jlong inSz, jobject out,
jintArray outSz, jobject keyDer, jlong keySz)
{
int ret;
RNG rng;
RsaKey myKey;
unsigned int idx;
unsigned int tmpOut;
/* check in and key sz */
if ((inSz < 0) || (keySz < 0)) {
return -1;
}
/* get pointers to our buffers */
unsigned char* inBuf = (*jenv)->GetDirectBufferAddress(jenv, in);
if (inBuf == NULL) {
printf("problem getting in buffer address\n");
return -1;
}
unsigned char* outBuf = (*jenv)->GetDirectBufferAddress(jenv, out);
if (outBuf == NULL) {
printf("problem getting out buffer address\n");
return -1;
}
unsigned char* keyBuf = (*jenv)->GetDirectBufferAddress(jenv, keyDer);
if (keyBuf == NULL) {
printf("problem getting key buffer address\n");
return -1;
}
/* get output buffer size */
(*jenv)->GetIntArrayRegion(jenv, outSz, 0, 1, (jint*)&tmpOut);
wc_InitRng(&rng);
wc_InitRsaKey(&myKey, NULL);
idx = 0;
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, (unsigned int)keySz);
if (ret == 0) {
ret = wc_RsaSSL_Sign(inBuf, (unsigned int)inSz, outBuf, tmpOut,
&myKey, &rng);
if (ret > 0) {
/* save and convert to 0 for success */
(*jenv)->SetIntArrayRegion(jenv, outSz, 0, 1, (jint*)&tmpOut);
ret = 0;
}
} else {
printf("wc_RsaPrivateKeyDecode failed, ret = %d\n", ret);
}
wc_FreeRsaKey(&myKey);
return ret;
}
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doVerify
(JNIEnv* jenv, jobject jcl, jobject sig, jlong sigSz, jobject out,
jlong outSz, jobject keyDer, jlong keySz)
{
int ret;
RsaKey myKey;
unsigned int idx;
/* check in and key sz */
if ((sigSz < 0) || (keySz < 0) || (outSz < 0)) {
return -1;
}
/* get pointers to our buffers */
unsigned char* sigBuf = (*jenv)->GetDirectBufferAddress(jenv, sig);
if (sigBuf == NULL) {
printf("problem getting sig buffer address\n");
return -1;
}
unsigned char* outBuf = (*jenv)->GetDirectBufferAddress(jenv, out);
if (outBuf == NULL) {
printf("problem getting out buffer address\n");
return -1;
}
unsigned char* keyBuf = (*jenv)->GetDirectBufferAddress(jenv, keyDer);
if (keyBuf == NULL) {
printf("problem getting key buffer address\n");
return -1;
}
wc_InitRsaKey(&myKey, NULL);
idx = 0;
ret = wc_RsaPublicKeyDecode(keyBuf, &idx, &myKey, (unsigned int)keySz);
if (ret == 0) {
ret = wc_RsaSSL_Verify(sigBuf, (unsigned int)sigSz, outBuf,
(unsigned int)outSz, &myKey);
if (ret < 0) {
printf("wc_RsaSSL_Verify failed, ret = %d\n", ret);
return ret;
}
} else {
printf("wc_RsaPublicKeyDecode failed, ret = %d\n", ret);
}
wc_FreeRsaKey(&myKey);
return ret;
}
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doEnc
(JNIEnv* jenv, jobject jcl, jobject in, jlong inSz, jobject out,
jintArray outSz, jobject keyDer, jlong keySz)
{
int ret;
RsaKey myKey;
RNG rng;
unsigned int idx;
unsigned int tmpOut;
/* check in and key sz */
if ((inSz < 0) || (keySz < 0)) {
return -1;
}
/* get pointers to our buffers */
unsigned char* inBuf = (*jenv)->GetDirectBufferAddress(jenv, in);
if (inBuf == NULL) {
printf("problem getting in buffer address\n");
return -1;
}
unsigned char* outBuf = (*jenv)->GetDirectBufferAddress(jenv, out);
if (outBuf == NULL) {
printf("problem getting out buffer address\n");
return -1;
}
unsigned char* keyBuf = (*jenv)->GetDirectBufferAddress(jenv, keyDer);
if (keyBuf == NULL) {
printf("problem getting key buffer address\n");
return -1;
}
/* get output buffer size */
(*jenv)->GetIntArrayRegion(jenv, outSz, 0, 1, (jint*)&tmpOut);
wc_InitRng(&rng);
wc_InitRsaKey(&myKey, NULL);
idx = 0;
ret = wc_RsaPublicKeyDecode(keyBuf, &idx, &myKey, (unsigned int)keySz);
if (ret == 0) {
ret = wc_RsaPublicEncrypt(inBuf, (unsigned int)inSz, outBuf, tmpOut,
&myKey, &rng);
if (ret > 0) {
/* save and convert to 0 for success */
(*jenv)->SetIntArrayRegion(jenv, outSz, 0, 1, (jint*)&ret);
ret = 0;
}
} else {
printf("wc_RsaPublicKeyDecode failed, ret = %d\n", ret);
}
wc_FreeRsaKey(&myKey);
return ret;
}
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doDec
(JNIEnv* jenv, jobject jcl, jobject in, jlong inSz, jobject out,
jlong outSz, jobject keyDer, jlong keySz)
{
int ret;
RsaKey myKey;
unsigned int idx;
/* check in and key sz */
if ((inSz < 0) || (keySz < 0) || (outSz < 0)) {
return -1;
}
/* get pointers to our buffers */
unsigned char* inBuf = (*jenv)->GetDirectBufferAddress(jenv, in);
if (inBuf == NULL) {
printf("problem getting in buffer address\n");
return -1;
}
unsigned char* outBuf = (*jenv)->GetDirectBufferAddress(jenv, out);
if (outBuf == NULL) {
printf("problem getting out buffer address\n");
return -1;
}
unsigned char* keyBuf = (*jenv)->GetDirectBufferAddress(jenv, keyDer);
if (keyBuf == NULL) {
printf("problem getting key buffer address\n");
return -1;
}
wc_InitRsaKey(&myKey, NULL);
idx = 0;
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, (unsigned int)keySz);
if (ret == 0) {
ret = wc_RsaPrivateDecrypt(inBuf, (unsigned int)inSz, outBuf,
(unsigned int)outSz, &myKey);
if (ret < 0) {
printf("wc_RsaPrivateDecrypt failed, ret = %d\n", ret);
return ret;
}
} else {
printf("wc_RsaPrivateKeyDecode failed, ret = %d\n", ret);
}
wc_FreeRsaKey(&myKey);
return ret;
}

View File

@ -0,0 +1,45 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_wolfssl_wolfcrypt_RSA */
#ifndef _Included_com_wolfssl_wolfcrypt_RSA
#define _Included_com_wolfssl_wolfcrypt_RSA
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_wolfssl_wolfcrypt_RSA
* Method: doSign
* Signature: (Ljava/nio/ByteBuffer;JLjava/nio/ByteBuffer;[ILjava/nio/ByteBuffer;J)I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doSign
(JNIEnv *, jobject, jobject, jlong, jobject, jintArray, jobject, jlong);
/*
* Class: com_wolfssl_wolfcrypt_RSA
* Method: doVerify
* Signature: (Ljava/nio/ByteBuffer;JLjava/nio/ByteBuffer;JLjava/nio/ByteBuffer;J)I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doVerify
(JNIEnv *, jobject, jobject, jlong, jobject, jlong, jobject, jlong);
/*
* Class: com_wolfssl_wolfcrypt_RSA
* Method: doEnc
* Signature: (Ljava/nio/ByteBuffer;JLjava/nio/ByteBuffer;[ILjava/nio/ByteBuffer;J)I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doEnc
(JNIEnv *, jobject, jobject, jlong, jobject, jintArray, jobject, jlong);
/*
* Class: com_wolfssl_wolfcrypt_RSA
* Method: doDec
* Signature: (Ljava/nio/ByteBuffer;JLjava/nio/ByteBuffer;JLjava/nio/ByteBuffer;J)I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_RSA_doDec
(JNIEnv *, jobject, jobject, jlong, jobject, jlong, jobject, jlong);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,50 @@
/* RSA.java
*
* Copyright (C) 2006-2016 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package com.wolfssl.wolfcrypt;
import java.nio.ByteBuffer;
/**
* Wrapper for the native WolfCrypt RSA implementation, used for examples.
* This class contains a subset of the WolfCrypt RSA implementation and was
* written to be used with this package's example RSA public key callbacks.
* Usage can be found in examples/Client.java and examples/Server.java.
*
* @author wolfSSL
* @version 1.0, August 2013
*/
public class RSA {
public native int doSign(ByteBuffer in, long inSz, ByteBuffer out,
int[] outSz, ByteBuffer key, long keySz);
public native int doVerify(ByteBuffer sig, long sigSz, ByteBuffer out,
long outSz, ByteBuffer keyDer, long keySz);
public native int doEnc(ByteBuffer in, long inSz, ByteBuffer out,
int[] outSz, ByteBuffer keyDer, long keySz);
public native int doDec(ByteBuffer in, long inSz, ByteBuffer out,
long outSz, ByteBuffer keyDer, long keySz);
}

24
build.gradle Normal file
View File

@ -0,0 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
//classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

0
build.properties Normal file
View File

12
docs/nc-wc-ndk Normal file
View File

@ -0,0 +1,12 @@
[[[ Normalized Crypto WolfCrypt NDK ]]]
[[ Features ]]
-uses gradle to build native files
-uses NEW CMake (CMake Android plugin)
-AEAD crypto support
-NO LEGACY. removes legacy crypto support
-WolfSSL crypto engine
-FIPS-140 ver available
-Quantum-Computing safe crypto
-super-fast NTRU algorithm

17
docs/nc-wc-ndk_dev Normal file
View File

@ -0,0 +1,17 @@
[[[ NC WC Dev Notes ]]]
[[ Links ]]
# gradle plugin versions
@ https://jcenter.bintray.com/com/android/tools/build/gradle/
# gradle ndk support
@ http://tools.android.com/tech-docs/new-build-system/gradle-experimental/migrate-to-stable
[ CMake ]
@ https://developer.android.com/ndk/guides/cmake.html
# cmake building examples
@ https://github.com/googlesamples/android-ndk/tree/master-cmake

0
gradle.properties Normal file
View File

1
settings.gradle Normal file
View File

@ -0,0 +1 @@
include ':app'

40
wolfcrypt/build.gradle Normal file
View File

@ -0,0 +1,40 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-9',
'-DANDROID_TOOLCHAIN=clang'
// explicitly build libs
targets 'gmath', 'gperf'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
}

0
wolfcrypt/dist/wolfcrypt.so vendored Normal file
View File

17
wolfcrypt/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/gfan/dev/sdk_current/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.buildlibs">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>

View File

@ -0,0 +1,32 @@
#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generate one static lib and one shared lib, copy them into
# ${project_dir}/distribution for other indepdendent applications
# to use.
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(lib_src_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(lib_build_DIR $ENV{HOME}/tmp)
file(MAKE_DIRECTORY ${lib_build_DIR})
add_subdirectory(${lib_src_DIR}/gmath ${lib_build_DIR}/gmath)
add_subdirectory(${lib_src_DIR}/gperf ${lib_build_DIR}/gperf)

View File

@ -0,0 +1,43 @@
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Build a static lib and copy it into distribution place for independent app to use
# we could not delete the bin directory is because android studio would error out
# when it checks target's existance. Only distribution place is used as import to app
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(gmath STATIC src/gmath.c)
# copy out the lib binary... need to leave the static lib around to pass gradle check
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gmath
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY
"${distribution_DIR}/gmath/lib/${ANDROID_ABI}")
# copy out lib header file...
add_custom_command(TARGET gmath POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
copy "${CMAKE_CURRENT_SOURCE_DIR}/src/gmath.h"
"${distribution_DIR}/gmath/include/gmath.h"
# **** the following 2 lines are for potential future debug purpose ****
# COMMAND "${CMAKE_COMMAND}" -E
# remove_directory "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Copying gmath to output directory")

View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <android/log.h>
#include "gmath.h"
#if defined(__GNUC__) && __GNUC__ >= 4
#define GMATH_EXPORT __attribute__((visibility("default")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define GMATH_EXPORT __attribute__((visibility("default")))
#else
#define GMATH_EXPORT
#endif
#define LOGE(...) \
((void)__android_log_print(ANDROID_LOG_ERROR, "gmath::", __VA_ARGS__))
/*
* return 2 ^ n with multiplication implementation
*/
GMATH_EXPORT unsigned gpower(unsigned n) {
if (n == 0)
return 1;
if (n > 31) {
LOGE("error from power(%d): integer overflow", n);
return 0;
}
unsigned val = gpower(n>>1) * gpower (n>>1);
if (n & 1)
val *= 2;
return val;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef __POWER_HPP__
#define __POWER_HPP__
/*
* return pow(2, n)
*/
#ifdef __cplusplus
extern "C"
#endif // __cplusplus
unsigned gpower(unsigned n);
#endif //__POWER_HPP__

View File

@ -0,0 +1,38 @@
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Build one shared lib. When we build, we set the bin to $user/tmp, and
# remove it after build complete, so only the distribution place could be
# used for application linking.
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(gperf SHARED src/gperf.c)
# copy out the lib binary and remove generated files
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gperf
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
"${distribution_DIR}/gperf/lib/${ANDROID_ABI}")
add_custom_command(TARGET gperf POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
copy "${CMAKE_CURRENT_SOURCE_DIR}/src/gperf.h"
"${distribution_DIR}/gperf/include/gperf.h"
COMMENT "Copying gperf to output directory")

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <time.h>
#include "gperf.h"
#if defined(__GNUC__) && __GNUC__ >= 4
#define GPERF_EXPORT __attribute__((visibility("default")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define GPERF_EXPORT __attribute__((visibility("default")))
#else
#define GPERF_EXPORT
#endif
/*
* return current ticks
*/
GPERF_EXPORT uint64_t GetTicks(void) {
struct timeval Time;
uint64_t cur_tick = (uint64_t) 1000000;
gettimeofday( &Time, NULL );
cur_tick *= Time.tv_sec;
return (cur_tick + Time.tv_usec);
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef __GPERF_HPP__
#define __GPERF_HPP__
#include <sys/types.h>
/*
* return current system ticks
*/
#ifdef __cplusplus
extern "C"
#endif // __cplusplus
uint64_t GetTicks(void);
#endif //__GPERF_HPP__

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">BuildLibs</string>
</resources>

40
wolfssl/build.gradle Normal file
View File

@ -0,0 +1,40 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 13
targetSdkVersion 23
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-9',
'-DANDROID_TOOLCHAIN=clang'
// explicitly build libs
targets 'gmath', 'gperf'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
wolfssl/dist/android-19/armeabi/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/armeabi/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

0
wolfssl/dist/android-19/kitkat_4.4 vendored Normal file
View File

BIN
wolfssl/dist/android-19/mips/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/mips/libwolfssl.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/mips/libwolfssljni.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/mips64/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/mips64/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

BIN
wolfssl/dist/android-19/x86/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/x86/libwolfssl.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/x86/libwolfssljni.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/x86_64/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-19/x86_64/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
wolfssl/dist/android-21/armeabi/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/armeabi/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

0
wolfssl/dist/android-21/lollipop_5.0 vendored Normal file
View File

BIN
wolfssl/dist/android-21/mips/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/mips/libwolfssl.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/mips/libwolfssljni.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/mips64/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/mips64/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

BIN
wolfssl/dist/android-21/x86/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/x86/libwolfssl.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/x86/libwolfssljni.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/x86_64/libjnitest.so vendored Executable file

Binary file not shown.

BIN
wolfssl/dist/android-21/x86_64/libwolfssl.so vendored Executable file

Binary file not shown.

Binary file not shown.

0
wolfssl/dist/include/include.h vendored Normal file
View File

0
wolfssl/dist/include/ssl.h vendored Normal file
View File

View File

@ -0,0 +1,4 @@
#!/bin/sh
git clone https://github.com/wolfSSL/wolfssl.git
git checkout v3.10.0-stable
git checkout -b building

17
wolfssl/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/gfan/dev/sdk_current/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.buildlibs">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>

View File

@ -0,0 +1,100 @@
TOP_PATH := $(call my-dir)/..
WOLFSSL_DIR := wolfssl
# Build wolfSSL shared library
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/$(WOLFSSL_DIR)
LOCAL_MODULE := libwolfssl
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := -DOPENSSL_EXTRA -DWOLFSSL_DTLS -D_POSIX_THREADS -DNDEBUG \
-DPERSIST_SESSION_CACHE -DPERSIST_CERT_CACHE -DATOMIC_USER \
-DHAVE_PK_CALLBACKS -DNO_DSA -DHAVE_ECC -DTFM_ECC256 \
-DECC_SHAMIR -DNO_MD4 -DNO_HC128 -DNO_RABBIT \
-DHAVE_OCSP -DHAVE_CRL -DWOLFSSL_JNI -DHAVE_DH \
-Wall
LOCAL_SRC_FILES := src/crl.c \
src/internal.c \
src/io.c \
src/keys.c \
src/ocsp.c \
src/sniffer.c \
src/ssl.c \
src/tls.c \
wolfcrypt/src/aes.c \
wolfcrypt/src/arc4.c \
wolfcrypt/src/asm.c \
wolfcrypt/src/asn.c \
wolfcrypt/src/blake2b.c \
wolfcrypt/src/camellia.c \
wolfcrypt/src/chacha.c \
wolfcrypt/src/chacha20_poly1305.c \
wolfcrypt/src/coding.c \
wolfcrypt/src/compress.c \
wolfcrypt/src/curve25519.c \
wolfcrypt/src/des3.c \
wolfcrypt/src/dh.c \
wolfcrypt/src/dsa.c \
wolfcrypt/src/ecc.c \
wolfcrypt/src/ecc_fp.c \
wolfcrypt/src/ed25519.c \
wolfcrypt/src/error.c \
wolfcrypt/src/fe_low_mem.c \
wolfcrypt/src/fe_operations.c \
wolfcrypt/src/ge_low_mem.c \
wolfcrypt/src/ge_operations.c \
wolfcrypt/src/hash.c \
wolfcrypt/src/hc128.c \
wolfcrypt/src/hmac.c \
wolfcrypt/src/idea.c \
wolfcrypt/src/integer.c \
wolfcrypt/src/logging.c \
wolfcrypt/src/md2.c \
wolfcrypt/src/md4.c \
wolfcrypt/src/md5.c \
wolfcrypt/src/memory.c \
wolfcrypt/src/misc.c \
wolfcrypt/src/pkcs7.c \
wolfcrypt/src/pkcs12.c \
wolfcrypt/src/poly1305.c \
wolfcrypt/src/pwdbased.c \
wolfcrypt/src/rabbit.c \
wolfcrypt/src/random.c \
wolfcrypt/src/ripemd.c \
wolfcrypt/src/rsa.c \
wolfcrypt/src/sha.c \
wolfcrypt/src/sha256.c \
wolfcrypt/src/sha512.c \
wolfcrypt/src/srp.c \
wolfcrypt/src/tfm.c \
wolfcrypt/src/wc_encrypt.c \
wolfcrypt/src/wc_port.c
include $(BUILD_SHARED_LIBRARY)
## Build wolfSSL JNI library
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/wolfssljni
LOCAL_MODULE := libwolfssljni
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/native
LOCAL_C_INCLUDES := $(LOCAL_PATH)/native
LOCAL_SRC_FILES := native/com_wolfssl_WolfSSL.c \
native/com_wolfssl_WolfSSLContext.c \
native/com_wolfssl_WolfSSLSession.c \
native/com_wolfssl_wolfcrypt_ECC.c \
native/com_wolfssl_wolfcrypt_RSA.c
LOCAL_CFLAGS := -Wall -Os -DWOLFSSL_DTLS -DHAVE_ECC
LOCAL_SHARED_LIBRARIES := libwolfssl
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/jni
LOCAL_MODULE := libjnitest
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := jnitest.c
LOCAL_CFLAGS := -Wall
LOCAL_SHARED_LIBRARIES := libwolfssl
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,5 @@
#
APP_ABI := all
#APP_ABI := armeabi armeabi-v7a x86 x86_64
#APP_ABI := mips mips64 arm64-v8a
#APP_ABI := arm64-v8a

View File

@ -0,0 +1,32 @@
#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generate one static lib and one shared lib, copy them into
# ${project_dir}/distribution for other indepdendent applications
# to use.
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(lib_src_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(lib_build_DIR $ENV{HOME}/tmp)
file(MAKE_DIRECTORY ${lib_build_DIR})
add_subdirectory(${lib_src_DIR}/gmath ${lib_build_DIR}/gmath)
add_subdirectory(${lib_src_DIR}/gperf ${lib_build_DIR}/gperf)

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">BuildLibs</string>
</resources>