sys-stir-random.int.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /***********************************************************************
  3. * Copyright (c) 2017-2018, Intel Corporation
  4. *
  5. * All rights reserved.
  6. ***********************************************************************/
  7. #ifdef HAVE_CONFIG_H
  8. #include <config.h>
  9. #endif
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "tss2_sys.h"
  14. #define LOGMODULE test
  15. #include "util/log.h"
  16. #include "test.h"
  17. /**
  18. * This program contains integration test for SYS Tss2_Sys_StirRandom.
  19. * Since StirRandom is quite simple we can only check for success if we
  20. * supply correct parameters.
  21. */
  22. int
  23. test_invoke (TSS2_SYS_CONTEXT *sys_context)
  24. {
  25. TSS2_RC rc;
  26. TPM2B_SENSITIVE_DATA inData = {
  27. .size = 20,
  28. .buffer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  29. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
  30. };
  31. LOG_INFO("StirRandom tests started.");
  32. /* Check invalid context */
  33. rc = Tss2_Sys_StirRandom(NULL, 0, NULL, 0);
  34. if (rc != TSS2_SYS_RC_BAD_REFERENCE) {
  35. LOG_ERROR("StirRandom (ctx) FAILED! Response Code : %x", rc);
  36. exit(1);
  37. }
  38. /* check empty input data */
  39. rc = Tss2_Sys_StirRandom(sys_context, 0, NULL, 0);
  40. if (rc != TSS2_RC_SUCCESS) {
  41. LOG_ERROR("StirRandom (empty) FAILED! Response Code : %x", rc);
  42. exit(1);
  43. }
  44. /* check with correct input data*/
  45. rc = Tss2_Sys_StirRandom(sys_context, 0, &inData, 0);
  46. if (rc != TSS2_RC_SUCCESS) {
  47. LOG_ERROR("StirRandom (indata) FAILED! Response Code : %x", rc);
  48. exit(1);
  49. }
  50. LOG_INFO("StirRandom Test Passed!");
  51. return 0;
  52. }