/src/openssl30/crypto/bf/bf_skey.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (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 | | /* |
11 | | * BF low level APIs are deprecated for public use, but still ok for internal |
12 | | * use. |
13 | | */ |
14 | | #include "internal/deprecated.h" |
15 | | |
16 | | #include <stdio.h> |
17 | | #include <string.h> |
18 | | #include <openssl/blowfish.h> |
19 | | #include "bf_local.h" |
20 | | #include "bf_pi.h" |
21 | | |
22 | | void BF_set_key(BF_KEY *key, int len, const unsigned char *data) |
23 | 0 | { |
24 | 0 | int i; |
25 | 0 | BF_LONG *p, ri, in[2]; |
26 | 0 | const unsigned char *d, *end; |
27 | |
|
28 | 0 | memcpy(key, &bf_init, sizeof(BF_KEY)); |
29 | 0 | p = key->P; |
30 | |
|
31 | 0 | if (len > ((BF_ROUNDS + 2) * 4)) |
32 | 0 | len = (BF_ROUNDS + 2) * 4; |
33 | |
|
34 | 0 | d = data; |
35 | 0 | end = &(data[len]); |
36 | 0 | for (i = 0; i < (BF_ROUNDS + 2); i++) { |
37 | 0 | ri = *(d++); |
38 | 0 | if (d >= end) |
39 | 0 | d = data; |
40 | |
|
41 | 0 | ri <<= 8; |
42 | 0 | ri |= *(d++); |
43 | 0 | if (d >= end) |
44 | 0 | d = data; |
45 | |
|
46 | 0 | ri <<= 8; |
47 | 0 | ri |= *(d++); |
48 | 0 | if (d >= end) |
49 | 0 | d = data; |
50 | |
|
51 | 0 | ri <<= 8; |
52 | 0 | ri |= *(d++); |
53 | 0 | if (d >= end) |
54 | 0 | d = data; |
55 | |
|
56 | 0 | p[i] ^= ri; |
57 | 0 | } |
58 | |
|
59 | 0 | in[0] = 0L; |
60 | 0 | in[1] = 0L; |
61 | 0 | for (i = 0; i < (BF_ROUNDS + 2); i += 2) { |
62 | 0 | BF_encrypt(in, key); |
63 | 0 | p[i] = in[0]; |
64 | 0 | p[i + 1] = in[1]; |
65 | 0 | } |
66 | |
|
67 | 0 | p = key->S; |
68 | 0 | for (i = 0; i < 4 * 256; i += 2) { |
69 | 0 | BF_encrypt(in, key); |
70 | 0 | p[i] = in[0]; |
71 | 0 | p[i + 1] = in[1]; |
72 | 0 | } |
73 | 0 | } |