LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_to_ubin.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 14 18 77.8 %
Date: 2024-04-13 12:30:31 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_TO_UBIN_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* store in unsigned [big endian] format */
       7         623 : mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
       8             : {
       9          16 :    size_t  x, count;
      10          16 :    mp_err  err;
      11          16 :    mp_int  t;
      12             : 
      13         623 :    count = mp_ubin_size(a);
      14         623 :    if (count > maxlen) {
      15           0 :       return MP_BUF;
      16             :    }
      17             : 
      18         623 :    if ((err = mp_init_copy(&t, a)) != MP_OKAY) {
      19           0 :       return err;
      20             :    }
      21             : 
      22      289487 :    for (x = count; x --> 0u;) {
      23             : #ifndef MP_8BIT
      24      288864 :       buf[x] = (unsigned char)(t.dp[0] & 255u);
      25             : #else
      26             :       buf[x] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
      27             : #endif
      28      288864 :       if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
      29           0 :          goto LBL_ERR;
      30             :       }
      31             :    }
      32             : 
      33         623 :    if (written != NULL) {
      34           0 :       *written = count;
      35             :    }
      36             : 
      37         623 : LBL_ERR:
      38         623 :    mp_clear(&t);
      39         623 :    return err;
      40             : }
      41             : #endif

Generated by: LCOV version 1.14