1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020-2024 Microsoft Corporation. All rights reserved.
9 * ipe_digest_parse() - parse a digest in IPE's policy.
10 * @valstr: Supplies the string parsed from the policy.
12 * Digests in IPE are defined in a standard way:
15 * Use this function to create a property to parse the digest
16 * consistently. The parsed digest will be saved in @value in IPE's
19 * Return: The parsed digest_info structure on success. If an error occurs,
20 * the function will return the error value (via ERR_PTR).
22 struct digest_info
*ipe_digest_parse(const char *valstr
)
24 struct digest_info
*info
= NULL
;
25 char *sep
, *raw_digest
;
26 size_t raw_digest_len
;
31 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
33 return ERR_PTR(-ENOMEM
);
35 sep
= strchr(valstr
, ':');
41 alg
= kstrndup(valstr
, sep
- valstr
, GFP_KERNEL
);
48 raw_digest_len
= strlen(raw_digest
);
50 info
->digest_len
= (raw_digest_len
+ 1) / 2;
51 digest
= kzalloc(info
->digest_len
, GFP_KERNEL
);
57 rc
= hex2bin(digest
, raw_digest
, info
->digest_len
);
64 info
->digest
= digest
;
75 * ipe_digest_eval() - evaluate an IPE digest against another digest.
76 * @expected: Supplies the policy-provided digest value.
77 * @digest: Supplies the digest to compare against the policy digest value.
80 * * %true - digests match
81 * * %false - digests do not match
83 bool ipe_digest_eval(const struct digest_info
*expected
,
84 const struct digest_info
*digest
)
86 return (expected
->digest_len
== digest
->digest_len
) &&
87 (!strcmp(expected
->alg
, digest
->alg
)) &&
88 (!memcmp(expected
->digest
, digest
->digest
, expected
->digest_len
));
92 * ipe_digest_free() - free an IPE digest.
93 * @info: Supplies a pointer the policy-provided digest to free.
95 void ipe_digest_free(struct digest_info
*info
)
97 if (IS_ERR_OR_NULL(info
))
106 * ipe_digest_audit() - audit a digest that was sourced from IPE's policy.
107 * @ab: Supplies the audit_buffer to append the formatted result.
108 * @info: Supplies a pointer to source the audit record from.
110 * Digests in IPE are audited in this format:
113 void ipe_digest_audit(struct audit_buffer
*ab
, const struct digest_info
*info
)
115 audit_log_untrustedstring(ab
, info
->alg
);
116 audit_log_format(ab
, ":");
117 audit_log_n_hex(ab
, info
->digest
, info
->digest_len
);