lk/openssl: Adding openssl to compile in lk build

This is used for verifying signed kernel.
Openssl library will be used for certificate parsing
and rsa decryption.

Change-Id: Icf0024afd8f4d8690d077b47f4b9e83cad1e4813
diff --git a/app/rules.mk b/app/rules.mk
index 74abd56..e564fe0 100644
--- a/app/rules.mk
+++ b/app/rules.mk
@@ -1,5 +1,8 @@
 LOCAL_DIR := $(GET_LOCAL_DIR)
 
+MODULES += \
+	lib/openssl
+
 OBJS += \
 	$(LOCAL_DIR)/app.o
 
diff --git a/include/assert.h b/include/assert.h
index 332dfdb..ecdfaca 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -28,6 +28,7 @@
 
 #define ASSERT(x) \
 	do { if (unlikely(!(x))) { panic("ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
+#define assert(x) ASSERT(x)
 
 #if DEBUGLEVEL > 1
 #define DEBUG_ASSERT(x) \
diff --git a/include/errno.h b/include/errno.h
new file mode 100644
index 0000000..aa53c68
--- /dev/null
+++ b/include/errno.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Code Aurora nor
+ *       the names of its contributors may be used to endorse or promote
+ *       products derived from this software without specific prior written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _ASM_GENERIC_ERRNO_H
+#define _ASM_GENERIC_ERRNO_H
+
+#endif
diff --git a/include/lib/heap.h b/include/lib/heap.h
index 54ea73b..0046e2f 100644
--- a/include/lib/heap.h
+++ b/include/lib/heap.h
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 
 void *heap_alloc(size_t, unsigned int alignment);
+void *heap_realloc(void *ptr, size_t size);
 void heap_free(void *);
 
 void heap_init(void);
diff --git a/include/malloc.h b/include/malloc.h
index d48f6d2..dc34742 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -34,6 +34,7 @@
 void *memalign(size_t boundary, size_t size) __MALLOC;
 void *calloc(size_t count, size_t size) __MALLOC;
 void free(void *ptr);
+void *realloc(void *ptr, size_t size);
 
 #if defined(__cplusplus)
 }
diff --git a/lib/heap/heap.c b/lib/heap/heap.c
index 385d13a..71b6fa4 100644
--- a/lib/heap/heap.c
+++ b/lib/heap/heap.c
@@ -333,6 +333,28 @@
 	return ptr;
 }
 
+void *heap_realloc(void *ptr, size_t size)
+{
+	void * tmp_ptr = NULL;
+	size_t min_size;
+	struct alloc_struct_begin *as = (struct alloc_struct_begin *)ptr;
+	as--;
+
+	if (size != 0){
+		tmp_ptr = heap_alloc(size, 0);
+		if (ptr != NULL && tmp_ptr != NULL){
+			min_size = (size < as->size) ? size : as->size;
+			memcpy(tmp_ptr, ptr, min_size);
+			heap_free(ptr);
+		}
+	} else {
+		if (ptr != NULL)
+			heap_free(ptr);
+	}
+	return(tmp_ptr);
+}
+
+
 void heap_free(void *ptr)
 {
 	if (ptr == 0)
diff --git a/lib/libc/malloc.c b/lib/libc/malloc.c
index fd5fe8a..6f05f63 100644
--- a/lib/libc/malloc.c
+++ b/lib/libc/malloc.c
@@ -53,3 +53,8 @@
 	return heap_free(ptr);
 }
 
+void *realloc(void *ptr, size_t size)
+{
+	return(heap_realloc(ptr, size));
+}
+
diff --git a/lib/openssl/android-config.mk b/lib/openssl/android-config.mk
index d76d6e3..f9f59aa 100644
--- a/lib/openssl/android-config.mk
+++ b/lib/openssl/android-config.mk
@@ -5,13 +5,21 @@
 #
 
 # From CLFAG=	
-LOCAL_CFLAGS += -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN #-DTERMIO
+CFLAGS += -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN #-DTERMIO
 
 # From DEPFLAG=
-LOCAL_CFLAGS += -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CAST -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_IDEA -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_SHA0 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED -DOPENSSL_NO_STORE -DOPENSSL_NO_WHIRLPOOL
+CFLAGS += -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CAST -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_IDEA -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_SHA0 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED -DOPENSSL_NO_STORE -DOPENSSL_NO_WHIRLPOOL
 
 # Extra
-LOCAL_CFLAGS += -DOPENSSL_NO_HW -DOPENSSL_NO_ENGINE -DZLIB
+CFLAGS += -DOPENSSL_NO_HW -DOPENSSL_NO_ENGINE -DZLIB
+
+# For Android Appsboot (LK)
+CFLAGS += -DLK_NO_TIME -DLK_NO_QSORT -DLK_NO_BIO -DLK_NO_HMAC -DLK_NO_ENCODE \
+	  -DLK_NO_STDERR -DLK_NO_ABORT -DLK_NO_PEM -DLK_NO_OAEP -DLK_NO_SSLV23 \
+	  -DLK_NO_RAND -DLK_NO_UNISTD
+
+# TODO: Should be able to classify these ones
+CFLAGS += -DOPENSSL_LK
 
 # Debug
 # LOCAL_CFLAGS += -DCIPHER_DEBUG
diff --git a/lib/openssl/crypto/aes/aes_wrap.c b/lib/openssl/crypto/aes/aes_wrap.c
index 9feacd6..33166ea 100644
--- a/lib/openssl/crypto/aes/aes_wrap.c
+++ b/lib/openssl/crypto/aes/aes_wrap.c
@@ -51,7 +51,7 @@
  * ====================================================================
  */
 
-#include "cryptlib.h"
+#include <cryptlib.h>
 #include <openssl/aes.h>
 #include <openssl/bio.h>
 
diff --git a/lib/openssl/crypto/asn1/a_digest.c b/lib/openssl/crypto/asn1/a_digest.c
index d00d9e2..4844909 100644
--- a/lib/openssl/crypto/asn1/a_digest.c
+++ b/lib/openssl/crypto/asn1/a_digest.c
@@ -57,7 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 
 #include "cryptlib.h"
 
diff --git a/lib/openssl/crypto/asn1/a_gentm.c b/lib/openssl/crypto/asn1/a_gentm.c
index c79c6f5..cbf3daa 100644
--- a/lib/openssl/crypto/asn1/a_gentm.c
+++ b/lib/openssl/crypto/asn1/a_gentm.c
@@ -59,7 +59,9 @@
 /* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include "o_time.h"
 #include <openssl/asn1.h>
diff --git a/lib/openssl/crypto/asn1/a_sign.c b/lib/openssl/crypto/asn1/a_sign.c
index ff63bfc..6f83e9f 100644
--- a/lib/openssl/crypto/asn1/a_sign.c
+++ b/lib/openssl/crypto/asn1/a_sign.c
@@ -110,8 +110,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
-
+#endif
 #include "cryptlib.h"
 
 #ifndef NO_SYS_TYPES_H
diff --git a/lib/openssl/crypto/asn1/a_time.c b/lib/openssl/crypto/asn1/a_time.c
index e2eb9b2..a25deef 100644
--- a/lib/openssl/crypto/asn1/a_time.c
+++ b/lib/openssl/crypto/asn1/a_time.c
@@ -62,7 +62,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include "o_time.h"
 #include <openssl/asn1t.h>
@@ -97,7 +99,7 @@
 	}
 #endif
 
-
+#ifndef LK_NO_TIME
 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
 	{
 	return ASN1_TIME_adj(s, t, 0, 0);
@@ -196,3 +198,4 @@
 
 	return 1;
 	}
+#endif
diff --git a/lib/openssl/crypto/asn1/a_utctm.c b/lib/openssl/crypto/asn1/a_utctm.c
index 072e236..685a6de 100644
--- a/lib/openssl/crypto/asn1/a_utctm.c
+++ b/lib/openssl/crypto/asn1/a_utctm.c
@@ -57,7 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include "o_time.h"
 #include <openssl/asn1.h>
@@ -81,7 +83,7 @@
 #endif
 	}
 
-
+#ifndef LK_NO_TIME
 ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
 	     long length)
 	{
@@ -277,7 +279,7 @@
 
 	return 0;
 	}
-
+#endif
 
 #if 0
 time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
diff --git a/lib/openssl/crypto/asn1/a_verify.c b/lib/openssl/crypto/asn1/a_verify.c
index cecdb13..e55df83 100644
--- a/lib/openssl/crypto/asn1/a_verify.c
+++ b/lib/openssl/crypto/asn1/a_verify.c
@@ -57,8 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
-
+#endif
 #include "cryptlib.h"
 #include "asn1_locl.h"
 
diff --git a/lib/openssl/crypto/asn1/ameth_lib.c b/lib/openssl/crypto/asn1/ameth_lib.c
index 9a8b6cc..c52f9c9 100644
--- a/lib/openssl/crypto/asn1/ameth_lib.c
+++ b/lib/openssl/crypto/asn1/ameth_lib.c
@@ -67,8 +67,13 @@
 extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
 extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
 extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
+#ifndef OPENSSL_NO_EC
 extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
+#endif
+
+#ifndef LK_NO_HMAC
 extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
+#endif
 
 /* Keep this sorted in type order !! */
 static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 
@@ -90,7 +95,11 @@
 #ifndef OPENSSL_NO_EC
 	&eckey_asn1_meth,
 #endif
+#ifndef LK_NO_HMAC
 	&hmac_asn1_meth
+#else
+	0
+#endif
 	};
 
 typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
@@ -150,10 +159,14 @@
 	tmp.pkey_id = type;
 	if (app_methods)
 		{
+#ifndef LK_NO_QSORT
 		int idx;
 		idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
 		if (idx >= 0)
 			return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
+#else
+		printf("Openssl LK: Removed qsort dependency in ameth_lib.c\n");
+#endif
 		}
 	ret = OBJ_bsearch_ameth(&t, standard_methods,
 			  sizeof(standard_methods)
@@ -172,8 +185,9 @@
 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
 	{
 	const EVP_PKEY_ASN1_METHOD *t;
+#ifndef OPENSSL_NO_ENGINE
 	ENGINE *e;
-
+#endif
 	for (;;)
 		{
 		t = pkey_asn1_find(type);
diff --git a/lib/openssl/crypto/asn1/asn1.h b/lib/openssl/crypto/asn1/asn1.h
index f7718b5..1f614e2 100644
--- a/lib/openssl/crypto/asn1/asn1.h
+++ b/lib/openssl/crypto/asn1/asn1.h
@@ -59,7 +59,9 @@
 #ifndef HEADER_ASN1_H
 #define HEADER_ASN1_H
 
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include <openssl/e_os2.h>
 #ifndef OPENSSL_NO_BIO
 #include <openssl/bio.h>
diff --git a/lib/openssl/crypto/asn1/asn1t.h b/lib/openssl/crypto/asn1/asn1t.h
index d230e4b..14485a2 100644
--- a/lib/openssl/crypto/asn1/asn1t.h
+++ b/lib/openssl/crypto/asn1/asn1t.h
@@ -878,11 +878,19 @@
 	stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
 	{ \
 		return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
+	}
+
+#ifndef LK_NO_ENCODE
+#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
+	stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
+	{ \
+		return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
 	} \
 	int i2d_##fname(const stname *a, unsigned char **out) \
 	{ \
 		return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
 	} 
+#endif
 
 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
 	stname * stname##_dup(stname *x) \
diff --git a/lib/openssl/crypto/asn1/tasn_enc.c b/lib/openssl/crypto/asn1/tasn_enc.c
index 936ad1f..b092680 100644
--- a/lib/openssl/crypto/asn1/tasn_enc.c
+++ b/lib/openssl/crypto/asn1/tasn_enc.c
@@ -435,7 +435,6 @@
 	}
 
 /* Output the content octets of SET OF or SEQUENCE OF */
-
 static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
 					int skcontlen, const ASN1_ITEM *item,
 					int do_sort, int iclass)
@@ -480,7 +479,7 @@
 		}
 
 	/* Now sort them */
-	qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
+	printf("Openssl LK: removing qsort dependency in tasn_enc\n");
 	/* Output sorted DER encoding */	
 	p = *out;
 	for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
diff --git a/lib/openssl/crypto/asn1/x_long.c b/lib/openssl/crypto/asn1/x_long.c
index 7531741..077988a 100644
--- a/lib/openssl/crypto/asn1/x_long.c
+++ b/lib/openssl/crypto/asn1/x_long.c
@@ -175,5 +175,9 @@
 static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
 			int indent, const ASN1_PCTX *pctx)
 	{
-	return BIO_printf(out, "%ld\n", *(long *)pval);
+#ifndef LK_NO_BIO
+	  return BIO_printf(out, "%ld\n", *(long *)pval);
+#else
+	  return 0;
+#endif
 	}
diff --git a/lib/openssl/crypto/asn1/x_name.c b/lib/openssl/crypto/asn1/x_name.c
index caa4409..4aabfd0 100644
--- a/lib/openssl/crypto/asn1/x_name.c
+++ b/lib/openssl/crypto/asn1/x_name.c
@@ -294,10 +294,15 @@
 						const char *fname, 
 						const ASN1_PCTX *pctx)
 	{
-	if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
+	  /* Removing a_strex.c dependency in LK */
+	  //TODO: revist this one
+#ifndef OPENSSL_LK
+	  if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
 					indent, pctx->nm_flags) <= 0)
 		return 0;
-	return 2;
+#else
+	  return 2;
+#endif
 	}
 
 /* This function generates the canonical encoding of the Name structure.
diff --git a/lib/openssl/crypto/bn/asm/armv4-mont.S b/lib/openssl/crypto/bn/asm/armv4-mont.S
new file mode 100644
index 0000000..0488455
--- /dev/null
+++ b/lib/openssl/crypto/bn/asm/armv4-mont.S
@@ -0,0 +1,145 @@
+.text
+
+.global	bn_mul_mont
+.type	bn_mul_mont,%function
+
+.align	2
+bn_mul_mont:
+	stmdb	sp!,{r0,r2}		@ sp points at argument block
+	ldr	r0,[sp,#3*4]		@ load num
+	cmp	r0,#2
+	movlt	r0,#0
+	addlt	sp,sp,#2*4
+	blt	.Labrt
+
+	stmdb	sp!,{r4-r12,lr}		@ save 10 registers
+
+	mov	r0,r0,lsl#2		@ rescale r0 for byte count
+	sub	sp,sp,r0		@ alloca(4*num)
+	sub	sp,sp,#4		@ +extra dword
+	sub	r0,r0,#4		@ "num=num-1"
+	add	r4,r2,r0		@ &bp[num-1]
+
+	add	r0,sp,r0		@ r0 to point at &tp[num-1]
+	ldr	r8,[r0,#14*4]		@ &n0
+	ldr	r2,[r2]		@ bp[0]
+	ldr	r5,[r1],#4		@ ap[0],ap++
+	ldr	r6,[r3],#4		@ np[0],np++
+	ldr	r8,[r8]		@ *n0
+	str	r4,[r0,#15*4]		@ save &bp[num]
+
+	umull	r10,r11,r5,r2	@ ap[0]*bp[0]
+	str	r8,[r0,#14*4]		@ save n0 value
+	mul	r8,r10,r8		@ "tp[0]"*n0
+	mov	r12,#0
+	umlal	r10,r12,r6,r8	@ np[0]*n0+"t[0]"
+	mov	r4,sp
+
+.L1st:
+	ldr	r5,[r1],#4		@ ap[j],ap++
+	mov	r10,r11
+	mov	r11,#0
+	umlal	r10,r11,r5,r2	@ ap[j]*bp[0]
+	ldr	r6,[r3],#4		@ np[j],np++
+	mov	r14,#0
+	umlal	r12,r14,r6,r8	@ np[j]*n0
+	adds	r12,r12,r10
+	str	r12,[r4],#4		@ tp[j-1]=,tp++
+	adc	r12,r14,#0
+	cmp	r4,r0
+	bne	.L1st
+
+	adds	r12,r12,r11
+	mov	r14,#0
+	adc	r14,r14,#0
+	ldr	r4,[r0,#13*4]		@ restore bp
+	str	r12,[r0]		@ tp[num-1]=
+	ldr	r8,[r0,#14*4]		@ restore n0
+	str	r14,[r0,#4]		@ tp[num]=
+
+.Louter:
+	sub	r7,r0,sp		@ "original" r0-1 value
+	sub	r1,r1,r7		@ "rewind" ap to &ap[1]
+	sub	r3,r3,r7		@ "rewind" np to &np[1]
+	ldr	r2,[r4,#4]!		@ *(++bp)
+	ldr	r5,[r1,#-4]		@ ap[0]
+	ldr	r6,[r3,#-4]		@ np[0]
+	ldr	r10,[sp]		@ tp[0]
+	ldr	r7,[sp,#4]		@ tp[1]
+
+	mov	r11,#0
+	umlal	r10,r11,r5,r2	@ ap[0]*bp[i]+tp[0]
+	str	r4,[r0,#13*4]		@ save bp
+	mul	r8,r10,r8
+	mov	r12,#0
+	umlal	r10,r12,r6,r8	@ np[0]*n0+"tp[0]"
+	mov	r4,sp
+
+.Linner:
+	ldr	r5,[r1],#4		@ ap[j],ap++
+	adds	r10,r11,r7		@ +=tp[j]
+	mov	r11,#0
+	umlal	r10,r11,r5,r2	@ ap[j]*bp[i]
+	ldr	r6,[r3],#4		@ np[j],np++
+	mov	r14,#0
+	umlal	r12,r14,r6,r8	@ np[j]*n0
+	ldr	r7,[r4,#8]		@ tp[j+1]
+	adc	r11,r11,#0
+	adds	r12,r12,r10
+	str	r12,[r4],#4		@ tp[j-1]=,tp++
+	adc	r12,r14,#0
+	cmp	r4,r0
+	bne	.Linner
+
+	adds	r12,r12,r11
+	mov	r14,#0
+	adc	r14,r14,#0
+	adds	r12,r12,r7
+	adc	r14,r14,#0
+	ldr	r4,[r0,#13*4]		@ restore bp
+	ldr	r7,[r0,#15*4]		@ restore &bp[num]
+	str	r12,[r0]		@ tp[num-1]=
+	ldr	r8,[r0,#14*4]		@ restore n0
+	str	r14,[r0,#4]		@ tp[num]=
+
+	cmp	r4,r7
+	bne	.Louter
+
+	ldr	r2,[r0,#12*4]		@ pull rp
+	add	r0,r0,#4		@ r0 to point at &tp[num]
+	sub	r5,r0,sp		@ "original" num value
+	mov	r4,sp			@ "rewind" r4
+	mov	r1,r4			@ "borrow" r1
+	sub	r3,r3,r5		@ "rewind" r3 to &np[0]
+
+	subs	r7,r7,r7		@ "clear" carry flag
+.Lsub:	ldr	r7,[r4],#4
+	ldr	r6,[r3],#4
+	sbcs	r7,r7,r6		@ tp[j]-np[j]
+	str	r7,[r2],#4		@ rp[j]=
+	teq	r4,r0		@ preserve carry
+	bne	.Lsub
+	sbcs	r14,r14,#0		@ upmost carry
+	mov	r4,sp			@ "rewind" r4
+	sub	r2,r2,r5		@ "rewind" r2
+
+	and	r1,r4,r14
+	bic	r3,r2,r14
+	orr	r1,r1,r3		@ ap=borrow?tp:rp
+
+.Lcopy:	ldr	r7,[r1],#4		@ copy or in-place refresh
+	str	sp,[r4],#4		@ zap tp
+	str	r7,[r2],#4
+	cmp	r4,r0
+	bne	.Lcopy
+
+	add	sp,r0,#4		@ skip over tp[num+1]
+	ldmia	sp!,{r4-r12,lr}		@ restore registers
+	add	sp,sp,#2*4		@ skip over {r0,r2}
+	mov	r0,#1
+.Labrt:	tst	lr,#1
+	moveq	pc,lr			@ be binary compatible with V4, yet
+	.word	0xe12fff1e			@ interoperable with Thumb ISA:-)
+.size	bn_mul_mont,.-bn_mul_mont
+.asciz	"Montgomery multiplication for ARMv4, CRYPTOGAMS by <appro@openssl.org>"
+.align	2
diff --git a/lib/openssl/crypto/bn/bn_blind.c b/lib/openssl/crypto/bn/bn_blind.c
index e060592..227c607 100644
--- a/lib/openssl/crypto/bn/bn_blind.c
+++ b/lib/openssl/crypto/bn/bn_blind.c
@@ -331,7 +331,12 @@
 		ret->m_ctx = m_ctx;
 
 	do {
-		if (!BN_rand_range(ret->A, ret->mod)) goto err;
+#ifndef LK_NO_RAND
+	  if (!BN_rand_range(ret->A, ret->mod)) goto err;
+#else
+	  printf("Openssl LK: Removing rand dependency in bn_blind.c\n");
+	  goto err;
+#endif
 		if (BN_mod_inverse(ret->Ai, ret->A, ret->mod, ctx) == NULL)
 			{
 			/* this should almost never happen for good RSA keys */
diff --git a/lib/openssl/crypto/bn/bn_prime.c b/lib/openssl/crypto/bn/bn_prime.c
index 7b25979..8ebab91 100644
--- a/lib/openssl/crypto/bn/bn_prime.c
+++ b/lib/openssl/crypto/bn/bn_prime.c
@@ -110,7 +110,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include "bn_lcl.h"
 #include <openssl/rand.h>
diff --git a/lib/openssl/crypto/bn/bn_print.c b/lib/openssl/crypto/bn/bn_print.c
index bebb466..e125ead 100644
--- a/lib/openssl/crypto/bn/bn_print.c
+++ b/lib/openssl/crypto/bn/bn_print.c
@@ -315,7 +315,8 @@
 	return 1;
 	}
 
-#ifndef OPENSSL_NO_BIO
+//TODO: Can take a look at this to use OPENSSL_NO_BIO
+#ifndef LK_NO_BIO
 #ifndef OPENSSL_NO_FP_API
 int BN_print_fp(FILE *fp, const BIGNUM *a)
 	{
diff --git a/lib/openssl/crypto/bn/bn_rand.c b/lib/openssl/crypto/bn/bn_rand.c
index b376c28..6b038a3 100644
--- a/lib/openssl/crypto/bn/bn_rand.c
+++ b/lib/openssl/crypto/bn/bn_rand.c
@@ -110,7 +110,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include "bn_lcl.h"
 #include <openssl/rand.h>
diff --git a/lib/openssl/crypto/conf/conf_api.c b/lib/openssl/crypto/conf/conf_api.c
index 22617e5..d39503c 100644
--- a/lib/openssl/crypto/conf/conf_api.c
+++ b/lib/openssl/crypto/conf/conf_api.c
@@ -67,7 +67,7 @@
 #include <string.h>
 #include <openssl/conf.h>
 #include <openssl/conf_api.h>
-#include "e_os.h"
+#include <openssl/e_os.h>
 
 static void value_free_hash_doall_arg(CONF_VALUE *a,
 				      LHASH_OF(CONF_VALUE) *conf);
diff --git a/lib/openssl/crypto/cryptlib.c b/lib/openssl/crypto/cryptlib.c
index b4449b8..5848446 100644
--- a/lib/openssl/crypto/cryptlib.c
+++ b/lib/openssl/crypto/cryptlib.c
@@ -478,6 +478,7 @@
 
 void CRYPTO_THREADID_current(CRYPTO_THREADID *id)
 	{
+	  unsigned char errno;
 	if (threadid_callback)
 		{
 		threadid_callback(id);
@@ -874,7 +875,9 @@
 { va_list ap;
 
     va_start (ap,fmta);
+#ifndef LK_NO_STDERR
     vfprintf (stderr,fmta,ap);
+#endif
     va_end (ap);
 }
 int OPENSSL_isservice (void) { return 0; }
@@ -886,7 +889,9 @@
 		"%s(%d): OpenSSL internal error, assertion failed: %s\n",
 		file,line,assertion);
 #if !defined(_WIN32) || defined(__CYGWIN__)
+#ifndef LK_NO_ABORT
 	abort();
+#endif
 #else
 	/* Win32 abort() customarily shows a dialog, but we just did that... */
 	raise(SIGABRT);
@@ -894,4 +899,11 @@
 #endif
 	}
 
-void *OPENSSL_stderr(void)	{ return stderr; }
+/* No stderr in LK */
+void *OPENSSL_stderr(void)	{
+#ifndef LK_NO_STDERR
+  return stderr;
+#else
+  return NULL;
+#endif
+}
diff --git a/lib/openssl/crypto/cryptlib.h b/lib/openssl/crypto/cryptlib.h
index fc249c5..7cde22e 100644
--- a/lib/openssl/crypto/cryptlib.h
+++ b/lib/openssl/crypto/cryptlib.h
@@ -62,7 +62,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "e_os.h"
+#include <openssl/e_os.h>
 
 #ifdef OPENSSL_USE_APPLINK
 #define BIO_FLAGS_UPLINK 0x8000
diff --git a/lib/openssl/crypto/evp/evp_key.c b/lib/openssl/crypto/evp/evp_key.c
index 839d6a3..7a3dd35 100644
--- a/lib/openssl/crypto/evp/evp_key.c
+++ b/lib/openssl/crypto/evp/evp_key.c
@@ -88,6 +88,8 @@
 /* For historical reasons, the standard function for reading passwords is
  * in the DES library -- if someone ever wants to disable DES,
  * this function will fail */
+
+#ifndef OPENSSL_NO_DES 
 int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
 	{
 	return EVP_read_pw_string_min(buf, 0, len, prompt, verify);
@@ -111,6 +113,7 @@
 	OPENSSL_cleanse(buff,BUFSIZ);
 	return ret;
 	}
+#endif
 
 int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, 
 	     const unsigned char *salt, const unsigned char *data, int datal,
diff --git a/lib/openssl/crypto/mem_dbg.c b/lib/openssl/crypto/mem_dbg.c
index ac79339..9a07537 100644
--- a/lib/openssl/crypto/mem_dbg.c
+++ b/lib/openssl/crypto/mem_dbg.c
@@ -111,7 +111,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <time.h>	
+#ifndef LK_NO_TIME
+#include <time.h>
+#endif
 #include "cryptlib.h"
 #include <openssl/crypto.h>
 #include <openssl/buffer.h>
@@ -661,6 +663,7 @@
 	long bytes;
 	} MEM_LEAK;
 
+#ifndef LK_NO_TIME
 static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
 	{
 	char buf[1024];
@@ -750,6 +753,7 @@
 		}
 #endif
 	}
+#endif
 
 static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM, MEM_LEAK)
 
diff --git a/lib/openssl/crypto/o_str.c b/lib/openssl/crypto/o_str.c
index 56104a6..ffe7138 100644
--- a/lib/openssl/crypto/o_str.c
+++ b/lib/openssl/crypto/o_str.c
@@ -57,7 +57,7 @@
  */
 
 #include <ctype.h>
-#include <e_os.h>
+#include <openssl/e_os.h>
 #include "o_str.h"
 
 #if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \
diff --git a/lib/openssl/crypto/o_time.h b/lib/openssl/crypto/o_time.h
index e391da7..6fc48d6 100644
--- a/lib/openssl/crypto/o_time.h
+++ b/lib/openssl/crypto/o_time.h
@@ -59,9 +59,10 @@
 #ifndef HEADER_O_TIME_H
 #define HEADER_O_TIME_H
 
+#ifndef LK_NO_TIME
 #include <time.h>
 
 struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
 int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
-
+#endif
 #endif
diff --git a/lib/openssl/crypto/pkcs12/p12_npas.c b/lib/openssl/crypto/pkcs12/p12_npas.c
index 2f71355..363d87b 100644
--- a/lib/openssl/crypto/pkcs12/p12_npas.c
+++ b/lib/openssl/crypto/pkcs12/p12_npas.c
@@ -59,7 +59,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef LK_NO_PEM
 #include <openssl/pem.h>
+#endif
 #include <openssl/err.h>
 #include <openssl/pkcs12.h>
 
diff --git a/lib/openssl/crypto/pkcs7/pk7_attr.c b/lib/openssl/crypto/pkcs7/pk7_attr.c
index a97db51..c6db344 100644
--- a/lib/openssl/crypto/pkcs7/pk7_attr.c
+++ b/lib/openssl/crypto/pkcs7/pk7_attr.c
@@ -61,7 +61,9 @@
 #include <openssl/bio.h>
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
+#ifndef LK_NO_PEM
 #include <openssl/pem.h>
+#endif
 #include <openssl/pkcs7.h>
 #include <openssl/x509.h>
 #include <openssl/err.h>
diff --git a/lib/openssl/crypto/rand/rand_lib.c b/lib/openssl/crypto/rand/rand_lib.c
index 513e338..df16da4 100644
--- a/lib/openssl/crypto/rand/rand_lib.c
+++ b/lib/openssl/crypto/rand/rand_lib.c
@@ -57,7 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include <openssl/rand.h>
 #ifndef OPENSSL_NO_ENGINE
diff --git a/lib/openssl/crypto/rsa/rsa_ameth.c b/lib/openssl/crypto/rsa/rsa_ameth.c
index 8c32098..033e2b6 100644
--- a/lib/openssl/crypto/rsa/rsa_ameth.c
+++ b/lib/openssl/crypto/rsa/rsa_ameth.c
@@ -180,6 +180,7 @@
 			*pbuflen = i;
 	}
 
+#ifndef LK_NO_BIO
 static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
 	{
 	char *str;
@@ -265,6 +266,7 @@
 	return do_rsa_print(bp, pkey->pkey.rsa, indent, 1);
 	}
 
+#endif
 
 static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
 	{
@@ -324,12 +326,18 @@
 		rsa_pub_decode,
 		rsa_pub_encode,
 		rsa_pub_cmp,
+#ifndef LK_NO_BIO
 		rsa_pub_print,
-
+#else
+		0,
+#endif
 		rsa_priv_decode,
 		rsa_priv_encode,
+#ifndef LK_NO_BIO
 		rsa_priv_print,
-
+#else
+		0,
+#endif
 		int_rsa_size,
 		rsa_bits,
 
diff --git a/lib/openssl/crypto/rsa/rsa_eay.c b/lib/openssl/crypto/rsa/rsa_eay.c
index c5eaeea..4cb33c1 100644
--- a/lib/openssl/crypto/rsa/rsa_eay.c
+++ b/lib/openssl/crypto/rsa/rsa_eay.c
@@ -197,14 +197,18 @@
 	case RSA_PKCS1_PADDING:
 		i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
 		break;
+#ifndef LK_NO_OAEP
 #ifndef OPENSSL_NO_SHA
 	case RSA_PKCS1_OAEP_PADDING:
 	        i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
 		break;
 #endif
+#endif
+#ifndef LK_NO_SSLV23
 	case RSA_SSLV23_PADDING:
 		i=RSA_padding_add_SSLv23(buf,num,from,flen);
 		break;
+#endif
 	case RSA_NO_PADDING:
 		i=RSA_padding_add_none(buf,num,from,flen);
 		break;
@@ -267,7 +271,9 @@
 		got_write_lock = 1;
 
 		if (rsa->blinding == NULL)
-			rsa->blinding = RSA_setup_blinding(rsa, ctx);
+		  /* removing dependency on RSA_setup_blinding in lk */
+		  //rsa->blinding = RSA_setup_blinding(rsa, ctx);
+		  return NULL;
 		}
 
 	ret = rsa->blinding;
@@ -299,9 +305,13 @@
 				CRYPTO_w_lock(CRYPTO_LOCK_RSA);
 				got_write_lock = 1;
 				}
-			
+
 			if (rsa->mt_blinding == NULL)
-				rsa->mt_blinding = RSA_setup_blinding(rsa, ctx);
+#ifndef LK_NO_RAND
+			  rsa->mt_blinding = RSA_setup_blinding(rsa, ctx);
+#else
+			  return NULL;
+#endif
 			}
 		ret = rsa->mt_blinding;
 		}
@@ -397,7 +407,12 @@
 
 	if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
 		{
-		blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
+#ifndef LK_NO_RAND
+		  blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
+#else
+		  blinding = NULL;
+		  printf("Openssl LK: Removed rand dependency in rsa_eay.c\n");
+#endif
 		if (blinding == NULL)
 			{
 			RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
@@ -520,7 +535,12 @@
 
 	if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
 		{
+#ifndef LK_NO_RAND
 		blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
+#else
+		blinding = NULL;
+		printf("Openssl LK: Removed rand dependency in rsa_eay.c\n");
+#endif
 		if (blinding == NULL)
 			{
 			RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);
@@ -575,14 +595,18 @@
 	case RSA_PKCS1_PADDING:
 		r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);
 		break;
+#ifndef LK_NO_OAEP
 #ifndef OPENSSL_NO_SHA
         case RSA_PKCS1_OAEP_PADDING:
 	        r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);
                 break;
 #endif
+#endif
+#ifndef LK_NO_SSLV23
  	case RSA_SSLV23_PADDING:
 		r=RSA_padding_check_SSLv23(to,num,buf,j,num);
 		break;
+#endif
 	case RSA_NO_PADDING:
 		r=RSA_padding_check_none(to,num,buf,j,num);
 		break;
diff --git a/lib/openssl/crypto/rsa/rsa_gen.c b/lib/openssl/crypto/rsa/rsa_gen.c
index 767f7ab..2aea10e 100644
--- a/lib/openssl/crypto/rsa/rsa_gen.c
+++ b/lib/openssl/crypto/rsa/rsa_gen.c
@@ -63,7 +63,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include "cryptlib.h"
 #include <openssl/bn.h>
 #include <openssl/rsa.h>
diff --git a/lib/openssl/crypto/rsa/rsa_lib.c b/lib/openssl/crypto/rsa/rsa_lib.c
index de45088..509e37e 100644
--- a/lib/openssl/crypto/rsa/rsa_lib.c
+++ b/lib/openssl/crypto/rsa/rsa_lib.c
@@ -324,7 +324,7 @@
 	rsa->flags &= ~RSA_FLAG_BLINDING;
 	rsa->flags |= RSA_FLAG_NO_BLINDING;
 	}
-
+#ifndef LK_NO_RAND
 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx)
 	{
 	int ret=0;
@@ -342,6 +342,7 @@
 err:
 	return(ret);
 	}
+#endif
 
 static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,
 	const BIGNUM *q, BN_CTX *ctx)
@@ -407,7 +408,11 @@
 		{
 		/* if PRNG is not properly seeded, resort to secret
 		 * exponent as unpredictable seed */
-		RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0.0);
+#ifndef LK_NO_RAND
+		  RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0.0);
+#else
+		  return NULL;
+#endif
 		}
 
 	if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
diff --git a/lib/openssl/crypto/rsa/rsa_pk1.c b/lib/openssl/crypto/rsa/rsa_pk1.c
index 8560755..5943747 100644
--- a/lib/openssl/crypto/rsa/rsa_pk1.c
+++ b/lib/openssl/crypto/rsa/rsa_pk1.c
@@ -140,6 +140,7 @@
 	return(j);
 	}
 
+#ifndef LK_NO_RAND
 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
 	     const unsigned char *from, int flen)
 	{
@@ -177,6 +178,14 @@
 	memcpy(p,from,(unsigned int)flen);
 	return(1);
 	}
+#else
+int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
+	     const unsigned char *from, int flen)
+	{
+	  printf("Openssl LK: Removing rand dependency in rsa_pk1.c\n");
+	  return -1;
+	}
+#endif
 
 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
 	     const unsigned char *from, int flen, int num)
diff --git a/lib/openssl/crypto/rsa/rsa_sign.c b/lib/openssl/crypto/rsa/rsa_sign.c
index 0be4ec7..73490da 100644
--- a/lib/openssl/crypto/rsa/rsa_sign.c
+++ b/lib/openssl/crypto/rsa/rsa_sign.c
@@ -67,6 +67,7 @@
 /* Size of an SSL signature: MD5+SHA1 */
 #define SSL_SIG_LENGTH	36
 
+#ifndef LK_NO_ENCRYPT
 int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
 	     unsigned char *sigret, unsigned int *siglen, RSA *rsa)
 	{
@@ -283,3 +284,19 @@
 
 	return int_rsa_verify(dtype, m, m_len, NULL, NULL, sigbuf, siglen, rsa);
 	}
+#else
+int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
+	     unsigned char *sigret, unsigned int *siglen, RSA *rsa)
+	{
+	  printf("Openssl LK: RSA Encrypt not available\n");
+	  return -1;
+	}
+
+int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
+		const unsigned char *sigbuf, unsigned int siglen,
+		RSA *rsa)
+	{
+	  printf("Openssl LK: RSA Encrypt not available\n");
+	  return -1;
+	}
+#endif
diff --git a/lib/openssl/crypto/rules.mk b/lib/openssl/crypto/rules.mk
new file mode 100644
index 0000000..d2fc6f0
--- /dev/null
+++ b/lib/openssl/crypto/rules.mk
@@ -0,0 +1,494 @@
+LOCAL_DIR:= $(GET_LOCAL_DIR)
+
+#Additional flags already in android-config.mk
+CFLAGS += -DOPENSSL_BN_ASM_MONT -DAES_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM \
+	-DOPENSSL_NO_STDIO -DOPENSSL_NO_FP_API -DNO_WINDOWS_BRAINDEATH \
+	-DOPENSSL_IMPLEMENTS_strncasecmp -DOPENSSL_NO_DSA -DOPENSSL_NO_DH \
+	-DGETPID_IS_MEANINGLESS -DOPENSSL_NO_EC -DOPENSSL_NO_DES
+
+INCLUDES += \
+			-I$(LOCAL_DIR) \
+			-I$(LOCAL_DIR)/asn1 \
+			-I$(LOCAL_DIR)/evp \
+			-I$(LOCAL_DIR)/x509 \
+			-I$(LOCAL_DIR)/../.. \
+			-I$(LOCAL_DIR)/../include \
+			-I$(LOCAL_DIR)/../include/openssl
+
+OBJS +=  $(LOCAL_DIR)/bn/asm/armv4-mont.o
+
+OBJS += \
+	$(LOCAL_DIR)/bio/b_print.o \
+	$(LOCAL_DIR)/cryptlib.o \
+	$(LOCAL_DIR)/mem.o \
+	$(LOCAL_DIR)/mem_clr.o \
+	$(LOCAL_DIR)/mem_dbg.o \
+	$(LOCAL_DIR)/cversion.o \
+	$(LOCAL_DIR)/ex_data.o \
+	$(LOCAL_DIR)/cpt_err.o \
+	$(LOCAL_DIR)/ebcdic.o \
+	$(LOCAL_DIR)/o_str.o \
+	$(LOCAL_DIR)/aes/aes_cbc.o \
+	$(LOCAL_DIR)/aes/aes_cfb.o \
+	$(LOCAL_DIR)/aes/aes_ctr.o \
+	$(LOCAL_DIR)/aes/aes_ecb.o \
+	$(LOCAL_DIR)/aes/aes_misc.o \
+	$(LOCAL_DIR)/aes/aes_ofb.o \
+	$(LOCAL_DIR)/aes/aes_wrap.o \
+	$(LOCAL_DIR)/asn1/a_bitstr.o \
+	$(LOCAL_DIR)/asn1/a_bool.o \
+	$(LOCAL_DIR)/asn1/a_bytes.o \
+	$(LOCAL_DIR)/asn1/a_d2i_fp.o \
+	$(LOCAL_DIR)/asn1/a_digest.o \
+	$(LOCAL_DIR)/asn1/a_dup.o \
+	$(LOCAL_DIR)/asn1/a_enum.o \
+	$(LOCAL_DIR)/asn1/a_i2d_fp.o \
+	$(LOCAL_DIR)/asn1/a_int.o \
+	$(LOCAL_DIR)/asn1/a_mbstr.o \
+	$(LOCAL_DIR)/asn1/a_object.o \
+	$(LOCAL_DIR)/asn1/a_octet.o \
+	$(LOCAL_DIR)/asn1/a_print.o \
+	$(LOCAL_DIR)/asn1/a_sign.o \
+	$(LOCAL_DIR)/asn1/a_strnid.o \
+	$(LOCAL_DIR)/asn1/a_strex.o \
+	$(LOCAL_DIR)/asn1/a_time.o \
+	$(LOCAL_DIR)/asn1/a_type.o \
+	$(LOCAL_DIR)/asn1/a_utctm.o \
+	$(LOCAL_DIR)/asn1/a_utf8.o \
+	$(LOCAL_DIR)/asn1/a_verify.o \
+	$(LOCAL_DIR)/asn1/ameth_lib.o \
+	$(LOCAL_DIR)/asn1/asn1_err.o \
+	$(LOCAL_DIR)/asn1/asn1_lib.o \
+	$(LOCAL_DIR)/asn1/asn1_par.o \
+	$(LOCAL_DIR)/asn1/asn_mime.o \
+	$(LOCAL_DIR)/asn1/asn_moid.o \
+	$(LOCAL_DIR)/asn1/asn_pack.o \
+	$(LOCAL_DIR)/asn1/bio_asn1.o \
+	$(LOCAL_DIR)/asn1/d2i_pr.o \
+	$(LOCAL_DIR)/asn1/d2i_pu.o \
+	$(LOCAL_DIR)/asn1/evp_asn1.o \
+	$(LOCAL_DIR)/asn1/f_enum.o \
+	$(LOCAL_DIR)/asn1/f_int.o \
+	$(LOCAL_DIR)/asn1/f_string.o \
+	$(LOCAL_DIR)/asn1/i2d_pr.o \
+	$(LOCAL_DIR)/asn1/i2d_pu.o \
+	$(LOCAL_DIR)/asn1/n_pkey.o \
+	$(LOCAL_DIR)/asn1/nsseq.o \
+	$(LOCAL_DIR)/asn1/p5_pbe.o \
+	$(LOCAL_DIR)/asn1/p5_pbev2.o \
+	$(LOCAL_DIR)/asn1/p8_pkey.o \
+	$(LOCAL_DIR)/asn1/t_bitst.o \
+	$(LOCAL_DIR)/asn1/t_crl.o \
+	$(LOCAL_DIR)/asn1/t_req.o \
+	$(LOCAL_DIR)/asn1/t_spki.o \
+	$(LOCAL_DIR)/asn1/t_x509.o \
+	$(LOCAL_DIR)/asn1/t_x509a.o \
+	$(LOCAL_DIR)/asn1/tasn_enc.o \
+	$(LOCAL_DIR)/asn1/tasn_dec.o \
+	$(LOCAL_DIR)/asn1/tasn_fre.o \
+	$(LOCAL_DIR)/asn1/tasn_new.o \
+	$(LOCAL_DIR)/asn1/tasn_prn.o \
+	$(LOCAL_DIR)/asn1/tasn_typ.o \
+	$(LOCAL_DIR)/asn1/tasn_utl.o \
+	$(LOCAL_DIR)/asn1/x_algor.o \
+	$(LOCAL_DIR)/asn1/x_attrib.o \
+	$(LOCAL_DIR)/asn1/x_bignum.o \
+	$(LOCAL_DIR)/asn1/x_crl.o \
+	$(LOCAL_DIR)/asn1/x_exten.o \
+	$(LOCAL_DIR)/asn1/x_info.o \
+	$(LOCAL_DIR)/asn1/x_long.o \
+	$(LOCAL_DIR)/asn1/x_name.o \
+	$(LOCAL_DIR)/asn1/x_nx509.o \
+	$(LOCAL_DIR)/asn1/x_pkey.o \
+	$(LOCAL_DIR)/asn1/x_pubkey.o \
+	$(LOCAL_DIR)/asn1/x_req.o \
+	$(LOCAL_DIR)/asn1/x_spki.o \
+	$(LOCAL_DIR)/asn1/x_val.o \
+	$(LOCAL_DIR)/asn1/x_x509.o \
+	$(LOCAL_DIR)/asn1/x_x509a.o \
+	$(LOCAL_DIR)/bf/bf_cfb64.o \
+	$(LOCAL_DIR)/bf/bf_ecb.o \
+	$(LOCAL_DIR)/bf/bf_enc.o \
+	$(LOCAL_DIR)/bf/bf_ofb64.o \
+	$(LOCAL_DIR)/bf/bf_skey.o \
+	$(LOCAL_DIR)/bn/bn_add.o \
+	$(LOCAL_DIR)/bn/bn_asm.o \
+	$(LOCAL_DIR)/bn/bn_blind.o \
+	$(LOCAL_DIR)/bn/bn_ctx.o \
+	$(LOCAL_DIR)/bn/bn_div.o \
+	$(LOCAL_DIR)/bn/bn_err.o \
+	$(LOCAL_DIR)/bn/bn_exp.o \
+	$(LOCAL_DIR)/bn/bn_exp2.o \
+	$(LOCAL_DIR)/bn/bn_gcd.o \
+	$(LOCAL_DIR)/bn/bn_gf2m.o \
+	$(LOCAL_DIR)/bn/bn_kron.o \
+	$(LOCAL_DIR)/bn/bn_lib.o \
+	$(LOCAL_DIR)/bn/bn_mod.o \
+	$(LOCAL_DIR)/bn/bn_mont.o \
+	$(LOCAL_DIR)/bn/bn_mpi.o \
+	$(LOCAL_DIR)/bn/bn_mul.o \
+	$(LOCAL_DIR)/bn/bn_nist.o \
+	$(LOCAL_DIR)/bn/bn_prime.o \
+	$(LOCAL_DIR)/bn/bn_print.o \
+	$(LOCAL_DIR)/bn/bn_recp.o \
+	$(LOCAL_DIR)/bn/bn_shift.o \
+	$(LOCAL_DIR)/bn/bn_sqr.o \
+	$(LOCAL_DIR)/bn/bn_sqrt.o \
+	$(LOCAL_DIR)/bn/bn_word.o \
+	$(LOCAL_DIR)/buffer/buf_err.o \
+	$(LOCAL_DIR)/buffer/buffer.o \
+	$(LOCAL_DIR)/conf/conf_api.o \
+	$(LOCAL_DIR)/conf/conf_def.o \
+	$(LOCAL_DIR)/conf/conf_err.o \
+	$(LOCAL_DIR)/conf/conf_lib.o \
+	$(LOCAL_DIR)/conf/conf_mall.o \
+	$(LOCAL_DIR)/err/err.o \
+	$(LOCAL_DIR)/err/err_all.o \
+	$(LOCAL_DIR)/err/err_prn.o \
+	$(LOCAL_DIR)/evp/c_all.o \
+	$(LOCAL_DIR)/evp/c_allc.o \
+	$(LOCAL_DIR)/evp/c_alld.o \
+	$(LOCAL_DIR)/evp/digest.o \
+	$(LOCAL_DIR)/evp/e_aes.o \
+	$(LOCAL_DIR)/evp/e_bf.o \
+	$(LOCAL_DIR)/evp/e_des.o \
+	$(LOCAL_DIR)/evp/e_des3.o \
+	$(LOCAL_DIR)/evp/e_null.o \
+	$(LOCAL_DIR)/evp/e_old.o \
+	$(LOCAL_DIR)/evp/e_rc2.o \
+	$(LOCAL_DIR)/evp/e_rc4.o \
+	$(LOCAL_DIR)/evp/e_rc5.o \
+	$(LOCAL_DIR)/evp/e_xcbc_d.o \
+	$(LOCAL_DIR)/evp/encode.o \
+	$(LOCAL_DIR)/evp/evp_acnf.o \
+	$(LOCAL_DIR)/evp/evp_enc.o \
+	$(LOCAL_DIR)/evp/evp_err.o \
+	$(LOCAL_DIR)/evp/evp_key.o \
+	$(LOCAL_DIR)/evp/evp_lib.o \
+	$(LOCAL_DIR)/evp/evp_pbe.o \
+	$(LOCAL_DIR)/evp/evp_pkey.o \
+	$(LOCAL_DIR)/evp/m_dss.o \
+	$(LOCAL_DIR)/evp/m_dss1.o \
+	$(LOCAL_DIR)/evp/m_mdc2.o \
+	$(LOCAL_DIR)/evp/m_null.o \
+	$(LOCAL_DIR)/evp/m_ripemd.o \
+	$(LOCAL_DIR)/evp/m_sha1.o \
+	$(LOCAL_DIR)/evp/m_sigver.o \
+	$(LOCAL_DIR)/evp/m_wp.o \
+	$(LOCAL_DIR)/evp/names.o \
+	$(LOCAL_DIR)/evp/p5_crpt.o \
+	$(LOCAL_DIR)/evp/p5_crpt2.o \
+	$(LOCAL_DIR)/evp/p_dec.o \
+	$(LOCAL_DIR)/evp/p_enc.o \
+	$(LOCAL_DIR)/evp/p_lib.o \
+	$(LOCAL_DIR)/evp/p_open.o \
+	$(LOCAL_DIR)/evp/p_seal.o \
+	$(LOCAL_DIR)/evp/p_sign.o \
+	$(LOCAL_DIR)/evp/p_verify.o \
+	$(LOCAL_DIR)/evp/pmeth_fn.o \
+	$(LOCAL_DIR)/evp/pmeth_gn.o \
+	$(LOCAL_DIR)/evp/pmeth_lib.o \
+	$(LOCAL_DIR)/lhash/lh_stats.o \
+	$(LOCAL_DIR)/lhash/lhash.o \
+	$(LOCAL_DIR)/md4/md4_dgst.o \
+	$(LOCAL_DIR)/md4/md4_one.o \
+	$(LOCAL_DIR)/md5/md5_dgst.o \
+	$(LOCAL_DIR)/md5/md5_one.o \
+	$(LOCAL_DIR)/modes/cbc128.o \
+	$(LOCAL_DIR)/modes/cfb128.o \
+	$(LOCAL_DIR)/modes/ctr128.o \
+	$(LOCAL_DIR)/modes/ofb128.o \
+	$(LOCAL_DIR)/objects/obj_dat.o \
+	$(LOCAL_DIR)/objects/obj_err.o \
+	$(LOCAL_DIR)/objects/obj_lib.o \
+	$(LOCAL_DIR)/objects/obj_xref.o \
+	$(LOCAL_DIR)/objects/o_names.o \
+	$(LOCAL_DIR)/pkcs12/p12_add.o \
+	$(LOCAL_DIR)/pkcs12/p12_asn.o \
+	$(LOCAL_DIR)/pkcs12/p12_attr.o \
+	$(LOCAL_DIR)/pkcs12/p12_crpt.o \
+	$(LOCAL_DIR)/pkcs12/p12_crt.o \
+	$(LOCAL_DIR)/pkcs12/p12_decr.o \
+	$(LOCAL_DIR)/pkcs12/p12_init.o \
+	$(LOCAL_DIR)/pkcs12/p12_key.o \
+	$(LOCAL_DIR)/pkcs12/p12_kiss.o \
+	$(LOCAL_DIR)/pkcs12/p12_mutl.o \
+	$(LOCAL_DIR)/pkcs12/p12_npas.o \
+	$(LOCAL_DIR)/pkcs12/p12_p8d.o \
+	$(LOCAL_DIR)/pkcs12/p12_p8e.o \
+	$(LOCAL_DIR)/pkcs12/p12_utl.o \
+	$(LOCAL_DIR)/pkcs12/pk12err.o \
+	$(LOCAL_DIR)/pkcs7/pk7_asn1.o \
+	$(LOCAL_DIR)/pkcs7/pk7_attr.o \
+	$(LOCAL_DIR)/pkcs7/pk7_doit.o \
+	$(LOCAL_DIR)/pkcs7/pk7_lib.o \
+	$(LOCAL_DIR)/pkcs7/pk7_mime.o \
+	$(LOCAL_DIR)/pkcs7/pk7_smime.o \
+	$(LOCAL_DIR)/pkcs7/pkcs7err.o \
+	$(LOCAL_DIR)/rc2/rc2_cbc.o \
+	$(LOCAL_DIR)/rc2/rc2_ecb.o \
+	$(LOCAL_DIR)/rc2/rc2_skey.o \
+	$(LOCAL_DIR)/rc2/rc2cfb64.o \
+	$(LOCAL_DIR)/rc2/rc2ofb64.o \
+	$(LOCAL_DIR)/rc4/rc4_enc.o \
+	$(LOCAL_DIR)/rc4/rc4_skey.o \
+	$(LOCAL_DIR)/ripemd/rmd_dgst.o \
+	$(LOCAL_DIR)/ripemd/rmd_one.o \
+	$(LOCAL_DIR)/rsa/rsa_ameth.o \
+	$(LOCAL_DIR)/rsa/rsa_asn1.o \
+	$(LOCAL_DIR)/rsa/rsa_chk.o \
+	$(LOCAL_DIR)/rsa/rsa_eay.o \
+	$(LOCAL_DIR)/rsa/rsa_err.o \
+	$(LOCAL_DIR)/rsa/rsa_gen.o \
+	$(LOCAL_DIR)/rsa/rsa_lib.o \
+	$(LOCAL_DIR)/rsa/rsa_none.o \
+	$(LOCAL_DIR)/rsa/rsa_null.o \
+	$(LOCAL_DIR)/rsa/rsa_pk1.o \
+	$(LOCAL_DIR)/rsa/rsa_pmeth.o \
+	$(LOCAL_DIR)/rsa/rsa_prn.o \
+	$(LOCAL_DIR)/rsa/rsa_pss.o \
+	$(LOCAL_DIR)/rsa/rsa_sign.o \
+	$(LOCAL_DIR)/rsa/rsa_saos.o \
+	$(LOCAL_DIR)/rsa/rsa_x931.o \
+	$(LOCAL_DIR)/sha/sha1_one.o \
+	$(LOCAL_DIR)/sha/sha1dgst.o \
+	$(LOCAL_DIR)/sha/sha256.o \
+	$(LOCAL_DIR)/sha/sha512.o \
+	$(LOCAL_DIR)/sha/sha_dgst.o \
+	$(LOCAL_DIR)/stack/stack.o \
+	$(LOCAL_DIR)/ts/ts_err.o \
+	$(LOCAL_DIR)/txt_db/txt_db.o \
+	$(LOCAL_DIR)/x509/x509_att.o \
+	$(LOCAL_DIR)/x509/x509_cmp.o \
+	$(LOCAL_DIR)/x509/x509_d2.o \
+	$(LOCAL_DIR)/x509/x509_def.o \
+	$(LOCAL_DIR)/x509/x509_err.o \
+	$(LOCAL_DIR)/x509/x509_ext.o \
+	$(LOCAL_DIR)/x509/x509_lu.o \
+	$(LOCAL_DIR)/x509/x509_obj.o \
+	$(LOCAL_DIR)/x509/x509_r2x.o \
+	$(LOCAL_DIR)/x509/x509_req.o \
+	$(LOCAL_DIR)/x509/x509_set.o \
+	$(LOCAL_DIR)/x509/x509_trs.o \
+	$(LOCAL_DIR)/x509/x509_txt.o \
+	$(LOCAL_DIR)/x509/x509_v3.o \
+	$(LOCAL_DIR)/x509/x509_vfy.o \
+	$(LOCAL_DIR)/x509/x509_vpm.o \
+	$(LOCAL_DIR)/x509/x509cset.o \
+	$(LOCAL_DIR)/x509/x509name.o \
+	$(LOCAL_DIR)/x509/x509rset.o \
+	$(LOCAL_DIR)/x509/x509spki.o \
+	$(LOCAL_DIR)/x509/x509type.o \
+	$(LOCAL_DIR)/x509/x_all.o \
+	$(LOCAL_DIR)/x509v3/pcy_cache.o \
+	$(LOCAL_DIR)/x509v3/pcy_data.o \
+	$(LOCAL_DIR)/x509v3/pcy_lib.o \
+	$(LOCAL_DIR)/x509v3/pcy_map.o \
+	$(LOCAL_DIR)/x509v3/pcy_node.o \
+	$(LOCAL_DIR)/x509v3/pcy_tree.o \
+	$(LOCAL_DIR)/x509v3/v3_akey.o \
+	$(LOCAL_DIR)/x509v3/v3_akeya.o \
+	$(LOCAL_DIR)/x509v3/v3_alt.o \
+	$(LOCAL_DIR)/x509v3/v3_bcons.o \
+	$(LOCAL_DIR)/x509v3/v3_bitst.o \
+	$(LOCAL_DIR)/x509v3/v3_conf.o \
+	$(LOCAL_DIR)/x509v3/v3_cpols.o \
+	$(LOCAL_DIR)/x509v3/v3_crld.o \
+	$(LOCAL_DIR)/x509v3/v3_enum.o \
+	$(LOCAL_DIR)/x509v3/v3_extku.o \
+	$(LOCAL_DIR)/x509v3/v3_genn.o \
+	$(LOCAL_DIR)/x509v3/v3_ia5.o \
+	$(LOCAL_DIR)/x509v3/v3_info.o \
+	$(LOCAL_DIR)/x509v3/v3_int.o \
+	$(LOCAL_DIR)/x509v3/v3_lib.o \
+	$(LOCAL_DIR)/x509v3/v3_ncons.o \
+	$(LOCAL_DIR)/x509v3/v3_ocsp.o \
+	$(LOCAL_DIR)/x509v3/v3_pci.o \
+	$(LOCAL_DIR)/x509v3/v3_pcia.o \
+	$(LOCAL_DIR)/x509v3/v3_pcons.o \
+	$(LOCAL_DIR)/x509v3/v3_pku.o \
+	$(LOCAL_DIR)/x509v3/v3_pmaps.o \
+	$(LOCAL_DIR)/x509v3/v3_prn.o \
+	$(LOCAL_DIR)/x509v3/v3_purp.o \
+	$(LOCAL_DIR)/x509v3/v3_skey.o \
+	$(LOCAL_DIR)/x509v3/v3_sxnet.o \
+	$(LOCAL_DIR)/x509v3/v3err.o \
+	$(LOCAL_DIR)/x509v3/v3_utl.o
+
+include $(LOCAL_PATH)/android-config.mk
+
+## Removed files from original openssl in Android space
+
+arm_src_files := \
+    $(LOCAL_DIR)/aes/asm/aes-armv4.o \
+    $(LOCAL_DIR)/bn/asm/armv4-mont.o \
+    $(LOCAL_DIR)/sha/asm/sha1-armv4-large.o \
+    $(LOCAL_DIR)/sha/asm/sha256-armv4.o \
+    $(LOCAL_DIR)/sha/asm/sha512-armv4.o
+
+non_arm_src_files := aes/aes_core.c
+
+removed_source_files := uid.o o_time.o o_dir.o \
+	/asn1/a_gentm.o \
+	/asn1/bio_ndef.o \
+	$(LOCAL_DIR)/asn1/asn1_gen.o \
+	$(LOCAL_DIR)/asn1/a_set.o \
+	$(LOCAL_DIR)/bio/b_dump.o \
+	$(LOCAL_DIR)/bio/b_sock.o \
+	$(LOCAL_DIR)/bio/bf_buff.o \
+	$(LOCAL_DIR)/bio/bf_nbio.o \
+	$(LOCAL_DIR)/bio/bf_null.o \
+	$(LOCAL_DIR)/bio/bio_cb.o \
+	$(LOCAL_DIR)/bio/bio_err.o \
+	$(LOCAL_DIR)/bio/bio_lib.o \
+	$(LOCAL_DIR)/bio/bss_acpt.o \
+	$(LOCAL_DIR)/bio/bss_bio.o \
+	$(LOCAL_DIR)/bio/bss_conn.o \
+	$(LOCAL_DIR)/bio/bss_dgram.o \
+	$(LOCAL_DIR)/bio/bss_fd.o \
+	$(LOCAL_DIR)/bio/bss_file.o \
+	$(LOCAL_DIR)/bio/bss_log.o \
+	$(LOCAL_DIR)/bio/bss_mem.o \
+	$(LOCAL_DIR)/bio/bss_null.o \
+	$(LOCAL_DIR)/bio/bss_sock.o \
+	$(LOCAL_DIR)/comp/c_rle.o \
+	$(LOCAL_DIR)/comp/c_zlib.o \
+	$(LOCAL_DIR)/comp/comp_err.o \
+	$(LOCAL_DIR)/comp/comp_lib.o \
+	$(LOCAL_DIR)/conf/conf_mod.o \
+	$(LOCAL_DIR)/conf/conf_sap.o \
+	$(LOCAL_DIR)/des/cbc_cksm.o \
+	$(LOCAL_DIR)/des/cbc_enc.o \
+	$(LOCAL_DIR)/des/cfb64ede.o \
+	$(LOCAL_DIR)/des/cfb64enc.o \
+	$(LOCAL_DIR)/des/cfb_enc.o \
+	$(LOCAL_DIR)/des/des_enc.o \
+	$(LOCAL_DIR)/des/des_old.o \
+	$(LOCAL_DIR)/des/des_old2.o \
+	$(LOCAL_DIR)/des/ecb3_enc.o \
+	$(LOCAL_DIR)/des/ecb_enc.o \
+	$(LOCAL_DIR)/des/ede_cbcm_enc.o \
+	$(LOCAL_DIR)/des/enc_read.o \
+	$(LOCAL_DIR)/des/enc_writ.o \
+	$(LOCAL_DIR)/des/fcrypt.o \
+	$(LOCAL_DIR)/des/fcrypt_b.o \
+	$(LOCAL_DIR)/des/ofb64ede.o \
+	$(LOCAL_DIR)/des/ofb64enc.o \
+	$(LOCAL_DIR)/des/ofb_enc.o \
+	$(LOCAL_DIR)/des/pcbc_enc.o \
+	$(LOCAL_DIR)/des/qud_cksm.o \
+	$(LOCAL_DIR)/des/rand_key.o \
+	$(LOCAL_DIR)/des/read2pwd.o \
+	$(LOCAL_DIR)/des/rpc_enc.o \
+	$(LOCAL_DIR)/des/set_key.o \
+	$(LOCAL_DIR)/des/str2key.o \
+	$(LOCAL_DIR)/des/xcbc_enc.o \
+	$(LOCAL_DIR)/dh/dh_ameth.o \
+	$(LOCAL_DIR)/dh/dh_asn1.o \
+	$(LOCAL_DIR)/dh/dh_check.o \
+	$(LOCAL_DIR)/dh/dh_depr.o \
+	$(LOCAL_DIR)/dh/dh_err.o \
+	$(LOCAL_DIR)/dh/dh_gen.o \
+	$(LOCAL_DIR)/dh/dh_key.o \
+	$(LOCAL_DIR)/dh/dh_lib.o \
+	$(LOCAL_DIR)/dh/dh_pmeth.o \
+	$(LOCAL_DIR)/dsa/dsa_ameth.o \
+	$(LOCAL_DIR)/dsa/dsa_asn1.o \
+	$(LOCAL_DIR)/dsa/dsa_depr.o \
+	$(LOCAL_DIR)/dsa/dsa_err.o \
+	$(LOCAL_DIR)/dsa/dsa_gen.o \
+	$(LOCAL_DIR)/dsa/dsa_key.o \
+	$(LOCAL_DIR)/dsa/dsa_lib.o \
+	$(LOCAL_DIR)/dsa/dsa_ossl.o \
+	$(LOCAL_DIR)/dsa/dsa_pmeth.o \
+	$(LOCAL_DIR)/dsa/dsa_prn.o \
+	$(LOCAL_DIR)/dsa/dsa_sign.o \
+	$(LOCAL_DIR)/dsa/dsa_vrf.o \
+	$(LOCAL_DIR)/dso/dso_dl.o \
+	$(LOCAL_DIR)/dso/dso_dlfcn.o \
+	$(LOCAL_DIR)/dso/dso_err.o \
+	$(LOCAL_DIR)/dso/dso_lib.o \
+	$(LOCAL_DIR)/dso/dso_null.o \
+	$(LOCAL_DIR)/dso/dso_openssl.o \
+	$(LOCAL_DIR)/dso/dso_vms.o \
+	$(LOCAL_DIR)/dso/dso_win32.o \
+	$(LOCAL_DIR)/ec/ec2_mult.o \
+	$(LOCAL_DIR)/ec/ec2_smpl.o \
+	$(LOCAL_DIR)/ec/ec_ameth.o \
+	$(LOCAL_DIR)/ec/ec_asn1.o \
+	$(LOCAL_DIR)/ec/ec_check.o \
+	$(LOCAL_DIR)/ec/ec_curve.o \
+	$(LOCAL_DIR)/ec/ec_cvt.o \
+	$(LOCAL_DIR)/ec/ec_err.o \
+	$(LOCAL_DIR)/ec/ec_key.o \
+	$(LOCAL_DIR)/ec/ec_lib.o \
+	$(LOCAL_DIR)/ec/ec_mult.o \
+	$(LOCAL_DIR)/ec/ec_pmeth.o \
+	$(LOCAL_DIR)/ec/ec_print.o \
+	$(LOCAL_DIR)/ec/eck_prn.o \
+	$(LOCAL_DIR)/ec/ecp_mont.o \
+	$(LOCAL_DIR)/ec/ecp_nist.o \
+	$(LOCAL_DIR)/ec/ecp_smpl.o \
+	$(LOCAL_DIR)/ecdh/ech_err.o \
+	$(LOCAL_DIR)/ecdh/ech_key.o \
+	$(LOCAL_DIR)/ecdh/ech_lib.o \
+	$(LOCAL_DIR)/ecdh/ech_ossl.o \
+	$(LOCAL_DIR)/ecdsa/ecs_asn1.o \
+	$(LOCAL_DIR)/ecdsa/ecs_err.o \
+	$(LOCAL_DIR)/ecdsa/ecs_lib.o \
+	$(LOCAL_DIR)/ecdsa/ecs_ossl.o \
+	$(LOCAL_DIR)/ecdsa/ecs_sign.o \
+	$(LOCAL_DIR)/ecdsa/ecs_vrf.o \
+	$(LOCAL_DIR)/evp/bio_b64.o \
+	$(LOCAL_DIR)/evp/bio_enc.o \
+	$(LOCAL_DIR)/evp/bio_md.o \
+	$(LOCAL_DIR)/evp/bio_ok.o \
+	$(LOCAL_DIR)/evp/m_ecdsa.o \
+	$(LOCAL_DIR)/evp/m_md4.o \
+	$(LOCAL_DIR)/evp/m_md5.o \
+	$(LOCAL_DIR)/hmac/hm_ameth.o \
+	$(LOCAL_DIR)/hmac/hm_pmeth.o \
+	$(LOCAL_DIR)/hmac/hmac.o \
+	$(LOCAL_DIR)/krb5/krb5_asn.o \
+	$(LOCAL_DIR)/ocsp/ocsp_asn.o \
+	$(LOCAL_DIR)/ocsp/ocsp_cl.o \
+	$(LOCAL_DIR)/ocsp/ocsp_err.o \
+	$(LOCAL_DIR)/ocsp/ocsp_ext.o \
+	$(LOCAL_DIR)/ocsp/ocsp_ht.o \
+	$(LOCAL_DIR)/ocsp/ocsp_lib.o \
+	$(LOCAL_DIR)/ocsp/ocsp_prn.o \
+	$(LOCAL_DIR)/ocsp/ocsp_srv.o \
+	$(LOCAL_DIR)/ocsp/ocsp_vfy.o \
+	$(LOCAL_DIR)/pem/pem_all.o \
+	$(LOCAL_DIR)/pem/pem_err.o \
+	$(LOCAL_DIR)/pem/pem_info.o \
+	$(LOCAL_DIR)/pem/pem_lib.o \
+	$(LOCAL_DIR)/pem/pem_oth.o \
+	$(LOCAL_DIR)/pem/pem_pk8.o \
+	$(LOCAL_DIR)/pem/pem_pkey.o \
+	$(LOCAL_DIR)/pem/pem_seal.o \
+	$(LOCAL_DIR)/pem/pem_sign.o \
+	$(LOCAL_DIR)/pem/pem_x509.o \
+	$(LOCAL_DIR)/pem/pem_xaux.o \
+	$(LOCAL_DIR)/pem/pvkfmt.o \
+	$(LOCAL_DIR)/rand/rand_egd.o \
+	$(LOCAL_DIR)/rand/md_rand.o \
+	$(LOCAL_DIR)/rand/rand_err.o \
+	$(LOCAL_DIR)/rand/rand_lib.o \
+	$(LOCAL_DIR)/rand/rand_unix.o \
+	$(LOCAL_DIR)/rand/randfile.o \
+	$(LOCAL_DIR)/ui/ui_compat.o \
+	$(LOCAL_DIR)/ui/ui_err.o \
+	$(LOCAL_DIR)/ui/ui_lib.o \
+	$(LOCAL_DIR)/ui/ui_openssl.o \
+	$(LOCAL_DIR)/ui/ui_util.o \
+	$(LOCAL_DIR)/x509/by_dir.o \
+	$(LOCAL_DIR)/x509/by_file.o \
+	$(LOCAL_DIR)/x509v3/v3_utl.o
+
+Files_removed_error_during_link := \
+	$(LOCAL_DIR)/rsa/rsa_oaep.o \
+	$(LOCAL_DIR)/rsa/rsa_ssl.o \
+	$(LOCAL_DIR)/asn1/x_sig.o \
+	$(LOCAL_DIR)/bn/bn_rand.o \
+	$(LOCAL_DIR)/asn1/t_pkey.o
diff --git a/lib/openssl/crypto/stack/stack.c b/lib/openssl/crypto/stack/stack.c
index 76cf1a1..068b684 100644
--- a/lib/openssl/crypto/stack/stack.c
+++ b/lib/openssl/crypto/stack/stack.c
@@ -209,7 +209,7 @@
 	st->num--;
 	return(ret);
 	}
-
+#ifndef LK_NO_QSORT
 static int internal_find(_STACK *st, void *data, int ret_val_options)
 	{
 	const void * const *r;
@@ -240,7 +240,7 @@
 	{
 	return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH);
 	}
-
+#endif
 int sk_push(_STACK *st, void *data)
 	{
 	return(sk_insert(st,data,st->num));
@@ -309,6 +309,7 @@
 	return (st->data[i] = value);
 }
 
+#ifndef LK_NO_QSORT
 void sk_sort(_STACK *st)
 	{
 	if (st && !st->sorted)
@@ -325,6 +326,7 @@
 		st->sorted=1;
 		}
 	}
+#endif
 
 int sk_is_sorted(const _STACK *st)
 	{
diff --git a/lib/openssl/crypto/x509/x509_req.c b/lib/openssl/crypto/x509/x509_req.c
index 48183dc..b8f9178 100644
--- a/lib/openssl/crypto/x509/x509_req.c
+++ b/lib/openssl/crypto/x509/x509_req.c
@@ -65,7 +65,9 @@
 #include <openssl/x509.h>
 #include <openssl/objects.h>
 #include <openssl/buffer.h>
+#ifndef LK_NO_PEM
 #include <openssl/pem.h>
+#endif
 
 X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
 	{
diff --git a/lib/openssl/crypto/x509/x509_txt.c b/lib/openssl/crypto/x509/x509_txt.c
index c44f753..fd43aee 100644
--- a/lib/openssl/crypto/x509/x509_txt.c
+++ b/lib/openssl/crypto/x509/x509_txt.c
@@ -57,7 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include <errno.h>
 
 #include "cryptlib.h"
diff --git a/lib/openssl/crypto/x509/x509_vfy.c b/lib/openssl/crypto/x509/x509_vfy.c
index 87ebf62..16baf47 100644
--- a/lib/openssl/crypto/x509/x509_vfy.c
+++ b/lib/openssl/crypto/x509/x509_vfy.c
@@ -57,7 +57,9 @@
  */
 
 #include <stdio.h>
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include <errno.h>
 
 #include "cryptlib.h"
@@ -486,8 +488,10 @@
 			!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
 		/* A hack to keep people who don't want to modify their
 		   software happy */
+#ifndef OPENSSL_LK
 		if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
 			allow_proxy_certs = 1;
+#endif
 		purpose = ctx->param->purpose;
 		}
 
@@ -1667,6 +1671,8 @@
 	return ok;
 	}
 
+/* Removing time dependency in LK */
+#if 0
 int X509_cmp_current_time(const ASN1_TIME *ctm)
 {
 	return X509_cmp_time(ctm, NULL);
@@ -1779,6 +1785,7 @@
 		}
 	return ASN1_TIME_adj(s, t, offset_day, offset_sec);
 	}
+#endif
 
 int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
 	{
diff --git a/lib/openssl/crypto/x509v3/v3_ncons.c b/lib/openssl/crypto/x509v3/v3_ncons.c
index 689df46..ec200ba 100644
--- a/lib/openssl/crypto/x509v3/v3_ncons.c
+++ b/lib/openssl/crypto/x509v3/v3_ncons.c
@@ -406,9 +406,11 @@
 			return X509_V_ERR_PERMITTED_VIOLATION;
 		}
 
+	/* Remove dependency on strcasecmp */
+#ifndef OPENSSL_LK
 	if (strcasecmp(baseptr, dnsptr))
 			return X509_V_ERR_PERMITTED_VIOLATION;
-
+#endif
 	return X509_V_OK;
 
 	}
diff --git a/lib/openssl/crypto/x509v3/v3_pci.c b/lib/openssl/crypto/x509v3/v3_pci.c
index 0dcfa00..7721824 100644
--- a/lib/openssl/crypto/x509v3/v3_pci.c
+++ b/lib/openssl/crypto/x509v3/v3_pci.c
@@ -159,6 +159,7 @@
 			}
 		else if (strncmp(val->value, "file:", 5) == 0)
 			{
+#ifndef LK_NO_BIO
 			unsigned char buf[2048];
 			int n;
 			BIO *b = BIO_new_file(val->value + 5, "r");
@@ -193,6 +194,7 @@
 				X509V3_conf_err(val);
 				goto err;
 				}
+#endif
 			}
 		else if (strncmp(val->value, "text:", 5) == 0)
 			{
diff --git a/lib/openssl/e_os.h b/lib/openssl/e_os.h
index 5ceeeeb..f527ae9 100644
--- a/lib/openssl/e_os.h
+++ b/lib/openssl/e_os.h
@@ -444,7 +444,9 @@
 #      define NO_SYS_PARAM_H
 #    endif
 #    ifdef OPENSSL_UNISTD
+#ifndef LK_NO_UNISTD
 #      include OPENSSL_UNISTD
+#endif
 #    else
 #      include <unistd.h>
 #    endif
diff --git a/lib/openssl/include/openssl/asn1.h b/lib/openssl/include/openssl/asn1.h
index f7718b5..1f614e2 100644
--- a/lib/openssl/include/openssl/asn1.h
+++ b/lib/openssl/include/openssl/asn1.h
@@ -59,7 +59,9 @@
 #ifndef HEADER_ASN1_H
 #define HEADER_ASN1_H
 
+#ifndef LK_NO_TIME
 #include <time.h>
+#endif
 #include <openssl/e_os2.h>
 #ifndef OPENSSL_NO_BIO
 #include <openssl/bio.h>
diff --git a/lib/openssl/include/openssl/conf.h b/lib/openssl/include/openssl/conf.h
index c219997..4936345 100644
--- a/lib/openssl/include/openssl/conf.h
+++ b/lib/openssl/include/openssl/conf.h
@@ -134,7 +134,9 @@
 long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group,
 		     const char *name);
 void CONF_free(LHASH_OF(CONF_VALUE) *conf);
+#ifndef OPENSSL_NO_FP_API
 int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
+#endif
 int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
 
 void OPENSSL_config(const char *config_name);
@@ -168,7 +170,9 @@
 char *NCONF_get_string(const CONF *conf,const char *group,const char *name);
 int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
 		       long *result);
+#ifndef OPENSSL_NO_FP_API
 int NCONF_dump_fp(const CONF *conf, FILE *out);
+#endif
 int NCONF_dump_bio(const CONF *conf, BIO *out);
 
 #if 0 /* The following function has no error checking,
diff --git a/lib/openssl/include/openssl/ec.h b/lib/openssl/include/openssl/ec.h
index ee70781..6ac4e6e 100644
--- a/lib/openssl/include/openssl/ec.h
+++ b/lib/openssl/include/openssl/ec.h
@@ -79,8 +79,10 @@
 #include <openssl/opensslconf.h>
 
 #ifdef OPENSSL_NO_EC
+#ifndef OPENSSL_LK
 #error EC is disabled.
 #endif
+#endif
 
 #include <openssl/asn1.h>
 #include <openssl/symhacks.h>
diff --git a/lib/openssl/include/openssl/pkcs12.h b/lib/openssl/include/openssl/pkcs12.h
index b17eb9f..2355c2e 100644
--- a/lib/openssl/include/openssl/pkcs12.h
+++ b/lib/openssl/include/openssl/pkcs12.h
@@ -257,9 +257,13 @@
 PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
 
 int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
+#ifndef OPENSSL_NO_FP_API
 int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
+#endif
 PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
+#ifndef OPENSSL_NO_FP_API
 PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
+#endif
 int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
 
 /* BEGIN ERROR CODES */
diff --git a/lib/openssl/include/openssl/ts.h b/lib/openssl/include/openssl/ts.h
index 190e8a1..3c9cc1d 100644
--- a/lib/openssl/include/openssl/ts.h
+++ b/lib/openssl/include/openssl/ts.h
@@ -291,8 +291,10 @@
 
 TS_REQ	*TS_REQ_dup(TS_REQ *a);
 
+#ifndef OPENSSL_NO_FP_API
 TS_REQ	*d2i_TS_REQ_fp(FILE *fp, TS_REQ **a);
 int	i2d_TS_REQ_fp(FILE *fp, TS_REQ *a);
+#endif
 TS_REQ	*d2i_TS_REQ_bio(BIO *fp, TS_REQ **a);
 int	i2d_TS_REQ_bio(BIO *fp, TS_REQ *a);
 
@@ -304,8 +306,10 @@
 
 TS_MSG_IMPRINT	*TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *a);
 
+#ifndef OPENSSL_NO_FP_API
 TS_MSG_IMPRINT	*d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a);
 int		i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a);
+#endif
 TS_MSG_IMPRINT	*d2i_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT **a);
 int		i2d_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT *a);
 
@@ -316,8 +320,10 @@
 TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token);
 TS_RESP	*TS_RESP_dup(TS_RESP *a);
 
+#ifndef OPENSSL_NO_FP_API
 TS_RESP	*d2i_TS_RESP_fp(FILE *fp, TS_RESP **a);
 int	i2d_TS_RESP_fp(FILE *fp, TS_RESP *a);
+#endif
 TS_RESP	*d2i_TS_RESP_bio(BIO *fp, TS_RESP **a);
 int	i2d_TS_RESP_bio(BIO *fp, TS_RESP *a);
 
@@ -335,8 +341,10 @@
 				    long length);
 TS_TST_INFO	*TS_TST_INFO_dup(TS_TST_INFO *a);
 
+#ifndef OPENSSL_NO_FP_API
 TS_TST_INFO	*d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a);
 int		i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a);
+#endif
 TS_TST_INFO	*d2i_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO **a);
 int		i2d_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO *a);
 
diff --git a/lib/openssl/include/openssl/x509v3.h b/lib/openssl/include/openssl/x509v3.h
index b308abe..2dbafe9 100644
--- a/lib/openssl/include/openssl/x509v3.h
+++ b/lib/openssl/include/openssl/x509v3.h
@@ -670,8 +670,10 @@
 void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
 								 int ml);
 int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent);
-int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
 
+#ifndef OPENSSL_NO_FP_API
+int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
+#endif
 int X509V3_extensions_print(BIO *out, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent);
 
 int X509_check_ca(X509 *x);
diff --git a/lib/openssl/rules.mk b/lib/openssl/rules.mk
new file mode 100644
index 0000000..696d945
--- /dev/null
+++ b/lib/openssl/rules.mk
@@ -0,0 +1,4 @@
+LOCAL_PATH := $(GET_LOCAL_DIR)
+
+MODULES += \
+	lib/openssl/crypto
diff --git a/lib/openssl/ssl/rules.mk b/lib/openssl/ssl/rules.mk
new file mode 100644
index 0000000..32a5092
--- /dev/null
+++ b/lib/openssl/ssl/rules.mk
@@ -0,0 +1,75 @@
+LOCAL_PATH:= $(GET_LOCAL_DIR)
+
+local_c_includes := \
+	external/openssl \
+	external/openssl/include \
+	external/openssl/crypto
+
+local_src_files:= \
+	s2_meth.c \
+	s2_srvr.c \
+	s2_clnt.c \
+	s2_lib.c \
+	s2_enc.c \
+	s2_pkt.c \
+	s3_meth.c \
+	s3_srvr.c \
+	s3_clnt.c \
+	s3_lib.c \
+	s3_enc.c \
+	s3_pkt.c \
+	s3_both.c \
+	s23_meth.c \
+	s23_srvr.c \
+	s23_clnt.c \
+	s23_lib.c \
+	s23_pkt.c \
+	t1_meth.c \
+	t1_srvr.c \
+	t1_clnt.c \
+	t1_lib.c \
+	t1_enc.c \
+	t1_reneg.c \
+	ssl_lib.c \
+	ssl_err2.c \
+	ssl_cert.c \
+	ssl_sess.c \
+	ssl_ciph.c \
+	ssl_stat.c \
+	ssl_rsa.c \
+	ssl_asn1.c \
+	ssl_txt.c \
+	ssl_algs.c \
+	bio_ssl.c \
+	ssl_err.c \
+	kssl.c
+
+include $(CLEAR_VARS)
+include $(LOCAL_PATH)/../android-config.mk
+LOCAL_SRC_FILES += $(local_src_files)
+LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SHARED_LIBRARIES += libcrypto
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE:= libssl
+include $(BUILD_SHARED_LIBRARY)
+
+ifeq ($(WITH_HOST_DALVIK),true)
+    include $(CLEAR_VARS)
+    include $(LOCAL_PATH)/../android-config.mk
+    LOCAL_SRC_FILES += $(local_src_files)
+    LOCAL_C_INCLUDES += $(local_c_includes)
+    LOCAL_SHARED_LIBRARIES += libcrypto
+    LOCAL_MODULE_TAGS := optional
+    LOCAL_MODULE:= libssl
+    include $(BUILD_HOST_SHARED_LIBRARY)
+endif
+
+# ssltest
+include $(CLEAR_VARS)
+include $(LOCAL_PATH)/../android-config.mk
+LOCAL_SRC_FILES:= ssltest.c
+LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SHARED_LIBRARIES := libssl libcrypto
+LOCAL_MODULE:= ssltest
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)