crypto4xx_sa.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * associate 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_state_ptr_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. + cts.bf.iv0
  55. + cts.bf.iv1
  56. + cts.bf.iv2
  57. + cts.bf.iv3;
  58. return sizeof(struct dynamic_sa_ctl) + offset * 4;
  59. }
  60. u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
  61. {
  62. union dynamic_sa_contents cts;
  63. if (ctx->direction == DIR_INBOUND)
  64. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
  65. else
  66. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
  67. return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
  68. }
  69. u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
  70. {
  71. union dynamic_sa_contents cts;
  72. if (ctx->direction == DIR_INBOUND)
  73. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
  74. else
  75. cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
  76. return sizeof(struct dynamic_sa_ctl);
  77. }