Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/des/qud_cksm.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/*
11
 * From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer IEEE
12
 * Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 This module in
13
 * only based on the code in this paper and is almost definitely not the same
14
 * as the MIT implementation.
15
 */
16
17
/*
18
 * DES low level APIs are deprecated for public use, but still ok for internal
19
 * use.
20
 */
21
#include "internal/deprecated.h"
22
23
#include "des_local.h"
24
25
0
#define Q_B0(a) (((DES_LONG)(a)))
26
0
#define Q_B1(a) (((DES_LONG)(a))<<8)
27
0
#define Q_B2(a) (((DES_LONG)(a))<<16)
28
0
#define Q_B3(a) (((DES_LONG)(a))<<24)
29
30
/* used to scramble things a bit */
31
/* Got the value MIT uses via brute force :-) 2/10/90 eay */
32
0
#define NOISE   ((DES_LONG)83653421L)
33
34
DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
35
                        long length, int out_count, DES_cblock *seed)
36
0
{
37
0
    DES_LONG z0, z1, t0, t1;
38
0
    int i;
39
0
    long l;
40
0
    const unsigned char *cp;
41
0
    DES_LONG *lp;
42
43
0
    if (out_count < 1)
44
0
        out_count = 1;
45
0
    lp = (DES_LONG *)&(output[0])[0];
46
47
0
    z0 = Q_B0((*seed)[0]) | Q_B1((*seed)[1]) | Q_B2((*seed)[2]) |
48
0
        Q_B3((*seed)[3]);
49
0
    z1 = Q_B0((*seed)[4]) | Q_B1((*seed)[5]) | Q_B2((*seed)[6]) |
50
0
        Q_B3((*seed)[7]);
51
52
0
    for (i = 0; ((i < 4) && (i < out_count)); i++) {
53
0
        cp = input;
54
0
        l = length;
55
0
        while (l > 0) {
56
0
            if (l > 1) {
57
0
                t0 = (DES_LONG)(*(cp++));
58
0
                t0 |= (DES_LONG)Q_B1(*(cp++));
59
0
                l--;
60
0
            } else
61
0
                t0 = (DES_LONG)(*(cp++));
62
0
            l--;
63
            /* add */
64
0
            t0 += z0;
65
0
            t0 &= 0xffffffffL;
66
0
            t1 = z1;
67
            /* square, well sort of square */
68
0
            z0 = ((((t0 * t0) & 0xffffffffL) + ((t1 * t1) & 0xffffffffL))
69
0
                  & 0xffffffffL) % 0x7fffffffL;
70
0
            z1 = ((t0 * ((t1 + NOISE) & 0xffffffffL)) & 0xffffffffL) %
71
0
                0x7fffffffL;
72
0
        }
73
0
        if (lp != NULL) {
74
            /*
75
             * The MIT library assumes that the checksum is composed of
76
             * 2*out_count 32 bit ints
77
             */
78
0
            *lp++ = z0;
79
0
            *lp++ = z1;
80
0
        }
81
0
    }
82
0
    return z0;
83
0
}