Coverage Report

Created: 2018-08-29 13:53

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