]>
Commit | Line | Data |
---|---|---|
4f22f405 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
0f113f3e | 3 | * |
4f22f405 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
11 | ||
d02b48c6 RE |
12 | #define DES_FCRYPT |
13 | #include "des_locl.h" | |
14 | #undef DES_FCRYPT | |
15 | ||
16 | #undef PERM_OP | |
17 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | |
0f113f3e MC |
18 | (b)^=(t),\ |
19 | (a)^=((t)<<(n))) | |
d02b48c6 RE |
20 | |
21 | #undef HPERM_OP | |
22 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | |
0f113f3e | 23 | (a)=(a)^(t)^(t>>(16-(n))))\ |
d02b48c6 | 24 | |
c2e4f17c | 25 | void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0, |
0f113f3e MC |
26 | DES_LONG Eswap1) |
27 | { | |
28 | register DES_LONG l, r, t, u; | |
0f113f3e MC |
29 | register DES_LONG *s; |
30 | register int j; | |
31 | register DES_LONG E0, E1; | |
d02b48c6 | 32 | |
0f113f3e MC |
33 | l = 0; |
34 | r = 0; | |
d02b48c6 | 35 | |
0f113f3e MC |
36 | s = (DES_LONG *)ks; |
37 | E0 = Eswap0; | |
38 | E1 = Eswap1; | |
d02b48c6 | 39 | |
0f113f3e | 40 | for (j = 0; j < 25; j++) { |
0f113f3e MC |
41 | D_ENCRYPT(l, r, 0); /* 1 */ |
42 | D_ENCRYPT(r, l, 2); /* 2 */ | |
43 | D_ENCRYPT(l, r, 4); /* 3 */ | |
44 | D_ENCRYPT(r, l, 6); /* 4 */ | |
45 | D_ENCRYPT(l, r, 8); /* 5 */ | |
46 | D_ENCRYPT(r, l, 10); /* 6 */ | |
47 | D_ENCRYPT(l, r, 12); /* 7 */ | |
48 | D_ENCRYPT(r, l, 14); /* 8 */ | |
49 | D_ENCRYPT(l, r, 16); /* 9 */ | |
50 | D_ENCRYPT(r, l, 18); /* 10 */ | |
51 | D_ENCRYPT(l, r, 20); /* 11 */ | |
52 | D_ENCRYPT(r, l, 22); /* 12 */ | |
53 | D_ENCRYPT(l, r, 24); /* 13 */ | |
54 | D_ENCRYPT(r, l, 26); /* 14 */ | |
55 | D_ENCRYPT(l, r, 28); /* 15 */ | |
56 | D_ENCRYPT(r, l, 30); /* 16 */ | |
0f113f3e MC |
57 | t = l; |
58 | l = r; | |
59 | r = t; | |
60 | } | |
61 | l = ROTATE(l, 3) & 0xffffffffL; | |
62 | r = ROTATE(r, 3) & 0xffffffffL; | |
d02b48c6 | 63 | |
3e9e810f RS |
64 | PERM_OP(l, r, t, 1, 0x55555555L); |
65 | PERM_OP(r, l, t, 8, 0x00ff00ffL); | |
66 | PERM_OP(l, r, t, 2, 0x33333333L); | |
0f113f3e | 67 | PERM_OP(r, l, t, 16, 0x0000ffffL); |
3e9e810f | 68 | PERM_OP(l, r, t, 4, 0x0f0f0f0fL); |
d02b48c6 | 69 | |
0f113f3e MC |
70 | out[0] = r; |
71 | out[1] = l; | |
72 | } |