tools/testing/selftests/sgx/sigstruct.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sgx/sigstruct.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sgx/sigstruct.c- Extension
.c- Size
- 8048 bytes
- Lines
- 392
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
assert.hgetopt.hstdbool.hstdint.hstdio.hstdlib.hstring.hsys/stat.hsys/types.hunistd.hopenssl/err.hopenssl/pem.hdefines.hmain.h
Detected Declarations
struct q1q2_ctxstruct sgx_sigstruct_payloadstruct mrecreatestruct mreaddstruct mreextendenum mrtagsfunction free_q1q2_ctxfunction alloc_q1q2_ctxfunction reverse_bytesfunction calc_q1q2function check_crypto_errorsfunction mrenclave_updatefunction mrenclave_commitfunction mrenclave_ecreatefunction mrenclave_eaddfunction mrenclave_eextendfunction mrenclave_segmentfunction encl_measure
Annotated Snippet
struct q1q2_ctx {
BN_CTX *bn_ctx;
BIGNUM *m;
BIGNUM *s;
BIGNUM *q1;
BIGNUM *qr;
BIGNUM *q2;
};
static void free_q1q2_ctx(struct q1q2_ctx *ctx)
{
BN_CTX_free(ctx->bn_ctx);
BN_free(ctx->m);
BN_free(ctx->s);
BN_free(ctx->q1);
BN_free(ctx->qr);
BN_free(ctx->q2);
}
static bool alloc_q1q2_ctx(const uint8_t *s, const uint8_t *m,
struct q1q2_ctx *ctx)
{
ctx->bn_ctx = BN_CTX_new();
ctx->s = BN_bin2bn(s, SGX_MODULUS_SIZE, NULL);
ctx->m = BN_bin2bn(m, SGX_MODULUS_SIZE, NULL);
ctx->q1 = BN_new();
ctx->qr = BN_new();
ctx->q2 = BN_new();
if (!ctx->bn_ctx || !ctx->s || !ctx->m || !ctx->q1 || !ctx->qr ||
!ctx->q2) {
free_q1q2_ctx(ctx);
return false;
}
return true;
}
static void reverse_bytes(void *data, int length)
{
int i = 0;
int j = length - 1;
uint8_t temp;
uint8_t *ptr = data;
while (i < j) {
temp = ptr[i];
ptr[i] = ptr[j];
ptr[j] = temp;
i++;
j--;
}
}
static bool calc_q1q2(const uint8_t *s, const uint8_t *m, uint8_t *q1,
uint8_t *q2)
{
struct q1q2_ctx ctx;
int len;
if (!alloc_q1q2_ctx(s, m, &ctx)) {
fprintf(stderr, "Not enough memory for Q1Q2 calculation\n");
return false;
}
if (!BN_mul(ctx.q1, ctx.s, ctx.s, ctx.bn_ctx))
goto out;
if (!BN_div(ctx.q1, ctx.qr, ctx.q1, ctx.m, ctx.bn_ctx))
goto out;
if (BN_num_bytes(ctx.q1) > SGX_MODULUS_SIZE) {
fprintf(stderr, "Too large Q1 %d bytes\n",
BN_num_bytes(ctx.q1));
goto out;
}
if (!BN_mul(ctx.q2, ctx.s, ctx.qr, ctx.bn_ctx))
goto out;
if (!BN_div(ctx.q2, NULL, ctx.q2, ctx.m, ctx.bn_ctx))
goto out;
if (BN_num_bytes(ctx.q2) > SGX_MODULUS_SIZE) {
fprintf(stderr, "Too large Q2 %d bytes\n",
BN_num_bytes(ctx.q2));
goto out;
}
len = BN_bn2bin(ctx.q1, q1);
Annotation
- Immediate include surface: `assert.h`, `getopt.h`, `stdbool.h`, `stdint.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/stat.h`.
- Detected declarations: `struct q1q2_ctx`, `struct sgx_sigstruct_payload`, `struct mrecreate`, `struct mreadd`, `struct mreextend`, `enum mrtags`, `function free_q1q2_ctx`, `function alloc_q1q2_ctx`, `function reverse_bytes`, `function calc_q1q2`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.