pkwrite.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * \file pkwrite.h
  3. *
  4. * \brief Internal defines shared by the PK write module
  5. */
  6. /*
  7. * Copyright The Mbed TLS Contributors
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. #ifndef MBEDTLS_PK_WRITE_H
  23. #define MBEDTLS_PK_WRITE_H
  24. #include "mbedtls/build_info.h"
  25. #include "mbedtls/pk.h"
  26. /*
  27. * Max sizes of key per types. Shown as tag + len (+ content).
  28. */
  29. #if defined(MBEDTLS_RSA_C)
  30. /*
  31. * RSA public keys:
  32. * SubjectPublicKeyInfo ::= SEQUENCE { 1 + 3
  33. * algorithm AlgorithmIdentifier, 1 + 1 (sequence)
  34. * + 1 + 1 + 9 (rsa oid)
  35. * + 1 + 1 (params null)
  36. * subjectPublicKey BIT STRING } 1 + 3 + (1 + below)
  37. * RSAPublicKey ::= SEQUENCE { 1 + 3
  38. * modulus INTEGER, -- n 1 + 3 + MPI_MAX + 1
  39. * publicExponent INTEGER -- e 1 + 3 + MPI_MAX + 1
  40. * }
  41. */
  42. #define MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES (38 + 2 * MBEDTLS_MPI_MAX_SIZE)
  43. /*
  44. * RSA private keys:
  45. * RSAPrivateKey ::= SEQUENCE { 1 + 3
  46. * version Version, 1 + 1 + 1
  47. * modulus INTEGER, 1 + 3 + MPI_MAX + 1
  48. * publicExponent INTEGER, 1 + 3 + MPI_MAX + 1
  49. * privateExponent INTEGER, 1 + 3 + MPI_MAX + 1
  50. * prime1 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
  51. * prime2 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
  52. * exponent1 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
  53. * exponent2 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
  54. * coefficient INTEGER, 1 + 3 + MPI_MAX / 2 + 1
  55. * otherPrimeInfos OtherPrimeInfos OPTIONAL 0 (not supported)
  56. * }
  57. */
  58. #define MBEDTLS_MPI_MAX_SIZE_2 (MBEDTLS_MPI_MAX_SIZE / 2 + \
  59. MBEDTLS_MPI_MAX_SIZE % 2)
  60. #define MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES (47 + 3 * MBEDTLS_MPI_MAX_SIZE \
  61. + 5 * MBEDTLS_MPI_MAX_SIZE_2)
  62. #else /* MBEDTLS_RSA_C */
  63. #define MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES 0
  64. #define MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES 0
  65. #endif /* MBEDTLS_RSA_C */
  66. #if defined(MBEDTLS_ECP_C)
  67. /*
  68. * EC public keys:
  69. * SubjectPublicKeyInfo ::= SEQUENCE { 1 + 2
  70. * algorithm AlgorithmIdentifier, 1 + 1 (sequence)
  71. * + 1 + 1 + 7 (ec oid)
  72. * + 1 + 1 + 9 (namedCurve oid)
  73. * subjectPublicKey BIT STRING 1 + 2 + 1 [1]
  74. * + 1 (point format) [1]
  75. * + 2 * ECP_MAX (coords) [1]
  76. * }
  77. */
  78. #define MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES (30 + 2 * MBEDTLS_ECP_MAX_BYTES)
  79. /*
  80. * EC private keys:
  81. * ECPrivateKey ::= SEQUENCE { 1 + 2
  82. * version INTEGER , 1 + 1 + 1
  83. * privateKey OCTET STRING, 1 + 1 + ECP_MAX
  84. * parameters [0] ECParameters OPTIONAL, 1 + 1 + (1 + 1 + 9)
  85. * publicKey [1] BIT STRING OPTIONAL 1 + 2 + [1] above
  86. * }
  87. */
  88. #define MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES (29 + 3 * MBEDTLS_ECP_MAX_BYTES)
  89. #else /* MBEDTLS_ECP_C */
  90. #define MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES 0
  91. #define MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES 0
  92. #endif /* MBEDTLS_ECP_C */
  93. #endif /* MBEDTLS_PK_WRITE_H */