refactor(storage): Refactor storage_upgrade().

pull/3971/head
Andrew Kozlik 2 months ago committed by Andrew Kozlik
parent a8f808822c
commit ecf31610b0

@ -1529,41 +1529,24 @@ static secbool storage_upgrade(void) {
unlocked = secfalse; unlocked = secfalse;
memzero(cached_keys, sizeof(cached_keys)); memzero(cached_keys, sizeof(cached_keys));
} else { } else if (norcow_active_version < 4) {
// Copy all entries. // Change data structure for encrypted entries.
uint32_t offset = 0; uint32_t offset = 0;
while (sectrue == norcow_get_next(&offset, &key, &val, &len)) { while (sectrue == norcow_get_next(&offset, &key, &val, &len)) {
if (norcow_active_version < 4) { const uint8_t app = key >> 8;
// Change data structure for encrypted entries. if (((app & FLAG_PUBLIC) == 0) &&
const uint8_t app = key >> 8; (app != APP_STORAGE || key == VERSION_KEY)) {
const uint8_t *iv = (const uint8_t *)val;
if (((app & FLAG_PUBLIC) == 0) && const uint8_t *tag = (const uint8_t *)val + CHACHA20_IV_SIZE;
!(key == PIN_LOGS_KEY || key == EDEK_PVC_KEY || const uint8_t *ciphertext =
key == PIN_NOT_SET_KEY || key == STORAGE_TAG_KEY || (const uint8_t *)val + CHACHA20_IV_SIZE + POLY1305_TAG_SIZE;
key == WIPE_CODE_DATA_KEY || key == STORAGE_UPGRADED_KEY || const size_t ciphertext_len =
key == UNAUTH_VERSION_KEY)) { len - CHACHA20_IV_SIZE - POLY1305_TAG_SIZE;
if (sectrue != norcow_set(key, NULL, len)) { if (sectrue != norcow_set(key, NULL, len) ||
return secfalse; sectrue != norcow_update_bytes(key, iv, CHACHA20_IV_SIZE) ||
} sectrue != norcow_update_bytes(key, ciphertext, ciphertext_len) ||
if (sectrue != sectrue != norcow_update_bytes(key, tag, POLY1305_TAG_SIZE)) {
norcow_update_bytes(key, ((uint8_t *)val), CHACHA20_IV_SIZE)) { return secfalse;
return secfalse;
}
if (sectrue !=
norcow_update_bytes(
key, ((uint8_t *)val) + CHACHA20_IV_SIZE + POLY1305_TAG_SIZE,
len - CHACHA20_IV_SIZE - POLY1305_TAG_SIZE)) {
return secfalse;
}
if (sectrue !=
norcow_update_bytes(key, ((uint8_t *)val) + CHACHA20_IV_SIZE,
POLY1305_TAG_SIZE)) {
return secfalse;
}
} else {
if (sectrue != norcow_set(key, val, len)) {
return secfalse;
}
} }
} else { } else {
if (sectrue != norcow_set(key, val, len)) { if (sectrue != norcow_set(key, val, len)) {
@ -1571,6 +1554,14 @@ static secbool storage_upgrade(void) {
} }
} }
} }
} else {
// Copy all entries.
uint32_t offset = 0;
while (sectrue == norcow_get_next(&offset, &key, &val, &len)) {
if (sectrue != norcow_set(key, val, len)) {
return secfalse;
}
}
} }
// Set wipe code. // Set wipe code.

Loading…
Cancel
Save