s4:torture: Adapt KDC canon test to Heimdal upstream changes
[samba.git] / source4 / heimdal / lib / hcrypto / libtommath / bn_mp_to_sbin.c
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