Coverage Report

Created: 2023-06-08 06:41

/src/openssl111/crypto/modes/ofb128.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2020 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/crypto.h>
11
#include "modes_local.h"
12
#include <string.h>
13
14
#if defined(__GNUC__) && !defined(STRICT_ALIGNMENT)
15
typedef size_t size_t_aX __attribute((__aligned__(1)));
16
#else
17
typedef size_t size_t_aX;
18
#endif
19
20
/*
21
 * The input and output encrypted as though 128bit ofb mode is being used.
22
 * The extra state information to record how much of the 128bit block we have
23
 * used is contained in *num;
24
 */
25
void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
26
                           size_t len, const void *key,
27
                           unsigned char ivec[16], int *num, block128_f block)
28
0
{
29
0
    unsigned int n;
30
0
    size_t l = 0;
31
32
0
    n = *num;
33
34
0
#if !defined(OPENSSL_SMALL_FOOTPRINT)
35
0
    if (16 % sizeof(size_t) == 0) { /* always true actually */
36
0
        do {
37
0
            while (n && len) {
38
0
                *(out++) = *(in++) ^ ivec[n];
39
0
                --len;
40
0
                n = (n + 1) % 16;
41
0
            }
42
0
# if defined(STRICT_ALIGNMENT)
43
0
            if (((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) !=
44
0
                0)
45
0
                break;
46
0
# endif
47
0
            while (len >= 16) {
48
0
                (*block) (ivec, ivec, key);
49
0
                for (; n < 16; n += sizeof(size_t))
50
0
                    *(size_t_aX *)(out + n) =
51
0
                        *(size_t_aX *)(in + n)
52
0
                        ^ *(size_t_aX *)(ivec + n);
53
0
                len -= 16;
54
0
                out += 16;
55
0
                in += 16;
56
0
                n = 0;
57
0
            }
58
0
            if (len) {
59
0
                (*block) (ivec, ivec, key);
60
0
                while (len--) {
61
0
                    out[n] = in[n] ^ ivec[n];
62
0
                    ++n;
63
0
                }
64
0
            }
65
0
            *num = n;
66
0
            return;
67
0
        } while (0);
68
0
    }
69
    /* the rest would be commonly eliminated by x86* compiler */
70
0
#endif
71
0
    while (l < len) {
72
0
        if (n == 0) {
73
0
            (*block) (ivec, ivec, key);
74
0
        }
75
0
        out[l] = in[l] ^ ivec[n];
76
0
        ++l;
77
0
        n = (n + 1) % 16;
78
0
    }
79
80
0
    *num = n;
81
0
}