kernel_driver.c (3424B)
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 45 #ifdef HAVE_CONFIG_H 46 #include <config.h> 47 #endif 48 49 #include <stdio.h> /* for printf() */ 50 #include "getopt_s.h" 51 #include "crypto_kernel.h" 52 53 void usage(char *prog_name) 54 { 55 printf("usage: %s [ -v ][ -d debug_module ]*\n", prog_name); 56 exit(255); 57 } 58 59 int main(int argc, char *argv[]) 60 { 61 int q; 62 int do_validation = 0; 63 srtp_err_status_t status; 64 65 if (argc == 1) 66 usage(argv[0]); 67 68 /* initialize kernel - we need to do this before anything else */ 69 status = srtp_crypto_kernel_init(); 70 if (status) { 71 printf("error: srtp_crypto_kernel init failed\n"); 72 exit(1); 73 } 74 printf("srtp_crypto_kernel successfully initalized\n"); 75 76 /* process input arguments */ 77 while (1) { 78 q = getopt_s(argc, argv, "vd:"); 79 if (q == -1) 80 break; 81 switch (q) { 82 case 'v': 83 do_validation = 1; 84 break; 85 case 'd': 86 status = srtp_crypto_kernel_set_debug_module(optarg_s, 1); 87 if (status) { 88 printf("error: set debug module (%s) failed\n", optarg_s); 89 exit(1); 90 } 91 break; 92 default: 93 usage(argv[0]); 94 } 95 } 96 97 if (do_validation) { 98 printf("checking srtp_crypto_kernel status...\n"); 99 status = srtp_crypto_kernel_status(); 100 if (status) { 101 printf("failed\n"); 102 exit(1); 103 } 104 printf("srtp_crypto_kernel passed self-tests\n"); 105 } 106 107 status = srtp_crypto_kernel_shutdown(); 108 if (status) { 109 printf("error: srtp_crypto_kernel shutdown failed\n"); 110 exit(1); 111 } 112 printf("srtp_crypto_kernel successfully shut down\n"); 113 114 return 0; 115 }