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

          Line data    Source code
       1             : #include "tommath_private.h"
       2             : #ifdef BN_S_MP_RAND_JENKINS_C
       3             : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
       4             : /* SPDX-License-Identifier: Unlicense */
       5             : 
       6             : /* Bob Jenkins' http://burtleburtle.net/bob/rand/smallprng.html */
       7             : /* Chosen for speed and a good "mix" */
       8             : typedef struct {
       9             :    uint64_t a;
      10             :    uint64_t b;
      11             :    uint64_t c;
      12             :    uint64_t d;
      13             : } ranctx;
      14             : 
      15             : static ranctx jenkins_x;
      16             : 
      17             : #define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
      18           0 : static uint64_t s_rand_jenkins_val(void)
      19             : {
      20           0 :    uint64_t e = jenkins_x.a - rot(jenkins_x.b, 7);
      21           0 :    jenkins_x.a = jenkins_x.b ^ rot(jenkins_x.c, 13);
      22           0 :    jenkins_x.b = jenkins_x.c + rot(jenkins_x.d, 37);
      23           0 :    jenkins_x.c = jenkins_x.d + e;
      24           0 :    jenkins_x.d = e + jenkins_x.a;
      25           0 :    return jenkins_x.d;
      26             : }
      27             : 
      28           0 : void s_mp_rand_jenkins_init(uint64_t seed)
      29             : {
      30           0 :    uint64_t i;
      31           0 :    jenkins_x.a = 0xf1ea5eedULL;
      32           0 :    jenkins_x.b = jenkins_x.c = jenkins_x.d = seed;
      33           0 :    for (i = 0uLL; i < 20uLL; ++i) {
      34           0 :       (void)s_rand_jenkins_val();
      35             :    }
      36           0 : }
      37             : 
      38           0 : mp_err s_mp_rand_jenkins(void *p, size_t n)
      39             : {
      40           0 :    char *q = (char *)p;
      41           0 :    while (n > 0u) {
      42           0 :       int i;
      43           0 :       uint64_t x = s_rand_jenkins_val();
      44           0 :       for (i = 0; (i < 8) && (n > 0u); ++i, --n) {
      45           0 :          *q++ = (char)(x & 0xFFuLL);
      46           0 :          x >>= 8;
      47             :       }
      48             :    }
      49           0 :    return MP_OKAY;
      50             : }
      51             : 
      52             : #endif

Generated by: LCOV version 1.14