pkcs12.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * \file pkcs12.h
  3. *
  4. * \brief PKCS#12 Personal Information Exchange Syntax
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: GPL-2.0
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * This file is part of mbed TLS (https://tls.mbed.org)
  24. */
  25. #ifndef MBEDTLS_PKCS12_H
  26. #define MBEDTLS_PKCS12_H
  27. #include "md.h"
  28. #include "cipher.h"
  29. #include "asn1.h"
  30. #include <stddef.h>
  31. #define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
  32. #define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
  33. #define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
  34. #define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
  35. #define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
  36. #define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
  37. #define MBEDTLS_PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
  38. #define MBEDTLS_PKCS12_PBE_DECRYPT 0
  39. #define MBEDTLS_PKCS12_PBE_ENCRYPT 1
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * \brief PKCS12 Password Based function (encryption / decryption)
  45. * for pbeWithSHAAnd128BitRC4
  46. *
  47. * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
  48. * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
  49. * \param pwd the password used (may be NULL if no password is used)
  50. * \param pwdlen length of the password (may be 0)
  51. * \param input the input data
  52. * \param len data length
  53. * \param output the output buffer
  54. *
  55. * \return 0 if successful, or a MBEDTLS_ERR_XXX code
  56. */
  57. int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
  58. const unsigned char *pwd, size_t pwdlen,
  59. const unsigned char *input, size_t len,
  60. unsigned char *output );
  61. /**
  62. * \brief PKCS12 Password Based function (encryption / decryption)
  63. * for cipher-based and mbedtls_md-based PBE's
  64. *
  65. * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
  66. * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
  67. * \param cipher_type the cipher used
  68. * \param md_type the mbedtls_md used
  69. * \param pwd the password used (may be NULL if no password is used)
  70. * \param pwdlen length of the password (may be 0)
  71. * \param input the input data
  72. * \param len data length
  73. * \param output the output buffer
  74. *
  75. * \return 0 if successful, or a MBEDTLS_ERR_XXX code
  76. */
  77. int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
  78. mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type,
  79. const unsigned char *pwd, size_t pwdlen,
  80. const unsigned char *input, size_t len,
  81. unsigned char *output );
  82. /**
  83. * \brief The PKCS#12 derivation function uses a password and a salt
  84. * to produce pseudo-random bits for a particular "purpose".
  85. *
  86. * Depending on the given id, this function can produce an
  87. * encryption/decryption key, an nitialization vector or an
  88. * integrity key.
  89. *
  90. * \param data buffer to store the derived data in
  91. * \param datalen length to fill
  92. * \param pwd password to use (may be NULL if no password is used)
  93. * \param pwdlen length of the password (may be 0)
  94. * \param salt salt buffer to use
  95. * \param saltlen length of the salt
  96. * \param mbedtls_md mbedtls_md type to use during the derivation
  97. * \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
  98. * MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
  99. * \param iterations number of iterations
  100. *
  101. * \return 0 if successful, or a MD, BIGNUM type error.
  102. */
  103. int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
  104. const unsigned char *pwd, size_t pwdlen,
  105. const unsigned char *salt, size_t saltlen,
  106. mbedtls_md_type_t mbedtls_md, int id, int iterations );
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* pkcs12.h */