comparison libtommath/bn_mp_from_sbin.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents 1051e4eea25a
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
1 #include "tommath_private.h"
2 #ifdef BN_MP_FROM_SBIN_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
5
6 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
7 mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
8 {
9 mp_err err;
10
11 /* read magnitude */
12 if ((err = mp_from_ubin(a, buf + 1, size - 1u)) != MP_OKAY) {
13 return err;
14 }
15
16 /* first byte is 0 for positive, non-zero for negative */
17 if (buf[0] == (unsigned char)0) {
18 a->sign = MP_ZPOS;
19 } else {
20 a->sign = MP_NEG;
21 }
22
23 return MP_OKAY;
24 }
25 #endif