bf_local.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 1995-2016 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. #ifndef OSSL_CRYPTO_BF_LOCAL_H
  10. # define OSSL_CRYPTO_BF_LOCAL_H
  11. # include <openssl/opensslconf.h>
  12. /* NOTE - c is not incremented as per n2l */
  13. # define n2ln(c,l1,l2,n) { \
  14. c+=n; \
  15. l1=l2=0; \
  16. switch (n) { \
  17. case 8: l2 =((unsigned long)(*(--(c)))) ; \
  18. /* fall through */ \
  19. case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
  20. /* fall through */ \
  21. case 6: l2|=((unsigned long)(*(--(c))))<<16; \
  22. /* fall through */ \
  23. case 5: l2|=((unsigned long)(*(--(c))))<<24; \
  24. /* fall through */ \
  25. case 4: l1 =((unsigned long)(*(--(c)))) ; \
  26. /* fall through */ \
  27. case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
  28. /* fall through */ \
  29. case 2: l1|=((unsigned long)(*(--(c))))<<16; \
  30. /* fall through */ \
  31. case 1: l1|=((unsigned long)(*(--(c))))<<24; \
  32. } \
  33. }
  34. /* NOTE - c is not incremented as per l2n */
  35. # define l2nn(l1,l2,c,n) { \
  36. c+=n; \
  37. switch (n) { \
  38. case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
  39. /* fall through */ \
  40. case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
  41. /* fall through */ \
  42. case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
  43. /* fall through */ \
  44. case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
  45. /* fall through */ \
  46. case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
  47. /* fall through */ \
  48. case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
  49. /* fall through */ \
  50. case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
  51. /* fall through */ \
  52. case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
  53. } \
  54. }
  55. # undef n2l
  56. # define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
  57. l|=((unsigned long)(*((c)++)))<<16L, \
  58. l|=((unsigned long)(*((c)++)))<< 8L, \
  59. l|=((unsigned long)(*((c)++))))
  60. # undef l2n
  61. # define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
  62. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  63. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  64. *((c)++)=(unsigned char)(((l) )&0xff))
  65. /*
  66. * This is actually a big endian algorithm, the most significant byte is used
  67. * to lookup array 0
  68. */
  69. # define BF_ENC(LL,R,S,P) ( \
  70. LL^=P, \
  71. LL^=((( S[ ((R>>24)&0xff)] + \
  72. S[0x0100+((R>>16)&0xff)])^ \
  73. S[0x0200+((R>> 8)&0xff)])+ \
  74. S[0x0300+((R )&0xff)])&0xffffffffU \
  75. )
  76. #endif