Coverage Report

Created: 2025-06-13 06:58

/src/openssl30/crypto/idea/i_cfb64.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2021 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
 * IDEA low level APIs are deprecated for public use, but still ok for internal
12
 * use where we're using them to implement the higher level EVP interface, as is
13
 * the case here.
14
 */
15
#include "internal/deprecated.h"
16
17
#include <openssl/idea.h>
18
#include "idea_local.h"
19
20
/*
21
 * The input and output encrypted as though 64bit cfb mode is being used.
22
 * The extra state information to record how much of the 64bit block we have
23
 * used is contained in *num;
24
 */
25
26
void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out,
27
                        long length, IDEA_KEY_SCHEDULE *schedule,
28
                        unsigned char *ivec, int *num, int encrypt)
29
0
{
30
0
    register unsigned long v0, v1, t;
31
0
    register int n = *num;
32
0
    register long l = length;
33
0
    unsigned long ti[2];
34
0
    unsigned char *iv, c, cc;
35
36
0
    if (n < 0) {
37
0
        *num = -1;
38
0
        return;
39
0
    }
40
41
0
    iv = (unsigned char *)ivec;
42
0
    if (encrypt) {
43
0
        while (l--) {
44
0
            if (n == 0) {
45
0
                n2l(iv, v0);
46
0
                ti[0] = v0;
47
0
                n2l(iv, v1);
48
0
                ti[1] = v1;
49
0
                IDEA_encrypt((unsigned long *)ti, schedule);
50
0
                iv = (unsigned char *)ivec;
51
0
                t = ti[0];
52
0
                l2n(t, iv);
53
0
                t = ti[1];
54
0
                l2n(t, iv);
55
0
                iv = (unsigned char *)ivec;
56
0
            }
57
0
            c = *(in++) ^ iv[n];
58
0
            *(out++) = c;
59
0
            iv[n] = c;
60
0
            n = (n + 1) & 0x07;
61
0
        }
62
0
    } else {
63
0
        while (l--) {
64
0
            if (n == 0) {
65
0
                n2l(iv, v0);
66
0
                ti[0] = v0;
67
0
                n2l(iv, v1);
68
0
                ti[1] = v1;
69
0
                IDEA_encrypt((unsigned long *)ti, schedule);
70
0
                iv = (unsigned char *)ivec;
71
0
                t = ti[0];
72
0
                l2n(t, iv);
73
0
                t = ti[1];
74
0
                l2n(t, iv);
75
0
                iv = (unsigned char *)ivec;
76
0
            }
77
0
            cc = *(in++);
78
0
            c = iv[n];
79
0
            iv[n] = cc;
80
0
            *(out++) = c ^ cc;
81
0
            n = (n + 1) & 0x07;
82
0
        }
83
0
    }
84
0
    v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
85
0
    *num = n;
86
0
}