comparison libtommath/bn_mp_to_sbin.c @ 1739:13d834efc376 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Thu, 15 Oct 2020 19:55:15 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1562:768ebf737aa0 1739:13d834efc376
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