fcrypt_b.c 1.9 KB

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