Coverage Report

Created: 2024-05-20 06:23

/src/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
static void *
15
null_hash_new_context(void)
16
0
{
17
0
    return NULL;
18
0
}
19
20
static void *
21
null_hash_clone_context(void *v)
22
0
{
23
0
    PORT_Assert(v == NULL);
24
0
    return NULL;
25
0
}
26
27
static void
28
null_hash_begin(void *v)
29
0
{
30
0
}
31
32
static void
33
null_hash_update(void *v, const unsigned char *input, unsigned int length)
34
0
{
35
0
}
36
37
static void
38
null_hash_end(void *v, unsigned char *output, unsigned int *outLen,
39
              unsigned int maxOut)
40
0
{
41
0
    *outLen = 0;
42
0
}
43
44
static void
45
null_hash_destroy_context(void *v, PRBool b)
46
0
{
47
0
    PORT_Assert(v == NULL);
48
0
}
49
50
const SECHashObject SECRawHashObjects[] = {
51
    { 0,
52
      (void *(*)(void))null_hash_new_context,
53
      (void *(*)(void *))null_hash_clone_context,
54
      (void (*)(void *, PRBool))null_hash_destroy_context,
55
      (void (*)(void *))null_hash_begin,
56
      (void (*)(void *, const unsigned char *, unsigned int))null_hash_update,
57
      (void (*)(void *, unsigned char *, unsigned int *,
58
                unsigned int))null_hash_end,
59
      0,
60
      HASH_AlgNULL,
61
      (void (*)(void *, unsigned char *, unsigned int *,
62
                unsigned int))null_hash_end },
63
    {
64
        MD2_LENGTH,
65
        (void *(*)(void))MD2_NewContext,
66
        (void *(*)(void *))null_hash_clone_context,
67
        (void (*)(void *, PRBool))MD2_DestroyContext,
68
        (void (*)(void *))MD2_Begin,
69
        (void (*)(void *, const unsigned char *, unsigned int))MD2_Update,
70
        (void (*)(void *, unsigned char *, unsigned int *, unsigned int))MD2_End,
71
        MD2_BLOCK_LENGTH,
72
        HASH_AlgMD2,
73
        NULL /* end_raw */
74
    },
75
    { MD5_LENGTH,
76
      (void *(*)(void))MD5_NewContext,
77
      (void *(*)(void *))null_hash_clone_context,
78
      (void (*)(void *, PRBool))MD5_DestroyContext,
79
      (void (*)(void *))MD5_Begin,
80
      (void (*)(void *, const unsigned char *, unsigned int))MD5_Update,
81
      (void (*)(void *, unsigned char *, unsigned int *, unsigned int))MD5_End,
82
      MD5_BLOCK_LENGTH,
83
      HASH_AlgMD5,
84
      (void (*)(void *, unsigned char *, unsigned int *, unsigned int))MD5_EndRaw },
85
    { SHA1_LENGTH,
86
      (void *(*)(void))SHA1_NewContext,
87
      (void *(*)(void *))null_hash_clone_context,
88
      (void (*)(void *, PRBool))SHA1_DestroyContext,
89
      (void (*)(void *))SHA1_Begin,
90
      (void (*)(void *, const unsigned char *, unsigned int))SHA1_Update,
91
      (void (*)(void *, unsigned char *, unsigned int *, unsigned int))SHA1_End,
92
      SHA1_BLOCK_LENGTH,
93
      HASH_AlgSHA1,
94
      (void (*)(void *, unsigned char *, unsigned int *, unsigned int))
95
          SHA1_EndRaw },
96
    { SHA256_LENGTH,
97
      (void *(*)(void))SHA256_NewContext,
98
      (void *(*)(void *))null_hash_clone_context,
99
      (void (*)(void *, PRBool))SHA256_DestroyContext,
100
      (void (*)(void *))SHA256_Begin,
101
      (void (*)(void *, const unsigned char *, unsigned int))SHA256_Update,
102
      (void (*)(void *, unsigned char *, unsigned int *,
103
                unsigned int))SHA256_End,
104
      SHA256_BLOCK_LENGTH,
105
      HASH_AlgSHA256,
106
      (void (*)(void *, unsigned char *, unsigned int *,
107
                unsigned int))SHA256_EndRaw },
108
    { SHA384_LENGTH,
109
      (void *(*)(void))SHA384_NewContext,
110
      (void *(*)(void *))null_hash_clone_context,
111
      (void (*)(void *, PRBool))SHA384_DestroyContext,
112
      (void (*)(void *))SHA384_Begin,
113
      (void (*)(void *, const unsigned char *, unsigned int))SHA384_Update,
114
      (void (*)(void *, unsigned char *, unsigned int *,
115
                unsigned int))SHA384_End,
116
      SHA384_BLOCK_LENGTH,
117
      HASH_AlgSHA384,
118
      (void (*)(void *, unsigned char *, unsigned int *,
119
                unsigned int))SHA384_EndRaw },
120
    { SHA512_LENGTH,
121
      (void *(*)(void))SHA512_NewContext,
122
      (void *(*)(void *))null_hash_clone_context,
123
      (void (*)(void *, PRBool))SHA512_DestroyContext,
124
      (void (*)(void *))SHA512_Begin,
125
      (void (*)(void *, const unsigned char *, unsigned int))SHA512_Update,
126
      (void (*)(void *, unsigned char *, unsigned int *,
127
                unsigned int))SHA512_End,
128
      SHA512_BLOCK_LENGTH,
129
      HASH_AlgSHA512,
130
      (void (*)(void *, unsigned char *, unsigned int *,
131
                unsigned int))SHA512_EndRaw },
132
    { SHA224_LENGTH,
133
      (void *(*)(void))SHA224_NewContext,
134
      (void *(*)(void *))null_hash_clone_context,
135
      (void (*)(void *, PRBool))SHA224_DestroyContext,
136
      (void (*)(void *))SHA224_Begin,
137
      (void (*)(void *, const unsigned char *, unsigned int))SHA224_Update,
138
      (void (*)(void *, unsigned char *, unsigned int *,
139
                unsigned int))SHA224_End,
140
      SHA224_BLOCK_LENGTH,
141
      HASH_AlgSHA224,
142
      (void (*)(void *, unsigned char *, unsigned int *,
143
                unsigned int))SHA224_EndRaw },
144
    { SHA3_224_LENGTH,
145
      (void *(*)(void))SHA3_224_NewContext,
146
      (void *(*)(void *))null_hash_clone_context,
147
      (void (*)(void *, PRBool))SHA3_224_DestroyContext,
148
      (void (*)(void *))SHA3_224_Begin,
149
      (void (*)(void *, const unsigned char *, unsigned int))SHA3_224_Update,
150
      (void (*)(void *, unsigned char *, unsigned int *,
151
                unsigned int))SHA3_224_End,
152
      SHA3_224_BLOCK_LENGTH,
153
      HASH_AlgSHA3_224,
154
      NULL },
155
    { SHA3_256_LENGTH,
156
      (void *(*)(void))SHA3_256_NewContext,
157
      (void *(*)(void *))null_hash_clone_context,
158
      (void (*)(void *, PRBool))SHA3_256_DestroyContext,
159
      (void (*)(void *))SHA3_256_Begin,
160
      (void (*)(void *, const unsigned char *, unsigned int))SHA3_256_Update,
161
      (void (*)(void *, unsigned char *, unsigned int *,
162
                unsigned int))SHA3_256_End,
163
      SHA3_256_BLOCK_LENGTH,
164
      HASH_AlgSHA3_256,
165
      NULL },
166
    { SHA3_384_LENGTH,
167
      (void *(*)(void))SHA3_384_NewContext,
168
      (void *(*)(void *))null_hash_clone_context,
169
      (void (*)(void *, PRBool))SHA3_384_DestroyContext,
170
      (void (*)(void *))SHA3_384_Begin,
171
      (void (*)(void *, const unsigned char *, unsigned int))SHA3_384_Update,
172
      (void (*)(void *, unsigned char *, unsigned int *,
173
                unsigned int))SHA3_384_End,
174
      SHA3_384_BLOCK_LENGTH,
175
      HASH_AlgSHA3_384,
176
      NULL },
177
    { SHA3_512_LENGTH,
178
      (void *(*)(void))SHA3_512_NewContext,
179
      (void *(*)(void *))null_hash_clone_context,
180
      (void (*)(void *, PRBool))SHA3_512_DestroyContext,
181
      (void (*)(void *))SHA3_512_Begin,
182
      (void (*)(void *, const unsigned char *, unsigned int))SHA3_512_Update,
183
      (void (*)(void *, unsigned char *, unsigned int *,
184
                unsigned int))SHA3_512_End,
185
      SHA3_512_BLOCK_LENGTH,
186
      HASH_AlgSHA3_512,
187
      NULL },
188
};
189
190
const SECHashObject *
191
HASH_GetRawHashObject(HASH_HashType hashType)
192
39.4k
{
193
39.4k
    if (hashType <= HASH_AlgNULL || hashType >= HASH_AlgTOTAL) {
194
0
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
195
0
        return NULL;
196
0
    }
197
39.4k
    return &SECRawHashObjects[hashType];
198
39.4k
}