Lines Matching refs:ctx

35 static void free_q1q2_ctx(struct q1q2_ctx *ctx)  in free_q1q2_ctx()  argument
37 BN_CTX_free(ctx->bn_ctx); in free_q1q2_ctx()
38 BN_free(ctx->m); in free_q1q2_ctx()
39 BN_free(ctx->s); in free_q1q2_ctx()
40 BN_free(ctx->q1); in free_q1q2_ctx()
41 BN_free(ctx->qr); in free_q1q2_ctx()
42 BN_free(ctx->q2); in free_q1q2_ctx()
46 struct q1q2_ctx *ctx) in alloc_q1q2_ctx() argument
48 ctx->bn_ctx = BN_CTX_new(); in alloc_q1q2_ctx()
49 ctx->s = BN_bin2bn(s, SGX_MODULUS_SIZE, NULL); in alloc_q1q2_ctx()
50 ctx->m = BN_bin2bn(m, SGX_MODULUS_SIZE, NULL); in alloc_q1q2_ctx()
51 ctx->q1 = BN_new(); in alloc_q1q2_ctx()
52 ctx->qr = BN_new(); in alloc_q1q2_ctx()
53 ctx->q2 = BN_new(); in alloc_q1q2_ctx()
55 if (!ctx->bn_ctx || !ctx->s || !ctx->m || !ctx->q1 || !ctx->qr || in alloc_q1q2_ctx()
56 !ctx->q2) { in alloc_q1q2_ctx()
57 free_q1q2_ctx(ctx); in alloc_q1q2_ctx()
83 struct q1q2_ctx ctx; in calc_q1q2() local
86 if (!alloc_q1q2_ctx(s, m, &ctx)) { in calc_q1q2()
91 if (!BN_mul(ctx.q1, ctx.s, ctx.s, ctx.bn_ctx)) in calc_q1q2()
94 if (!BN_div(ctx.q1, ctx.qr, ctx.q1, ctx.m, ctx.bn_ctx)) in calc_q1q2()
97 if (BN_num_bytes(ctx.q1) > SGX_MODULUS_SIZE) { in calc_q1q2()
99 BN_num_bytes(ctx.q1)); in calc_q1q2()
103 if (!BN_mul(ctx.q2, ctx.s, ctx.qr, ctx.bn_ctx)) in calc_q1q2()
106 if (!BN_div(ctx.q2, NULL, ctx.q2, ctx.m, ctx.bn_ctx)) in calc_q1q2()
109 if (BN_num_bytes(ctx.q2) > SGX_MODULUS_SIZE) { in calc_q1q2()
111 BN_num_bytes(ctx.q2)); in calc_q1q2()
115 len = BN_bn2bin(ctx.q1, q1); in calc_q1q2()
117 len = BN_bn2bin(ctx.q2, q2); in calc_q1q2()
120 free_q1q2_ctx(&ctx); in calc_q1q2()
123 free_q1q2_ctx(&ctx); in calc_q1q2()
186 static bool mrenclave_update(EVP_MD_CTX *ctx, const void *data) in mrenclave_update() argument
188 if (!EVP_DigestUpdate(ctx, data, 64)) { in mrenclave_update()
196 static bool mrenclave_commit(EVP_MD_CTX *ctx, uint8_t *mrenclave) in mrenclave_commit() argument
200 if (!EVP_DigestFinal_ex(ctx, (unsigned char *)mrenclave, &size)) { in mrenclave_commit()
221 static bool mrenclave_ecreate(EVP_MD_CTX *ctx, uint64_t blob_size) in mrenclave_ecreate() argument
234 if (!EVP_DigestInit_ex(ctx, EVP_sha256(), NULL)) in mrenclave_ecreate()
237 return mrenclave_update(ctx, &mrecreate); in mrenclave_ecreate()
247 static bool mrenclave_eadd(EVP_MD_CTX *ctx, uint64_t offset, uint64_t flags) in mrenclave_eadd() argument
256 return mrenclave_update(ctx, &mreadd); in mrenclave_eadd()
265 static bool mrenclave_eextend(EVP_MD_CTX *ctx, uint64_t offset, in mrenclave_eextend() argument
276 if (!mrenclave_update(ctx, &mreextend)) in mrenclave_eextend()
279 if (!mrenclave_update(ctx, &data[i + 0x00])) in mrenclave_eextend()
282 if (!mrenclave_update(ctx, &data[i + 0x40])) in mrenclave_eextend()
285 if (!mrenclave_update(ctx, &data[i + 0x80])) in mrenclave_eextend()
288 if (!mrenclave_update(ctx, &data[i + 0xC0])) in mrenclave_eextend()
295 static bool mrenclave_segment(EVP_MD_CTX *ctx, struct encl *encl, in mrenclave_segment() argument
302 if (!mrenclave_eadd(ctx, seg->offset + offset, seg->flags)) in mrenclave_segment()
306 if (!mrenclave_eextend(ctx, seg->offset + offset, seg->src + offset)) in mrenclave_segment()
321 EVP_MD_CTX *ctx = NULL; in encl_measure() local
348 ctx = EVP_MD_CTX_create(); in encl_measure()
349 if (!ctx) in encl_measure()
352 if (!mrenclave_ecreate(ctx, encl->src_size)) in encl_measure()
358 if (!mrenclave_segment(ctx, encl, seg)) in encl_measure()
362 if (!mrenclave_commit(ctx, sigstruct->body.mrenclave)) in encl_measure()
382 EVP_MD_CTX_destroy(ctx); in encl_measure()
387 if (ctx) in encl_measure()
388 EVP_MD_CTX_destroy(ctx); in encl_measure()