Coverage Report

Created: 2018-08-29 13:53

/src/openssl/crypto/bf/bf_skey.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 <stdio.h>
11
#include <string.h>
12
#include <openssl/blowfish.h>
13
#include "bf_locl.h"
14
#include "bf_pi.h"
15
16
void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
17
0
{
18
0
    int i;
19
0
    BF_LONG *p, ri, in[2];
20
0
    const unsigned char *d, *end;
21
0
22
0
    memcpy(key, &bf_init, sizeof(BF_KEY));
23
0
    p = key->P;
24
0
25
0
    if (len > ((BF_ROUNDS + 2) * 4))
26
0
        len = (BF_ROUNDS + 2) * 4;
27
0
28
0
    d = data;
29
0
    end = &(data[len]);
30
0
    for (i = 0; i < (BF_ROUNDS + 2); i++) {
31
0
        ri = *(d++);
32
0
        if (d >= end)
33
0
            d = data;
34
0
35
0
        ri <<= 8;
36
0
        ri |= *(d++);
37
0
        if (d >= end)
38
0
            d = data;
39
0
40
0
        ri <<= 8;
41
0
        ri |= *(d++);
42
0
        if (d >= end)
43
0
            d = data;
44
0
45
0
        ri <<= 8;
46
0
        ri |= *(d++);
47
0
        if (d >= end)
48
0
            d = data;
49
0
50
0
        p[i] ^= ri;
51
0
    }
52
0
53
0
    in[0] = 0L;
54
0
    in[1] = 0L;
55
0
    for (i = 0; i < (BF_ROUNDS + 2); i += 2) {
56
0
        BF_encrypt(in, key);
57
0
        p[i] = in[0];
58
0
        p[i + 1] = in[1];
59
0
    }
60
0
61
0
    p = key->S;
62
0
    for (i = 0; i < 4 * 256; i += 2) {
63
0
        BF_encrypt(in, key);
64
0
        p[i] = in[0];
65
0
        p[i + 1] = in[1];
66
0
    }
67
0
}