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