Coverage Report

Created: 2022-11-30 06:20

/src/openssl/crypto/md32_common.h
Line
Count
Source (jump to first uncovered line)
1
/* crypto/md32_common.h */
2
/* ====================================================================
3
 * Copyright (c) 1999-2007 The OpenSSL Project.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in
14
 *    the documentation and/or other materials provided with the
15
 *    distribution.
16
 *
17
 * 3. All advertising materials mentioning features or use of this
18
 *    software must display the following acknowledgment:
19
 *    "This product includes software developed by the OpenSSL Project
20
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21
 *
22
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23
 *    endorse or promote products derived from this software without
24
 *    prior written permission. For written permission, please contact
25
 *    licensing@OpenSSL.org.
26
 *
27
 * 5. Products derived from this software may not be called "OpenSSL"
28
 *    nor may "OpenSSL" appear in their names without prior written
29
 *    permission of the OpenSSL Project.
30
 *
31
 * 6. Redistributions of any form whatsoever must retain the following
32
 *    acknowledgment:
33
 *    "This product includes software developed by the OpenSSL Project
34
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35
 *
36
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47
 * OF THE POSSIBILITY OF SUCH DAMAGE.
48
 * ====================================================================
49
 *
50
 */
51
52
/*-
53
 * This is a generic 32 bit "collector" for message digest algorithms.
54
 * Whenever needed it collects input character stream into chunks of
55
 * 32 bit values and invokes a block function that performs actual hash
56
 * calculations.
57
 *
58
 * Porting guide.
59
 *
60
 * Obligatory macros:
61
 *
62
 * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
63
 *      this macro defines byte order of input stream.
64
 * HASH_CBLOCK
65
 *      size of a unit chunk HASH_BLOCK operates on.
66
 * HASH_LONG
67
 *      has to be at lest 32 bit wide, if it's wider, then
68
 *      HASH_LONG_LOG2 *has to* be defined along
69
 * HASH_CTX
70
 *      context structure that at least contains following
71
 *      members:
72
 *              typedef struct {
73
 *                      ...
74
 *                      HASH_LONG       Nl,Nh;
75
 *                      either {
76
 *                      HASH_LONG       data[HASH_LBLOCK];
77
 *                      unsigned char   data[HASH_CBLOCK];
78
 *                      };
79
 *                      unsigned int    num;
80
 *                      ...
81
 *                      } HASH_CTX;
82
 *      data[] vector is expected to be zeroed upon first call to
83
 *      HASH_UPDATE.
84
 * HASH_UPDATE
85
 *      name of "Update" function, implemented here.
86
 * HASH_TRANSFORM
87
 *      name of "Transform" function, implemented here.
88
 * HASH_FINAL
89
 *      name of "Final" function, implemented here.
90
 * HASH_BLOCK_DATA_ORDER
91
 *      name of "block" function capable of treating *unaligned* input
92
 *      message in original (data) byte order, implemented externally.
93
 * HASH_MAKE_STRING
94
 *      macro convering context variables to an ASCII hash string.
95
 *
96
 * MD5 example:
97
 *
98
 *      #define DATA_ORDER_IS_LITTLE_ENDIAN
99
 *
100
 *      #define HASH_LONG               MD5_LONG
101
 *      #define HASH_LONG_LOG2          MD5_LONG_LOG2
102
 *      #define HASH_CTX                MD5_CTX
103
 *      #define HASH_CBLOCK             MD5_CBLOCK
104
 *      #define HASH_UPDATE             MD5_Update
105
 *      #define HASH_TRANSFORM          MD5_Transform
106
 *      #define HASH_FINAL              MD5_Final
107
 *      #define HASH_BLOCK_DATA_ORDER   md5_block_data_order
108
 *
109
 *                                      <appro@fy.chalmers.se>
110
 */
111
112
#include <openssl/crypto.h>
113
114
#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
115
# error "DATA_ORDER must be defined!"
116
#endif
117
118
#ifndef HASH_CBLOCK
119
# error "HASH_CBLOCK must be defined!"
120
#endif
121
#ifndef HASH_LONG
122
# error "HASH_LONG must be defined!"
123
#endif
124
#ifndef HASH_CTX
125
# error "HASH_CTX must be defined!"
126
#endif
127
128
#ifndef HASH_UPDATE
129
# error "HASH_UPDATE must be defined!"
130
#endif
131
#ifndef HASH_TRANSFORM
132
# error "HASH_TRANSFORM must be defined!"
133
#endif
134
#ifndef HASH_FINAL
135
# error "HASH_FINAL must be defined!"
136
#endif
137
138
#ifndef HASH_BLOCK_DATA_ORDER
139
# error "HASH_BLOCK_DATA_ORDER must be defined!"
140
#endif
141
142
/*
143
 * Engage compiler specific rotate intrinsic function if available.
144
 */
145
#undef ROTATE
146
#ifndef PEDANTIC
147
# if defined(_MSC_VER)
148
#  define ROTATE(a,n)   _lrotl(a,n)
149
# elif defined(__ICC)
150
#  define ROTATE(a,n)   _rotl(a,n)
151
# elif defined(__MWERKS__)
152
#  if defined(__POWERPC__)
153
#   define ROTATE(a,n)  __rlwinm(a,n,0,31)
154
#  elif defined(__MC68K__)
155
    /* Motorola specific tweak. <appro@fy.chalmers.se> */
156
#   define ROTATE(a,n)  ( n<24 ? __rol(a,n) : __ror(a,32-n) )
157
#  else
158
#   define ROTATE(a,n)  __rol(a,n)
159
#  endif
160
# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
161
  /*
162
   * Some GNU C inline assembler templates. Note that these are
163
   * rotates by *constant* number of bits! But that's exactly
164
   * what we need here...
165
   *                                    <appro@fy.chalmers.se>
166
   */
167
#  if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
168
#   define ROTATE(a,n)  ({ register unsigned int ret;   \
169
                                asm (                   \
170
                                "roll %1,%0"            \
171
                                : "=r"(ret)             \
172
                                : "I"(n), "0"((unsigned int)(a))        \
173
                                : "cc");                \
174
                           ret;                         \
175
                        })
176
#  elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
177
        defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
178
#   define ROTATE(a,n)  ({ register unsigned int ret;   \
179
                                asm (                   \
180
                                "rlwinm %0,%1,%2,0,31"  \
181
                                : "=r"(ret)             \
182
                                : "r"(a), "I"(n));      \
183
                           ret;                         \
184
                        })
185
#  elif defined(__s390x__)
186
#   define ROTATE(a,n) ({ register unsigned int ret;    \
187
                                asm ("rll %0,%1,%2"     \
188
                                : "=r"(ret)             \
189
                                : "r"(a), "I"(n));      \
190
                          ret;                          \
191
                        })
192
#  endif
193
# endif
194
#endif                          /* PEDANTIC */
195
196
#ifndef ROTATE
197
0
# define ROTATE(a,n)     (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
198
#endif
199
200
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
201
202
# ifndef PEDANTIC
203
#  if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
204
#   if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \
205
      (defined(__x86_64) || defined(__x86_64__))
206
#    if !defined(B_ENDIAN)
207
    /*
208
     * This gives ~30-40% performance improvement in SHA-256 compiled
209
     * with gcc [on P4]. Well, first macro to be frank. We can pull
210
     * this trick on x86* platforms only, because these CPUs can fetch
211
     * unaligned data without raising an exception.
212
     */
213
#     define HOST_c2l(c,l)        ({ unsigned int r=*((const unsigned int *)(c)); \
214
                                   asm ("bswapl %0":"=r"(r):"0"(r));    \
215
                                   (c)+=4; (l)=r;                       })
216
#     define HOST_l2c(l,c)        ({ unsigned int r=(l);                  \
217
                                   asm ("bswapl %0":"=r"(r):"0"(r));    \
218
                                   *((unsigned int *)(c))=r; (c)+=4; r; })
219
#    endif
220
#   elif defined(__aarch64__)
221
#    if defined(__BYTE_ORDER__)
222
#     if defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
223
#      define HOST_c2l(c,l)      ({ unsigned int r;              \
224
                                   asm ("rev    %w0,%w1"        \
225
                                        :"=r"(r)                \
226
                                        :"r"(*((const unsigned int *)(c))));\
227
                                   (c)+=4; (l)=r;               })
228
#      define HOST_l2c(l,c)      ({ unsigned int r;              \
229
                                   asm ("rev    %w0,%w1"        \
230
                                        :"=r"(r)                \
231
                                        :"r"((unsigned int)(l)));\
232
                                   *((unsigned int *)(c))=r; (c)+=4; r; })
233
#     elif defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
234
#      define HOST_c2l(c,l)      ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
235
#      define HOST_l2c(l,c)      (*((unsigned int *)(c))=(l), (c)+=4, (l))
236
#     endif
237
#    endif
238
#   endif
239
#  endif
240
#  if defined(__s390__) || defined(__s390x__)
241
#   define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
242
#   define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l))
243
#  endif
244
# endif
245
246
# ifndef HOST_c2l
247
0
#  define HOST_c2l(c,l)   (l =(((unsigned long)(*((c)++)))<<24),          \
248
0
                         l|=(((unsigned long)(*((c)++)))<<16),          \
249
0
                         l|=(((unsigned long)(*((c)++)))<< 8),          \
250
0
                         l|=(((unsigned long)(*((c)++)))    )           )
251
# endif
252
# ifndef HOST_l2c
253
627k
#  define HOST_l2c(l,c)   (*((c)++)=(unsigned char)(((l)>>24)&0xff),      \
254
627k
                         *((c)++)=(unsigned char)(((l)>>16)&0xff),      \
255
627k
                         *((c)++)=(unsigned char)(((l)>> 8)&0xff),      \
256
627k
                         *((c)++)=(unsigned char)(((l)    )&0xff),      \
257
627k
                         l)
258
# endif
259
260
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
261
262
# ifndef PEDANTIC
263
#  if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
264
#   if defined(__s390x__)
265
#    define HOST_c2l(c,l)        ({ asm ("lrv    %0,%1"                  \
266
                                   :"=d"(l) :"m"(*(const unsigned int *)(c)));\
267
                                   (c)+=4; (l);                         })
268
#    define HOST_l2c(l,c)        ({ asm ("strv   %1,%0"                  \
269
                                   :"=m"(*(unsigned int *)(c)) :"d"(l));\
270
                                   (c)+=4; (l);                         })
271
#   endif
272
#  endif
273
#  if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
274
#   ifndef B_ENDIAN
275
    /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
276
#    define HOST_c2l(c,l)        ((l)=*((const unsigned int *)(c)), (c)+=4, l)
277
#    define HOST_l2c(l,c)        (*((unsigned int *)(c))=(l), (c)+=4, l)
278
#   endif
279
#  endif
280
# endif
281
282
# ifndef HOST_c2l
283
#  define HOST_c2l(c,l)   (l =(((unsigned long)(*((c)++)))    ),          \
284
                         l|=(((unsigned long)(*((c)++)))<< 8),          \
285
                         l|=(((unsigned long)(*((c)++)))<<16),          \
286
                         l|=(((unsigned long)(*((c)++)))<<24)           )
287
# endif
288
# ifndef HOST_l2c
289
#  define HOST_l2c(l,c)   (*((c)++)=(unsigned char)(((l)    )&0xff),      \
290
                         *((c)++)=(unsigned char)(((l)>> 8)&0xff),      \
291
                         *((c)++)=(unsigned char)(((l)>>16)&0xff),      \
292
                         *((c)++)=(unsigned char)(((l)>>24)&0xff),      \
293
                         l)
294
# endif
295
296
#endif
297
298
/*
299
 * Time for some action:-)
300
 */
301
302
int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len)
303
1.18M
{
304
1.18M
    const unsigned char *data = data_;
305
1.18M
    unsigned char *p;
306
1.18M
    HASH_LONG l;
307
1.18M
    size_t n;
308
309
1.18M
    if (len == 0)
310
1.67k
        return 1;
311
312
1.17M
    l = (c->Nl + (((HASH_LONG) len) << 3)) & 0xffffffffUL;
313
    /*
314
     * 95-05-24 eay Fixed a bug with the overflow handling, thanks to Wei Dai
315
     * <weidai@eskimo.com> for pointing it out.
316
     */
317
1.17M
    if (l < c->Nl)              /* overflow */
318
0
        c->Nh++;
319
1.17M
    c->Nh += (HASH_LONG) (len >> 29); /* might cause compiler warning on
320
                                       * 16-bit */
321
1.17M
    c->Nl = l;
322
323
1.17M
    n = c->num;
324
1.17M
    if (n != 0) {
325
1.08M
        p = (unsigned char *)c->data;
326
327
1.08M
        if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {
328
15.0k
            memcpy(p + n, data, HASH_CBLOCK - n);
329
15.0k
            HASH_BLOCK_DATA_ORDER(c, p, 1);
330
15.0k
            n = HASH_CBLOCK - n;
331
15.0k
            data += n;
332
15.0k
            len -= n;
333
15.0k
            c->num = 0;
334
            /*
335
             * We use memset rather than OPENSSL_cleanse() here deliberately.
336
             * Using OPENSSL_cleanse() here could be a performance issue. It
337
             * will get properly cleansed on finalisation so this isn't a
338
             * security problem.
339
             */
340
15.0k
            memset(p, 0, HASH_CBLOCK); /* keep it zeroed */
341
1.06M
        } else {
342
1.06M
            memcpy(p + n, data, len);
343
1.06M
            c->num += (unsigned int)len;
344
1.06M
            return 1;
345
1.06M
        }
346
1.08M
    }
347
348
109k
    n = len / HASH_CBLOCK;
349
109k
    if (n > 0) {
350
2.87k
        HASH_BLOCK_DATA_ORDER(c, data, n);
351
2.87k
        n *= HASH_CBLOCK;
352
2.87k
        data += n;
353
2.87k
        len -= n;
354
2.87k
    }
355
356
109k
    if (len != 0) {
357
95.6k
        p = (unsigned char *)c->data;
358
95.6k
        c->num = (unsigned int)len;
359
95.6k
        memcpy(p, data, len);
360
95.6k
    }
361
109k
    return 1;
362
1.17M
}
SHA1_Update
Line
Count
Source
303
261k
{
304
261k
    const unsigned char *data = data_;
305
261k
    unsigned char *p;
306
261k
    HASH_LONG l;
307
261k
    size_t n;
308
309
261k
    if (len == 0)
310
31
        return 1;
311
312
261k
    l = (c->Nl + (((HASH_LONG) len) << 3)) & 0xffffffffUL;
313
    /*
314
     * 95-05-24 eay Fixed a bug with the overflow handling, thanks to Wei Dai
315
     * <weidai@eskimo.com> for pointing it out.
316
     */
317
261k
    if (l < c->Nl)              /* overflow */
318
0
        c->Nh++;
319
261k
    c->Nh += (HASH_LONG) (len >> 29); /* might cause compiler warning on
320
                                       * 16-bit */
321
261k
    c->Nl = l;
322
323
261k
    n = c->num;
324
261k
    if (n != 0) {
325
196k
        p = (unsigned char *)c->data;
326
327
196k
        if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {
328
954
            memcpy(p + n, data, HASH_CBLOCK - n);
329
954
            HASH_BLOCK_DATA_ORDER(c, p, 1);
330
954
            n = HASH_CBLOCK - n;
331
954
            data += n;
332
954
            len -= n;
333
954
            c->num = 0;
334
            /*
335
             * We use memset rather than OPENSSL_cleanse() here deliberately.
336
             * Using OPENSSL_cleanse() here could be a performance issue. It
337
             * will get properly cleansed on finalisation so this isn't a
338
             * security problem.
339
             */
340
954
            memset(p, 0, HASH_CBLOCK); /* keep it zeroed */
341
195k
        } else {
342
195k
            memcpy(p + n, data, len);
343
195k
            c->num += (unsigned int)len;
344
195k
            return 1;
345
195k
        }
346
196k
    }
347
348
66.3k
    n = len / HASH_CBLOCK;
349
66.3k
    if (n > 0) {
350
0
        HASH_BLOCK_DATA_ORDER(c, data, n);
351
0
        n *= HASH_CBLOCK;
352
0
        data += n;
353
0
        len -= n;
354
0
    }
355
356
66.3k
    if (len != 0) {
357
66.3k
        p = (unsigned char *)c->data;
358
66.3k
        c->num = (unsigned int)len;
359
66.3k
        memcpy(p, data, len);
360
66.3k
    }
361
66.3k
    return 1;
362
261k
}
SHA256_Update
Line
Count
Source
303
919k
{
304
919k
    const unsigned char *data = data_;
305
919k
    unsigned char *p;
306
919k
    HASH_LONG l;
307
919k
    size_t n;
308
309
919k
    if (len == 0)
310
1.64k
        return 1;
311
312
917k
    l = (c->Nl + (((HASH_LONG) len) << 3)) & 0xffffffffUL;
313
    /*
314
     * 95-05-24 eay Fixed a bug with the overflow handling, thanks to Wei Dai
315
     * <weidai@eskimo.com> for pointing it out.
316
     */
317
917k
    if (l < c->Nl)              /* overflow */
318
0
        c->Nh++;
319
917k
    c->Nh += (HASH_LONG) (len >> 29); /* might cause compiler warning on
320
                                       * 16-bit */
321
917k
    c->Nl = l;
322
323
917k
    n = c->num;
324
917k
    if (n != 0) {
325
888k
        p = (unsigned char *)c->data;
326
327
888k
        if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {
328
14.1k
            memcpy(p + n, data, HASH_CBLOCK - n);
329
14.1k
            HASH_BLOCK_DATA_ORDER(c, p, 1);
330
14.1k
            n = HASH_CBLOCK - n;
331
14.1k
            data += n;
332
14.1k
            len -= n;
333
14.1k
            c->num = 0;
334
            /*
335
             * We use memset rather than OPENSSL_cleanse() here deliberately.
336
             * Using OPENSSL_cleanse() here could be a performance issue. It
337
             * will get properly cleansed on finalisation so this isn't a
338
             * security problem.
339
             */
340
14.1k
            memset(p, 0, HASH_CBLOCK); /* keep it zeroed */
341
874k
        } else {
342
874k
            memcpy(p + n, data, len);
343
874k
            c->num += (unsigned int)len;
344
874k
            return 1;
345
874k
        }
346
888k
    }
347
348
43.5k
    n = len / HASH_CBLOCK;
349
43.5k
    if (n > 0) {
350
2.87k
        HASH_BLOCK_DATA_ORDER(c, data, n);
351
2.87k
        n *= HASH_CBLOCK;
352
2.87k
        data += n;
353
2.87k
        len -= n;
354
2.87k
    }
355
356
43.5k
    if (len != 0) {
357
29.3k
        p = (unsigned char *)c->data;
358
29.3k
        c->num = (unsigned int)len;
359
29.3k
        memcpy(p, data, len);
360
29.3k
    }
361
43.5k
    return 1;
362
917k
}
Unexecuted instantiation: SHA_Update
363
364
void HASH_TRANSFORM(HASH_CTX *c, const unsigned char *data)
365
0
{
366
0
    HASH_BLOCK_DATA_ORDER(c, data, 1);
367
0
}
Unexecuted instantiation: SHA1_Transform
Unexecuted instantiation: SHA256_Transform
Unexecuted instantiation: SHA_Transform
368
369
int HASH_FINAL(unsigned char *md, HASH_CTX *c)
370
82.3k
{
371
82.3k
    unsigned char *p = (unsigned char *)c->data;
372
82.3k
    size_t n = c->num;
373
374
82.3k
    p[n] = 0x80;                /* there is always room for one */
375
82.3k
    n++;
376
377
82.3k
    if (n > (HASH_CBLOCK - 8)) {
378
35.5k
        memset(p + n, 0, HASH_CBLOCK - n);
379
35.5k
        n = 0;
380
35.5k
        HASH_BLOCK_DATA_ORDER(c, p, 1);
381
35.5k
    }
382
82.3k
    memset(p + n, 0, HASH_CBLOCK - 8 - n);
383
384
82.3k
    p += HASH_CBLOCK - 8;
385
82.3k
#if   defined(DATA_ORDER_IS_BIG_ENDIAN)
386
82.3k
    (void)HOST_l2c(c->Nh, p);
387
82.3k
    (void)HOST_l2c(c->Nl, p);
388
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
389
    (void)HOST_l2c(c->Nl, p);
390
    (void)HOST_l2c(c->Nh, p);
391
#endif
392
82.3k
    p -= HASH_CBLOCK;
393
82.3k
    HASH_BLOCK_DATA_ORDER(c, p, 1);
394
82.3k
    c->num = 0;
395
82.3k
    OPENSSL_cleanse(p, HASH_CBLOCK);
396
397
#ifndef HASH_MAKE_STRING
398
# error "HASH_MAKE_STRING must be defined!"
399
#else
400
82.3k
    HASH_MAKE_STRING(c, md);
401
16.9k
#endif
402
403
16.9k
    return 1;
404
82.3k
}
SHA1_Final
Line
Count
Source
370
65.3k
{
371
65.3k
    unsigned char *p = (unsigned char *)c->data;
372
65.3k
    size_t n = c->num;
373
374
65.3k
    p[n] = 0x80;                /* there is always room for one */
375
65.3k
    n++;
376
377
65.3k
    if (n > (HASH_CBLOCK - 8)) {
378
34.0k
        memset(p + n, 0, HASH_CBLOCK - n);
379
34.0k
        n = 0;
380
34.0k
        HASH_BLOCK_DATA_ORDER(c, p, 1);
381
34.0k
    }
382
65.3k
    memset(p + n, 0, HASH_CBLOCK - 8 - n);
383
384
65.3k
    p += HASH_CBLOCK - 8;
385
65.3k
#if   defined(DATA_ORDER_IS_BIG_ENDIAN)
386
65.3k
    (void)HOST_l2c(c->Nh, p);
387
65.3k
    (void)HOST_l2c(c->Nl, p);
388
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
389
    (void)HOST_l2c(c->Nl, p);
390
    (void)HOST_l2c(c->Nh, p);
391
#endif
392
65.3k
    p -= HASH_CBLOCK;
393
65.3k
    HASH_BLOCK_DATA_ORDER(c, p, 1);
394
65.3k
    c->num = 0;
395
65.3k
    OPENSSL_cleanse(p, HASH_CBLOCK);
396
397
#ifndef HASH_MAKE_STRING
398
# error "HASH_MAKE_STRING must be defined!"
399
#else
400
65.3k
    HASH_MAKE_STRING(c, md);
401
65.3k
#endif
402
403
65.3k
    return 1;
404
65.3k
}
SHA256_Final
Line
Count
Source
370
16.9k
{
371
16.9k
    unsigned char *p = (unsigned char *)c->data;
372
16.9k
    size_t n = c->num;
373
374
16.9k
    p[n] = 0x80;                /* there is always room for one */
375
16.9k
    n++;
376
377
16.9k
    if (n > (HASH_CBLOCK - 8)) {
378
1.52k
        memset(p + n, 0, HASH_CBLOCK - n);
379
1.52k
        n = 0;
380
1.52k
        HASH_BLOCK_DATA_ORDER(c, p, 1);
381
1.52k
    }
382
16.9k
    memset(p + n, 0, HASH_CBLOCK - 8 - n);
383
384
16.9k
    p += HASH_CBLOCK - 8;
385
16.9k
#if   defined(DATA_ORDER_IS_BIG_ENDIAN)
386
16.9k
    (void)HOST_l2c(c->Nh, p);
387
16.9k
    (void)HOST_l2c(c->Nl, p);
388
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
389
    (void)HOST_l2c(c->Nl, p);
390
    (void)HOST_l2c(c->Nh, p);
391
#endif
392
16.9k
    p -= HASH_CBLOCK;
393
16.9k
    HASH_BLOCK_DATA_ORDER(c, p, 1);
394
16.9k
    c->num = 0;
395
16.9k
    OPENSSL_cleanse(p, HASH_CBLOCK);
396
397
#ifndef HASH_MAKE_STRING
398
# error "HASH_MAKE_STRING must be defined!"
399
#else
400
16.9k
    HASH_MAKE_STRING(c, md);
401
16.9k
#endif
402
403
16.9k
    return 1;
404
16.9k
}
Unexecuted instantiation: SHA_Final
405
406
#ifndef MD32_REG_T
407
# if defined(__alpha) || defined(__sparcv9) || defined(__mips)
408
#  define MD32_REG_T long
409
/*
410
 * This comment was originaly written for MD5, which is why it
411
 * discusses A-D. But it basically applies to all 32-bit digests,
412
 * which is why it was moved to common header file.
413
 *
414
 * In case you wonder why A-D are declared as long and not
415
 * as MD5_LONG. Doing so results in slight performance
416
 * boost on LP64 architectures. The catch is we don't
417
 * really care if 32 MSBs of a 64-bit register get polluted
418
 * with eventual overflows as we *save* only 32 LSBs in
419
 * *either* case. Now declaring 'em long excuses the compiler
420
 * from keeping 32 MSBs zeroed resulting in 13% performance
421
 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
422
 * Well, to be honest it should say that this *prevents*
423
 * performance degradation.
424
 *                              <appro@fy.chalmers.se>
425
 */
426
# else
427
/*
428
 * Above is not absolute and there are LP64 compilers that
429
 * generate better code if MD32_REG_T is defined int. The above
430
 * pre-processor condition reflects the circumstances under which
431
 * the conclusion was made and is subject to further extension.
432
 *                              <appro@fy.chalmers.se>
433
 */
434
#  define MD32_REG_T int
435
# endif
436
#endif