## Coverage Report

#### Created: 2025-03-01 02:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /libfido2/fuzz/prng.c

    Line
    Count
    Source
    1
    /*
    2
       A C-program for MT19937, with initialization improved 2002/1/26.
    3
       Coded by Takuji Nishimura and Makoto Matsumoto.
    4
    5
       Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
    6
       All rights reserved.
    7
    8
       Redistribution and use in source and binary forms, with or without
    9
       modification, are permitted provided that the following conditions
    10
       are met:
    11
    12
         1. Redistributions of source code must retain the above copyright
    13
            notice, this list of conditions and the following disclaimer.
    14
    15
         2. Redistributions in binary form must reproduce the above copyright
    16
            notice, this list of conditions and the following disclaimer in the
    17
            documentation and/or other materials provided with the distribution.
    18
    19
         3. The names of its contributors may not be used to endorse or promote
    20
            products derived from this software without specific prior written
    21
            permission.
    22
    23
       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    24
       "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    25
       LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    26
       A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    27
       CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    28
       EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    29
       PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    30
       PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    31
       LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    32
       NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    33
       SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    34
    35
    36
       Any feedback is very welcome.
    37
       http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
    38
       email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
    39
    */
    40
    41
    #include <assert.h>
    42
    #include <stdio.h>
    43
    #include <stdlib.h>
    44
    #include "mutator_aux.h"
    45
    46
    #define init_genrand prng_init
    47
    #define genrand_int32 prng_uint32
    48
    49
    /* Period parameters */
    50
    506M
    #define N 624
    51
    242M
    #define M 397
    52
    109M
    #define MATRIX_A 0x9908b0dfUL   /* constant vector a */
    53
    177M
    #define UPPER_MASK 0x80000000UL /* most significant w-r bits */
    54
    177M
    #define LOWER_MASK 0x7fffffffUL /* least significant r bits */
    55
    56
    int prng_up = 0;
    57
    static unsigned long mt[N]; /* the array for the state vector  */
    58
    static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
    59
    60
    /* initializes mt[N] with a seed */
    61
    void init_genrand(unsigned long s)
    62
    170k
    {
    63
    170k
        mt[0]= s & 0xffffffffUL;
    64
    106M
        for (mti=1; mti<N; mti++) {
    65
    106M
            mt[mti] =
    66
    106M
                (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) +
    67
    106M
                  (unsigned long)mti);
    68
            /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
    69
            /* In the previous versions, MSBs of the seed affect   */
    70
            /* only MSBs of the array mt[].                        */
    71
            /* 2002/01/09 modified by Makoto Matsumoto             */
    72
    106M
            mt[mti] &= 0xffffffffUL;
    73
            /* for >32 bit machines */
    74
    106M
        }
    75
    170k
        prng_up = 1;
    76
    170k
    }
    77
    78
    /* generates a random number on [0,0xffffffff]-interval */
    79
    unsigned long genrand_int32(void)
    80
    109M
    {
    81
    109M
        unsigned long y;
    82
    109M
        static unsigned long mag01[2]={0x0UL, MATRIX_A};
    83
        /* mag01[x] = x * MATRIX_A  for x=0,1 */
    84
    85
    109M
        if (mti >= N) { /* generate N words at one time */
    86
    284k
            int kk;
    87
    88
    284k
            assert(mti != N+1);
    89
    90
    64.7M
            for (kk=0;kk<N-M;kk++) {
    91
    64.5M
                y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
    92
    64.5M
                mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
    93
    64.5M
            }
    94
    112M
            for (;kk<N-1;kk++) {
    95
    112M
                y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
    96
    112M
                mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
    97
    112M
            }
    98
    284k
            y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
    99
    284k
            mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
    100
    101
    284k
            mti = 0;
    102
    284k
        }
    103
    104
    109M
        y = mt[mti++];
    105
    106
        /* Tempering */
    107
    109M
        y ^= (y >> 11);
    108
    109M
        y ^= (y << 7) & 0x9d2c5680UL;
    109
    109M
        y ^= (y << 15) & 0xefc60000UL;
    110
    109M
        y ^= (y >> 18);
    111
    112
    109M
        return y;
    113
    109M
    }