Add ENGINE for BoringSSL.

This change adds a new ENGINE implementation for BoringSSL. It's a no-op
until external/openssl is switched to BoringSSL.

BoringSSL's ENGINEs are very different from OpenSSL's (and very much
smaller). Thus this change adds replacement code that is conditionally
compiled when BoringSSL is used.

Rather than building a .so that is put in a special directory and loaded
by OpenSSL dymanically, the code becomes a normal library that exports a
single function: EVP_PKEY_from_keystore. All the |ENGINE_load| etc
functions that callers previously needed become moot with BoringSSL.

Bug: 17409664
Change-Id: I8b5ba255f86ec5d0f28994358dc0f0b516f0af40
diff --git a/keystore-engine/Android.mk b/keystore-engine/Android.mk
index bd86b6a..b33a347 100644
--- a/keystore-engine/Android.mk
+++ b/keystore-engine/Android.mk
@@ -15,25 +15,33 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
+include $(TOP)/external/openssl/flavor.mk
 
-LOCAL_MODULE := libkeystore
+ifeq ($(OPENSSL_FLAVOR),BoringSSL)
+  LOCAL_MODULE := libkeystore-engine
 
-LOCAL_MODULE_TAGS := optional
+  LOCAL_SRC_FILES := \
+	android_engine.cpp
 
-LOCAL_MODULE_RELATIVE_PATH := ssl/engines
+  LOCAL_C_INCLUDES += \
+	external/openssl/src/include
+else
+  LOCAL_MODULE := libkeystore
 
-LOCAL_SRC_FILES := \
+  LOCAL_SRC_FILES := \
 	eng_keystore.cpp \
 	keyhandle.cpp \
 	ecdsa_meth.cpp \
 	dsa_meth.cpp \
 	rsa_meth.cpp
 
-LOCAL_CFLAGS := -fvisibility=hidden -Wall -Werror
-
-LOCAL_C_INCLUDES += \
+  LOCAL_C_INCLUDES += \
 	external/openssl/include \
 	external/openssl
+endif
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -fvisibility=hidden -Wall -Werror
 
 LOCAL_SHARED_LIBRARIES += \
 	libcrypto \