Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cryptoLayer.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _MATRIXSSL_CRYPTOLAYER_H
  2. #define _MATRIXSSL_CRYPTOLAYER_H
  3. /** @file
  4. *
  5. * Compatibility layer for MatrixSSL
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <stddef.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <assert.h>
  14. #include <byteswap.h>
  15. #include <gpxe/bitops.h>
  16. #include <gpxe/crypto.h>
  17. /* Drag in pscrypto.h */
  18. typedef uint64_t ulong64;
  19. typedef void psPool_t;
  20. #define SMALL_CODE
  21. #define USE_INT64
  22. #define USE_RSA
  23. #define USE_RSA_PUBLIC_ENCRYPT
  24. #define CRYPT
  25. #include "matrixssl/pscrypto.h"
  26. #define SMALL_CODE
  27. #undef CLEAN_STACK
  28. #define sslAssert( ... ) assert ( __VA_ARGS__ )
  29. static inline __attribute__ (( always_inline )) void * __malloc
  30. psMalloc ( psPool_t *pool __unused, size_t len ) {
  31. return malloc ( len );
  32. }
  33. static inline __attribute__ (( always_inline )) void *
  34. psRealloc ( void *ptr, size_t len ) {
  35. return realloc ( ptr, len );
  36. }
  37. static inline __attribute__ (( always_inline )) void psFree ( void *ptr ) {
  38. free ( ptr );
  39. }
  40. #define matrixStrDebugMsg( ... ) DBG ( __VA_ARGS__ )
  41. #define matrixIntDebugMsg( ... ) DBG ( __VA_ARGS__ )
  42. /* Use our standard cpu_to_leXX etc. macros */
  43. #undef LOAD32L
  44. #define LOAD32L( cpu32, ptr ) do { \
  45. uint32_t *le32 = ( ( uint32_t * ) ptr ); \
  46. cpu32 = le32_to_cpu ( *le32 ); \
  47. } while ( 0 )
  48. #undef LOAD32H
  49. #define LOAD32H( cpu32, ptr ) do { \
  50. uint32_t *be32 = ( ( uint32_t * ) ptr ); \
  51. cpu32 = be32_to_cpu ( *be32 ); \
  52. } while ( 0 )
  53. #undef LOAD64L
  54. #define LOAD64L( cpu64, ptr ) do { \
  55. uint64_t *le64 = ( ( uint64_t * ) ptr ); \
  56. cpu64 = le64_to_cpu ( *le64 ); \
  57. } while ( 0 )
  58. #undef LOAD64H
  59. #define LOAD64H( cpu64, ptr ) do { \
  60. uint64_t *be64 = ( ( uint64_t * ) ptr ); \
  61. cpu64 = be64_to_cpu ( *be64 ); \
  62. } while ( 0 )
  63. #undef STORE32L
  64. #define STORE32L( cpu32, ptr ) do { \
  65. uint32_t *le32 = ( ( uint32_t * ) ptr ); \
  66. *le32 = cpu_to_le32 ( cpu32 ); \
  67. } while ( 0 )
  68. #undef STORE32H
  69. #define STORE32H( cpu32, ptr ) do { \
  70. uint32_t *be32 = ( ( uint32_t * ) ptr ); \
  71. *be32 = cpu_to_be32 ( cpu32 ); \
  72. } while ( 0 )
  73. #undef STORE64L
  74. #define STORE64L( cpu64, ptr ) do { \
  75. uint64_t *le64 = ( ( uint64_t * ) ptr ); \
  76. *le64 = cpu_to_le64 ( cpu64 ); \
  77. } while ( 0 )
  78. #undef STORE64H
  79. #define STORE64H( cpu64, ptr ) do { \
  80. uint64_t *be64 = ( ( uint64_t * ) ptr ); \
  81. *be64 = cpu_to_be64 ( cpu64 ); \
  82. } while ( 0 )
  83. /* Use rolXX etc. from bitops.h */
  84. #undef ROL
  85. #define ROL( data, rotation ) rol32 ( (data), (rotation) )
  86. #undef ROLc
  87. #define ROLc( data, rotation ) rol32 ( (data), (rotation) )
  88. #undef ROR
  89. #define ROR( data, rotation ) ror32 ( (data), (rotation) )
  90. #undef RORc
  91. #define RORc( data, rotation ) ror32 ( (data), (rotation) )
  92. #undef ROL64
  93. #define ROL64( data, rotation ) rol64 ( (data), (rotation) )
  94. #undef ROL64c
  95. #define ROL64c( data, rotation ) rol64 ( (data), (rotation) )
  96. #undef ROR64
  97. #define ROR64( data, rotation ) ror64 ( (data), (rotation) )
  98. #undef ROR64c
  99. #define ROR64c( data, rotation ) ror64 ( (data), (rotation) )
  100. #endif /* _MATRIXSSL_CRYPTOLAYER_H */