2
0

idea_local.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define idea_mul(r,a,b,ul) \
  10. ul=(unsigned long)a*b; \
  11. if (ul != 0) \
  12. { \
  13. r=(ul&0xffff)-(ul>>16); \
  14. r-=((r)>>16); \
  15. } \
  16. else \
  17. r=(-(int)a-b+1); /* assuming a or b is 0 and in range */
  18. /* NOTE - c is not incremented as per n2l */
  19. #define n2ln(c,l1,l2,n) { \
  20. c+=n; \
  21. l1=l2=0; \
  22. switch (n) { \
  23. case 8: l2 =((unsigned long)(*(--(c)))) ; \
  24. /* fall thru */ \
  25. case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
  26. /* fall thru */ \
  27. case 6: l2|=((unsigned long)(*(--(c))))<<16; \
  28. /* fall thru */ \
  29. case 5: l2|=((unsigned long)(*(--(c))))<<24; \
  30. /* fall thru */ \
  31. case 4: l1 =((unsigned long)(*(--(c)))) ; \
  32. /* fall thru */ \
  33. case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
  34. /* fall thru */ \
  35. case 2: l1|=((unsigned long)(*(--(c))))<<16; \
  36. /* fall thru */ \
  37. case 1: l1|=((unsigned long)(*(--(c))))<<24; \
  38. } \
  39. }
  40. /* NOTE - c is not incremented as per l2n */
  41. #define l2nn(l1,l2,c,n) { \
  42. c+=n; \
  43. switch (n) { \
  44. case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
  45. /* fall thru */ \
  46. case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
  47. /* fall thru */ \
  48. case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
  49. /* fall thru */ \
  50. case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
  51. /* fall thru */ \
  52. case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
  53. /* fall thru */ \
  54. case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
  55. /* fall thru */ \
  56. case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
  57. /* fall thru */ \
  58. case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
  59. } \
  60. }
  61. #undef n2l
  62. #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
  63. l|=((unsigned long)(*((c)++)))<<16L, \
  64. l|=((unsigned long)(*((c)++)))<< 8L, \
  65. l|=((unsigned long)(*((c)++))))
  66. #undef l2n
  67. #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
  68. *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
  69. *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
  70. *((c)++)=(unsigned char)(((l) )&0xff))
  71. #undef s2n
  72. #define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
  73. *((c)++)=(unsigned char)(((l)>> 8L)&0xff))
  74. #undef n2s
  75. #define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \
  76. l|=((IDEA_INT)(*((c)++))) )
  77. #define E_IDEA(num) \
  78. x1&=0xffff; \
  79. idea_mul(x1,x1,*p,ul); p++; \
  80. x2+= *(p++); \
  81. x3+= *(p++); \
  82. x4&=0xffff; \
  83. idea_mul(x4,x4,*p,ul); p++; \
  84. t0=(x1^x3)&0xffff; \
  85. idea_mul(t0,t0,*p,ul); p++; \
  86. t1=(t0+(x2^x4))&0xffff; \
  87. idea_mul(t1,t1,*p,ul); p++; \
  88. t0+=t1; \
  89. x1^=t1; \
  90. x4^=t0; \
  91. ul=x2^t0; /* do the swap to x3 */ \
  92. x2=x3^t1; \
  93. x3=ul;