LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_rand.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 20 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_MP_RAND_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : mp_err(*s_mp_rand_source)(void *out, size_t size) = s_mp_rand_platform;
       7             : 
       8           0 : void mp_rand_source(mp_err(*source)(void *out, size_t size))
       9             : {
      10           0 :    s_mp_rand_source = (source == NULL) ? s_mp_rand_platform : source;
      11           0 : }
      12             : 
      13           0 : mp_err mp_rand(mp_int *a, int digits)
      14             : {
      15           0 :    int i;
      16           0 :    mp_err err;
      17             : 
      18           0 :    mp_zero(a);
      19             : 
      20           0 :    if (digits <= 0) {
      21           0 :       return MP_OKAY;
      22             :    }
      23             : 
      24           0 :    if ((err = mp_grow(a, digits)) != MP_OKAY) {
      25           0 :       return err;
      26             :    }
      27             : 
      28           0 :    if ((err = s_mp_rand_source(a->dp, (size_t)digits * sizeof(mp_digit))) != MP_OKAY) {
      29           0 :       return err;
      30             :    }
      31             : 
      32             :    /* TODO: We ensure that the highest digit is nonzero. Should this be removed? */
      33           0 :    while ((a->dp[digits - 1] & MP_MASK) == 0u) {
      34           0 :       if ((err = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) {
      35           0 :          return err;
      36             :       }
      37             :    }
      38             : 
      39           0 :    a->used = digits;
      40           0 :    for (i = 0; i < digits; ++i) {
      41           0 :       a->dp[i] &= MP_MASK;
      42             :    }
      43             : 
      44           0 :    return MP_OKAY;
      45             : }
      46             : #endif

Generated by: LCOV version 1.14