PageRenderTime 122ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/crypto/amcc/crypto4xx_sa.c

https://bitbucket.org/cresqo/cm7-p500-kernel
C | 108 lines | 76 code | 11 blank | 21 comment | 8 complexity | 3bd0f83f306ba0a0b810cb6f13bc6ab3 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /**
  2. * AMCC SoC PPC4xx Crypto Driver
  3. *
  4. * Copyright (c) 2008 Applied Micro Circuits Corporation.
  5. * All rights reserved. James Hsiao <jhsiao@amcc.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * @file crypto4xx_sa.c
  18. *
  19. * This file implements the security context
  20. * assoicate format.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/mod_devicetable.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/spinlock_types.h>
  28. #include <linux/highmem.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/crypto.h>
  31. #include <crypto/algapi.h>
  32. #include <crypto/des.h>
  33. #include "crypto4xx_reg_def.h"
  34. #include "crypto4xx_sa.h"
  35. #include "crypto4xx_core.h"
  36. u32 get_dynamic_sa_offset_iv_field(struct crypto4xx_ctx *ctx)
  37. {
  38. u32 offset;
  39. union dynamic_sa_contents cts;
  40. if (ctx->direction == DIR_INBOUND)
  41. cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
  42. else
  43. cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;
  44. offset = cts.bf.key_size
  45. + cts.bf.inner_size
  46. + cts.bf.outer_size
  47. + cts.bf.spi
  48. + cts.bf.seq_num0
  49. + cts.bf.seq_num1
  50. + cts.bf.seq_num_mask0
  51. + cts.bf.seq_num_mask1
  52. + cts.bf.seq_num_mask2
  53. + cts.bf.seq_num_mask3;
  54. return sizeof(struct dynamic_sa_ctl) + offset * 4;
  55. }
  56. u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)
  57. {
  58. u32 offset;
  59. union dynamic_sa_contents cts;
  60. if (ctx->direction == DIR_INBOUND)
  61. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
  62. else
  63. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
  64. offset = cts.bf.key_size
  65. + cts.bf.inner_size
  66. + cts.bf.outer_size
  67. + cts.bf.spi
  68. + cts.bf.seq_num0
  69. + cts.bf.seq_num1
  70. + cts.bf.seq_num_mask0
  71. + cts.bf.seq_num_mask1
  72. + cts.bf.seq_num_mask2
  73. + cts.bf.seq_num_mask3
  74. + cts.bf.iv0
  75. + cts.bf.iv1
  76. + cts.bf.iv2
  77. + cts.bf.iv3;
  78. return sizeof(struct dynamic_sa_ctl) + offset * 4;
  79. }
  80. u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
  81. {
  82. union dynamic_sa_contents cts;
  83. if (ctx->direction == DIR_INBOUND)
  84. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
  85. else
  86. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
  87. return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
  88. }
  89. u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
  90. {
  91. union dynamic_sa_contents cts;
  92. if (ctx->direction == DIR_INBOUND)
  93. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
  94. else
  95. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
  96. return sizeof(struct dynamic_sa_ctl);
  97. }