2
0

kernel_driver.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * kernel_driver.c
  3. *
  4. * a test driver for the crypto_kernel
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright(c) 2001-2017 Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. #ifdef HAVE_CONFIG_H
  45. #include <config.h>
  46. #endif
  47. #include <stdio.h> /* for printf() */
  48. #include "getopt_s.h"
  49. #include "crypto_kernel.h"
  50. void usage(char *prog_name)
  51. {
  52. printf("usage: %s [ -v ][ -d debug_module ]*\n", prog_name);
  53. exit(255);
  54. }
  55. int main(int argc, char *argv[])
  56. {
  57. int q;
  58. int do_validation = 0;
  59. srtp_err_status_t status;
  60. if (argc == 1)
  61. usage(argv[0]);
  62. /* initialize kernel - we need to do this before anything else */
  63. status = srtp_crypto_kernel_init();
  64. if (status) {
  65. printf("error: srtp_crypto_kernel init failed\n");
  66. exit(1);
  67. }
  68. printf("srtp_crypto_kernel successfully initalized\n");
  69. /* process input arguments */
  70. while (1) {
  71. q = getopt_s(argc, argv, "vd:");
  72. if (q == -1)
  73. break;
  74. switch (q) {
  75. case 'v':
  76. do_validation = 1;
  77. break;
  78. case 'd':
  79. status = srtp_crypto_kernel_set_debug_module(optarg_s, 1);
  80. if (status) {
  81. printf("error: set debug module (%s) failed\n", optarg_s);
  82. exit(1);
  83. }
  84. break;
  85. default:
  86. usage(argv[0]);
  87. }
  88. }
  89. if (do_validation) {
  90. printf("checking srtp_crypto_kernel status...\n");
  91. status = srtp_crypto_kernel_status();
  92. if (status) {
  93. printf("failed\n");
  94. exit(1);
  95. }
  96. printf("srtp_crypto_kernel passed self-tests\n");
  97. }
  98. status = srtp_crypto_kernel_shutdown();
  99. if (status) {
  100. printf("error: srtp_crypto_kernel shutdown failed\n");
  101. exit(1);
  102. }
  103. printf("srtp_crypto_kernel successfully shut down\n");
  104. return 0;
  105. }
  106. /*
  107. * crypto_kernel_cipher_test() is a test of the cipher interface
  108. * of the crypto_kernel
  109. */
  110. srtp_err_status_t crypto_kernel_cipher_test(void)
  111. {
  112. /* not implemented yet! */
  113. return srtp_err_status_ok;
  114. }