xref: /openbmc/linux/arch/s390/purgatory/purgatory.c (revision 65844828)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Purgatory code running between two kernels.
4  *
5  * Copyright IBM Corp. 2018
6  *
7  * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
8  */
9 
10 #include <linux/kexec.h>
11 #include <linux/string.h>
12 #include <crypto/sha2.h>
13 #include <asm/purgatory.h>
14 
15 int verify_sha256_digest(void)
16 {
17 	struct kexec_sha_region *ptr, *end;
18 	u8 digest[SHA256_DIGEST_SIZE];
19 	struct sha256_state sctx;
20 
21 	sha256_init(&sctx);
22 	end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
23 
24 	for (ptr = purgatory_sha_regions; ptr < end; ptr++)
25 		sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
26 
27 	sha256_final(&sctx, digest);
28 
29 	if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)))
30 		return 1;
31 
32 	return 0;
33 }
34