caampkc.h 4.0 KB

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