pk_internal.h 4.5 KB

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