pk_internal.h 3.6 KB

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