Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
lk/openssl: Adding openssl to compile in lk build
Browse files Browse the repository at this point in the history
This is used for verifying signed kernel.
Openssl library will be used for certificate parsing
and rsa decryption.

Change-Id: Icf0024afd8f4d8690d077b47f4b9e83cad1e4813
  • Loading branch information
Kinson Chik authored and Shashank Mittal committed Aug 13, 2011
1 parent df5ae14 commit 2cd211f
Show file tree
Hide file tree
Showing 58 changed files with 1,012 additions and 35 deletions.
3 changes: 3 additions & 0 deletions app/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
LOCAL_DIR := $(GET_LOCAL_DIR)

MODULES += \
lib/openssl

OBJS += \
$(LOCAL_DIR)/app.o

1 change: 1 addition & 0 deletions include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
33 changes: 33 additions & 0 deletions include/errno.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions include/lib/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void *malloc(size_t size) __MALLOC;
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)
}
Expand Down
22 changes: 22 additions & 0 deletions lib/heap/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,28 @@ void *heap_alloc(size_t size, unsigned int alignment)
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)
Expand Down
5 changes: 5 additions & 0 deletions lib/libc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ void free(void *ptr)
return heap_free(ptr);
}

void *realloc(void *ptr, size_t size)
{
return(heap_realloc(ptr, size));
}

14 changes: 11 additions & 3 deletions lib/openssl/android-config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/openssl/crypto/aes/aes_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* ====================================================================
*/

#include "cryptlib.h"
#include <cryptlib.h>
#include <openssl/aes.h>
#include <openssl/bio.h>

Expand Down
2 changes: 2 additions & 0 deletions lib/openssl/crypto/asn1/a_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
*/

#include <stdio.h>
#ifndef LK_NO_TIME
#include <time.h>
#endif

#include "cryptlib.h"

Expand Down
2 changes: 2 additions & 0 deletions lib/openssl/crypto/asn1/a_gentm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/openssl/crypto/asn1/a_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@
*/

#include <stdio.h>
#ifndef LK_NO_TIME
#include <time.h>

#endif
#include "cryptlib.h"

#ifndef NO_SYS_TYPES_H
Expand Down
5 changes: 4 additions & 1 deletion lib/openssl/crypto/asn1/a_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -97,7 +99,7 @@ int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
}
#endif


#ifndef LK_NO_TIME
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
{
return ASN1_TIME_adj(s, t, 0, 0);
Expand Down Expand Up @@ -196,3 +198,4 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str)

return 1;
}
#endif
6 changes: 4 additions & 2 deletions lib/openssl/crypto/asn1/a_utctm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -81,7 +83,7 @@ int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
#endif
}


#ifndef LK_NO_TIME
ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
long length)
{
Expand Down Expand Up @@ -277,7 +279,7 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)

return 0;
}

#endif

#if 0
time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
Expand Down
3 changes: 2 additions & 1 deletion lib/openssl/crypto/asn1/a_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
*/

#include <stdio.h>
#ifndef LK_NO_TIME
#include <time.h>

#endif
#include "cryptlib.h"
#include "asn1_locl.h"

Expand Down
16 changes: 15 additions & 1 deletion lib/openssl/crypto/asn1/ameth_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand All @@ -90,7 +95,11 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] =
#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);
Expand Down Expand Up @@ -150,10 +159,14 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
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)
Expand All @@ -172,8 +185,9 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
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);
Expand Down
2 changes: 2 additions & 0 deletions lib/openssl/crypto/asn1/asn1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions lib/openssl/crypto/asn1/asn1t.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ typedef struct ASN1_STREAM_ARG_st {
/* This includes evil casts to remove const: they will go away when full
* ASN1 constification is done.
*/
#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));\
}

#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) \
{ \
Expand All @@ -883,6 +890,7 @@ typedef struct ASN1_STREAM_ARG_st {
{ \
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
}
#endif

#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
stname * stname##_dup(stname *x) \
Expand Down
3 changes: 1 addition & 2 deletions lib/openssl/crypto/asn1/tasn_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ static int der_cmp(const void *a, const void *b)
}

/* 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)
Expand Down Expand Up @@ -480,7 +479,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
}

/* 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++)
Expand Down
6 changes: 5 additions & 1 deletion lib/openssl/crypto/asn1/x_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,9 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
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
}
9 changes: 7 additions & 2 deletions lib/openssl/crypto/asn1/x_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,15 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
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.
Expand Down
Loading

0 comments on commit 2cd211f

Please sign in to comment.