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