Coverage Report

Created: 2018-08-29 13:53

/src/openssl/crypto/bf/bf_cfb64.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/blowfish.h>
11
#include "bf_locl.h"
12
13
/*
14
 * The input and output encrypted as though 64bit cfb mode is being used.
15
 * The extra state information to record how much of the 64bit block we have
16
 * used is contained in *num;
17
 */
18
19
void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
20
                      long length, const BF_KEY *schedule,
21
                      unsigned char *ivec, int *num, int encrypt)
22
0
{
23
0
    register BF_LONG v0, v1, t;
24
0
    register int n = *num;
25
0
    register long l = length;
26
0
    BF_LONG ti[2];
27
0
    unsigned char *iv, c, cc;
28
0
29
0
    iv = (unsigned char *)ivec;
30
0
    if (encrypt) {
31
0
        while (l--) {
32
0
            if (n == 0) {
33
0
                n2l(iv, v0);
34
0
                ti[0] = v0;
35
0
                n2l(iv, v1);
36
0
                ti[1] = v1;
37
0
                BF_encrypt((BF_LONG *)ti, schedule);
38
0
                iv = (unsigned char *)ivec;
39
0
                t = ti[0];
40
0
                l2n(t, iv);
41
0
                t = ti[1];
42
0
                l2n(t, iv);
43
0
                iv = (unsigned char *)ivec;
44
0
            }
45
0
            c = *(in++) ^ iv[n];
46
0
            *(out++) = c;
47
0
            iv[n] = c;
48
0
            n = (n + 1) & 0x07;
49
0
        }
50
0
    } else {
51
0
        while (l--) {
52
0
            if (n == 0) {
53
0
                n2l(iv, v0);
54
0
                ti[0] = v0;
55
0
                n2l(iv, v1);
56
0
                ti[1] = v1;
57
0
                BF_encrypt((BF_LONG *)ti, schedule);
58
0
                iv = (unsigned char *)ivec;
59
0
                t = ti[0];
60
0
                l2n(t, iv);
61
0
                t = ti[1];
62
0
                l2n(t, iv);
63
0
                iv = (unsigned char *)ivec;
64
0
            }
65
0
            cc = *(in++);
66
0
            c = iv[n];
67
0
            iv[n] = cc;
68
0
            *(out++) = c ^ cc;
69
0
            n = (n + 1) & 0x07;
70
0
        }
71
0
    }
72
0
    v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
73
0
    *num = n;
74
0
}