Lines Matching refs:ctx

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