1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* store in unsigned [big endian] format */
7 mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
13 count = mp_ubin_size(a);
18 if ((err = mp_init_copy(&t, a)) != MP_OKAY) {
22 for (x = count; x --> 0u;) {
24 buf[x] = (unsigned char)(t.dp[0] & 255u);
26 buf[x] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
28 if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
33 if (written != NULL) {