blob: f5a4f315c9837e51ff868f5f212be502d30440ff [file] [log] [blame]
dp-armb3e85802016-12-12 14:48:13 +00001/*
Masahiro Yamadaa27c1662017-05-22 12:11:24 +09002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
dp-armb3e85802016-12-12 14:48:13 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
dp-armb3e85802016-12-12 14:48:13 +00005 */
6
7#include <assert.h>
8#include <auth/auth_mod.h>
9#include <platform.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090010#if USE_TBBR_DEFS
11#include <tbbr_oid.h>
12#else
dp-armb3e85802016-12-12 14:48:13 +000013#include <platform_oid.h>
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090014#endif
dp-armb3e85802016-12-12 14:48:13 +000015#include <string.h>
16
17/*
18 * Store a new non-volatile counter value. This implementation
19 * only allows updating of the platform's Trusted NV counter when a
20 * certificate protected by the Trusted NV counter is signed with
21 * the ROT key. This avoids a compromised secondary certificate from
22 * updating the platform's Trusted NV counter, which could lead to the
23 * platform becoming unusable. The function is suitable for all TBBR
24 * compliant platforms.
25 *
26 * Return: 0 = success, Otherwise = error
27 */
28int plat_set_nv_ctr2(void *cookie, const auth_img_desc_t *img_desc,
29 unsigned int nv_ctr)
30{
31 int trusted_nv_ctr;
32
33 assert(cookie != NULL);
34 assert(img_desc != NULL);
35
36 trusted_nv_ctr = strcmp(cookie, TRUSTED_FW_NVCOUNTER_OID) == 0;
37
38 /*
39 * Only update the Trusted NV Counter if the certificate
40 * has been signed with the ROT key. Non Trusted NV counter
41 * updates are unconditional.
42 */
dp-arm3d1b8a62017-01-31 10:54:39 +000043 if (!trusted_nv_ctr || img_desc->parent == NULL)
dp-armb3e85802016-12-12 14:48:13 +000044 return plat_set_nv_ctr(cookie, nv_ctr);
45
46 /*
47 * Trusted certificates not signed with the ROT key are not
48 * allowed to update the Trusted NV Counter.
49 */
50 return 1;
51}