2016-05-17 18:51:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 03:40:55 +00:00
|
|
|
*
|
2016-05-17 18:51:04 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define DES_FCRYPT
|
|
|
|
#include "des_locl.h"
|
|
|
|
#undef DES_FCRYPT
|
|
|
|
|
|
|
|
#undef PERM_OP
|
|
|
|
#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
|
2015-01-22 03:40:55 +00:00
|
|
|
(b)^=(t),\
|
|
|
|
(a)^=((t)<<(n)))
|
1998-12-21 10:52:47 +00:00
|
|
|
|
|
|
|
#undef HPERM_OP
|
|
|
|
#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
|
2015-01-22 03:40:55 +00:00
|
|
|
(a)=(a)^(t)^(t>>(16-(n))))\
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2001-10-24 21:21:12 +00:00
|
|
|
void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
|
2015-01-22 03:40:55 +00:00
|
|
|
DES_LONG Eswap1)
|
|
|
|
{
|
|
|
|
register DES_LONG l, r, t, u;
|
|
|
|
register DES_LONG *s;
|
|
|
|
register int j;
|
|
|
|
register DES_LONG E0, E1;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
l = 0;
|
|
|
|
r = 0;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
s = (DES_LONG *)ks;
|
|
|
|
E0 = Eswap0;
|
|
|
|
E1 = Eswap1;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
for (j = 0; j < 25; j++) {
|
|
|
|
D_ENCRYPT(l, r, 0); /* 1 */
|
|
|
|
D_ENCRYPT(r, l, 2); /* 2 */
|
|
|
|
D_ENCRYPT(l, r, 4); /* 3 */
|
|
|
|
D_ENCRYPT(r, l, 6); /* 4 */
|
|
|
|
D_ENCRYPT(l, r, 8); /* 5 */
|
|
|
|
D_ENCRYPT(r, l, 10); /* 6 */
|
|
|
|
D_ENCRYPT(l, r, 12); /* 7 */
|
|
|
|
D_ENCRYPT(r, l, 14); /* 8 */
|
|
|
|
D_ENCRYPT(l, r, 16); /* 9 */
|
|
|
|
D_ENCRYPT(r, l, 18); /* 10 */
|
|
|
|
D_ENCRYPT(l, r, 20); /* 11 */
|
|
|
|
D_ENCRYPT(r, l, 22); /* 12 */
|
|
|
|
D_ENCRYPT(l, r, 24); /* 13 */
|
|
|
|
D_ENCRYPT(r, l, 26); /* 14 */
|
|
|
|
D_ENCRYPT(l, r, 28); /* 15 */
|
|
|
|
D_ENCRYPT(r, l, 30); /* 16 */
|
|
|
|
t = l;
|
|
|
|
l = r;
|
|
|
|
r = t;
|
|
|
|
}
|
|
|
|
l = ROTATE(l, 3) & 0xffffffffL;
|
|
|
|
r = ROTATE(r, 3) & 0xffffffffL;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-01-27 23:43:25 +00:00
|
|
|
PERM_OP(l, r, t, 1, 0x55555555L);
|
|
|
|
PERM_OP(r, l, t, 8, 0x00ff00ffL);
|
|
|
|
PERM_OP(l, r, t, 2, 0x33333333L);
|
2015-01-22 03:40:55 +00:00
|
|
|
PERM_OP(r, l, t, 16, 0x0000ffffL);
|
2016-01-27 23:43:25 +00:00
|
|
|
PERM_OP(l, r, t, 4, 0x0f0f0f0fL);
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
out[0] = r;
|
|
|
|
out[1] = l;
|
|
|
|
}
|