diff --git a/cryptography/src/androidMain/jni/Android.mk b/cryptography/src/androidMain/jni/Android.mk deleted file mode 100644 index 92b75e2c49b..00000000000 --- a/cryptography/src/androidMain/jni/Android.mk +++ /dev/null @@ -1,16 +0,0 @@ -TOP_DIR := $(call my-dir) -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := lzw-decoder -LOCAL_SRC_FILES := LzwDecoder.cpp -LOCAL_LDLIBS := -llog -LOCAL_CFLAGS := -O2 -Wall -pedantic -Wno-variadic-macros -fstack-protector-all -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := randombytes -LOCAL_SRC_FILES := randombytes.c -LOCAL_CFLAGS := -std=c99 -O2 -Wall -pedantic -Wno-variadic-macros -lsodium -fstack-protector-all -LOCAL_LDLIBS += $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/libsodium.so -include $(BUILD_SHARED_LIBRARY) diff --git a/cryptography/src/androidMain/jni/Application.mk b/cryptography/src/androidMain/jni/Application.mk deleted file mode 100644 index d7f8a091dac..00000000000 --- a/cryptography/src/androidMain/jni/Application.mk +++ /dev/null @@ -1 +0,0 @@ -APP_ABI := armeabi-v7a x86 arm64-v8a x86_64 diff --git a/cryptography/src/androidMain/jni/LzwDecoder.cpp b/cryptography/src/androidMain/jni/LzwDecoder.cpp deleted file mode 100644 index fae4b625aa8..00000000000 --- a/cryptography/src/androidMain/jni/LzwDecoder.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Wire - * Copyright (C) 2016 Wire Swiss GmbH - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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, see . - */ - -#include "LzwDecoder.h" - -#ifdef __ANDROID__ -#include -#define LOG(...) __android_log_print(ANDROID_LOG_VERBOSE,"LzwDecoder_native",__VA_ARGS__) -#endif - -#ifndef __ANDROID__ -#include -#define LOG(...) printf(__VA_ARGS__) -#endif - -#define INT_MIN (-INT_MAX - 1) -#define INT_MAX 2147483647 - -static const int MAX_STACK_SIZE = 4096; -static const int PIXEL_STACK_SIZE = 8192; -static const int NULL_CODE = -1; - - -/* We use failed to signal failure since using exceptions would require us to include the entire - * C++ stdlib in this library, and we are trying to keep the size down */ -LzwDecoder::LzwDecoder(byte* image, int* pixels, int* colors, int width, int height, int* failed) { - if (image == 0 || width <= 0 || height <= 0) { - *failed = -1; - } else { - this->image = image; - this->pixels = pixels; - this->colors = colors; - this->width = width; - this->height = height; - - prefix = new unsigned short[MAX_STACK_SIZE]; - suffix = new byte[MAX_STACK_SIZE]; - pixelStack = new byte[PIXEL_STACK_SIZE]; - block = new byte[256]; - *failed = 0; - } -} - - -LzwDecoder::~LzwDecoder() { - delete[] prefix; - delete[] suffix; - delete[] pixelStack; - delete[] block; -} - - -void LzwDecoder::clear(int x, int y, int w, int h, int color) { - if (x < 0 || y < 0 || x >= w || y >= h || - (((y > 0) && (x > (INT_MAX - y))) || - ((y < 0) && (x < (INT_MIN - y))))) { - return; - } - int* dst = pixels + (x + y * width); - for (int l = 0; l < h; ++l) { - for (int i = 0; i < w; ++i) { - (*dst++) = color; - } - dst += width - w - x; - } -} - -void LzwDecoder::decode(int fx, int fy, int fw, int fh, int inputSize, int transIndex, int bgColor, bool interlace, bool transparency) { - int idx = 0; - int npix = fw * fh; - int available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, count, i, datum, data_size, first, top, bi, pi; - int endX, x, end, pass, inc, line; - - // Initialize GIF data stream decoder. - data_size = image[idx++]; - clear = 1 << data_size; - end_of_information = clear + 1; - available = clear + 2; - old_code = NULL_CODE; - code_size = data_size + 1; - code_mask = (1 << code_size) - 1; - if (clear >= MAX_STACK_SIZE || clear < 0) return; - for (code = 0; code < clear; ++code) { - prefix[code] = 0; - suffix[code] = (byte)code; - } - - // Decode GIF pixel stream. - datum = bits = count = first = top = pi = bi = 0; - endX = fx + fw; - x = fx; - - // line number with interlacing - end = fy + fh; - pass = 1; - inc = interlace ? 8 : 1; - line = fy; - - for (i = 0; i < npix;) { - if (bits < code_size) { - // Load bytes until there are enough bits for a code. - if (count == 0) { - // Read a new data block. - if (idx >= inputSize) break; //bounds check - count = image[idx++]; - if (idx + count >= inputSize) break; // bounds check - for (int k = 0; k < count; ++k) { - block[k] = image[idx++]; - } - - if (count <= 0) { - break; - } - bi = 0; - } - datum += (block[bi] & 0xff) << bits; - bits += 8; - bi++; - count--; - continue; - } - // Get the next code. - code = datum & code_mask; - datum >>= code_size; - bits -= code_size; - if (code >= MAX_STACK_SIZE) { - return; - } - // Interpret the code - if (code == end_of_information) { - break; - } - if (code == clear) { - // Reset decoder. - code_size = data_size + 1; - code_mask = (1 << code_size) - 1; - available = clear + 2; - old_code = NULL_CODE; - continue; - } - if (old_code == NULL_CODE) { - pixelStack[top++] = suffix[code]; - old_code = code; - first = code; - continue; - } - in_code = code; - if (code >= available) { - pixelStack[top++] = (byte)first; - code = old_code; - } - while (code > clear) { - if (top >= PIXEL_STACK_SIZE) { - return; - } - pixelStack[top++] = suffix[code]; - code = prefix[code]; - } - first = suffix[code] & 0xff; - pixelStack[top++] = (byte)first; - - if (available < MAX_STACK_SIZE) { - prefix[available] = (short)old_code; - suffix[available] = (byte)first; - available++; - if (((available & code_mask) == 0) && (available < MAX_STACK_SIZE)) { - code_size++; - code_mask += available; - } - } - old_code = in_code; - - // Pop pixels off the pixel stack. - while (top > 0 && i < npix) { - if (x == endX) { - x = fx; - line += inc; - if (interlace) { - while (line >= end && pass < 5) { - switch (++pass) { - case 2: - line = fy + 4; - break; - case 3: - line = fy + 2; - inc = 4; - break; - case 4: - line = fy + 1; - inc = 2; - break; - default: - line = fy; - inc = 1; - break; - } - } - } - } - - --top; - ++i; - if (line < end && x < endX) { - if (!transparency || pixelStack[top] != transIndex) { - pixels[x + line * width] = colors[pixelStack[top]]; - } - ++x; - } - } - } -} - - diff --git a/cryptography/src/androidMain/jni/LzwDecoder.h b/cryptography/src/androidMain/jni/LzwDecoder.h deleted file mode 100644 index acd53333e11..00000000000 --- a/cryptography/src/androidMain/jni/LzwDecoder.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Wire - * Copyright (C) 2016 Wire Swiss GmbH - * - * This program 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 3 of the License, or - * (at your option) any later version. - * - * This program 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, see . - */ - -#include - -#ifndef LzwDecoder_h -#define LzwDecoder_h - -typedef unsigned char byte; - -class LzwDecoder { - - public: - LzwDecoder(byte* image, int* pixels, int* colors, int width, int height, int* failed); - ~LzwDecoder(); - - void clear(int x, int y, int w, int h, int color); - void decode(int x, int y, int w, int h, int inputSize, int transIndex, int bgColor, bool interlace, bool transparency); - - private: - byte* image; - int* pixels; // pixels array for whole image - int* colors; // current color table - - int width; - int height; - - unsigned short *prefix; - byte *suffix; - byte *pixelStack; - byte *block; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT long JNICALL Java_com_waz_bitmap_gif_LzwDecoder_init(JNIEnv *env, jobject obj, jobject image, jobject pixels, jobject colors, jint width, jint height, jobject failed) { - return (long) (new LzwDecoder((byte*) env->GetDirectBufferAddress(image), (int*) env->GetDirectBufferAddress(pixels), (int*) env->GetDirectBufferAddress(colors), width, height, (int*) env->GetDirectBufferAddress(failed))); -} - -JNIEXPORT void JNICALL Java_com_waz_bitmap_gif_LzwDecoder_destroy(JNIEnv *env, jobject obj, jlong decoder) { - delete (LzwDecoder*) decoder; -} - -JNIEXPORT void JNICALL Java_com_waz_bitmap_gif_LzwDecoder_clear(JNIEnv *env, jobject obj, jlong decoder, jint x, jint y, jint w, jint h, jint color) { - ((LzwDecoder*) decoder)->clear(x, y, w, h, color); -} - -JNIEXPORT void JNICALL Java_com_waz_bitmap_gif_LzwDecoder_decode(JNIEnv *env, jobject obj, jlong decoder, jint x, jint y, jint w, jint h, jint inputSize, jint transIndex, jint bgColor, jboolean interlace, jboolean transparency) { - ((LzwDecoder*) decoder)->decode(x, y, w, h, inputSize, transIndex, bgColor, interlace, transparency); -} - -#ifdef __cplusplus -} -#endif -#endif diff --git a/cryptography/src/androidMain/jni/arm64-v8a/libsodium.so b/cryptography/src/androidMain/jni/arm64-v8a/libsodium.so deleted file mode 100644 index e9838813f5b..00000000000 Binary files a/cryptography/src/androidMain/jni/arm64-v8a/libsodium.so and /dev/null differ diff --git a/cryptography/src/androidMain/jni/armeabi-v7a/libsodium.so b/cryptography/src/androidMain/jni/armeabi-v7a/libsodium.so deleted file mode 100644 index d84f23d0bab..00000000000 Binary files a/cryptography/src/androidMain/jni/armeabi-v7a/libsodium.so and /dev/null differ diff --git a/cryptography/src/androidMain/jni/randombytes.c b/cryptography/src/androidMain/jni/randombytes.c deleted file mode 100644 index 11bb7f08030..00000000000 --- a/cryptography/src/androidMain/jni/randombytes.c +++ /dev/null @@ -1,19 +0,0 @@ - -#include -#include -#include - -JNIEXPORT void JNICALL Java_com_waz_utils_crypto_RandomBytes_randomBytes(JNIEnv *jenv, jobject obj, jbyteArray jarr, jint jcount) { - unsigned char* buffer = (unsigned char *) (*jenv)->GetByteArrayElements(jenv, jarr, 0); - size_t count = (size_t) jcount; - randombytes_buf(buffer, count); - (*jenv)->ReleaseByteArrayElements(jenv, jarr, (jbyte *) buffer, 0); -} - -jint JNI_OnLoad(JavaVM * vm, void* reserved) { - if (sodium_init() < 0) { - return -1; - } - - return JNI_VERSION_1_6; -} diff --git a/cryptography/src/androidMain/jni/sodium/core.h b/cryptography/src/androidMain/jni/sodium/core.h deleted file mode 100644 index 3ca447628e4..00000000000 --- a/cryptography/src/androidMain/jni/sodium/core.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef sodium_core_H -#define sodium_core_H - -#include "export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -SODIUM_EXPORT -int sodium_init(void) - __attribute__ ((warn_unused_result)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cryptography/src/androidMain/jni/sodium/export.h b/cryptography/src/androidMain/jni/sodium/export.h deleted file mode 100644 index 2566778f03e..00000000000 --- a/cryptography/src/androidMain/jni/sodium/export.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef sodium_export_H -#define sodium_export_H - -#ifndef __GNUC__ -# ifdef __attribute__ -# undef __attribute__ -# endif -# define __attribute__(a) -#endif - -#ifdef SODIUM_STATIC -# define SODIUM_EXPORT -#else -# if defined(_MSC_VER) -# ifdef SODIUM_DLL_EXPORT -# define SODIUM_EXPORT __declspec(dllexport) -# else -# define SODIUM_EXPORT __declspec(dllimport) -# endif -# else -# if defined(__SUNPRO_C) -# ifndef __GNU_C__ -# define SODIUM_EXPORT __attribute__ (visibility(__global)) -# else -# define SODIUM_EXPORT __attribute__ __global -# endif -# elif defined(_MSG_VER) -# define SODIUM_EXPORT extern __declspec(dllexport) -# else -# define SODIUM_EXPORT __attribute__ ((visibility ("default"))) -# endif -# endif -#endif - -#ifndef CRYPTO_ALIGN -# if defined(__INTEL_COMPILER) || defined(_MSC_VER) -# define CRYPTO_ALIGN(x) __declspec(align(x)) -# else -# define CRYPTO_ALIGN(x) __attribute__ ((aligned(x))) -# endif -#endif - -#endif diff --git a/cryptography/src/androidMain/jni/sodium/randombytes.h b/cryptography/src/androidMain/jni/sodium/randombytes.h deleted file mode 100644 index cbb9d6866a4..00000000000 --- a/cryptography/src/androidMain/jni/sodium/randombytes.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef randombytes_H -#define randombytes_H - -#include - -#include -#include - -#include "export.h" - -#ifdef __cplusplus -# if __GNUC__ -# pragma GCC diagnostic ignored "-Wlong-long" -# endif -extern "C" { -#endif - -typedef struct randombytes_implementation { - const char *(*implementation_name)(void); /* required */ - uint32_t (*random)(void); /* required */ - void (*stir)(void); /* optional */ - uint32_t (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */ - void (*buf)(void * const buf, const size_t size); /* required */ - int (*close)(void); /* optional */ -} randombytes_implementation; - -SODIUM_EXPORT -void randombytes_buf(void * const buf, const size_t size); - -SODIUM_EXPORT -uint32_t randombytes_random(void); - -SODIUM_EXPORT -uint32_t randombytes_uniform(const uint32_t upper_bound); - -SODIUM_EXPORT -void randombytes_stir(void); - -SODIUM_EXPORT -int randombytes_close(void); - -SODIUM_EXPORT -int randombytes_set_implementation(randombytes_implementation *impl); - -SODIUM_EXPORT -const char *randombytes_implementation_name(void); - -/* -- NaCl compatibility interface -- */ - -SODIUM_EXPORT -void randombytes(unsigned char * const buf, const unsigned long long buf_len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cryptography/src/androidMain/jni/x86/libsodium.so b/cryptography/src/androidMain/jni/x86/libsodium.so deleted file mode 100644 index accde30e767..00000000000 Binary files a/cryptography/src/androidMain/jni/x86/libsodium.so and /dev/null differ diff --git a/cryptography/src/androidMain/jni/x86_64/libsodium.so b/cryptography/src/androidMain/jni/x86_64/libsodium.so deleted file mode 100644 index 4b333bb260b..00000000000 Binary files a/cryptography/src/androidMain/jni/x86_64/libsodium.so and /dev/null differ