caampkc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * caam - Freescale FSL CAAM support for Public Key Cryptography descriptors
  4. *
  5. * Copyright 2016 Freescale Semiconductor, Inc.
  6. *
  7. * There is no Shared Descriptor for PKC so that the Job Descriptor must carry
  8. * all the desired key parameters, input and output pointers.
  9. */
  10. #ifndef _PKC_DESC_H_
  11. #define _PKC_DESC_H_
  12. #include "compat.h"
  13. #include "pdb.h"
  14. /**
  15. * caam_priv_key_form - CAAM RSA private key representation
  16. * CAAM RSA private key may have either of three forms.
  17. *
  18. * 1. The first representation consists of the pair (n, d), where the
  19. * components have the following meanings:
  20. * n the RSA modulus
  21. * d the RSA private exponent
  22. *
  23. * 2. The second representation consists of the triplet (p, q, d), where the
  24. * components have the following meanings:
  25. * p the first prime factor of the RSA modulus n
  26. * q the second prime factor of the RSA modulus n
  27. * d the RSA private exponent
  28. *
  29. * 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv),
  30. * where the components have the following meanings:
  31. * p the first prime factor of the RSA modulus n
  32. * q the second prime factor of the RSA modulus n
  33. * dP the first factors's CRT exponent
  34. * dQ the second factors's CRT exponent
  35. * qInv the (first) CRT coefficient
  36. *
  37. * The benefit of using the third or the second key form is lower computational
  38. * cost for the decryption and signature operations.
  39. */
  40. enum caam_priv_key_form {
  41. FORM1,
  42. FORM2,
  43. FORM3
  44. };
  45. /**
  46. * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone.
  47. * @n : RSA modulus raw byte stream
  48. * @e : RSA public exponent raw byte stream
  49. * @d : RSA private exponent raw byte stream
  50. * @p : RSA prime factor p of RSA modulus n
  51. * @q : RSA prime factor q of RSA modulus n
  52. * @dp : RSA CRT exponent of p
  53. * @dp : RSA CRT exponent of q
  54. * @qinv : RSA CRT coefficient
  55. * @tmp1 : CAAM uses this temporary buffer as internal state buffer.
  56. * It is assumed to be as long as p.
  57. * @tmp2 : CAAM uses this temporary buffer as internal state buffer.
  58. * It is assumed to be as long as q.
  59. * @n_sz : length in bytes of RSA modulus n
  60. * @e_sz : length in bytes of RSA public exponent
  61. * @d_sz : length in bytes of RSA private exponent
  62. * @p_sz : length in bytes of RSA prime factor p of RSA modulus n
  63. * @q_sz : length in bytes of RSA prime factor q of RSA modulus n
  64. * @priv_form : CAAM RSA private key representation
  65. */
  66. struct caam_rsa_key {
  67. u8 *n;
  68. u8 *e;
  69. u8 *d;
  70. u8 *p;
  71. u8 *q;
  72. u8 *dp;
  73. u8 *dq;
  74. u8 *qinv;
  75. u8 *tmp1;
  76. u8 *tmp2;
  77. size_t n_sz;
  78. size_t e_sz;
  79. size_t d_sz;
  80. size_t p_sz;
  81. size_t q_sz;
  82. enum caam_priv_key_form priv_form;
  83. };
  84. /**
  85. * caam_rsa_ctx - per session context.
  86. * @key : RSA key in DMA zone
  87. * @dev : device structure
  88. */
  89. struct caam_rsa_ctx {
  90. struct caam_rsa_key key;
  91. struct device *dev;
  92. };
  93. /**
  94. * rsa_edesc - s/w-extended rsa descriptor
  95. * @src_nents : number of segments in input scatterlist
  96. * @dst_nents : number of segments in output scatterlist
  97. * @sec4_sg_bytes : length of h/w link table
  98. * @sec4_sg_dma : dma address of h/w link table
  99. * @sec4_sg : pointer to h/w link table
  100. * @pdb : specific RSA Protocol Data Block (PDB)
  101. * @hw_desc : descriptor followed by link tables if any
  102. */
  103. struct rsa_edesc {
  104. int src_nents;
  105. int dst_nents;
  106. int sec4_sg_bytes;
  107. dma_addr_t sec4_sg_dma;
  108. struct sec4_sg_entry *sec4_sg;
  109. union {
  110. struct rsa_pub_pdb pub;
  111. struct rsa_priv_f1_pdb priv_f1;
  112. struct rsa_priv_f2_pdb priv_f2;
  113. struct rsa_priv_f3_pdb priv_f3;
  114. } pdb;
  115. u32 hw_desc[];
  116. };
  117. /* Descriptor construction primitives. */
  118. void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb);
  119. void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb);
  120. void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb);
  121. void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb);
  122. #endif