seed_local.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2007-2018 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. /*
  10. * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Neither the name of author nor the names of its contributors may
  18. * be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. */
  34. #ifndef OSSL_CRYPTO_SEED_LOCAL_H
  35. # define OSSL_CRYPTO_SEED_LOCAL_H
  36. # include "openssl/e_os2.h"
  37. # include <openssl/seed.h>
  38. # ifdef SEED_LONG /* need 32-bit type */
  39. typedef unsigned long seed_word;
  40. # else
  41. typedef unsigned int seed_word;
  42. # endif
  43. # define char2word(c, i) \
  44. (i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3]))
  45. # define word2char(l, c) \
  46. *((c)+0) = (unsigned char)((l)>>24) & 0xff; \
  47. *((c)+1) = (unsigned char)((l)>>16) & 0xff; \
  48. *((c)+2) = (unsigned char)((l)>> 8) & 0xff; \
  49. *((c)+3) = (unsigned char)((l)) & 0xff
  50. # define KEYSCHEDULE_UPDATE0(T0, T1, X1, X2, X3, X4, KC) \
  51. (T0) = (X3); \
  52. (X3) = (((X3)<<8) ^ ((X4)>>24)) & 0xffffffff; \
  53. (X4) = (((X4)<<8) ^ ((T0)>>24)) & 0xffffffff; \
  54. (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \
  55. (T1) = ((X2) + (KC) - (X4)) & 0xffffffff
  56. # define KEYSCHEDULE_UPDATE1(T0, T1, X1, X2, X3, X4, KC) \
  57. (T0) = (X1); \
  58. (X1) = (((X1)>>8) ^ ((X2)<<24)) & 0xffffffff; \
  59. (X2) = (((X2)>>8) ^ ((T0)<<24)) & 0xffffffff; \
  60. (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \
  61. (T1) = ((X2) + (KC) - (X4)) & 0xffffffff
  62. # define KEYUPDATE_TEMP(T0, T1, K) \
  63. (K)[0] = G_FUNC((T0)); \
  64. (K)[1] = G_FUNC((T1))
  65. # define XOR_SEEDBLOCK(DST, SRC) \
  66. ((DST))[0] ^= ((SRC))[0]; \
  67. ((DST))[1] ^= ((SRC))[1]; \
  68. ((DST))[2] ^= ((SRC))[2]; \
  69. ((DST))[3] ^= ((SRC))[3]
  70. # define MOV_SEEDBLOCK(DST, SRC) \
  71. ((DST))[0] = ((SRC))[0]; \
  72. ((DST))[1] = ((SRC))[1]; \
  73. ((DST))[2] = ((SRC))[2]; \
  74. ((DST))[3] = ((SRC))[3]
  75. # define CHAR2WORD(C, I) \
  76. char2word((C), (I)[0]); \
  77. char2word((C+4), (I)[1]); \
  78. char2word((C+8), (I)[2]); \
  79. char2word((C+12), (I)[3])
  80. # define WORD2CHAR(I, C) \
  81. word2char((I)[0], (C)); \
  82. word2char((I)[1], (C+4)); \
  83. word2char((I)[2], (C+8)); \
  84. word2char((I)[3], (C+12))
  85. # define E_SEED(T0, T1, X1, X2, X3, X4, rbase) \
  86. (T0) = (X3) ^ (ks->data)[(rbase)]; \
  87. (T1) = (X4) ^ (ks->data)[(rbase)+1]; \
  88. (T1) ^= (T0); \
  89. (T1) = G_FUNC((T1)); \
  90. (T0) = ((T0) + (T1)) & 0xffffffff; \
  91. (T0) = G_FUNC((T0)); \
  92. (T1) = ((T1) + (T0)) & 0xffffffff; \
  93. (T1) = G_FUNC((T1)); \
  94. (T0) = ((T0) + (T1)) & 0xffffffff; \
  95. (X1) ^= (T0); \
  96. (X2) ^= (T1)
  97. #endif /* OSSL_CRYPTO_SEED_LOCAL_H */