pk_wrap.h 4.6 KB

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