Coverage Report

Created: 2025-07-23 06:42

/src/irssi/subprojects/openssl-1.1.1l/crypto/rc4/rc4_enc.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the OpenSSL license (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
#include <openssl/rc4.h>
11
#include "rc4_local.h"
12
13
/*-
14
 * RC4 as implemented from a posting from
15
 * Newsgroups: sci.crypt
16
 * Subject: RC4 Algorithm revealed.
17
 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
18
 * Date: Wed, 14 Sep 1994 06:35:31 GMT
19
 */
20
21
void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
22
         unsigned char *outdata)
23
0
{
24
0
    register RC4_INT *d;
25
0
    register RC4_INT x, y, tx, ty;
26
0
    size_t i;
27
28
0
    x = key->x;
29
0
    y = key->y;
30
0
    d = key->data;
31
32
0
#define LOOP(in,out) \
33
0
                x=((x+1)&0xff); \
34
0
                tx=d[x]; \
35
0
                y=(tx+y)&0xff; \
36
0
                d[x]=ty=d[y]; \
37
0
                d[y]=tx; \
38
0
                (out) = d[(tx+ty)&0xff]^ (in);
39
40
0
    i = len >> 3;
41
0
    if (i) {
42
0
        for (;;) {
43
0
            LOOP(indata[0], outdata[0]);
44
0
            LOOP(indata[1], outdata[1]);
45
0
            LOOP(indata[2], outdata[2]);
46
0
            LOOP(indata[3], outdata[3]);
47
0
            LOOP(indata[4], outdata[4]);
48
0
            LOOP(indata[5], outdata[5]);
49
0
            LOOP(indata[6], outdata[6]);
50
0
            LOOP(indata[7], outdata[7]);
51
0
            indata += 8;
52
0
            outdata += 8;
53
0
            if (--i == 0)
54
0
                break;
55
0
        }
56
0
    }
57
0
    i = len & 0x07;
58
0
    if (i) {
59
0
        for (;;) {
60
0
            LOOP(indata[0], outdata[0]);
61
0
            if (--i == 0)
62
0
                break;
63
0
            LOOP(indata[1], outdata[1]);
64
0
            if (--i == 0)
65
0
                break;
66
0
            LOOP(indata[2], outdata[2]);
67
0
            if (--i == 0)
68
0
                break;
69
0
            LOOP(indata[3], outdata[3]);
70
0
            if (--i == 0)
71
0
                break;
72
0
            LOOP(indata[4], outdata[4]);
73
0
            if (--i == 0)
74
0
                break;
75
0
            LOOP(indata[5], outdata[5]);
76
0
            if (--i == 0)
77
0
                break;
78
0
            LOOP(indata[6], outdata[6]);
79
0
            if (--i == 0)
80
0
                break;
81
0
        }
82
0
    }
83
0
    key->x = x;
84
0
    key->y = y;
85
0
}