Line data Source code
1 : #include "tommath_private.h"
2 : #ifdef BN_MP_TO_SBIN_C
3 : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 : /* SPDX-License-Identifier: Unlicense */
5 :
6 : /* store in signed [big endian] format */
7 0 : mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
8 : {
9 : mp_err err;
10 0 : if (maxlen == 0u) {
11 0 : return MP_BUF;
12 : }
13 0 : if ((err = mp_to_ubin(a, buf + 1, maxlen - 1u, written)) != MP_OKAY) {
14 0 : return err;
15 : }
16 0 : if (written != NULL) {
17 0 : (*written)++;
18 : }
19 0 : buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
20 0 : return MP_OKAY;
21 : }
22 : #endif
|