comparison libtommath/bn_mp_to_sbin.c @ 1692:1051e4eea25a

Update LibTomMath to 1.2.0 (#84) * update C files * update other files * update headers * update makefiles * remove mp_set/get_double() * use ltm 1.2.0 API * update ltm_desc * use bundled tommath if system-tommath is too old * XMALLOC etc. were changed to MP_MALLOC etc.
author Steffen Jaeckel <s@jaeckel.eu>
date Tue, 26 May 2020 17:36:47 +0200
parents
children
comparison
equal deleted inserted replaced
1691:2d3745d58843 1692:1051e4eea25a
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 mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
8 {
9 mp_err err;
10 if (maxlen == 0u) {
11 return MP_BUF;
12 }
13 if ((err = mp_to_ubin(a, buf + 1, maxlen - 1u, written)) != MP_OKAY) {
14 return err;
15 }
16 if (written != NULL) {
17 (*written)++;
18 }
19 buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
20 return MP_OKAY;
21 }
22 #endif