#define EFI_CERT_X509_SHA256_GUID \
EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, \
0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
+#define EFI_CERT_X509_SHA384_GUID \
+ EFI_GUID(0x7076876e, 0x80c2, 0x4ee6, \
+ 0xaa, 0xd2, 0x28, 0xb3, 0x49, 0xa6, 0x86, 0x5b)
+#define EFI_CERT_X509_SHA512_GUID \
+ EFI_GUID(0x446dbf63, 0x2502, 0x4cda, \
+ 0xbc, 0xfa, 0x24, 0x65, 0xd2, 0xb0, 0xfe, 0x9d)
#define EFI_CERT_TYPE_PKCS7_GUID \
EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
const efi_guid_t efi_guid_cert_rsa2048 = EFI_CERT_RSA2048_GUID;
const efi_guid_t efi_guid_cert_x509 = EFI_CERT_X509_GUID;
const efi_guid_t efi_guid_cert_x509_sha256 = EFI_CERT_X509_SHA256_GUID;
+const efi_guid_t efi_guid_cert_x509_sha384 = EFI_CERT_X509_SHA384_GUID;
+const efi_guid_t efi_guid_cert_x509_sha512 = EFI_CERT_X509_SHA512_GUID;
const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
static u8 pkcs7_hdr[] = {
* Return: true on success, false on error
*/
static bool efi_hash_regions(struct image_region *regs, int count,
- void **hash, size_t *size)
+ void **hash, const char *hash_algo, int *len)
{
+ int ret, hash_len;
+
+ if (!hash_algo)
+ return false;
+
+ hash_len = algo_to_len(hash_algo);
+ if (!hash_len)
+ return false;
+
if (!*hash) {
- *hash = calloc(1, SHA256_SUM_LEN);
+ *hash = calloc(1, hash_len);
if (!*hash) {
EFI_PRINT("Out of memory\n");
return false;
}
}
- if (size)
- *size = SHA256_SUM_LEN;
- hash_calculate("sha256", regs, count, *hash);
+ ret = hash_calculate(hash_algo, regs, count, *hash);
+ if (ret)
+ return false;
+
+ if (len)
+ *len = hash_len;
#ifdef DEBUG
EFI_PRINT("hash calculated:\n");
print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
- *hash, SHA256_SUM_LEN, false);
+ *hash, hash_len, false);
#endif
return true;
struct efi_signature_store *siglist;
struct efi_sig_data *sig_data;
void *hash = NULL;
- size_t size = 0;
bool found = false;
bool hash_done = false;
goto out;
for (siglist = db; siglist; siglist = siglist->next) {
+ int len = 0;
+ const char *hash_algo = NULL;
/*
* if the hash algorithm is unsupported and we get an entry in
* dbx reject the image
if (guidcmp(&siglist->sig_type, &efi_guid_sha256))
continue;
+ hash_algo = guid_to_sha_str(&efi_guid_sha256);
+ /*
+ * We could check size and hash_algo but efi_hash_regions()
+ * will do that for us
+ */
if (!hash_done &&
- !efi_hash_regions(regs->reg, regs->num, &hash, &size)) {
+ !efi_hash_regions(regs->reg, regs->num, &hash, hash_algo,
+ &len)) {
EFI_PRINT("Digesting an image failed\n");
break;
}
print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
sig_data->data, sig_data->size, false);
#endif
- if (sig_data->size == size &&
- !memcmp(sig_data->data, hash, size)) {
+ if (sig_data->size == len &&
+ !memcmp(sig_data->data, hash, len)) {
found = true;
free(hash);
goto out;
struct efi_sig_data *sig_data;
struct image_region reg[1];
void *hash = NULL, *hash_tmp = NULL;
- size_t size = 0;
+ int len = 0;
bool found = false;
+ const char *hash_algo = NULL;
EFI_PRINT("%s: Enter, %p, %p\n", __func__, cert, db);
/* calculate hash of TBSCertificate */
reg[0].data = cert->tbs;
reg[0].size = cert->tbs_size;
- if (!efi_hash_regions(reg, 1, &hash, &size))
+
+ /* We just need any sha256 algo to start the matching */
+ hash_algo = guid_to_sha_str(&efi_guid_sha256);
+ if (!efi_hash_regions(reg, 1, &hash, hash_algo, &len))
goto out;
EFI_PRINT("%s: searching for %s\n", __func__, cert->subject);
cert_tmp->subject);
reg[0].data = cert_tmp->tbs;
reg[0].size = cert_tmp->tbs_size;
- if (!efi_hash_regions(reg, 1, &hash_tmp, NULL))
+ if (!efi_hash_regions(reg, 1, &hash_tmp, hash_algo,
+ NULL))
goto out;
x509_free_certificate(cert_tmp);
- if (!memcmp(hash, hash_tmp, size)) {
+ if (!memcmp(hash, hash_tmp, len)) {
found = true;
goto out;
}
struct efi_sig_data *sig_data;
struct image_region reg[1];
void *hash = NULL;
- size_t size = 0;
+ int len = 0;
time64_t revoc_time;
bool revoked = false;
+ const char *hash_algo = NULL;
EFI_PRINT("%s: Enter, %p, %p, %p\n", __func__, sinfo, cert, dbx);
EFI_PRINT("Checking revocation against %s\n", cert->subject);
for (siglist = dbx; siglist; siglist = siglist->next) {
- if (guidcmp(&siglist->sig_type, &efi_guid_cert_x509_sha256))
+ hash_algo = guid_to_sha_str(&siglist->sig_type);
+ if (!hash_algo)
continue;
/* calculate hash of TBSCertificate */
reg[0].data = cert->tbs;
reg[0].size = cert->tbs_size;
- if (!efi_hash_regions(reg, 1, &hash, &size))
+ if (!efi_hash_regions(reg, 1, &hash, hash_algo, &len))
goto out;
for (sig_data = siglist->sig_data_list; sig_data;
* };
*/
#ifdef DEBUG
- if (sig_data->size >= size) {
+ if (sig_data->size >= len) {
EFI_PRINT("hash in db:\n");
print_hex_dump(" ", DUMP_PREFIX_OFFSET,
16, 1,
- sig_data->data, size, false);
+ sig_data->data, len, false);
}
#endif
- if ((sig_data->size < size + sizeof(time64_t)) ||
- memcmp(sig_data->data, hash, size))
+ if ((sig_data->size < len + sizeof(time64_t)) ||
+ memcmp(sig_data->data, hash, len))
continue;
- memcpy(&revoc_time, sig_data->data + size,
+ memcpy(&revoc_time, sig_data->data + len,
sizeof(revoc_time));
EFI_PRINT("revocation time: 0x%llx\n", revoc_time);
/*
*/
if (!msg->data &&
!efi_hash_regions(regs->reg, regs->num,
- (void **)&sinfo->sig->digest, NULL)) {
+ (void **)&sinfo->sig->digest,
+ guid_to_sha_str(&efi_guid_sha256),
+ NULL)) {
EFI_PRINT("Digesting an image failed\n");
goto out;
}