Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_to_sbin.c
blob00884c3be8289313f3f4be417fb77ec3ff74ee84
1 #include "tommath_private.h"
2 #ifdef MP_TO_SBIN_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* store in signed [big endian] format */
7 mp_err mp_to_sbin(const mp_int *a, uint8_t *buf, size_t maxlen, size_t *written)
9 mp_err err;
10 if (maxlen == 0u) {
11 return MP_BUF;
13 if ((err = mp_to_ubin(a, buf + 1, maxlen - 1u, written)) != MP_OKAY) {
14 return err;
16 if (written != NULL) {
17 (*written)++;
19 buf[0] = mp_isneg(a) ? (uint8_t)1 : (uint8_t)0;
20 return MP_OKAY;
22 #endif