Commit baaa810e604aa3afd8cf9832a5b29828d6ffc6f4
Committed by
Ye Li
1 parent
6ecfd9ed2a
Exists in
smarc_8mq_lf_v2020.04
and in
4 other branches
MA-18325 Pad keyslot_package struct to one block size
blk_dwrite() will write data in blocks, padding the keyslot_package struct to one block to avoid redundant data write. Test: RPMB key set. Change-Id: I326d7f4394d15e6e22b12c3abd6a5e2de18920cc Signed-off-by: Ji Luo <ji.luo@nxp.com> (cherry picked from commit 8a0deb19628d2752b516fbce00fc1b988f2e78b5)
Showing 2 changed files with 9 additions and 4 deletions Side-by-side Diff
lib/avb/fsl/fsl_avbkey.c
... | ... | @@ -712,6 +712,7 @@ |
712 | 712 | read_keyslot_package(&kp); |
713 | 713 | if (strcmp(kp.magic, KEYPACK_MAGIC)) { |
714 | 714 | printf("keyslot package magic error. Will generate new one\n"); |
715 | + memset((void *)&kp, 0, sizeof(struct keyslot_package)); | |
715 | 716 | gen_rpmb_key(&kp); |
716 | 717 | } |
717 | 718 | #ifndef CONFIG_IMX_TRUSTY_OS |
... | ... | @@ -1229,6 +1230,7 @@ |
1229 | 1230 | printf("RPMB key programed successfully!\n"); |
1230 | 1231 | |
1231 | 1232 | /* Generate keyblob with CAAM. */ |
1233 | + memset((void *)&kp, 0, sizeof(struct keyslot_package)); | |
1232 | 1234 | kp.rpmb_keyblob_len = RPMBKEY_LENGTH + CAAM_PAD; |
1233 | 1235 | strcpy(kp.magic, KEYPACK_MAGIC); |
1234 | 1236 | if (hwcrypto_gen_blob((uint32_t)(ulong)rpmb_key, RPMBKEY_LENGTH, |
... | ... | @@ -1241,6 +1243,10 @@ |
1241 | 1243 | |
1242 | 1244 | memcpy(kp.rpmb_keyblob, blob, kp.rpmb_keyblob_len); |
1243 | 1245 | |
1246 | + /* Reset key after use */ | |
1247 | + memset(rpmb_key, 0, RPMBKEY_LENGTH); | |
1248 | + memset(key, 0, RPMBKEY_LENGTH); | |
1249 | + | |
1244 | 1250 | /* Store the rpmb key blob to last block of boot1 partition. */ |
1245 | 1251 | if (mmc_switch_part(mmc, KEYSLOT_HWPARTITION_ID) != 0) { |
1246 | 1252 | printf("ERROR - can't switch to boot1 partition! \n"); |
... | ... | @@ -1260,10 +1266,6 @@ |
1260 | 1266 | ret = -1; |
1261 | 1267 | goto fail; |
1262 | 1268 | } |
1263 | - | |
1264 | - /* Erase the key buffer. */ | |
1265 | - memset(rpmb_key, 0, RPMBKEY_LENGTH); | |
1266 | - memset(key, 0, RPMBKEY_LENGTH); | |
1267 | 1269 | |
1268 | 1270 | fail: |
1269 | 1271 | /* Return to original partition */ |
lib/avb/fsl/fsl_avbkey.h
... | ... | @@ -82,12 +82,15 @@ |
82 | 82 | |
83 | 83 | #define RPMBKEY_LEN (32 + CAAM_PAD) |
84 | 84 | #define KEYPACK_MAGIC "!KS" |
85 | +#define KEYPACK_PAD_LENGTH (512 - 4 * sizeof(char) - sizeof(unsigned int) - RPMBKEY_LEN * sizeof(unsigned char)) | |
85 | 86 | |
86 | 87 | struct keyslot_package |
87 | 88 | { |
88 | 89 | char magic[4]; |
89 | 90 | unsigned int rpmb_keyblob_len; |
90 | 91 | unsigned char rpmb_keyblob[RPMBKEY_LEN]; |
92 | + // padding keyslot_package to 1 block size | |
93 | + unsigned char pad[KEYPACK_PAD_LENGTH]; | |
91 | 94 | }; |
92 | 95 | |
93 | 96 | int gen_rpmb_key(struct keyslot_package *kp); |
-
mentioned in commit 14b721