Coverage Report

Created: 2025-03-18 06:55

/src/gnutls/lib/nettle/gost/bignum-le.c
Line
Count
Source (jump to first uncovered line)
1
/* bignum.c
2
3
   Bignum operations that are missing from gmp.
4
5
   Copyright (C) 2001 Niels Möller
6
7
   This file is part of GNU Nettle.
8
9
   GNU Nettle is free software: you can redistribute it and/or
10
   modify it under the terms of either:
11
12
     * the GNU Lesser General Public License as published by the Free
13
       Software Foundation; either version 3 of the License, or (at your
14
       option) any later version.
15
16
   or
17
18
     * the GNU General Public License as published by the Free
19
       Software Foundation; either version 2 of the License, or (at your
20
       option) any later version.
21
22
   or both in parallel, as here.
23
24
   GNU Nettle is distributed in the hope that it will be useful,
25
   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27
   General Public License for more details.
28
29
   You should have received copies of the GNU General Public License and
30
   the GNU Lesser General Public License along with this program.  If
31
   not, see https://www.gnu.org/licenses/.
32
*/
33
34
#if HAVE_CONFIG_H
35
#include "config.h"
36
#endif
37
38
#include "gnutls_int.h"
39
40
#include <string.h>
41
42
#include <nettle/bignum.h>
43
#include "bignum-le.h"
44
45
void nettle_mpz_get_str_256_u_le(size_t length, uint8_t *s, const mpz_t x)
46
0
{
47
0
  if (!length) {
48
    /* x must be zero */
49
0
    assert(!mpz_sgn(x));
50
0
    return;
51
0
  }
52
53
0
  size_t count;
54
55
0
  assert(nettle_mpz_sizeinbase_256_u(x) <= length);
56
0
  mpz_export(s, &count, -1, 1, 0, 0, x);
57
0
  memset(s + count, 0, length - count);
58
0
}
59
60
#define nettle_mpz_from_octets_le(x, length, s) \
61
0
  mpz_import((x), (length), -1, 1, 0, 0, (s))
62
63
void nettle_mpz_set_str_256_u_le(mpz_t x, size_t length, const uint8_t *s)
64
0
{
65
0
  nettle_mpz_from_octets_le(x, length, s);
66
0
}
67
68
void nettle_mpz_init_set_str_256_u_le(mpz_t x, size_t length, const uint8_t *s)
69
0
{
70
0
  mpz_init(x);
71
0
  nettle_mpz_from_octets_le(x, length, s);
72
0
}