rsa.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2013, Google Inc.
  3. *
  4. * (C) Copyright 2008 Semihalf
  5. *
  6. * (C) Copyright 2000-2006
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #ifndef _RSA_H
  12. #define _RSA_H
  13. #include <errno.h>
  14. #include <image.h>
  15. #if IMAGE_ENABLE_SIGN
  16. /**
  17. * sign() - calculate and return signature for given input data
  18. *
  19. * @info: Specifies key and FIT information
  20. * @data: Pointer to the input data
  21. * @data_len: Data length
  22. * @sigp: Set to an allocated buffer holding the signature
  23. * @sig_len: Set to length of the calculated hash
  24. *
  25. * This computes input data signature according to selected algorithm.
  26. * Resulting signature value is placed in an allocated buffer, the
  27. * pointer is returned as *sigp. The length of the calculated
  28. * signature is returned via the sig_len pointer argument. The caller
  29. * should free *sigp.
  30. *
  31. * @return: 0, on success, -ve on error
  32. */
  33. int rsa_sign(struct image_sign_info *info,
  34. const struct image_region region[],
  35. int region_count, uint8_t **sigp, uint *sig_len);
  36. /**
  37. * add_verify_data() - Add verification information to FDT
  38. *
  39. * Add public key information to the FDT node, suitable for
  40. * verification at run-time. The information added depends on the
  41. * algorithm being used.
  42. *
  43. * @info: Specifies key and FIT information
  44. * @keydest: Destination FDT blob for public key data
  45. * @return: 0, on success, -ve on error
  46. */
  47. int rsa_add_verify_data(struct image_sign_info *info, void *keydest);
  48. #else
  49. static inline int rsa_sign(struct image_sign_info *info,
  50. const struct image_region region[], int region_count,
  51. uint8_t **sigp, uint *sig_len)
  52. {
  53. return -ENXIO;
  54. }
  55. static inline int rsa_add_verify_data(struct image_sign_info *info,
  56. void *keydest)
  57. {
  58. return -ENXIO;
  59. }
  60. #endif
  61. #if IMAGE_ENABLE_VERIFY
  62. /**
  63. * rsa_verify() - Verify a signature against some data
  64. *
  65. * Verify a RSA PKCS1.5 signature against an expected hash.
  66. *
  67. * @info: Specifies key and FIT information
  68. * @data: Pointer to the input data
  69. * @data_len: Data length
  70. * @sig: Signature
  71. * @sig_len: Number of bytes in signature
  72. * @return 0 if verified, -ve on error
  73. */
  74. int rsa_verify(struct image_sign_info *info,
  75. const struct image_region region[], int region_count,
  76. uint8_t *sig, uint sig_len);
  77. #else
  78. static inline int rsa_verify(struct image_sign_info *info,
  79. const struct image_region region[], int region_count,
  80. uint8_t *sig, uint sig_len)
  81. {
  82. return -ENXIO;
  83. }
  84. #endif
  85. #endif