21#include <mbedtls/bignum.h>
41 "BnExpmodBytes outgrew PC_WORK_BIGNUM_HW - raise it; PC_SECURE_ARENA_SIZE derives from it");
48 SecureBorrow ws_b(
sizeof(BnExpmodBytes),
alignof(BnExpmodBytes));
49 const pc_span &ws = ws_b.span();
52 memset(out, 0,
sizeof(*out));
55 BnExpmodBytes *w =
reinterpret_cast<BnExpmodBytes *
>(ws.
buf);
56 uint8_t *base_be = w->base_be;
57 uint8_t *exp_be = w->exp_be;
58 uint8_t *p_be = w->p_be;
59 uint8_t *res_be = w->res_be;
73 mbedtls_mpi_read_binary(&B, base_be, 256);
74 mbedtls_mpi_read_binary(&E, exp_be, 256);
75 mbedtls_mpi_read_binary(&P, p_be, 256);
77 mbedtls_mpi_exp_mod(&R, &B, &E, &P, NULL);
78 mbedtls_mpi_write_binary(&R, res_be, 256);
PC_CRYPTO_HOT const pc_bignum group14_p
The RFC 3526 MODP group-14 prime (2048-bit).
void bn_to_bytes(uint8_t bytes[256], const pc_bignum *in)
Write a pc_bignum as a 256-byte big-endian array.
void bn_from_bytes(pc_bignum *out, const uint8_t *bytes, size_t len)
Read a big-endian byte array of len bytes into a pc_bignum.
2048-bit big-integer arithmetic for DH-group14 and RSA-2048.
A secure borrow whose acquire and release are one call each.
Per-translation-unit optimization override for hot, pure-integer crypto.
void bn_expmod_group14(pc_bignum *out, const pc_bignum *base, const pc_bignum *exp)
#define PC_WORK_BIGNUM_HW
Worst-case bytes each module borrows from the secure pool in a single call.
Secure pool accessor - borrows that hold key material.
bool pc_span_ok(const pc_span &s)
True when the span refers to real storage and every write so far has fit.
A 2048-bit unsigned integer stored as 64 little-endian 32-bit limbs.
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
uint8_t * buf
first byte, or nullptr when the region could not be obtained