Lines Matching refs:ctx

27 			       struct pefile_context *ctx)  in pefile_parse_binary()  argument
64 ctx->image_checksum_offset = in pefile_parse_binary()
66 ctx->header_size = pe32->header_size; in pefile_parse_binary()
68 ctx->n_data_dirents = pe32->data_dirs; in pefile_parse_binary()
73 ctx->image_checksum_offset = in pefile_parse_binary()
75 ctx->header_size = pe64->header_size; in pefile_parse_binary()
77 ctx->n_data_dirents = pe64->data_dirs; in pefile_parse_binary()
85 pr_debug("checksum @ %x\n", ctx->image_checksum_offset); in pefile_parse_binary()
86 pr_debug("header size = %x\n", ctx->header_size); in pefile_parse_binary()
88 if (cursor >= ctx->header_size || ctx->header_size >= datalen) in pefile_parse_binary()
91 if (ctx->n_data_dirents > (ctx->header_size - cursor) / sizeof(*dde)) in pefile_parse_binary()
95 cursor += sizeof(*dde) * ctx->n_data_dirents; in pefile_parse_binary()
97 ctx->cert_dirent_offset = in pefile_parse_binary()
99 ctx->certs_size = ddir->certs.size; in pefile_parse_binary()
106 chkaddr(ctx->header_size, ddir->certs.virtual_address, in pefile_parse_binary()
108 ctx->sig_offset = ddir->certs.virtual_address; in pefile_parse_binary()
109 ctx->sig_len = ddir->certs.size; in pefile_parse_binary()
111 ctx->sig_len, ctx->sig_offset, in pefile_parse_binary()
112 ctx->sig_len, pebuf + ctx->sig_offset); in pefile_parse_binary()
114 ctx->n_sections = pe->sections; in pefile_parse_binary()
115 if (ctx->n_sections > (ctx->header_size - cursor) / sizeof(*sec)) in pefile_parse_binary()
117 ctx->secs = secs = pebuf + cursor; in pefile_parse_binary()
127 struct pefile_context *ctx) in pefile_strip_sig_wrapper() argument
133 if (ctx->sig_len < sizeof(wrapper)) { in pefile_strip_sig_wrapper()
138 memcpy(&wrapper, pebuf + ctx->sig_offset, sizeof(wrapper)); in pefile_strip_sig_wrapper()
145 if (round_up(wrapper.length, 8) != ctx->sig_len) { in pefile_strip_sig_wrapper()
163 ctx->sig_len = wrapper.length; in pefile_strip_sig_wrapper()
164 ctx->sig_offset += sizeof(wrapper); in pefile_strip_sig_wrapper()
165 ctx->sig_len -= sizeof(wrapper); in pefile_strip_sig_wrapper()
166 if (ctx->sig_len < 4) { in pefile_strip_sig_wrapper()
172 pkcs7 = pebuf + ctx->sig_offset; in pefile_strip_sig_wrapper()
195 if (len <= ctx->sig_len) { in pefile_strip_sig_wrapper()
197 ctx->sig_len = len; in pefile_strip_sig_wrapper()
246 struct pefile_context *ctx, in pefile_digest_pe_contents() argument
255 ret = crypto_shash_update(desc, pebuf, ctx->image_checksum_offset); in pefile_digest_pe_contents()
259 tmp = ctx->image_checksum_offset + sizeof(uint32_t); in pefile_digest_pe_contents()
261 ctx->cert_dirent_offset - tmp); in pefile_digest_pe_contents()
265 tmp = ctx->cert_dirent_offset + sizeof(struct data_dirent); in pefile_digest_pe_contents()
266 ret = crypto_shash_update(desc, pebuf + tmp, ctx->header_size - tmp); in pefile_digest_pe_contents()
270 canon = kcalloc(ctx->n_sections, sizeof(unsigned), GFP_KERNEL); in pefile_digest_pe_contents()
278 for (loop = 1; loop < ctx->n_sections; loop++) { in pefile_digest_pe_contents()
280 if (pefile_compare_shdrs(&ctx->secs[canon[i]], in pefile_digest_pe_contents()
281 &ctx->secs[loop]) > 0) { in pefile_digest_pe_contents()
290 hashed_bytes = ctx->header_size; in pefile_digest_pe_contents()
291 for (loop = 0; loop < ctx->n_sections; loop++) { in pefile_digest_pe_contents()
293 if (ctx->secs[i].raw_data_size == 0) in pefile_digest_pe_contents()
296 pebuf + ctx->secs[i].data_addr, in pefile_digest_pe_contents()
297 ctx->secs[i].raw_data_size); in pefile_digest_pe_contents()
302 hashed_bytes += ctx->secs[i].raw_data_size; in pefile_digest_pe_contents()
307 tmp = hashed_bytes + ctx->certs_size; in pefile_digest_pe_contents()
323 struct pefile_context *ctx) in pefile_digest_pe() argument
331 kenter(",%u", ctx->digest_algo); in pefile_digest_pe()
336 tfm = crypto_alloc_shash(hash_algo_name[ctx->digest_algo], 0, 0); in pefile_digest_pe()
343 if (digest_size != ctx->digest_len) { in pefile_digest_pe()
345 digest_size, ctx->digest_len); in pefile_digest_pe()
362 ret = pefile_digest_pe_contents(pebuf, pelen, ctx, desc); in pefile_digest_pe()
371 pr_debug("Digest calc = [%*ph]\n", ctx->digest_len, digest); in pefile_digest_pe()
376 if (memcmp(digest, ctx->digest, ctx->digest_len) != 0) { in pefile_digest_pe()
426 struct pefile_context ctx; in verify_pefile_signature() local
433 memset(&ctx, 0, sizeof(ctx)); in verify_pefile_signature()
434 ret = pefile_parse_binary(pebuf, pelen, &ctx); in verify_pefile_signature()
438 ret = pefile_strip_sig_wrapper(pebuf, &ctx); in verify_pefile_signature()
442 pkcs7 = pkcs7_parse_message(pebuf + ctx.sig_offset, ctx.sig_len); in verify_pefile_signature()
445 ctx.pkcs7 = pkcs7; in verify_pefile_signature()
447 ret = pkcs7_get_content_data(ctx.pkcs7, &data, &datalen, false); in verify_pefile_signature()
454 ret = mscode_parse(&ctx); in verify_pefile_signature()
459 ctx.digest_len, ctx.digest_len, ctx.digest); in verify_pefile_signature()
464 ret = pefile_digest_pe(pebuf, pelen, &ctx); in verify_pefile_signature()
475 pkcs7_free_message(ctx.pkcs7); in verify_pefile_signature()