pcprij128safe2.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2016 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #if !defined(_PCP_RIJ_SAFE2_H)
  32. #define _PCP_RIJ_SAFE2_H
  33. // transpose 4x4 Ipp8u matrix
  34. #define TRANSPOSE(out, inp) \
  35. (out)[ 0] = (inp)[ 0]; \
  36. (out)[ 4] = (inp)[ 1]; \
  37. (out)[ 8] = (inp)[ 2]; \
  38. (out)[12] = (inp)[ 3]; \
  39. \
  40. (out)[ 1] = (inp)[ 4]; \
  41. (out)[ 5] = (inp)[ 5]; \
  42. (out)[ 9] = (inp)[ 6]; \
  43. (out)[13] = (inp)[ 7]; \
  44. \
  45. (out)[ 2] = (inp)[ 8]; \
  46. (out)[ 6] = (inp)[ 9]; \
  47. (out)[10] = (inp)[10]; \
  48. (out)[14] = (inp)[11]; \
  49. \
  50. (out)[ 3] = (inp)[12]; \
  51. (out)[ 7] = (inp)[13]; \
  52. (out)[11] = (inp)[14]; \
  53. (out)[15] = (inp)[15]
  54. __INLINE void XorRoundKey(Ipp32u* state, const Ipp32u* RoundKey)
  55. {
  56. state[0] ^= RoundKey[0];
  57. state[1] ^= RoundKey[1];
  58. state[2] ^= RoundKey[2];
  59. state[3] ^= RoundKey[3];
  60. }
  61. // xtime is a macro that finds the product of {02} and the argument to xtime modulo {1b}
  62. __INLINE Ipp32u mask4(Ipp32u x)
  63. {
  64. x &= 0x80808080;
  65. return (Ipp32u)((x<<1) - (x>>7));
  66. }
  67. __INLINE Ipp32u xtime4(Ipp32u x)
  68. {
  69. Ipp32u t = (x+x) &0xFEFEFEFE;
  70. t ^= mask4(x) & 0x1B1B1B1B;
  71. return t;
  72. }
  73. #endif /* _PCP_RIJ_SAFE2_H */