Coverage Report

Created: 2018-08-29 13:53

/src/openssl/crypto/rc5/rc5_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 <openssl/rc5.h>
11
#include "rc5_locl.h"
12
13
void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
14
                    int rounds)
15
0
{
16
0
    RC5_32_INT L[64], l, ll, A, B, *S, k;
17
0
    int i, j, m, c, t, ii, jj;
18
0
19
0
    if ((rounds != RC5_16_ROUNDS) &&
20
0
        (rounds != RC5_12_ROUNDS) && (rounds != RC5_8_ROUNDS))
21
0
        rounds = RC5_16_ROUNDS;
22
0
23
0
    key->rounds = rounds;
24
0
    S = &(key->data[0]);
25
0
    j = 0;
26
0
    for (i = 0; i <= (len - 8); i += 8) {
27
0
        c2l(data, l);
28
0
        L[j++] = l;
29
0
        c2l(data, l);
30
0
        L[j++] = l;
31
0
    }
32
0
    ii = len - i;
33
0
    if (ii) {
34
0
        k = len & 0x07;
35
0
        c2ln(data, l, ll, k);
36
0
        L[j + 0] = l;
37
0
        L[j + 1] = ll;
38
0
    }
39
0
40
0
    c = (len + 3) / 4;
41
0
    t = (rounds + 1) * 2;
42
0
    S[0] = RC5_32_P;
43
0
    for (i = 1; i < t; i++)
44
0
        S[i] = (S[i - 1] + RC5_32_Q) & RC5_32_MASK;
45
0
46
0
    j = (t > c) ? t : c;
47
0
    j *= 3;
48
0
    ii = jj = 0;
49
0
    A = B = 0;
50
0
    for (i = 0; i < j; i++) {
51
0
        k = (S[ii] + A + B) & RC5_32_MASK;
52
0
        A = S[ii] = ROTATE_l32(k, 3);
53
0
        m = (int)(A + B);
54
0
        k = (L[jj] + A + B) & RC5_32_MASK;
55
0
        B = L[jj] = ROTATE_l32(k, m);
56
0
        if (++ii >= t)
57
0
            ii = 0;
58
0
        if (++jj >= c)
59
0
            jj = 0;
60
0
    }
61
0
}