Print this page
fixup .text where possible
additional style updates in crypto
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/crypto/io/arcfour.c
+++ new/usr/src/uts/common/crypto/io/arcfour.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * RC4 provider for the Kernel Cryptographic Framework (KCF)
28 28 */
29 29
30 30 #include <sys/types.h>
31 31 #include <sys/systm.h>
32 32 #include <sys/modctl.h>
33 33 #include <sys/cmn_err.h>
34 34 #include <sys/ddi.h>
35 35 #include <sys/crypto/common.h>
36 36 #include <sys/crypto/spi.h>
37 37 #include <sys/sysmacros.h>
38 38 #include <sys/strsun.h>
39 39 #include <arcfour.h>
40 40
41 41 extern struct mod_ops mod_cryptoops;
42 42
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
43 43 /*
44 44 * Module linkage information for the kernel.
45 45 */
46 46 static struct modlcrypto modlcrypto = {
47 47 &mod_cryptoops,
48 48 "RC4 Kernel SW Provider"
49 49 };
50 50
51 51 static struct modlinkage modlinkage = {
52 52 MODREV_1,
53 - (void *)&modlcrypto,
54 - NULL
53 + { (void *)&modlcrypto,
54 + NULL }
55 55 };
56 56
57 57 /*
58 58 * CSPI information (entry points, provider info, etc.)
59 59 */
60 60
61 61 #define RC4_MECH_INFO_TYPE 0
62 62 /*
63 63 * Mechanism info structure passed to KCF during registration.
64 64 */
65 65 static crypto_mech_info_t rc4_mech_info_tab[] = {
66 66 {SUN_CKM_RC4, RC4_MECH_INFO_TYPE,
67 67 CRYPTO_FG_ENCRYPT | CRYPTO_FG_ENCRYPT_ATOMIC |
68 68 CRYPTO_FG_DECRYPT | CRYPTO_FG_DECRYPT_ATOMIC,
69 69 ARCFOUR_MIN_KEY_BITS, ARCFOUR_MAX_KEY_BITS,
70 70 CRYPTO_KEYSIZE_UNIT_IN_BITS | CRYPTO_CAN_SHARE_OPSTATE}
71 71 };
72 72
73 73 static void rc4_provider_status(crypto_provider_handle_t, uint_t *);
74 74
75 75 static crypto_control_ops_t rc4_control_ops = {
76 76 rc4_provider_status
77 77 };
78 78
79 79 static int rc4_common_init(crypto_ctx_t *, crypto_mechanism_t *,
80 80 crypto_key_t *, crypto_spi_ctx_template_t, crypto_req_handle_t);
81 81
82 82 static int rc4_crypt_update(crypto_ctx_t *, crypto_data_t *, crypto_data_t *,
83 83 crypto_req_handle_t);
84 84
85 85 static int rc4_crypt_final(crypto_ctx_t *, crypto_data_t *,
86 86 crypto_req_handle_t);
87 87
88 88 static int rc4_crypt(crypto_ctx_t *, crypto_data_t *, crypto_data_t *,
89 89 crypto_req_handle_t);
90 90
91 91 static int rc4_crypt_atomic(crypto_provider_handle_t, crypto_session_id_t,
92 92 crypto_mechanism_t *, crypto_key_t *, crypto_data_t *,
93 93 crypto_data_t *, crypto_spi_ctx_template_t, crypto_req_handle_t);
94 94
95 95
96 96 static crypto_cipher_ops_t rc4_cipher_ops = {
97 97 rc4_common_init,
98 98 rc4_crypt,
99 99 rc4_crypt_update,
100 100 rc4_crypt_final,
101 101 rc4_crypt_atomic,
102 102 rc4_common_init,
103 103 rc4_crypt,
104 104 rc4_crypt_update,
105 105 rc4_crypt_final,
106 106 rc4_crypt_atomic
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
107 107 };
108 108
109 109 static int rc4_free_context(crypto_ctx_t *);
110 110
111 111 static crypto_ctx_ops_t rc4_ctx_ops = {
112 112 NULL,
113 113 rc4_free_context
114 114 };
115 115
116 116 static crypto_ops_t rc4_crypto_ops = {
117 - &rc4_control_ops,
118 - NULL,
119 - &rc4_cipher_ops,
120 - NULL,
121 - NULL,
122 - NULL,
123 - NULL,
124 - NULL,
125 - NULL,
126 - NULL,
127 - NULL,
128 - NULL,
129 - NULL,
130 - &rc4_ctx_ops
117 + .co_control_ops = &rc4_control_ops,
118 + .co_digest_ops = NULL,
119 + .co_cipher_ops = &rc4_cipher_ops,
120 + .co_mac_ops = NULL,
121 + .co_sign_ops = NULL,
122 + .co_verify_ops = NULL,
123 + .co_dual_ops = NULL,
124 + .co_dual_cipher_mac_ops = NULL,
125 + .co_random_ops = NULL,
126 + .co_session_ops = NULL,
127 + .co_object_ops = NULL,
128 + .co_key_ops = NULL,
129 + .co_provider_ops = NULL,
130 + .co_ctx_ops = &rc4_ctx_ops
131 131 };
132 132
133 -static crypto_provider_info_t rc4_prov_info = {
133 +static crypto_provider_info_t rc4_prov_info = {{{{
134 134 CRYPTO_SPI_VERSION_1,
135 135 "RC4 Software Provider",
136 136 CRYPTO_SW_PROVIDER,
137 137 {&modlinkage},
138 138 NULL,
139 139 &rc4_crypto_ops,
140 140 sizeof (rc4_mech_info_tab)/sizeof (crypto_mech_info_t),
141 141 rc4_mech_info_tab
142 -};
142 +}}}};
143 143
144 144 static crypto_kcf_provider_handle_t rc4_prov_handle = NULL;
145 145
146 146 static mblk_t *advance_position(mblk_t *, off_t, uchar_t **);
147 147 static int crypto_arcfour_crypt(ARCFour_key *, uchar_t *, crypto_data_t *,
148 148 int);
149 149
150 150 int
151 151 _init(void)
152 152 {
153 153 int ret;
154 154
155 155 if ((ret = mod_install(&modlinkage)) != 0)
156 156 return (ret);
157 157
158 158 /* Register with KCF. If the registration fails, remove the module. */
159 159 if (crypto_register_provider(&rc4_prov_info, &rc4_prov_handle)) {
160 160 (void) mod_remove(&modlinkage);
161 161 return (EACCES);
162 162 }
163 163
164 164 return (0);
165 165 }
166 166
167 167 int
168 168 _fini(void)
169 169 {
170 170 /* Unregister from KCF if module is registered */
171 171 if (rc4_prov_handle != NULL) {
172 172 if (crypto_unregister_provider(rc4_prov_handle))
173 173 return (EBUSY);
174 174
175 175 rc4_prov_handle = NULL;
176 176 }
177 177
178 178 return (mod_remove(&modlinkage));
179 179 }
180 180
181 181 int
182 182 _info(struct modinfo *modinfop)
183 183 {
184 184 return (mod_info(&modlinkage, modinfop));
185 185 }
186 186
187 187
188 188 /*
189 189 * KCF software provider control entry points.
190 190 */
191 191 /* ARGSUSED */
192 192 static void
193 193 rc4_provider_status(crypto_provider_handle_t provider, uint_t *status)
194 194 {
195 195 *status = CRYPTO_PROVIDER_READY;
196 196 }
197 197
198 198 /* ARGSUSED */
199 199 static int
200 200 rc4_common_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
201 201 crypto_key_t *key, crypto_spi_ctx_template_t template,
202 202 crypto_req_handle_t req)
203 203 {
204 204 ARCFour_key *keystream;
205 205
206 206 if ((mechanism)->cm_type != RC4_MECH_INFO_TYPE)
207 207 return (CRYPTO_MECHANISM_INVALID);
208 208
209 209 if (key->ck_format != CRYPTO_KEY_RAW)
210 210 return (CRYPTO_KEY_TYPE_INCONSISTENT);
211 211
212 212 if (key->ck_length < ARCFOUR_MIN_KEY_BITS ||
213 213 key->ck_length > ARCFOUR_MAX_KEY_BITS) {
214 214 return (CRYPTO_KEY_SIZE_RANGE);
215 215 }
216 216
217 217 /*
218 218 * Allocate an RC4 key stream.
219 219 */
220 220 if ((keystream = kmem_alloc(sizeof (ARCFour_key),
221 221 crypto_kmflag(req))) == NULL)
222 222 return (CRYPTO_HOST_MEMORY);
223 223
224 224 arcfour_key_init(keystream, key->ck_data,
225 225 CRYPTO_BITS2BYTES(key->ck_length));
226 226
227 227 ctx->cc_provider_private = keystream;
228 228
229 229 return (CRYPTO_SUCCESS);
230 230 }
231 231
232 232 static int
233 233 rc4_crypt(crypto_ctx_t *ctx, crypto_data_t *input, crypto_data_t *output,
234 234 crypto_req_handle_t req)
235 235 {
236 236 int ret;
237 237
238 238 ret = rc4_crypt_update(ctx, input, output, req);
239 239
240 240 if (ret != CRYPTO_BUFFER_TOO_SMALL)
241 241 (void) rc4_free_context(ctx);
242 242
243 243 return (ret);
244 244 }
245 245
246 246 /* ARGSUSED */
247 247 static int
248 248 rc4_crypt_update(crypto_ctx_t *ctx, crypto_data_t *input, crypto_data_t *output,
249 249 crypto_req_handle_t req)
250 250 {
251 251 int ret = CRYPTO_SUCCESS;
252 252
253 253 ARCFour_key *key;
254 254 off_t saveoffset;
255 255
256 256 ASSERT(ctx->cc_provider_private != NULL);
257 257
258 258 if ((ctx->cc_flags & CRYPTO_USE_OPSTATE) && ctx->cc_opstate != NULL)
259 259 key = ctx->cc_opstate;
260 260 else
261 261 key = ctx->cc_provider_private;
262 262
263 263 /* Simple case: in-line encipherment */
264 264
265 265 if (output == NULL) {
266 266 switch (input->cd_format) {
267 267 case CRYPTO_DATA_RAW: {
268 268 char *start, *end;
269 269 start = input->cd_raw.iov_base + input->cd_offset;
270 270
271 271 end = input->cd_raw.iov_base + input->cd_raw.iov_len;
272 272
273 273 if (start + input->cd_length > end)
274 274 return (CRYPTO_DATA_INVALID);
275 275
276 276 arcfour_crypt(key, (uchar_t *)start, (uchar_t *)start,
277 277 input->cd_length);
278 278 break;
279 279 }
280 280 case CRYPTO_DATA_MBLK: {
281 281 uchar_t *start, *end;
282 282 size_t len, left;
283 283 mblk_t *mp = input->cd_mp, *mp1, *mp2;
284 284
285 285 ASSERT(mp != NULL);
286 286
287 287 mp1 = advance_position(mp, input->cd_offset, &start);
288 288
289 289 if (mp1 == NULL)
290 290 return (CRYPTO_DATA_LEN_RANGE);
291 291
292 292 mp2 = advance_position(mp, input->cd_offset +
293 293 input->cd_length, &end);
294 294
295 295 if (mp2 == NULL)
296 296 return (CRYPTO_DATA_LEN_RANGE);
297 297
298 298 left = input->cd_length;
299 299 while (mp1 != NULL) {
300 300 if (_PTRDIFF(mp1->b_wptr, start) > left) {
301 301 len = left;
302 302 arcfour_crypt(key, start, start, len);
303 303 mp1 = NULL;
304 304 } else {
305 305 len = _PTRDIFF(mp1->b_wptr, start);
306 306 arcfour_crypt(key, start, start, len);
307 307 mp1 = mp1->b_cont;
308 308 start = mp1->b_rptr;
309 309 left -= len;
310 310 }
311 311 }
312 312 break;
313 313 }
314 314 case CRYPTO_DATA_UIO: {
315 315 uio_t *uiop = input->cd_uio;
316 316 off_t offset = input->cd_offset;
317 317 size_t length = input->cd_length;
318 318 uint_t vec_idx;
319 319 size_t cur_len;
320 320
321 321 /*
322 322 * Jump to the first iovec containing data to be
323 323 * processed.
324 324 */
325 325 for (vec_idx = 0; vec_idx < uiop->uio_iovcnt &&
326 326 offset >= uiop->uio_iov[vec_idx].iov_len;
327 327 offset -= uiop->uio_iov[vec_idx++].iov_len)
328 328 ;
329 329 if (vec_idx == uiop->uio_iovcnt) {
330 330 return (CRYPTO_DATA_LEN_RANGE);
331 331 }
332 332
333 333 /*
334 334 * Now process the iovecs.
335 335 */
336 336 while (vec_idx < uiop->uio_iovcnt && length > 0) {
337 337 uchar_t *start;
338 338 iovec_t *iovp = &(uiop->uio_iov[vec_idx]);
339 339
340 340 cur_len = MIN(iovp->iov_len - offset, length);
341 341
342 342 start = (uchar_t *)(iovp->iov_base + offset);
343 343 arcfour_crypt(key, start + offset,
344 344 start + offset, cur_len);
345 345
346 346 length -= cur_len;
347 347 vec_idx++;
348 348 offset = 0;
349 349 }
350 350
351 351 if (vec_idx == uiop->uio_iovcnt && length > 0) {
352 352
353 353 return (CRYPTO_DATA_LEN_RANGE);
354 354 }
355 355 break;
356 356 }
357 357 }
358 358 return (CRYPTO_SUCCESS);
359 359 }
360 360
361 361 /*
362 362 * We need to just return the length needed to store the output.
363 363 * We should not destroy the context for the following case.
364 364 */
365 365
366 366 if (input->cd_length > output->cd_length) {
367 367 output->cd_length = input->cd_length;
368 368 return (CRYPTO_BUFFER_TOO_SMALL);
369 369 }
370 370
371 371 saveoffset = output->cd_offset;
372 372
373 373 switch (input->cd_format) {
374 374 case CRYPTO_DATA_RAW: {
375 375 char *start, *end;
376 376 start = input->cd_raw.iov_base + input->cd_offset;
377 377
378 378 end = input->cd_raw.iov_base + input->cd_raw.iov_len;
379 379
380 380 if (start + input->cd_length > end)
381 381 return (CRYPTO_DATA_LEN_RANGE);
382 382
383 383 ret = crypto_arcfour_crypt(key, (uchar_t *)start, output,
384 384 input->cd_length);
385 385
386 386 if (ret != CRYPTO_SUCCESS)
387 387 return (ret);
388 388 break;
389 389 }
390 390 case CRYPTO_DATA_MBLK: {
391 391 uchar_t *start, *end;
392 392 size_t len, left;
393 393 mblk_t *mp = input->cd_mp, *mp1, *mp2;
394 394
395 395 ASSERT(mp != NULL);
396 396
397 397 mp1 = advance_position(mp, input->cd_offset, &start);
398 398
399 399 if (mp1 == NULL)
400 400 return (CRYPTO_DATA_LEN_RANGE);
401 401
402 402 mp2 = advance_position(mp, input->cd_offset + input->cd_length,
403 403 &end);
404 404
405 405 if (mp2 == NULL)
406 406 return (CRYPTO_DATA_LEN_RANGE);
407 407
408 408 left = input->cd_length;
409 409 while (mp1 != NULL) {
410 410 if (_PTRDIFF(mp1->b_wptr, start) > left) {
411 411 len = left;
412 412 ret = crypto_arcfour_crypt(key, start, output,
413 413 len);
414 414 if (ret != CRYPTO_SUCCESS)
415 415 return (ret);
416 416 mp1 = NULL;
417 417 } else {
418 418 len = _PTRDIFF(mp1->b_wptr, start);
419 419 ret = crypto_arcfour_crypt(key, start, output,
420 420 len);
421 421 if (ret != CRYPTO_SUCCESS)
422 422 return (ret);
423 423 mp1 = mp1->b_cont;
424 424 start = mp1->b_rptr;
425 425 left -= len;
426 426 output->cd_offset += len;
427 427 }
428 428 }
429 429 break;
430 430 }
431 431 case CRYPTO_DATA_UIO: {
432 432 uio_t *uiop = input->cd_uio;
433 433 off_t offset = input->cd_offset;
434 434 size_t length = input->cd_length;
435 435 uint_t vec_idx;
436 436 size_t cur_len;
437 437
438 438 /*
439 439 * Jump to the first iovec containing data to be
440 440 * processed.
441 441 */
442 442 for (vec_idx = 0; vec_idx < uiop->uio_iovcnt &&
443 443 offset >= uiop->uio_iov[vec_idx].iov_len;
444 444 offset -= uiop->uio_iov[vec_idx++].iov_len)
445 445 ;
446 446 if (vec_idx == uiop->uio_iovcnt) {
447 447 return (CRYPTO_DATA_LEN_RANGE);
448 448 }
449 449
450 450 /*
451 451 * Now process the iovecs.
452 452 */
453 453 while (vec_idx < uiop->uio_iovcnt && length > 0) {
454 454 uchar_t *start;
455 455 iovec_t *iovp = &(uiop->uio_iov[vec_idx]);
456 456 cur_len = MIN(iovp->iov_len - offset, length);
457 457
458 458 start = (uchar_t *)(iovp->iov_base + offset);
459 459 ret = crypto_arcfour_crypt(key, start + offset,
460 460 output, cur_len);
461 461 if (ret != CRYPTO_SUCCESS)
462 462 return (ret);
463 463
464 464 length -= cur_len;
465 465 vec_idx++;
466 466 offset = 0;
467 467 output->cd_offset += cur_len;
468 468 }
469 469
470 470 if (vec_idx == uiop->uio_iovcnt && length > 0) {
471 471
472 472 return (CRYPTO_DATA_LEN_RANGE);
473 473 }
474 474 }
475 475 }
476 476
477 477 output->cd_offset = saveoffset;
478 478 output->cd_length = input->cd_length;
479 479
480 480 return (ret);
481 481 }
482 482
483 483 /* ARGSUSED */
484 484 static int rc4_crypt_final(crypto_ctx_t *ctx, crypto_data_t *data,
485 485 crypto_req_handle_t req)
486 486 {
487 487 /* No final part for streams ciphers. Just free the context */
488 488 if (data != NULL)
489 489 data->cd_length = 0;
490 490
491 491 return (rc4_free_context(ctx));
492 492 }
493 493
494 494 /* ARGSUSED */
495 495 static int
496 496 rc4_crypt_atomic(crypto_provider_handle_t handle, crypto_session_id_t session,
497 497 crypto_mechanism_t *mechanism, crypto_key_t *key, crypto_data_t *input,
498 498 crypto_data_t *output, crypto_spi_ctx_template_t template,
499 499 crypto_req_handle_t req)
500 500 {
501 501 crypto_ctx_t ctx;
502 502 int ret;
503 503
504 504 bzero(&ctx, sizeof (crypto_ctx_t));
505 505 ret = rc4_common_init(&ctx, mechanism, key, template, req);
506 506
507 507 if (ret != CRYPTO_SUCCESS)
508 508 return (ret);
509 509
510 510 ret = rc4_crypt_update(&ctx, input, output, req);
511 511
512 512 (void) rc4_free_context(&ctx);
513 513
514 514 return (ret);
515 515 }
516 516
517 517 /* ARGSUSED */
518 518 static int
519 519 rc4_free_context(crypto_ctx_t *ctx)
520 520 {
521 521 ARCFour_key *keystream = ctx->cc_provider_private;
522 522
523 523 if (keystream != NULL) {
524 524 bzero(keystream, sizeof (ARCFour_key));
525 525 kmem_free(keystream, sizeof (ARCFour_key));
526 526 ctx->cc_provider_private = NULL;
527 527 }
528 528
529 529 return (CRYPTO_SUCCESS);
530 530 }
531 531
532 532 /* Encrypts a contiguous input 'in' into the 'out' crypto_data_t */
533 533
534 534 static int
535 535 crypto_arcfour_crypt(ARCFour_key *key, uchar_t *in, crypto_data_t *out,
536 536 int length)
537 537 {
538 538 switch (out->cd_format) {
539 539 case CRYPTO_DATA_RAW: {
540 540 uchar_t *start, *end;
541 541 start = (uchar_t *)(out->cd_raw.iov_base +
542 542 out->cd_offset);
543 543
544 544 end = (uchar_t *)(out->cd_raw.iov_base +
545 545 out->cd_raw.iov_len);
546 546
547 547 if (start + out->cd_length > end)
548 548 return (CRYPTO_DATA_LEN_RANGE);
549 549
550 550 arcfour_crypt(key, in, start, length);
551 551
552 552 return (CRYPTO_SUCCESS);
553 553 }
554 554 case CRYPTO_DATA_MBLK: {
555 555 uchar_t *start, *end;
556 556 size_t len, left;
557 557 mblk_t *mp = out->cd_mp, *mp1, *mp2;
558 558
559 559 ASSERT(mp != NULL);
560 560
561 561 mp1 = advance_position(mp, out->cd_offset, &start);
562 562
563 563 if (mp1 == NULL)
564 564 return (CRYPTO_DATA_LEN_RANGE);
565 565
566 566 mp2 = advance_position(mp, out->cd_offset +
567 567 out->cd_length, &end);
568 568
569 569 if (mp2 == NULL)
570 570 return (CRYPTO_DATA_LEN_RANGE);
571 571
572 572 left = length;
573 573 while (mp1 != NULL) {
574 574 if (_PTRDIFF(mp1->b_wptr, start) > left) {
575 575 len = left;
576 576 arcfour_crypt(key, in, start, len);
577 577 mp1 = NULL;
578 578 } else {
579 579 len = _PTRDIFF(mp1->b_wptr, start);
580 580 arcfour_crypt(key, in, start, len);
581 581 mp1 = mp1->b_cont;
582 582 start = mp1->b_rptr;
583 583 left -= len;
584 584 }
585 585 }
586 586 break;
587 587 }
588 588 case CRYPTO_DATA_UIO: {
589 589 uio_t *uiop = out->cd_uio;
590 590 off_t offset = out->cd_offset;
591 591 size_t len = length;
592 592 uint_t vec_idx;
593 593 size_t cur_len;
594 594
595 595 /*
596 596 * Jump to the first iovec containing data to be
597 597 * processed.
598 598 */
599 599 for (vec_idx = 0; vec_idx < uiop->uio_iovcnt &&
600 600 offset >= uiop->uio_iov[vec_idx].iov_len;
601 601 offset -= uiop->uio_iov[vec_idx++].iov_len)
602 602 ;
603 603 if (vec_idx == uiop->uio_iovcnt) {
604 604 return (CRYPTO_DATA_LEN_RANGE);
605 605 }
606 606
607 607 /*
608 608 * Now process the iovecs.
609 609 */
610 610 while (vec_idx < uiop->uio_iovcnt && len > 0) {
611 611 uchar_t *start;
612 612 iovec_t *iovp = &(uiop->uio_iov[vec_idx]);
613 613 cur_len = MIN(iovp->iov_len - offset, len);
614 614
615 615 start = (uchar_t *)(iovp->iov_base + offset);
616 616 arcfour_crypt(key, start + offset,
617 617 start + offset, cur_len);
618 618
619 619 len -= cur_len;
620 620 vec_idx++;
621 621 offset = 0;
622 622 }
623 623
624 624 if (vec_idx == uiop->uio_iovcnt && len > 0) {
625 625 return (CRYPTO_DATA_LEN_RANGE);
626 626 }
627 627 break;
628 628 }
629 629 default:
630 630 return (CRYPTO_DATA_INVALID);
631 631 }
632 632 return (CRYPTO_SUCCESS);
633 633 }
634 634
635 635 /*
636 636 * Advances 'offset' bytes from the beginning of the first block in 'mp',
637 637 * possibly jumping across b_cont boundary
638 638 * '*cpp' is set to the position of the byte we want, and the block where
639 639 * 'cpp' is returned.
640 640 */
641 641 static mblk_t *
642 642 advance_position(mblk_t *mp, off_t offset, uchar_t **cpp)
643 643 {
644 644 mblk_t *mp1 = mp;
645 645 size_t l;
646 646 off_t o = offset;
647 647
648 648 while (mp1 != NULL) {
649 649 l = MBLKL(mp1);
650 650
651 651 if (l <= o) {
652 652 o -= l;
653 653 mp1 = mp1->b_cont;
654 654 } else {
655 655 *cpp = (uchar_t *)(mp1->b_rptr + o);
656 656 break;
657 657 }
658 658 }
659 659 return (mp1);
660 660 }
↓ open down ↓ |
508 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX