pk_internal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * \file pk_internal.h
  3. *
  4. * \brief Public Key abstraction layer: wrapper functions
  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_WRAP_H
  23. #define MBEDTLS_PK_WRAP_H
  24. #if !defined(MBEDTLS_CONFIG_FILE)
  25. #include "mbedtls/config.h"
  26. #else
  27. #include MBEDTLS_CONFIG_FILE
  28. #endif
  29. #include "mbedtls/pk.h"
  30. struct mbedtls_pk_info_t
  31. {
  32. /** Public key type */
  33. mbedtls_pk_type_t type;
  34. /** Type name */
  35. const char *name;
  36. /** Get key size in bits */
  37. size_t (*get_bitlen)( const void * );
  38. /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
  39. int (*can_do)( mbedtls_pk_type_t type );
  40. /** Verify signature */
  41. int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
  42. const unsigned char *hash, size_t hash_len,
  43. const unsigned char *sig, size_t sig_len );
  44. /** Make signature */
  45. int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
  46. const unsigned char *hash, size_t hash_len,
  47. unsigned char *sig, size_t *sig_len,
  48. int (*f_rng)(void *, unsigned char *, size_t),
  49. void *p_rng );
  50. #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
  51. /** Verify signature (restartable) */
  52. int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
  53. const unsigned char *hash, size_t hash_len,
  54. const unsigned char *sig, size_t sig_len,
  55. void *rs_ctx );
  56. /** Make signature (restartable) */
  57. int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
  58. const unsigned char *hash, size_t hash_len,
  59. unsigned char *sig, size_t *sig_len,
  60. int (*f_rng)(void *, unsigned char *, size_t),
  61. void *p_rng, void *rs_ctx );
  62. #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
  63. /** Decrypt message */
  64. int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  65. unsigned char *output, size_t *olen, size_t osize,
  66. int (*f_rng)(void *, unsigned char *, size_t),
  67. void *p_rng );
  68. /** Encrypt message */
  69. int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  70. unsigned char *output, size_t *olen, size_t osize,
  71. int (*f_rng)(void *, unsigned char *, size_t),
  72. void *p_rng );
  73. /** Check public-private key pair */
  74. int (*check_pair_func)( const void *pub, const void *prv );
  75. /** Allocate a new context */
  76. void * (*ctx_alloc_func)( void );
  77. /** Free the given context */
  78. void (*ctx_free_func)( void *ctx );
  79. #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
  80. /** Allocate the restart context */
  81. void * (*rs_alloc_func)( void );
  82. /** Free the restart context */
  83. void (*rs_free_func)( void *rs_ctx );
  84. #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
  85. /** Interface with the debug module */
  86. void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
  87. };
  88. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  89. /* Container for RSA-alt */
  90. typedef struct
  91. {
  92. void *key;
  93. mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
  94. mbedtls_pk_rsa_alt_sign_func sign_func;
  95. mbedtls_pk_rsa_alt_key_len_func key_len_func;
  96. } mbedtls_rsa_alt_context;
  97. #endif
  98. #if defined(MBEDTLS_RSA_C)
  99. extern const mbedtls_pk_info_t mbedtls_rsa_info;
  100. #endif
  101. #if defined(MBEDTLS_ECP_C)
  102. extern const mbedtls_pk_info_t mbedtls_eckey_info;
  103. extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
  104. #endif
  105. #if defined(MBEDTLS_ECDSA_C)
  106. extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
  107. #endif
  108. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  109. extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
  110. #endif
  111. #if defined(MBEDTLS_USE_PSA_CRYPTO)
  112. extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
  113. #endif
  114. #endif /* MBEDTLS_PK_WRAP_H */