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