caamhash_desc.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Shared descriptors for ahash algorithms
  4. *
  5. * Copyright 2017 NXP
  6. */
  7. #include "compat.h"
  8. #include "desc_constr.h"
  9. #include "caamhash_desc.h"
  10. /**
  11. * cnstr_shdsc_ahash - ahash shared descriptor
  12. * @desc: pointer to buffer used for descriptor construction
  13. * @adata: pointer to authentication transform definitions.
  14. * A split key is required for SEC Era < 6; the size of the split key
  15. * is specified in this case.
  16. * Valid algorithm values - one of OP_ALG_ALGSEL_{MD5, SHA1, SHA224,
  17. * SHA256, SHA384, SHA512}.
  18. * @state: algorithm state OP_ALG_AS_{INIT, FINALIZE, INITFINALIZE, UPDATE}
  19. * @digestsize: algorithm's digest size
  20. * @ctx_len: size of Context Register
  21. * @import_ctx: true if previous Context Register needs to be restored
  22. * must be true for ahash update and final
  23. * must be false for for ahash first and digest
  24. * @era: SEC Era
  25. */
  26. void cnstr_shdsc_ahash(u32 * const desc, struct alginfo *adata, u32 state,
  27. int digestsize, int ctx_len, bool import_ctx, int era)
  28. {
  29. u32 op = adata->algtype;
  30. init_sh_desc(desc, HDR_SHARE_SERIAL);
  31. /* Append key if it has been set; ahash update excluded */
  32. if (state != OP_ALG_AS_UPDATE && adata->keylen) {
  33. u32 *skip_key_load;
  34. /* Skip key loading if already shared */
  35. skip_key_load = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
  36. JUMP_COND_SHRD);
  37. if (era < 6)
  38. append_key_as_imm(desc, adata->key_virt,
  39. adata->keylen_pad,
  40. adata->keylen, CLASS_2 |
  41. KEY_DEST_MDHA_SPLIT | KEY_ENC);
  42. else
  43. append_proto_dkp(desc, adata);
  44. set_jump_tgt_here(desc, skip_key_load);
  45. op |= OP_ALG_AAI_HMAC_PRECOMP;
  46. }
  47. /* If needed, import context from software */
  48. if (import_ctx)
  49. append_seq_load(desc, ctx_len, LDST_CLASS_2_CCB |
  50. LDST_SRCDST_BYTE_CONTEXT);
  51. /* Class 2 operation */
  52. append_operation(desc, op | state | OP_ALG_ENCRYPT);
  53. /*
  54. * Load from buf and/or src and write to req->result or state->context
  55. * Calculate remaining bytes to read
  56. */
  57. append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
  58. /* Read remaining bytes */
  59. append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_LAST2 |
  60. FIFOLD_TYPE_MSG | KEY_VLF);
  61. /* Store class2 context bytes */
  62. append_seq_store(desc, digestsize, LDST_CLASS_2_CCB |
  63. LDST_SRCDST_BYTE_CONTEXT);
  64. }
  65. EXPORT_SYMBOL(cnstr_shdsc_ahash);
  66. MODULE_LICENSE("Dual BSD/GPL");
  67. MODULE_DESCRIPTION("FSL CAAM ahash descriptors support");
  68. MODULE_AUTHOR("NXP Semiconductors");