summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcryptfs_hw.c26
-rwxr-xr-xcryptfs_hw.h2
2 files changed, 13 insertions, 15 deletions
diff --git a/cryptfs_hw.c b/cryptfs_hw.c
index a7164ab..ce522e5 100755
--- a/cryptfs_hw.c
+++ b/cryptfs_hw.c
@@ -63,7 +63,6 @@
#define UPDATE_HW_DISK_ENC_KEY 2
static int loaded_library = 0;
-static unsigned char current_passwd[MAX_PASSWORD_LEN];
static int (*qseecom_create_key)(int, void*);
static int (*qseecom_update_key)(int, void*, void*);
static int (*qseecom_wipe_key)(int);
@@ -155,25 +154,25 @@ static int load_qseecom_library()
* For NON-ICE targets, it would return 0 on success. On ICE based targets,
* it would return key index in the ICE Key LUT
*/
-static int set_key(const char* passwd, const char* enc_mode, int operation)
+static int set_key(const char* currentpasswd, const char* passwd, const char* enc_mode, int operation)
{
int err = -1;
if (is_hw_disk_encryption(enc_mode) && load_qseecom_library()) {
unsigned char* tmp_passwd = get_tmp_passwd(passwd);
+ unsigned char* tmp_currentpasswd = get_tmp_passwd(currentpasswd);
if(tmp_passwd) {
- if (operation == UPDATE_HW_DISK_ENC_KEY)
- err = qseecom_update_key(map_usage(QSEECOM_DISK_ENCRYPTION), current_passwd, tmp_passwd);
- else if (operation == SET_HW_DISK_ENC_KEY)
+ if (operation == UPDATE_HW_DISK_ENC_KEY) {
+ if (tmp_currentpasswd)
+ err = qseecom_update_key(map_usage(QSEECOM_DISK_ENCRYPTION), tmp_currentpasswd, tmp_passwd);
+ } else if (operation == SET_HW_DISK_ENC_KEY) {
err = qseecom_create_key(map_usage(QSEECOM_DISK_ENCRYPTION), tmp_passwd);
-
- if(err >= 0) {
- memset(current_passwd, 0, MAX_PASSWORD_LEN);
- memcpy(current_passwd, tmp_passwd, MAX_PASSWORD_LEN);
- } else {
+ }
+ if(err < 0) {
if(ERR_MAX_PASSWORD_ATTEMPTS == err)
wipe_userdata();
}
free(tmp_passwd);
+ free(tmp_currentpasswd);
}
}
return err;
@@ -181,13 +180,12 @@ static int set_key(const char* passwd, const char* enc_mode, int operation)
int set_hw_device_encryption_key(const char* passwd, const char* enc_mode)
{
- return set_key(passwd, enc_mode, SET_HW_DISK_ENC_KEY);
+ return set_key(NULL, passwd, enc_mode, SET_HW_DISK_ENC_KEY);
}
-int update_hw_device_encryption_key(const char* newpw, const char* enc_mode)
+int update_hw_device_encryption_key(const char* oldpw, const char* newpw, const char* enc_mode)
{
-
- return set_key(newpw, enc_mode, UPDATE_HW_DISK_ENC_KEY);
+ return set_key(oldpw, newpw, enc_mode, UPDATE_HW_DISK_ENC_KEY);
}
unsigned int is_hw_disk_encryption(const char* encryption_mode)
diff --git a/cryptfs_hw.h b/cryptfs_hw.h
index c7b1746..5d4881c 100755
--- a/cryptfs_hw.h
+++ b/cryptfs_hw.h
@@ -34,7 +34,7 @@ extern "C" {
#endif
int set_hw_device_encryption_key(const char*, const char*);
-int update_hw_device_encryption_key(const char*, const char*);
+int update_hw_device_encryption_key(const char*, const char*, const char*);
int wipe_hw_device_encryption_key(const char*);
unsigned int is_hw_disk_encryption(const char*);
int is_ice_enabled(void);