Coverage Report

Created: 2024-11-21 07:03

/src/nss-nspr/nss/lib/freebl/rawhash.c
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifdef FREEBL_NO_DEPEND
6
#include "stubs.h"
7
#endif
8
9
#include "nspr.h"
10
#include "hasht.h"
11
#include "blapi.h" /* below the line */
12
#include "secerr.h"
13
14
#define RawHashBase(ctxtype, mmm)                                                        \
15
    static void *                                                                        \
16
        RawHash_##mmm##_NewContext(void)                                                 \
17
371
    {                                                                                    \
18
371
        ctxtype *ctx = mmm##_NewContext();                                               \
19
371
        return ctx;                                                                      \
20
371
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_MD2_NewContext
rawhash.c:RawHash_MD5_NewContext
Line
Count
Source
17
21
    {                                                                                    \
18
21
        ctxtype *ctx = mmm##_NewContext();                                               \
19
21
        return ctx;                                                                      \
20
21
    }                                                                                    \
rawhash.c:RawHash_SHA1_NewContext
Line
Count
Source
17
127
    {                                                                                    \
18
127
        ctxtype *ctx = mmm##_NewContext();                                               \
19
127
        return ctx;                                                                      \
20
127
    }                                                                                    \
rawhash.c:RawHash_SHA256_NewContext
Line
Count
Source
17
52
    {                                                                                    \
18
52
        ctxtype *ctx = mmm##_NewContext();                                               \
19
52
        return ctx;                                                                      \
20
52
    }                                                                                    \
rawhash.c:RawHash_SHA384_NewContext
Line
Count
Source
17
45
    {                                                                                    \
18
45
        ctxtype *ctx = mmm##_NewContext();                                               \
19
45
        return ctx;                                                                      \
20
45
    }                                                                                    \
rawhash.c:RawHash_SHA512_NewContext
Line
Count
Source
17
67
    {                                                                                    \
18
67
        ctxtype *ctx = mmm##_NewContext();                                               \
19
67
        return ctx;                                                                      \
20
67
    }                                                                                    \
rawhash.c:RawHash_SHA224_NewContext
Line
Count
Source
17
59
    {                                                                                    \
18
59
        ctxtype *ctx = mmm##_NewContext();                                               \
19
59
        return ctx;                                                                      \
20
59
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_SHA3_224_NewContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_256_NewContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_384_NewContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_512_NewContext
21
    static void                                                                          \
22
        RawHash_##mmm##_Begin(void *vctx)                                                \
23
13.9k
    {                                                                                    \
24
13.9k
        ctxtype *ctx = vctx;                                                             \
25
13.9k
        mmm##_Begin(ctx);                                                                \
26
13.9k
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_MD2_Begin
rawhash.c:RawHash_MD5_Begin
Line
Count
Source
23
956
    {                                                                                    \
24
956
        ctxtype *ctx = vctx;                                                             \
25
956
        mmm##_Begin(ctx);                                                                \
26
956
    }                                                                                    \
rawhash.c:RawHash_SHA1_Begin
Line
Count
Source
23
5.14k
    {                                                                                    \
24
5.14k
        ctxtype *ctx = vctx;                                                             \
25
5.14k
        mmm##_Begin(ctx);                                                                \
26
5.14k
    }                                                                                    \
rawhash.c:RawHash_SHA256_Begin
Line
Count
Source
23
1.96k
    {                                                                                    \
24
1.96k
        ctxtype *ctx = vctx;                                                             \
25
1.96k
        mmm##_Begin(ctx);                                                                \
26
1.96k
    }                                                                                    \
rawhash.c:RawHash_SHA384_Begin
Line
Count
Source
23
3.12k
    {                                                                                    \
24
3.12k
        ctxtype *ctx = vctx;                                                             \
25
3.12k
        mmm##_Begin(ctx);                                                                \
26
3.12k
    }                                                                                    \
rawhash.c:RawHash_SHA512_Begin
Line
Count
Source
23
2.49k
    {                                                                                    \
24
2.49k
        ctxtype *ctx = vctx;                                                             \
25
2.49k
        mmm##_Begin(ctx);                                                                \
26
2.49k
    }                                                                                    \
rawhash.c:RawHash_SHA224_Begin
Line
Count
Source
23
316
    {                                                                                    \
24
316
        ctxtype *ctx = vctx;                                                             \
25
316
        mmm##_Begin(ctx);                                                                \
26
316
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_SHA3_224_Begin
Unexecuted instantiation: rawhash.c:RawHash_SHA3_256_Begin
Unexecuted instantiation: rawhash.c:RawHash_SHA3_384_Begin
Unexecuted instantiation: rawhash.c:RawHash_SHA3_512_Begin
27
    static void                                                                          \
28
        RawHash_##mmm##_Update(void *vctx, const unsigned char *input, unsigned int len) \
29
39.6k
    {                                                                                    \
30
39.6k
        ctxtype *ctx = vctx;                                                             \
31
39.6k
        mmm##_Update(ctx, input, len);                                                   \
32
39.6k
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_MD2_Update
rawhash.c:RawHash_MD5_Update
Line
Count
Source
29
2.21k
    {                                                                                    \
30
2.21k
        ctxtype *ctx = vctx;                                                             \
31
2.21k
        mmm##_Update(ctx, input, len);                                                   \
32
2.21k
    }                                                                                    \
rawhash.c:RawHash_SHA1_Update
Line
Count
Source
29
14.3k
    {                                                                                    \
30
14.3k
        ctxtype *ctx = vctx;                                                             \
31
14.3k
        mmm##_Update(ctx, input, len);                                                   \
32
14.3k
    }                                                                                    \
rawhash.c:RawHash_SHA256_Update
Line
Count
Source
29
5.77k
    {                                                                                    \
30
5.77k
        ctxtype *ctx = vctx;                                                             \
31
5.77k
        mmm##_Update(ctx, input, len);                                                   \
32
5.77k
    }                                                                                    \
rawhash.c:RawHash_SHA384_Update
Line
Count
Source
29
9.25k
    {                                                                                    \
30
9.25k
        ctxtype *ctx = vctx;                                                             \
31
9.25k
        mmm##_Update(ctx, input, len);                                                   \
32
9.25k
    }                                                                                    \
rawhash.c:RawHash_SHA512_Update
Line
Count
Source
29
7.33k
    {                                                                                    \
30
7.33k
        ctxtype *ctx = vctx;                                                             \
31
7.33k
        mmm##_Update(ctx, input, len);                                                   \
32
7.33k
    }                                                                                    \
rawhash.c:RawHash_SHA224_Update
Line
Count
Source
29
639
    {                                                                                    \
30
639
        ctxtype *ctx = vctx;                                                             \
31
639
        mmm##_Update(ctx, input, len);                                                   \
32
639
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_SHA3_224_Update
Unexecuted instantiation: rawhash.c:RawHash_SHA3_256_Update
Unexecuted instantiation: rawhash.c:RawHash_SHA3_384_Update
Unexecuted instantiation: rawhash.c:RawHash_SHA3_512_Update
33
    static void                                                                          \
34
        RawHash_##mmm##_End(void *vctx, unsigned char *digest,                           \
35
                            unsigned int *len, unsigned int maxLen)                      \
36
13.9k
    {                                                                                    \
37
13.9k
        ctxtype *ctx = vctx;                                                             \
38
13.9k
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
13.9k
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_MD2_End
rawhash.c:RawHash_MD5_End
Line
Count
Source
36
956
    {                                                                                    \
37
956
        ctxtype *ctx = vctx;                                                             \
38
956
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
956
    }                                                                                    \
rawhash.c:RawHash_SHA1_End
Line
Count
Source
36
5.14k
    {                                                                                    \
37
5.14k
        ctxtype *ctx = vctx;                                                             \
38
5.14k
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
5.14k
    }                                                                                    \
rawhash.c:RawHash_SHA256_End
Line
Count
Source
36
1.96k
    {                                                                                    \
37
1.96k
        ctxtype *ctx = vctx;                                                             \
38
1.96k
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
1.96k
    }                                                                                    \
rawhash.c:RawHash_SHA384_End
Line
Count
Source
36
3.12k
    {                                                                                    \
37
3.12k
        ctxtype *ctx = vctx;                                                             \
38
3.12k
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
3.12k
    }                                                                                    \
rawhash.c:RawHash_SHA512_End
Line
Count
Source
36
2.49k
    {                                                                                    \
37
2.49k
        ctxtype *ctx = vctx;                                                             \
38
2.49k
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
2.49k
    }                                                                                    \
rawhash.c:RawHash_SHA224_End
Line
Count
Source
36
316
    {                                                                                    \
37
316
        ctxtype *ctx = vctx;                                                             \
38
316
        mmm##_End(ctx, digest, len, maxLen);                                             \
39
316
    }                                                                                    \
Unexecuted instantiation: rawhash.c:RawHash_SHA3_224_End
Unexecuted instantiation: rawhash.c:RawHash_SHA3_256_End
Unexecuted instantiation: rawhash.c:RawHash_SHA3_384_End
Unexecuted instantiation: rawhash.c:RawHash_SHA3_512_End
40
    static void                                                                          \
41
        RawHash_##mmm##_DestroyContext(void *vctx, PRBool freeit)                        \
42
371
    {                                                                                    \
43
371
        ctxtype *ctx = vctx;                                                             \
44
371
        mmm##_DestroyContext(ctx, freeit);                                               \
45
371
    }
Unexecuted instantiation: rawhash.c:RawHash_MD2_DestroyContext
rawhash.c:RawHash_MD5_DestroyContext
Line
Count
Source
42
21
    {                                                                                    \
43
21
        ctxtype *ctx = vctx;                                                             \
44
21
        mmm##_DestroyContext(ctx, freeit);                                               \
45
21
    }
rawhash.c:RawHash_SHA1_DestroyContext
Line
Count
Source
42
127
    {                                                                                    \
43
127
        ctxtype *ctx = vctx;                                                             \
44
127
        mmm##_DestroyContext(ctx, freeit);                                               \
45
127
    }
rawhash.c:RawHash_SHA256_DestroyContext
Line
Count
Source
42
52
    {                                                                                    \
43
52
        ctxtype *ctx = vctx;                                                             \
44
52
        mmm##_DestroyContext(ctx, freeit);                                               \
45
52
    }
rawhash.c:RawHash_SHA384_DestroyContext
Line
Count
Source
42
45
    {                                                                                    \
43
45
        ctxtype *ctx = vctx;                                                             \
44
45
        mmm##_DestroyContext(ctx, freeit);                                               \
45
45
    }
rawhash.c:RawHash_SHA512_DestroyContext
Line
Count
Source
42
67
    {                                                                                    \
43
67
        ctxtype *ctx = vctx;                                                             \
44
67
        mmm##_DestroyContext(ctx, freeit);                                               \
45
67
    }
rawhash.c:RawHash_SHA224_DestroyContext
Line
Count
Source
42
59
    {                                                                                    \
43
59
        ctxtype *ctx = vctx;                                                             \
44
59
        mmm##_DestroyContext(ctx, freeit);                                               \
45
59
    }
Unexecuted instantiation: rawhash.c:RawHash_SHA3_224_DestroyContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_256_DestroyContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_384_DestroyContext
Unexecuted instantiation: rawhash.c:RawHash_SHA3_512_DestroyContext
46
47
RawHashBase(MD2Context, MD2);
48
RawHashBase(MD5Context, MD5);
49
RawHashBase(SHA1Context, SHA1);
50
RawHashBase(SHA224Context, SHA224);
51
RawHashBase(SHA256Context, SHA256);
52
RawHashBase(SHA384Context, SHA384);
53
RawHashBase(SHA512Context, SHA512);
54
RawHashBase(SHA3_224Context, SHA3_224);
55
RawHashBase(SHA3_256Context, SHA3_256);
56
RawHashBase(SHA3_384Context, SHA3_384);
57
RawHashBase(SHA3_512Context, SHA3_512);
58
59
#define RawHashExtra(ctxtype, mmm)                                     \
60
    static void                                                        \
61
        RawHash_##mmm##_EndRaw(void *vctx, unsigned char *digest,      \
62
                               unsigned int *len, unsigned int maxLen) \
63
0
    {                                                                  \
64
0
        ctxtype *ctx = vctx;                                           \
65
0
        mmm##_EndRaw(ctx, digest, len, maxLen);                        \
66
0
    }
Unexecuted instantiation: rawhash.c:RawHash_MD5_EndRaw
Unexecuted instantiation: rawhash.c:RawHash_SHA1_EndRaw
Unexecuted instantiation: rawhash.c:RawHash_SHA256_EndRaw
Unexecuted instantiation: rawhash.c:RawHash_SHA384_EndRaw
Unexecuted instantiation: rawhash.c:RawHash_SHA512_EndRaw
Unexecuted instantiation: rawhash.c:RawHash_SHA224_EndRaw
67
68
RawHashExtra(MD5Context, MD5);
69
RawHashExtra(SHA1Context, SHA1);
70
RawHashExtra(SHA224Context, SHA224);
71
RawHashExtra(SHA256Context, SHA256);
72
RawHashExtra(SHA384Context, SHA384);
73
RawHashExtra(SHA512Context, SHA512);
74
75
static void *
76
null_hash_new_context(void)
77
0
{
78
0
    return NULL;
79
0
}
80
81
static void *
82
null_hash_clone_context(void *v)
83
0
{
84
0
    PORT_Assert(v == NULL);
85
0
    return NULL;
86
0
}
87
88
static void
89
null_hash_begin(void *v)
90
0
{
91
0
}
92
93
static void
94
null_hash_update(void *v, const unsigned char *input, unsigned int length)
95
0
{
96
0
}
97
98
static void
99
null_hash_end(void *v, unsigned char *output, unsigned int *outLen,
100
              unsigned int maxOut)
101
0
{
102
0
    *outLen = 0;
103
0
}
104
105
static void
106
null_hash_destroy_context(void *v, PRBool b)
107
0
{
108
0
    PORT_Assert(v == NULL);
109
0
}
110
111
const SECHashObject SECRawHashObjects[] = {
112
    { 0,
113
      null_hash_new_context,
114
      null_hash_clone_context,
115
      null_hash_destroy_context,
116
      null_hash_begin,
117
      null_hash_update,
118
      null_hash_end,
119
      0,
120
      HASH_AlgNULL,
121
      null_hash_end },
122
    {
123
        MD2_LENGTH,
124
        RawHash_MD2_NewContext,
125
        null_hash_clone_context,
126
        RawHash_MD2_DestroyContext,
127
        RawHash_MD2_Begin,
128
        RawHash_MD2_Update,
129
        RawHash_MD2_End,
130
        MD2_BLOCK_LENGTH,
131
        HASH_AlgMD2,
132
        NULL /* end_raw */
133
    },
134
    { MD5_LENGTH,
135
      RawHash_MD5_NewContext,
136
      null_hash_clone_context,
137
      RawHash_MD5_DestroyContext,
138
      RawHash_MD5_Begin,
139
      RawHash_MD5_Update,
140
      RawHash_MD5_End,
141
      MD5_BLOCK_LENGTH,
142
      HASH_AlgMD5,
143
      RawHash_MD5_EndRaw },
144
    { SHA1_LENGTH,
145
      RawHash_SHA1_NewContext,
146
      null_hash_clone_context,
147
      RawHash_SHA1_DestroyContext,
148
      RawHash_SHA1_Begin,
149
      RawHash_SHA1_Update,
150
      RawHash_SHA1_End,
151
      SHA1_BLOCK_LENGTH,
152
      HASH_AlgSHA1,
153
      RawHash_SHA1_EndRaw },
154
    { SHA256_LENGTH,
155
      RawHash_SHA256_NewContext,
156
      null_hash_clone_context,
157
      RawHash_SHA256_DestroyContext,
158
      RawHash_SHA256_Begin,
159
      RawHash_SHA256_Update,
160
      RawHash_SHA256_End,
161
      SHA256_BLOCK_LENGTH,
162
      HASH_AlgSHA256,
163
      RawHash_SHA256_EndRaw },
164
    { SHA384_LENGTH,
165
      RawHash_SHA384_NewContext,
166
      null_hash_clone_context,
167
      RawHash_SHA384_DestroyContext,
168
      RawHash_SHA384_Begin,
169
      RawHash_SHA384_Update,
170
      RawHash_SHA384_End,
171
      SHA384_BLOCK_LENGTH,
172
      HASH_AlgSHA384,
173
      RawHash_SHA384_EndRaw },
174
    { SHA512_LENGTH,
175
      RawHash_SHA512_NewContext,
176
      null_hash_clone_context,
177
      RawHash_SHA512_DestroyContext,
178
      RawHash_SHA512_Begin,
179
      RawHash_SHA512_Update,
180
      RawHash_SHA512_End,
181
      SHA512_BLOCK_LENGTH,
182
      HASH_AlgSHA512,
183
      RawHash_SHA512_EndRaw },
184
    { SHA224_LENGTH,
185
      RawHash_SHA224_NewContext,
186
      null_hash_clone_context,
187
      RawHash_SHA224_DestroyContext,
188
      RawHash_SHA224_Begin,
189
      RawHash_SHA224_Update,
190
      RawHash_SHA224_End,
191
      SHA224_BLOCK_LENGTH,
192
      HASH_AlgSHA224,
193
      RawHash_SHA224_EndRaw },
194
    { SHA3_224_LENGTH,
195
      RawHash_SHA3_224_NewContext,
196
      null_hash_clone_context,
197
      RawHash_SHA3_224_DestroyContext,
198
      RawHash_SHA3_224_Begin,
199
      RawHash_SHA3_224_Update,
200
      RawHash_SHA3_224_End,
201
      SHA3_224_BLOCK_LENGTH,
202
      HASH_AlgSHA3_224,
203
      NULL },
204
    { SHA3_256_LENGTH,
205
      RawHash_SHA3_256_NewContext,
206
      null_hash_clone_context,
207
      RawHash_SHA3_256_DestroyContext,
208
      RawHash_SHA3_256_Begin,
209
      RawHash_SHA3_256_Update,
210
      RawHash_SHA3_256_End,
211
      SHA3_256_BLOCK_LENGTH,
212
      HASH_AlgSHA3_256,
213
      NULL },
214
    { SHA3_384_LENGTH,
215
      RawHash_SHA3_384_NewContext,
216
      null_hash_clone_context,
217
      RawHash_SHA3_384_DestroyContext,
218
      RawHash_SHA3_384_Begin,
219
      RawHash_SHA3_384_Update,
220
      RawHash_SHA3_384_End,
221
      SHA3_384_BLOCK_LENGTH,
222
      HASH_AlgSHA3_384,
223
      NULL },
224
    { SHA3_512_LENGTH,
225
      RawHash_SHA3_512_NewContext,
226
      null_hash_clone_context,
227
      RawHash_SHA3_512_DestroyContext,
228
      RawHash_SHA3_512_Begin,
229
      RawHash_SHA3_512_Update,
230
      RawHash_SHA3_512_End,
231
      SHA3_512_BLOCK_LENGTH,
232
      HASH_AlgSHA3_512,
233
      NULL },
234
};
235
236
const SECHashObject *
237
HASH_GetRawHashObject(HASH_HashType hashType)
238
194
{
239
194
    if (hashType <= HASH_AlgNULL || hashType >= HASH_AlgTOTAL) {
240
0
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
241
0
        return NULL;
242
0
    }
243
194
    return &SECRawHashObjects[hashType];
244
194
}