auth_common.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef AUTH_COMMON_H
  7. #define AUTH_COMMON_H
  8. /*
  9. * Authentication framework common types
  10. */
  11. /*
  12. * Type of parameters that can be extracted from an image and
  13. * used for authentication
  14. */
  15. typedef enum auth_param_type_enum {
  16. AUTH_PARAM_NONE,
  17. AUTH_PARAM_RAW_DATA, /* Raw image data */
  18. AUTH_PARAM_SIG, /* The image signature */
  19. AUTH_PARAM_SIG_ALG, /* The image signature algorithm */
  20. AUTH_PARAM_HASH, /* A hash (including the algorithm) */
  21. AUTH_PARAM_PUB_KEY, /* A public key */
  22. AUTH_PARAM_NV_CTR, /* A non-volatile counter */
  23. } auth_param_type_t;
  24. /*
  25. * Defines an authentication parameter. The cookie will be interpreted by the
  26. * image parser module.
  27. */
  28. typedef struct auth_param_type_desc_s {
  29. auth_param_type_t type;
  30. void *cookie;
  31. } auth_param_type_desc_t;
  32. /*
  33. * Store a pointer to the authentication parameter and its length
  34. */
  35. typedef struct auth_param_data_desc_s {
  36. void *ptr;
  37. unsigned int len;
  38. } auth_param_data_desc_t;
  39. /*
  40. * Authentication parameter descriptor, including type and value
  41. */
  42. typedef struct auth_param_desc_s {
  43. auth_param_type_desc_t *type_desc;
  44. auth_param_data_desc_t data;
  45. } auth_param_desc_t;
  46. /*
  47. * The method type defines how an image is authenticated
  48. */
  49. typedef enum auth_method_type_enum {
  50. AUTH_METHOD_NONE = 0,
  51. AUTH_METHOD_HASH, /* Authenticate by hash matching */
  52. AUTH_METHOD_SIG, /* Authenticate by PK operation */
  53. AUTH_METHOD_NV_CTR, /* Authenticate by Non-Volatile Counter */
  54. AUTH_METHOD_NUM /* Number of methods */
  55. } auth_method_type_t;
  56. /*
  57. * Parameters for authentication by hash matching
  58. */
  59. typedef struct auth_method_param_hash_s {
  60. auth_param_type_desc_t *data; /* Data to hash */
  61. auth_param_type_desc_t *hash; /* Hash to match with */
  62. } auth_method_param_hash_t;
  63. /*
  64. * Parameters for authentication by signature
  65. */
  66. typedef struct auth_method_param_sig_s {
  67. auth_param_type_desc_t *pk; /* Public key */
  68. auth_param_type_desc_t *sig; /* Signature to check */
  69. auth_param_type_desc_t *alg; /* Signature algorithm */
  70. auth_param_type_desc_t *data; /* Data signed */
  71. } auth_method_param_sig_t;
  72. /*
  73. * Parameters for authentication by NV counter
  74. */
  75. typedef struct auth_method_param_nv_ctr_s {
  76. auth_param_type_desc_t *cert_nv_ctr; /* NV counter in certificate */
  77. auth_param_type_desc_t *plat_nv_ctr; /* NV counter in platform */
  78. } auth_method_param_nv_ctr_t;
  79. /*
  80. * Authentication method descriptor
  81. */
  82. typedef struct auth_method_desc_s {
  83. auth_method_type_t type;
  84. union {
  85. auth_method_param_hash_t hash;
  86. auth_method_param_sig_t sig;
  87. auth_method_param_nv_ctr_t nv_ctr;
  88. } param;
  89. } auth_method_desc_t;
  90. /*
  91. * Helper macro to define an authentication parameter type descriptor
  92. */
  93. #define AUTH_PARAM_TYPE_DESC(_type, _cookie) \
  94. { \
  95. .type = _type, \
  96. .cookie = (void *)_cookie \
  97. }
  98. /*
  99. * Helper macro to define an authentication parameter data descriptor
  100. */
  101. #define AUTH_PARAM_DATA_DESC(_ptr, _len) \
  102. { \
  103. .ptr = (void *)_ptr, \
  104. .len = (unsigned int)_len \
  105. }
  106. #endif /* AUTH_COMMON_H */