blob: 548a9f3e75db615af097ea210fe8a9ec77f50a3a [file] [log] [blame]
developer70436792023-05-19 09:31:20 +08001/*
2 * Copyright 2012-2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include <openssl/bio.h>
11#include <openssl/evp.h>
12#include <openssl/engine.h>
13#include <openssl/x509.h>
14#include <openssl/x509v3.h>
15#include <openssl/pem.h>
16#include <openssl/pkcs12.h>
17#include <openssl/safestack.h>
18#include <openssl/err.h>
19#include <openssl/bn.h>
20#include <openssl/ssl.h>
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sys/types.h>
26#include <ctype.h>
27#include <errno.h>
28#include <unistd.h>
29
30#include "common.h"
31#include "aesgcm.h"
32#include "aesccm.h"
33
34int main(int argc, char **argv)
35{
36 ENGINE *e;
37 int opt;
38
39 e = setup_engine();
40 if (e == NULL) {
41 printf("engine set error\n");
42 return 0;
43 }
44
45 while ((opt = getopt(argc, argv, "a:c:def:i:k:l:n:p:t:g:")) > 0) {
46 switch (opt) {
47 case 'a':
48 input_data.add = optarg;
49 input_data.add_len = strlen(optarg);
50 break;
51 case 'd':
52 input_data.oper = DECRYPT;
53 break;
54 case 'e':
55 input_data.oper = ENCRYPT;
56 break;
57 case 'i':
58 input_data.iv = optarg;
59 input_data.iv_len = strlen(optarg);
60 break;
61 case 'k':
62 input_data.key = optarg;
63 input_data.key_len = strlen(optarg);
64 if (!(input_data.key_len == 32 || input_data.key_len == 48
65 || input_data.key_len == 64)) {
66 printf("Key size must be 128, 192 or 256 .\n");
67 return 0;
68 }
69 case 'n':
70 input_data.nonce = optarg;
71 input_data.nonce_len = strlen(optarg);
72 break;
73 case 'c':
74 input_data.ct = optarg;
75 input_data.ct_len = strlen(optarg);
76 break;
77 case 't':
78 input_data.tag = optarg;
79 input_data.tag_len = strlen(optarg);
80 break;
81 case 'f':
82 input_data.adata = optarg;
83 input_data.adata_len = strlen(optarg);
84 break;
85 case 'l':
86 input_data.payload = optarg;
87 input_data.payload_len = strlen(optarg);
88 break;
89 case 'p':
90 input_data.pt = optarg;
91 input_data.pt_len = strlen(optarg);
92 break;
93 case 'g':
94 input_data.tag_output_size = atoi(optarg);
95 break;
96 case '?':
97 usage();
98 default:
99 break;
100 }
101
102 }
103 if (argc > optind) {
104 if (strncmp("gcm", argv[optind], 3) == 0) {
105 input_data.algo = GCM;
106 } else if (strncmp("ccm", argv[optind], 3) == 0) {
107 input_data.algo = CCM;
108 } else {
109 printf("parameter error !!\n");
110 usage();
111 return 0;
112 }
113 } else {
114 printf("select algorithm gcm or ccm\n");
115 usage();
116 return 0;
117 }
118 init_algo_data();
119 do_operation();
120
121 return 0;
122}