/src/openssl/crypto/des/fcrypt_b.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 | | * DES 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 | | |
18 | | #define DES_FCRYPT |
19 | | #include "des_local.h" |
20 | | #undef DES_FCRYPT |
21 | | |
22 | | #undef PERM_OP |
23 | 0 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ |
24 | 0 | (b)^=(t),\ |
25 | 0 | (a)^=((t)<<(n))) |
26 | | |
27 | | #undef HPERM_OP |
28 | | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ |
29 | | (a)=(a)^(t)^(t>>(16-(n))))\ |
30 | | |
31 | | void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0, |
32 | | DES_LONG Eswap1) |
33 | 0 | { |
34 | 0 | register DES_LONG l, r, t, u; |
35 | 0 | register DES_LONG *s; |
36 | 0 | register int j; |
37 | 0 | register DES_LONG E0, E1; |
38 | |
|
39 | 0 | l = 0; |
40 | 0 | r = 0; |
41 | |
|
42 | 0 | s = (DES_LONG *)ks; |
43 | 0 | E0 = Eswap0; |
44 | 0 | E1 = Eswap1; |
45 | |
|
46 | 0 | for (j = 0; j < 25; j++) { |
47 | 0 | D_ENCRYPT(l, r, 0); /* 1 */ |
48 | 0 | D_ENCRYPT(r, l, 2); /* 2 */ |
49 | 0 | D_ENCRYPT(l, r, 4); /* 3 */ |
50 | 0 | D_ENCRYPT(r, l, 6); /* 4 */ |
51 | 0 | D_ENCRYPT(l, r, 8); /* 5 */ |
52 | 0 | D_ENCRYPT(r, l, 10); /* 6 */ |
53 | 0 | D_ENCRYPT(l, r, 12); /* 7 */ |
54 | 0 | D_ENCRYPT(r, l, 14); /* 8 */ |
55 | 0 | D_ENCRYPT(l, r, 16); /* 9 */ |
56 | 0 | D_ENCRYPT(r, l, 18); /* 10 */ |
57 | 0 | D_ENCRYPT(l, r, 20); /* 11 */ |
58 | 0 | D_ENCRYPT(r, l, 22); /* 12 */ |
59 | 0 | D_ENCRYPT(l, r, 24); /* 13 */ |
60 | 0 | D_ENCRYPT(r, l, 26); /* 14 */ |
61 | 0 | D_ENCRYPT(l, r, 28); /* 15 */ |
62 | 0 | D_ENCRYPT(r, l, 30); /* 16 */ |
63 | 0 | t = l; |
64 | 0 | l = r; |
65 | 0 | r = t; |
66 | 0 | } |
67 | 0 | l = ROTATE(l, 3) & 0xffffffffL; |
68 | 0 | r = ROTATE(r, 3) & 0xffffffffL; |
69 | |
|
70 | 0 | PERM_OP(l, r, t, 1, 0x55555555L); |
71 | 0 | PERM_OP(r, l, t, 8, 0x00ff00ffL); |
72 | 0 | PERM_OP(l, r, t, 2, 0x33333333L); |
73 | 0 | PERM_OP(r, l, t, 16, 0x0000ffffL); |
74 | 0 | PERM_OP(l, r, t, 4, 0x0f0f0f0fL); |
75 | |
|
76 | 0 | out[0] = r; |
77 | 0 | out[1] = l; |
78 | 0 | } |