Wed Jun 14 21:43:02 2017 UTC ()
constify more to avoid gcc stupidity.


(christos)
diff -r1.2 -r1.3 src/tests/crypto/opencrypto/h_ioctl.c

cvs diff -r1.2 -r1.3 src/tests/crypto/opencrypto/h_ioctl.c (expand / switch to unified diff)

--- src/tests/crypto/opencrypto/h_ioctl.c 2017/06/13 08:16:16 1.2
+++ src/tests/crypto/opencrypto/h_ioctl.c 2017/06/14 21:43:02 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: h_ioctl.c,v 1.2 2017/06/13 08:16:16 martin Exp $ */ 1/* $NetBSD: h_ioctl.c,v 1.3 2017/06/14 21:43:02 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017 Internet Initiative Japan Inc. 4 * Copyright (c) 2017 Internet Initiative Japan Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -47,174 +47,171 @@ unsigned char aes_key[AES_KEY_LEN] = @@ -47,174 +47,171 @@ unsigned char aes_key[AES_KEY_LEN] =
47#define AES_IV_LEN 16 47#define AES_IV_LEN 16
48unsigned char aes_iv[AES_IV_LEN] = 48unsigned char aes_iv[AES_IV_LEN] =
49{ 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 49{ 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
50 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41, }; 50 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41, };
51 51
52#define AES_PLAINTX_LEN 64 52#define AES_PLAINTX_LEN 64
53unsigned char aes_plaintx[AES_PLAINTX_LEN] = "Single block msg"; 53unsigned char aes_plaintx[AES_PLAINTX_LEN] = "Single block msg";
54 54
55#define AES_CIPHER_LEN 64 55#define AES_CIPHER_LEN 64
56unsigned char aes_cipher[AES_CIPHER_LEN] = 56unsigned char aes_cipher[AES_CIPHER_LEN] =
57{ 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, 57{ 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8,
58 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a, }; 58 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a, };
59 59
 60#define COUNT 2
 61
60/* 62/*
61 * CRIOGET is deprecated. 63 * CRIOGET is deprecated.
62 */ 64 */
63 65
64/* 66/*
65 * CIOCNGSESSION 67 * CIOCNGSESSION
66 * Hmm, who uses? (1) 68 * Hmm, who uses? (1)
67 */ 69 */
68static int 70static int
69test_ngsession(int fd) 71test_ngsession(int fd)
70{ 72{
71 int ret; 73 int ret;
72 struct crypt_sgop sg; 74 struct crypt_sgop sg;
73 struct session_n_op css[2]; 75 struct session_n_op css[COUNT];
74 const size_t cs_count = __arraycount(css); 
75 76
76 for (size_t i = 0; i < cs_count; i++) { 77 for (size_t i = 0; i < COUNT; i++) {
77 struct session_n_op *cs = &css[i]; 78 struct session_n_op *cs = &css[i];
78 79
79 memset(cs, 0, sizeof(*cs)); 80 memset(cs, 0, sizeof(*cs));
80 cs->cipher = CRYPTO_AES_CBC; 81 cs->cipher = CRYPTO_AES_CBC;
81 cs->keylen = AES_KEY_LEN; 82 cs->keylen = AES_KEY_LEN;
82 cs->key = __UNCONST(&aes_key); 83 cs->key = __UNCONST(&aes_key);
83 } 84 }
84 memset(&sg, 0, sizeof(sg)); 85 memset(&sg, 0, sizeof(sg));
85 sg.count = cs_count; 86 sg.count = COUNT;
86 sg.sessions = css; 87 sg.sessions = css;
87 88
88 ret = ioctl(fd, CIOCNGSESSION, &sg); 89 ret = ioctl(fd, CIOCNGSESSION, &sg);
89 if (ret < 0) 90 if (ret < 0)
90 fprintf(stderr, "failed: CIOCNGSESSION\n"); 91 fprintf(stderr, "failed: CIOCNGSESSION\n");
91 92
92 return ret; 93 return ret;
93} 94}
94 95
95/* 96/*
96 * CIOCNFSESSION 97 * CIOCNFSESSION
97 * Hmm, who uses? (2) 98 * Hmm, who uses? (2)
98 */ 99 */
99static int 100static int
100test_nfsession(int fd) 101test_nfsession(int fd)
101{ 102{
102 int ret; 103 int ret;
103 struct crypt_sfop sf; 104 struct crypt_sfop sf;
104 u_int32_t sids[2]; 105 u_int32_t sids[COUNT];
105 const size_t sid_count = __arraycount(sids); 
106 106
107 memset(sids, 0, sizeof(sids)); 107 memset(sids, 0, sizeof(sids));
108 memset(&sf, 0, sizeof(sf)); 108 memset(&sf, 0, sizeof(sf));
109 sf.count = sid_count; 109 sf.count = COUNT;
110 sf.sesid = sids; 110 sf.sesid = sids;
111 111
112 ret = ioctl(fd, CIOCNFSESSION, &sf); 112 ret = ioctl(fd, CIOCNFSESSION, &sf);
113 if (ret < 0) 113 if (ret < 0)
114 fprintf(stderr, "failed: CIOCNFSESSION\n"); 114 fprintf(stderr, "failed: CIOCNFSESSION\n");
115 115
116 return ret; 116 return ret;
117} 117}
118 118
119/* 119/*
120 * CIOCNCRYPTM 120 * CIOCNCRYPTM
121 * Hmm, who uses? (3) 121 * Hmm, who uses? (3)
122 */ 122 */
123static int 123static int
124test_ncryptm(int fd) 124test_ncryptm(int fd)
125{ 125{
126 int ret; 126 int ret;
127 struct crypt_mop mop; 127 struct crypt_mop mop;
128 struct crypt_n_op css[2]; 128 struct crypt_n_op css[COUNT];
129 const size_t cs_count = __arraycount(css); 
130 129
131 for (size_t i = 0; i < cs_count; i++) { 130 for (size_t i = 0; i < COUNT; i++) {
132 struct crypt_n_op *cs; 131 struct crypt_n_op *cs;
133 cs = &css[i]; 132 cs = &css[i];
134 133
135 memset(cs, 0, sizeof(*cs)); 134 memset(cs, 0, sizeof(*cs));
136 cs->ses = 0; /* session id */ 135 cs->ses = 0; /* session id */
137 cs->op = COP_ENCRYPT; 136 cs->op = COP_ENCRYPT;
138 /* XXX */ 137 /* XXX */
139 } 138 }
140 139
141 memset(&mop, 0, sizeof(mop)); 140 memset(&mop, 0, sizeof(mop));
142 mop.count = cs_count; 141 mop.count = COUNT;
143 mop.reqs = css; 142 mop.reqs = css;
144 143
145 ret = ioctl(fd, CIOCNCRYPTM, &mop); 144 ret = ioctl(fd, CIOCNCRYPTM, &mop);
146 if (ret < 0) 145 if (ret < 0)
147 fprintf(stderr, "failed: CIOCNCRYPTM\n"); 146 fprintf(stderr, "failed: CIOCNCRYPTM\n");
148 147
149 return ret; 148 return ret;
150} 149}
151 150
152/* 151/*
153 * CIOCNCRYPTRETM 152 * CIOCNCRYPTRETM
154 * Hmm, who uses? (4) 153 * Hmm, who uses? (4)
155 */ 154 */
156static int 155static int
157test_ncryptretm(int fd) 156test_ncryptretm(int fd)
158{ 157{
159 int ret; 158 int ret;
160 struct session_op cs; 159 struct session_op cs;
161 160
162 struct crypt_mop mop; 161 struct crypt_mop mop;
163 struct crypt_n_op cnos[2]; 162 struct crypt_n_op cnos[COUNT];
164 const size_t req_count = __arraycount(cnos); 163 unsigned char cno_dst[COUNT][AES_CIPHER_LEN];
165 unsigned char cno_dst[req_count][AES_CIPHER_LEN]; 
166 
167 struct cryptret cret; 164 struct cryptret cret;
168 struct crypt_result crs[req_count]; 165 struct crypt_result crs[COUNT];
169 166
170 memset(&cs, 0, sizeof(cs)); 167 memset(&cs, 0, sizeof(cs));
171 cs.cipher = CRYPTO_AES_CBC; 168 cs.cipher = CRYPTO_AES_CBC;
172 cs.keylen = AES_KEY_LEN; 169 cs.keylen = AES_KEY_LEN;
173 cs.key = __UNCONST(&aes_key); 170 cs.key = __UNCONST(&aes_key);
174 ret = ioctl(fd, CIOCGSESSION, &cs); 171 ret = ioctl(fd, CIOCGSESSION, &cs);
175 if (ret < 0) { 172 if (ret < 0) {
176 fprintf(stderr, "failed: CIOCGSESSION\n"); 173 fprintf(stderr, "failed: CIOCGSESSION\n");
177 return ret; 174 return ret;
178 } 175 }
179 176
180 for (size_t i = 0; i < req_count; i++) { 177 for (size_t i = 0; i < COUNT; i++) {
181 struct crypt_n_op *cno = &cnos[i]; 178 struct crypt_n_op *cno = &cnos[i];
182 179
183 memset(cno, 0, sizeof(*cno)); 180 memset(cno, 0, sizeof(*cno));
184 cno->ses = cs.ses; 181 cno->ses = cs.ses;
185 cno->op = COP_ENCRYPT; 182 cno->op = COP_ENCRYPT;
186 cno->len = AES_PLAINTX_LEN; 183 cno->len = AES_PLAINTX_LEN;
187 cno->src = aes_plaintx; 184 cno->src = aes_plaintx;
188 cno->dst_len = AES_CIPHER_LEN; 185 cno->dst_len = AES_CIPHER_LEN;
189 cno->dst = cno_dst[i]; 186 cno->dst = cno_dst[i];
190 } 187 }
191 188
192 memset(&mop, 0, sizeof(mop)); 189 memset(&mop, 0, sizeof(mop));
193 mop.count = req_count; 190 mop.count = COUNT;
194 mop.reqs = cnos; 191 mop.reqs = cnos;
195 ret = ioctl(fd, CIOCNCRYPTM, &mop); 192 ret = ioctl(fd, CIOCNCRYPTM, &mop);
196 if (ret < 0) 193 if (ret < 0)
197 fprintf(stderr, "failed: CIOCNCRYPTM\n"); 194 fprintf(stderr, "failed: CIOCNCRYPTM\n");
198 195
199 for (size_t i = 0; i < req_count; i++) { 196 for (size_t i = 0; i < COUNT; i++) {
200 struct crypt_result *cr = &crs[i]; 197 struct crypt_result *cr = &crs[i];
201 198
202 memset(cr, 0, sizeof(*cr)); 199 memset(cr, 0, sizeof(*cr));
203 cr->reqid = cnos[i].reqid; 200 cr->reqid = cnos[i].reqid;
204 } 201 }
205 202
206 memset(&cret, 0, sizeof(cret)); 203 memset(&cret, 0, sizeof(cret));
207 cret.count = req_count; 204 cret.count = COUNT;
208 cret.results = crs; 205 cret.results = crs;
209 ret = ioctl(fd, CIOCNCRYPTRETM, &cret); 206 ret = ioctl(fd, CIOCNCRYPTRETM, &cret);
210 if (ret < 0) 207 if (ret < 0)
211 fprintf(stderr, "failed: CIOCNCRYPTRETM\n"); 208 fprintf(stderr, "failed: CIOCNCRYPTRETM\n");
212 209
213 return ret; 210 return ret;
214} 211}
215 212
216/* 213/*
217 * CIOCNCRYPTRET 214 * CIOCNCRYPTRET
218 * Hmm, who uses? (5) 215 * Hmm, who uses? (5)
219 */ 216 */
220/* test when it does not request yet. */ 217/* test when it does not request yet. */