1d35dee23Sdp-arm /* 2*bb41eb7aSMasahiro Yamada * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3d35dee23Sdp-arm * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5d35dee23Sdp-arm */ 6d35dee23Sdp-arm 7d35dee23Sdp-arm #include <assert.h> 8d35dee23Sdp-arm #include <auth/auth_mod.h> 9d35dee23Sdp-arm #include <platform.h> 10*bb41eb7aSMasahiro Yamada #if USE_TBBR_DEFS 11*bb41eb7aSMasahiro Yamada #include <tbbr_oid.h> 12*bb41eb7aSMasahiro Yamada #else 13d35dee23Sdp-arm #include <platform_oid.h> 14*bb41eb7aSMasahiro Yamada #endif 15d35dee23Sdp-arm #include <string.h> 16d35dee23Sdp-arm 17d35dee23Sdp-arm /* 18d35dee23Sdp-arm * Store a new non-volatile counter value. This implementation 19d35dee23Sdp-arm * only allows updating of the platform's Trusted NV counter when a 20d35dee23Sdp-arm * certificate protected by the Trusted NV counter is signed with 21d35dee23Sdp-arm * the ROT key. This avoids a compromised secondary certificate from 22d35dee23Sdp-arm * updating the platform's Trusted NV counter, which could lead to the 23d35dee23Sdp-arm * platform becoming unusable. The function is suitable for all TBBR 24d35dee23Sdp-arm * compliant platforms. 25d35dee23Sdp-arm * 26d35dee23Sdp-arm * Return: 0 = success, Otherwise = error 27d35dee23Sdp-arm */ 28d35dee23Sdp-arm int plat_set_nv_ctr2(void *cookie, const auth_img_desc_t *img_desc, 29d35dee23Sdp-arm unsigned int nv_ctr) 30d35dee23Sdp-arm { 31d35dee23Sdp-arm int trusted_nv_ctr; 32d35dee23Sdp-arm 33d35dee23Sdp-arm assert(cookie != NULL); 34d35dee23Sdp-arm assert(img_desc != NULL); 35d35dee23Sdp-arm 36d35dee23Sdp-arm trusted_nv_ctr = strcmp(cookie, TRUSTED_FW_NVCOUNTER_OID) == 0; 37d35dee23Sdp-arm 38d35dee23Sdp-arm /* 39d35dee23Sdp-arm * Only update the Trusted NV Counter if the certificate 40d35dee23Sdp-arm * has been signed with the ROT key. Non Trusted NV counter 41d35dee23Sdp-arm * updates are unconditional. 42d35dee23Sdp-arm */ 43f3ded378Sdp-arm if (!trusted_nv_ctr || img_desc->parent == NULL) 44d35dee23Sdp-arm return plat_set_nv_ctr(cookie, nv_ctr); 45d35dee23Sdp-arm 46d35dee23Sdp-arm /* 47d35dee23Sdp-arm * Trusted certificates not signed with the ROT key are not 48d35dee23Sdp-arm * allowed to update the Trusted NV Counter. 49d35dee23Sdp-arm */ 50d35dee23Sdp-arm return 1; 51d35dee23Sdp-arm } 52