1 /*
2 * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
3 */
4 #include <getopt.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <strings.h>
8 #include "test_ae.h"
9 #include "test_otp_key_crypto.h"
10 #include "test_throughput.h"
11 #include "test_cipher.h"
12 #include "test_crypto_mem.h"
13 #include "test_hash.h"
14 #include "test_random.h"
15 #include "test_stress.h"
16 #include "test_multi.h"
17 #include "test_rsa.h"
18
19 enum {
20 OPTION_TOP = 0,
21 ALL,
22 CIPHER,
23 AEAD,
24 HASH,
25 HMAC,
26 SETKEY,
27 OTPKEY,
28 MEM,
29 RANDOM,
30 THROUGHPUT,
31 STRESS,
32 MULTI,
33 RSA,
34 OPTION_BUTT,
35 };
36
guide(void)37 static void guide(void)
38 {
39 printf("\n######## rkcrypto api test ########\n");
40 printf("%s\n", RK_CRYPTO_API_FULL_VERSION);
41
42 printf("Entry one parameter as follow:\n");
43 printf("\t-all Function of all ciphers\n");
44 printf("\t-cipher Function of cipher\n");
45 printf("\t-aead Function of aead\n");
46 printf("\t-hash Function of hash\n");
47 printf("\t-hmac Function of hmac\n");
48 printf("\t-rsa Function of rsa\n");
49 printf("\t-setkey Function of setkey. NOTE: it will write key to OTP area.\n");
50 printf("\t-otpkey Function of otpkey\n");
51 printf("\t-mem Maximum buffer size requested by crypto mem alloc, test until alloc failed\n");
52 printf("\t-random Function of get random\n");
53 printf("\t-throughput Throughput of all ciphers, MB/s\n");
54 printf("\t-stress [cnt] stress cnt times of all cipher/hash/hmac\n");
55 }
56
main(int argc,char * argv[])57 int main(int argc, char *argv[])
58 {
59 int opt;
60 int option_index = 0;
61 int stress_cnt = 1;
62 int verbose = 1;
63 static struct option long_options[] = {
64 {"all", 0, NULL, ALL},
65 {"cipher", 0, NULL, CIPHER},
66 {"aead", 0, NULL, AEAD},
67 {"hash", 0, NULL, HASH},
68 {"hmac", 0, NULL, HMAC},
69 {"setkey", 0, NULL, SETKEY},
70 {"otpkey", 0, NULL, OTPKEY},
71 {"mem", 0, NULL, MEM},
72 {"random", 0, NULL, RANDOM},
73 {"throughput", 0, NULL, THROUGHPUT},
74 {"stress", 1, NULL, STRESS},
75 {"multi", 0, NULL, MULTI},
76 {"rsa", 0, NULL, RSA},
77 {NULL, 0, NULL, 0},
78 };
79
80 if (argc < 2)
81 guide();
82
83 while ((opt = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
84 switch (opt) {
85 case ALL:
86 test_cipher(verbose);
87 test_ae(verbose);
88 test_hash(verbose);
89 test_hmac(verbose);
90 test_rsa(verbose);
91 test_write_otp_key();
92 test_otp_key();
93 test_crypto_mem();
94 break;
95 case CIPHER:
96 test_cipher(verbose);
97 break;
98 case AEAD:
99 test_ae(verbose);
100 break;
101 case HASH:
102 test_hash(verbose);
103 break;
104 case HMAC:
105 test_hmac(verbose);
106 break;
107 case RSA:
108 test_rsa(verbose);
109 break;
110 case SETKEY:
111 test_write_otp_key();
112 break;
113 case OTPKEY:
114 test_otp_key();
115 break;
116 case MEM:
117 test_crypto_mem();
118 break;
119 case RANDOM:
120 test_random();
121 break;
122 case THROUGHPUT:
123 test_throughput();
124 break;
125 case STRESS:
126 stress_cnt = atoi(optarg);
127 stress_test(stress_cnt);
128 break;
129 case MULTI:
130 test_multi();
131 break;
132 case '?':
133 guide();
134 break;
135 default:
136 break;
137 }
138
139 }
140
141 printf("\n######## Test done ########\n");
142
143 return 0;
144 }
145