summaryrefslogtreecommitdiffstats
path: root/applypatch
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-02-04 20:26:29 +0100
committerTao Bao <tbao@google.com>2016-02-04 20:26:29 +0100
commit50aa63f9bd7a524c9923991a9f90334bbb9175fa (patch)
tree630b9657f29cb549fe690d9bdd437a04f3bed3df /applypatch
parentMerge "uncrypt: add options to setup bcb and clear bcb." am: e3434279c8 (diff)
parentMerge "Switch from mincrypt to BoringSSL in applypatch and updater." (diff)
downloadandroid_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar.gz
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar.bz2
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar.lz
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar.xz
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.tar.zst
android_bootable_recovery-50aa63f9bd7a524c9923991a9f90334bbb9175fa.zip
Diffstat (limited to 'applypatch')
-rw-r--r--applypatch/Android.mk8
-rw-r--r--applypatch/applypatch.cpp47
-rw-r--r--applypatch/applypatch.h6
-rw-r--r--applypatch/bspatch.cpp4
-rw-r--r--applypatch/imgpatch.cpp6
-rw-r--r--applypatch/main.cpp4
6 files changed, 37 insertions, 38 deletions
diff --git a/applypatch/Android.mk b/applypatch/Android.mk
index bc2e69e62..481de0511 100644
--- a/applypatch/Android.mk
+++ b/applypatch/Android.mk
@@ -21,7 +21,7 @@ LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.c
LOCAL_MODULE := libapplypatch
LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += bootable/recovery
-LOCAL_STATIC_LIBRARIES += libbase libotafault libmtdutils libmincrypt libbz libz
+LOCAL_STATIC_LIBRARIES += libbase libotafault libmtdutils libcrypto_static libbz libz
include $(BUILD_STATIC_LIBRARY)
@@ -32,7 +32,7 @@ LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp
LOCAL_MODULE := libimgpatch
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz
+LOCAL_STATIC_LIBRARIES += libcrypto_static libbz libz
include $(BUILD_STATIC_LIBRARY)
@@ -44,7 +44,7 @@ LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp
LOCAL_MODULE := libimgpatch
LOCAL_C_INCLUDES += bootable/recovery
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz
+LOCAL_STATIC_LIBRARIES += libcrypto_static libbz libz
include $(BUILD_HOST_STATIC_LIBRARY)
endif # HOST_OS == linux
@@ -55,7 +55,7 @@ LOCAL_CLANG := true
LOCAL_SRC_FILES := main.cpp
LOCAL_MODULE := applypatch
LOCAL_C_INCLUDES += bootable/recovery
-LOCAL_STATIC_LIBRARIES += libapplypatch libbase libotafault libmtdutils libmincrypt libbz
+LOCAL_STATIC_LIBRARIES += libapplypatch libbase libotafault libmtdutils libcrypto_static libbz
LOCAL_SHARED_LIBRARIES += libz libcutils libc
include $(BUILD_EXECUTABLE)
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index 93e6b25ac..5f591b05a 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -27,7 +27,7 @@
#include <android-base/strings.h>
-#include "mincrypt/sha.h"
+#include "openssl/sha.h"
#include "applypatch.h"
#include "mtdutils/mtdutils.h"
#include "edify/expr.h"
@@ -42,7 +42,7 @@ static int GenerateTarget(FileContents* source_file,
const Value* copy_patch_value,
const char* source_filename,
const char* target_filename,
- const uint8_t target_sha1[SHA_DIGEST_SIZE],
+ const uint8_t target_sha1[SHA_DIGEST_LENGTH],
size_t target_size,
const Value* bonus_data);
@@ -87,7 +87,7 @@ int LoadFileContents(const char* filename, FileContents* file) {
}
ota_fclose(f);
- SHA_hash(file->data, file->size, file->sha1);
+ SHA1(file->data, file->size, file->sha1);
return 0;
}
@@ -182,8 +182,8 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
}
SHA_CTX sha_ctx;
- SHA_init(&sha_ctx);
- uint8_t parsed_sha[SHA_DIGEST_SIZE];
+ SHA1_Init(&sha_ctx);
+ uint8_t parsed_sha[SHA_DIGEST_LENGTH];
// Allocate enough memory to hold the largest size.
file->data = reinterpret_cast<unsigned char*>(malloc(size[index[pairs-1]]));
@@ -213,7 +213,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
file->data = NULL;
return -1;
}
- SHA_update(&sha_ctx, p, read);
+ SHA1_Update(&sha_ctx, p, read);
file->size += read;
}
@@ -221,7 +221,8 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
// check it against this pair's expected hash.
SHA_CTX temp_ctx;
memcpy(&temp_ctx, &sha_ctx, sizeof(SHA_CTX));
- const uint8_t* sha_so_far = SHA_final(&temp_ctx);
+ uint8_t sha_so_far[SHA_DIGEST_LENGTH];
+ SHA1_Final(sha_so_far, &temp_ctx);
if (ParseSha1(sha1sum[index[i]].c_str(), parsed_sha) != 0) {
printf("failed to parse sha1 %s in %s\n", sha1sum[index[i]].c_str(), filename);
@@ -230,7 +231,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
return -1;
}
- if (memcmp(sha_so_far, parsed_sha, SHA_DIGEST_SIZE) == 0) {
+ if (memcmp(sha_so_far, parsed_sha, SHA_DIGEST_LENGTH) == 0) {
// we have a match. stop reading the partition; we'll return
// the data we've read so far.
printf("partition read matched size %zu sha %s\n",
@@ -261,10 +262,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
return -1;
}
- const uint8_t* sha_final = SHA_final(&sha_ctx);
- for (size_t i = 0; i < SHA_DIGEST_SIZE; ++i) {
- file->sha1[i] = sha_final[i];
- }
+ SHA1_Final(file->sha1, &sha_ctx);
// Fake some stat() info.
file->st.st_mode = 0644;
@@ -495,7 +493,7 @@ int WriteToPartition(unsigned char* data, size_t len, const char* target) {
int ParseSha1(const char* str, uint8_t* digest) {
const char* ps = str;
uint8_t* pd = digest;
- for (int i = 0; i < SHA_DIGEST_SIZE * 2; ++i, ++ps) {
+ for (int i = 0; i < SHA_DIGEST_LENGTH * 2; ++i, ++ps) {
int digit;
if (*ps >= '0' && *ps <= '9') {
digit = *ps - '0';
@@ -522,10 +520,10 @@ int ParseSha1(const char* str, uint8_t* digest) {
// found.
int FindMatchingPatch(uint8_t* sha1, char* const * const patch_sha1_str,
int num_patches) {
- uint8_t patch_sha1[SHA_DIGEST_SIZE];
+ uint8_t patch_sha1[SHA_DIGEST_LENGTH];
for (int i = 0; i < num_patches; ++i) {
if (ParseSha1(patch_sha1_str[i], patch_sha1) == 0 &&
- memcmp(patch_sha1, sha1, SHA_DIGEST_SIZE) == 0) {
+ memcmp(patch_sha1, sha1, SHA_DIGEST_LENGTH) == 0) {
return i;
}
}
@@ -671,7 +669,7 @@ int applypatch(const char* source_filename,
target_filename = source_filename;
}
- uint8_t target_sha1[SHA_DIGEST_SIZE];
+ uint8_t target_sha1[SHA_DIGEST_LENGTH];
if (ParseSha1(target_sha1_str, target_sha1) != 0) {
printf("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
return 1;
@@ -686,7 +684,7 @@ int applypatch(const char* source_filename,
// We try to load the target file into the source_file object.
if (LoadFileContents(target_filename, &source_file) == 0) {
- if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+ if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_LENGTH) == 0) {
// The early-exit case: the patch was already applied, this file
// has the desired hash, nothing for us to do.
printf("already %s\n", short_sha1(target_sha1).c_str());
@@ -757,7 +755,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename,
const char* target_sha1_str, size_t target_size) {
printf("flash %s: ", target_filename);
- uint8_t target_sha1[SHA_DIGEST_SIZE];
+ uint8_t target_sha1[SHA_DIGEST_LENGTH];
if (ParseSha1(target_sha1_str, target_sha1) != 0) {
printf("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
return 1;
@@ -778,7 +776,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename,
pieces.push_back(target_sha1_str);
std::string fullname = android::base::Join(pieces, ':');
if (LoadPartitionContents(fullname.c_str(), &source_file) == 0 &&
- memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+ memcmp(source_file.sha1, target_sha1, SHA_DIGEST_LENGTH) == 0) {
// The early-exit case: the image was already applied, this partition
// has the desired hash, nothing for us to do.
printf("already %s\n", short_sha1(target_sha1).c_str());
@@ -787,7 +785,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename,
}
if (LoadFileContents(source_filename, &source_file) == 0) {
- if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
+ if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_LENGTH) != 0) {
// The source doesn't have desired checksum.
printf("source \"%s\" doesn't have expected sha1 sum\n", source_filename);
printf("expected: %s, found: %s\n", short_sha1(target_sha1).c_str(),
@@ -813,7 +811,7 @@ static int GenerateTarget(FileContents* source_file,
const Value* copy_patch_value,
const char* source_filename,
const char* target_filename,
- const uint8_t target_sha1[SHA_DIGEST_SIZE],
+ const uint8_t target_sha1[SHA_DIGEST_LENGTH],
size_t target_size,
const Value* bonus_data) {
int retry = 1;
@@ -958,7 +956,7 @@ static int GenerateTarget(FileContents* source_file,
char* header = patch->data;
ssize_t header_bytes_read = patch->size;
- SHA_init(&ctx);
+ SHA1_Init(&ctx);
int result;
@@ -1002,8 +1000,9 @@ static int GenerateTarget(FileContents* source_file,
}
} while (retry-- > 0);
- const uint8_t* current_target_sha1 = SHA_final(&ctx);
- if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
+ uint8_t current_target_sha1[SHA_DIGEST_LENGTH];
+ SHA1_Final(current_target_sha1, &ctx);
+ if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_LENGTH) != 0) {
printf("patch did not produce expected sha1\n");
return 1;
} else {
diff --git a/applypatch/applypatch.h b/applypatch/applypatch.h
index 415bc1b3c..e0df104b5 100644
--- a/applypatch/applypatch.h
+++ b/applypatch/applypatch.h
@@ -18,16 +18,16 @@
#define _APPLYPATCH_H
#include <sys/stat.h>
-#include "mincrypt/sha.h"
+#include "openssl/sha.h"
#include "edify/expr.h"
typedef struct _Patch {
- uint8_t sha1[SHA_DIGEST_SIZE];
+ uint8_t sha1[SHA_DIGEST_LENGTH];
const char* patch_filename;
} Patch;
typedef struct _FileContents {
- uint8_t sha1[SHA_DIGEST_SIZE];
+ uint8_t sha1[SHA_DIGEST_LENGTH];
unsigned char* data;
ssize_t size;
struct stat st;
diff --git a/applypatch/bspatch.cpp b/applypatch/bspatch.cpp
index 75975ad6d..25171170a 100644
--- a/applypatch/bspatch.cpp
+++ b/applypatch/bspatch.cpp
@@ -30,7 +30,7 @@
#include <bzlib.h>
-#include "mincrypt/sha.h"
+#include "openssl/sha.h"
#include "applypatch.h"
void ShowBSDiffLicense() {
@@ -114,7 +114,7 @@ int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
printf("short write of output: %d (%s)\n", errno, strerror(errno));
return 1;
}
- if (ctx) SHA_update(ctx, new_data, new_size);
+ if (ctx) SHA1_Update(ctx, new_data, new_size);
free(new_data);
return 0;
diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp
index 3e72b2cb5..c9944dfc1 100644
--- a/applypatch/imgpatch.cpp
+++ b/applypatch/imgpatch.cpp
@@ -26,7 +26,7 @@
#include <string.h>
#include "zlib.h"
-#include "mincrypt/sha.h"
+#include "openssl/sha.h"
#include "applypatch.h"
#include "imgdiff.h"
#include "utils.h"
@@ -109,7 +109,7 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
printf("failed to read chunk %d raw data\n", i);
return -1;
}
- if (ctx) SHA_update(ctx, patch->data + pos, data_len);
+ if (ctx) SHA1_Update(ctx, patch->data + pos, data_len);
if (sink((unsigned char*)patch->data + pos,
data_len, token) != data_len) {
printf("failed to write chunk %d raw data\n", i);
@@ -236,7 +236,7 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
(long)have);
return -1;
}
- if (ctx) SHA_update(ctx, temp_data, have);
+ if (ctx) SHA1_Update(ctx, temp_data, have);
} while (ret != Z_STREAM_END);
deflateEnd(&strm);
diff --git a/applypatch/main.cpp b/applypatch/main.cpp
index 966d8b91f..445a7fee7 100644
--- a/applypatch/main.cpp
+++ b/applypatch/main.cpp
@@ -21,7 +21,7 @@
#include "applypatch.h"
#include "edify/expr.h"
-#include "mincrypt/sha.h"
+#include "openssl/sha.h"
static int CheckMode(int argc, char** argv) {
if (argc < 3) {
@@ -54,7 +54,7 @@ static bool ParsePatchArgs(int argc, char** argv, char*** sha1s,
*patches = reinterpret_cast<Value**>(malloc(*num_patches * sizeof(Value*)));
memset(*patches, 0, *num_patches * sizeof(Value*));
- uint8_t digest[SHA_DIGEST_SIZE];
+ uint8_t digest[SHA_DIGEST_LENGTH];
for (int i = 0; i < *num_patches; ++i) {
char* colon = strchr(argv[i], ':');