LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib/nettle/gost - bignum-le.c (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 9 15 60.0 %
Date: 2020-10-30 04:50:48 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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
      46         941 : nettle_mpz_get_str_256_u_le(size_t length, uint8_t *s, const mpz_t x)
      47             : {
      48         941 :   if (!length)
      49             :     {
      50             :       /* x must be zero */
      51           0 :       assert(!mpz_sgn(x));
      52           0 :       return;
      53             :     }
      54             : 
      55         941 :   size_t count;
      56             : 
      57         941 :   assert(nettle_mpz_sizeinbase_256_u(x) <= length);
      58         941 :   mpz_export(s, &count, -1, 1, 0, 0, x);
      59         941 :   memset(s + count, 0, length - count);
      60             : }
      61             : 
      62             : #define nettle_mpz_from_octets_le(x, length, s) \
      63             :    mpz_import((x), (length), -1, 1, 0, 0, (s))
      64             : 
      65             : void
      66        1076 : nettle_mpz_set_str_256_u_le(mpz_t x,
      67             :                             size_t length, const uint8_t *s)
      68             : {
      69        1076 :   nettle_mpz_from_octets_le(x, length, s);
      70        1076 : }
      71             : 
      72             : void
      73           0 : nettle_mpz_init_set_str_256_u_le(mpz_t x,
      74             :                                  size_t length, const uint8_t *s)
      75             : {
      76           0 :   mpz_init(x);
      77           0 :   nettle_mpz_from_octets_le(x, length, s);
      78           0 : }

Generated by: LCOV version 1.14