2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
7 * by Alex Hornung <alexh@dragonflybsd.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
19 * 3. Neither the name of The DragonFly Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific, prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * Setup crypto for pthreads
42 static pthread_mutex_t *crypto_locks;
47 hammer2_crypto_id_callback(void)
49 return ((unsigned long)(uintptr_t)pthread_self());
54 hammer2_crypto_locking_callback(int mode, int type,
55 const char *file __unused, int line __unused)
57 assert(type >= 0 && type < crypto_count);
58 if (mode & CRYPTO_LOCK) {
59 pthread_mutex_lock(&crypto_locks[type]);
61 pthread_mutex_unlock(&crypto_locks[type]);
66 hammer2_crypto_setup(void)
68 crypto_count = CRYPTO_num_locks();
69 crypto_locks = calloc(crypto_count, sizeof(crypto_locks[0]));
70 CRYPTO_set_id_callback(hammer2_crypto_id_callback);
71 CRYPTO_set_locking_callback(hammer2_crypto_locking_callback);
76 _gcm_init(hammer2_ioq_t *ioq, char *key, int klen, char *iv_fixed, int ivlen,
81 if (klen < 32 /* 256 bits */ || ivlen < 4 /* 32 bits */) {
83 fprintf(stderr, "Not enough key or iv material\n");
87 printf("%s key: ", enc ? "Encryption" : "Decryption");
88 for (i = 0; i < HAMMER2_AES_KEY_SIZE; ++i)
89 printf("%02x", (unsigned char)key[i]);
92 printf("%s iv: ", enc ? "Encryption" : "Decryption");
93 for (i = 0; i < HAMMER2_CRYPTO_IV_FIXED_SIZE; ++i)
94 printf("%02x", (unsigned char)iv_fixed[i]);
95 printf(" (fixed part only)\n");
98 EVP_CIPHER_CTX_init(&ioq->ctx);
101 ok = EVP_EncryptInit_ex(&ioq->ctx, EVP_aes_256_gcm(), NULL,
104 ok = EVP_DecryptInit_ex(&ioq->ctx, EVP_aes_256_gcm(), NULL,
110 * According to the original Galois/Counter Mode of Operation (GCM)
111 * proposal, only IVs that are exactly 96 bits get used without any
112 * further processing. Other IV sizes cause the GHASH() operation
113 * to be applied to the IV, which is more costly.
115 * The NIST SP 800-38D also recommends using a 96 bit IV for the same
116 * reasons. We actually follow the deterministic construction
117 * recommended in NIST SP 800-38D with a 64 bit invocation field as an
118 * integer counter and a random, session-specific fixed field.
120 * This means that we can essentially use the same session key and
121 * IV fixed field for up to 2^64 invocations of the authenticated
122 * encryption or decryption.
124 * With a chunk size of 64 bytes, this adds up to 1 zettabyte of
127 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_SET_IVLEN,
128 HAMMER2_CRYPTO_IV_SIZE, NULL);
132 memset(ioq->iv, 0, HAMMER2_CRYPTO_IV_SIZE);
133 memcpy(ioq->iv, iv_fixed, HAMMER2_CRYPTO_IV_FIXED_SIZE);
136 * Strictly speaking, padding is irrelevant with a counter mode
139 * However, setting padding to 0, even if using a counter mode such
140 * as GCM, will cause an error in _finish if the pt/ct size is not
141 * a multiple of the cipher block size.
143 EVP_CIPHER_CTX_set_padding(&ioq->ctx, 0);
149 fprintf(stderr, "Error during _gcm_init\n");
155 _gcm_iv_increment(char *iv)
158 * Deterministic construction according to NIST SP 800-38D, with
159 * 64 bit invocation field as integer counter.
161 * In other words, our 96 bit IV consists of a 32 bit fixed field
162 * unique to the session and a 64 bit integer counter.
165 uint64_t *c = (uint64_t *)(&iv[HAMMER2_CRYPTO_IV_FIXED_SIZE]);
167 /* Increment invocation field integer counter */
169 * XXX: this should ideally be an atomic update, but we don't have
170 * an atomic_fetchadd_64 for i386 yet
175 * Detect wrap-around, which means it is time to renegotiate
176 * the session to get a new key and/or fixed field.
178 return (c == 0) ? 0 : 1;
183 hammer2_crypto_encrypt_chunk(hammer2_ioq_t *ioq, char *ct, char *pt,
184 int in_size, int *out_size)
194 /* Re-initialize with new IV (but without redoing the key schedule) */
195 ok = EVP_EncryptInit_ex(&ioq->ctx, NULL, NULL, NULL, ioq->iv);
199 ok = EVP_EncryptUpdate(&ioq->ctx, ct, &u_len, pt, in_size);
203 ok = EVP_EncryptFinal(&ioq->ctx, ct + u_len, &f_len);
207 /* Retrieve auth tag */
208 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_GET_TAG,
209 HAMMER2_CRYPTO_TAG_SIZE,
215 printf("enc_chunk iv: ");
216 for (i = 0; i < HAMMER2_CRYPTO_IV_SIZE; i++)
217 printf("%02x", (unsigned char)ioq->iv[i]);
220 printf("enc_chunk pt: ");
221 for (i = 0; i < in_size; i++)
222 printf("%02x", (unsigned char)pt[i]);
225 printf("enc_chunk ct: ");
226 for (i = 0; i < in_size; i++)
227 printf("%02x", (unsigned char)ct[i]);
230 printf("enc_chunk tag: ");
231 for (i = 0; i < HAMMER2_CRYPTO_TAG_SIZE; i++)
232 printf("%02x", (unsigned char)ct[i + u_len + f_len]);
236 ok = _gcm_iv_increment(ioq->iv);
238 ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
242 *out_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
247 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
250 fprintf(stderr, "error during encrypt_chunk\n");
256 hammer2_crypto_decrypt_chunk(hammer2_ioq_t *ioq, char *ct, char *pt,
257 int out_size, int *consume_size)
267 /* Re-initialize with new IV (but without redoing the key schedule) */
268 ok = EVP_DecryptInit_ex(&ioq->ctx, NULL, NULL, NULL, ioq->iv);
270 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
275 printf("dec_chunk iv: ");
276 for (i = 0; i < HAMMER2_CRYPTO_IV_SIZE; i++)
277 printf("%02x", (unsigned char)ioq->iv[i]);
280 printf("dec_chunk ct: ");
281 for (i = 0; i < out_size; i++)
282 printf("%02x", (unsigned char)ct[i]);
285 printf("dec_chunk tag: ");
286 for (i = 0; i < HAMMER2_CRYPTO_TAG_SIZE; i++)
287 printf("%02x", (unsigned char)ct[out_size + i]);
291 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_SET_TAG,
292 HAMMER2_CRYPTO_TAG_SIZE,
295 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
299 ok = EVP_DecryptUpdate(&ioq->ctx, pt, &u_len, ct, out_size);
303 ok = EVP_DecryptFinal(&ioq->ctx, pt + u_len, &f_len);
307 ok = _gcm_iv_increment(ioq->iv);
309 ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
313 *consume_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
316 printf("dec_chunk pt: ");
317 for (i = 0; i < out_size; i++)
318 printf("%02x", (unsigned char)pt[i]);
325 ioq->error = HAMMER2_IOQ_ERROR_MACFAIL;
328 fprintf(stderr, "error during decrypt_chunk (likely authentication error)\n");
333 * Synchronously negotiate crypto for a new session. This must occur
334 * within 10 seconds or the connection is error'd out.
336 * We work off the IP address and/or reverse DNS. The IP address is
337 * checked first, followed by the IP address at various levels of granularity,
338 * followed by the full domain name and domain names at various levels of
341 * /etc/hammer2/remote/<name>.pub - Contains a public key
342 * /etc/hammer2/remote/<name>.none - Indicates no encryption (empty file)
343 * (e.g. localhost.none).
345 * We first attempt to locate a public key file based on the peer address or
348 * <name>.none - No further negotiation is needed. We simply return.
349 * All communication proceeds without encryption.
350 * No public key handshake occurs in this situation.
351 * (both ends must match).
353 * <name>.pub - We have located the public key for the peer. Both
354 * sides transmit a block encrypted with their private
355 * keys and the peer's public key.
357 * Both sides receive a block and decrypt it.
359 * Both sides formulate a reply using the decrypted
360 * block and transmit it.
362 * communication proceeds with the negotiated session
363 * key (typically AES-256-CBC).
365 * If we fail to locate the appropriate file and no floating.db exists the
366 * connection is terminated without further action.
368 * If floating.db exists the connection proceeds with a floating negotiation.
372 struct sockaddr_in sa_in;
373 struct sockaddr_in6 sa_in6;
377 hammer2_crypto_negotiate(hammer2_iocom_t *iocom)
380 socklen_t salen = sizeof(sa);
383 hammer2_handshake_t handtx;
384 hammer2_handshake_t handrx;
385 char buf1[sizeof(handtx)];
386 char buf2[sizeof(handtx)];
391 RSA *keys[3] = { NULL, NULL, NULL };
400 * Get the peer IP address for the connection as a string.
402 if (getpeername(iocom->sock_fd, &sa.sa, &salen) < 0) {
403 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOPEER;
404 iocom->flags |= HAMMER2_IOCOMF_EOF;
406 fprintf(stderr, "accept: getpeername() failed\n");
409 if (getnameinfo(&sa.sa, salen, peername, sizeof(peername),
410 NULL, 0, NI_NUMERICHOST) < 0) {
411 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOPEER;
412 iocom->flags |= HAMMER2_IOCOMF_EOF;
414 fprintf(stderr, "accept: cannot decode sockaddr\n");
418 if (realhostname_sa(realname, sizeof(realname),
419 &sa.sa, salen) == HOSTNAME_FOUND) {
420 fprintf(stderr, "accept from %s (%s)\n",
423 fprintf(stderr, "accept from %s\n", peername);
428 * Find the remote host's public key
430 * If the link is not to be encrypted (<ip>.none located) we shortcut
431 * the handshake entirely. No buffers are exchanged.
433 asprintf(&path, "%s/%s.pub", HAMMER2_PATH_REMOTE, peername);
434 if ((fp = fopen(path, "r")) == NULL) {
436 asprintf(&path, "%s/%s.none",
437 HAMMER2_PATH_REMOTE, peername);
438 if (stat(path, &st) < 0) {
439 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NORKEY;
440 iocom->flags |= HAMMER2_IOCOMF_EOF;
442 fprintf(stderr, "auth failure: unknown host\n");
446 fprintf(stderr, "auth succeeded, unencrypted link\n");
450 keys[0] = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
452 if (keys[0] == NULL) {
453 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
454 iocom->flags |= HAMMER2_IOCOMF_EOF;
457 "auth failure: bad key format\n");
463 * Get our public and private keys
466 asprintf(&path, HAMMER2_DEFAULT_DIR "/rsa.pub");
467 if ((fp = fopen(path, "r")) == NULL) {
468 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOLKEY;
469 iocom->flags |= HAMMER2_IOCOMF_EOF;
472 keys[1] = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
474 if (keys[1] == NULL) {
475 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
476 iocom->flags |= HAMMER2_IOCOMF_EOF;
478 fprintf(stderr, "auth failure: bad host key format\n");
483 asprintf(&path, HAMMER2_DEFAULT_DIR "/rsa.prv");
484 if ((fp = fopen(path, "r")) == NULL) {
485 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOLKEY;
486 iocom->flags |= HAMMER2_IOCOMF_EOF;
488 fprintf(stderr, "auth failure: bad host key format\n");
491 keys[2] = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
493 if (keys[2] == NULL) {
494 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
495 iocom->flags |= HAMMER2_IOCOMF_EOF;
497 fprintf(stderr, "auth failure: bad host key format\n");
504 * public key encrypt/decrypt block size.
507 blksize = (size_t)RSA_size(keys[0]);
508 if (blksize != (size_t)RSA_size(keys[1]) ||
509 blksize != (size_t)RSA_size(keys[2]) ||
510 sizeof(handtx) % blksize != 0) {
511 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
512 iocom->flags |= HAMMER2_IOCOMF_EOF;
514 fprintf(stderr, "auth failure: "
515 "key size mismatch\n");
519 blksize = sizeof(handtx);
521 blkmask = blksize - 1;
523 bzero(&handrx, sizeof(handrx));
524 bzero(&handtx, sizeof(handtx));
527 * Fill all unused fields (particular all junk fields) with random
528 * data, and also set the session key.
530 fd = open("/dev/urandom", O_RDONLY);
532 fstat(fd, &st) < 0 || /* something wrong */
533 S_ISREG(st.st_mode) || /* supposed to be a RNG dev! */
534 read(fd, &handtx, sizeof(handtx)) != sizeof(handtx)) {
538 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_BADURANDOM;
539 iocom->flags |= HAMMER2_IOCOMF_EOF;
541 fprintf(stderr, "auth failure: bad rng\n");
544 if (bcmp(&handrx, &handtx, sizeof(handtx)) == 0)
545 goto urandfail; /* read all zeros */
547 /* ERR_load_crypto_strings(); openssl debugging */
550 * Handshake with the remote.
552 * Encrypt with my private and remote's public
553 * Decrypt with my private and remote's public
555 * When encrypting we have to make sure our buffer fits within the
556 * modulus, which typically requires bit 7 o the first byte to be
557 * zero. To be safe make sure that bit 7 and bit 6 is zero.
559 snprintf(handtx.quickmsg, sizeof(handtx.quickmsg), "Testing 1 2 3");
560 handtx.magic = HAMMER2_MSGHDR_MAGIC;
563 assert(sizeof(handtx.verf) * 4 == sizeof(handtx.sess));
564 bzero(handtx.verf, sizeof(handtx.verf));
566 handtx.pad1[0] &= 0x3f; /* message must fit within modulus */
567 handtx.pad2[0] &= 0x3f; /* message must fit within modulus */
569 for (i = 0; i < sizeof(handtx.sess); ++i)
570 handtx.verf[i / 4] ^= handtx.sess[i];
573 * Write handshake buffer to remote
575 for (i = 0; i < sizeof(handtx); i += blksize) {
576 ptr = (char *)&handtx + i;
579 * Since we are double-encrypting we have to make
580 * sure that the result of the first stage does
581 * not blow out the modulus for the second stage.
583 * The pointer is pointing to the pad*[] area so
584 * we can mess with that until the first stage
589 if (RSA_private_encrypt(blksize, ptr, buf1,
590 keys[2], RSA_NO_PADDING) < 0) {
591 iocom->ioq_rx.error =
592 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
594 } while (buf1[0] & 0xC0);
596 if (RSA_public_encrypt(blksize, buf1, buf2,
597 keys[0], RSA_NO_PADDING) < 0) {
598 iocom->ioq_rx.error =
599 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
602 if (write(iocom->sock_fd, buf2, blksize) != (ssize_t)blksize) {
603 fprintf(stderr, "WRITE ERROR\n");
606 if (iocom->ioq_rx.error) {
607 iocom->flags |= HAMMER2_IOCOMF_EOF;
609 fprintf(stderr, "auth failure: key exchange failure "
610 "during encryption\n");
615 * Read handshake buffer from remote
618 while (i < sizeof(handrx)) {
619 ptr = (char *)&handrx + i;
620 n = read(iocom->sock_fd, ptr, blksize - (i & blkmask));
623 ptr -= (i & blkmask);
625 if (keys[0] && (i & blkmask) == 0) {
626 if (RSA_private_decrypt(blksize, ptr, buf1,
627 keys[2], RSA_NO_PADDING) < 0)
628 iocom->ioq_rx.error =
629 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
630 if (RSA_public_decrypt(blksize, buf1, ptr,
631 keys[0], RSA_NO_PADDING) < 0)
632 iocom->ioq_rx.error =
633 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
636 if (iocom->ioq_rx.error) {
637 iocom->flags |= HAMMER2_IOCOMF_EOF;
639 fprintf(stderr, "auth failure: key exchange failure "
640 "during decryption\n");
645 * Validate the received data. Try to make this a constant-time
648 if (i != sizeof(handrx)) {
650 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
651 iocom->flags |= HAMMER2_IOCOMF_EOF;
653 fprintf(stderr, "auth failure: key exchange failure\n");
657 if (handrx.magic == HAMMER2_MSGHDR_MAGIC_REV) {
658 handrx.version = bswap16(handrx.version);
659 handrx.flags = bswap32(handrx.flags);
661 for (i = 0; i < sizeof(handrx.sess); ++i)
662 handrx.verf[i / 4] ^= handrx.sess[i];
664 for (i = 0; i < sizeof(handrx.verf); ++i)
666 if (handrx.version != 1)
671 assert(HAMMER2_AES_KEY_SIZE * 2 == sizeof(handrx.sess));
673 * Use separate session keys and session fixed IVs for receive and
676 error = _gcm_init(&iocom->ioq_rx, handrx.sess, HAMMER2_AES_KEY_SIZE,
677 handrx.sess + HAMMER2_AES_KEY_SIZE,
678 sizeof(handrx.sess) - HAMMER2_AES_KEY_SIZE,
683 error = _gcm_init(&iocom->ioq_tx, handtx.sess, HAMMER2_AES_KEY_SIZE,
684 handtx.sess + HAMMER2_AES_KEY_SIZE,
685 sizeof(handtx.sess) - HAMMER2_AES_KEY_SIZE,
690 iocom->flags |= HAMMER2_IOCOMF_CRYPTED;
693 fprintf(stderr, "auth success: %s\n", handrx.quickmsg);
706 * Decrypt pending data in the ioq's fifo. The data is decrypted in-place.
709 hammer2_crypto_decrypt(hammer2_iocom_t *iocom __unused, hammer2_ioq_t *ioq)
717 * fifo_beg to fifo_cdx is data already decrypted.
718 * fifo_cdn to fifo_end is data not yet decrypted.
720 p_len = ioq->fifo_end - ioq->fifo_cdn; /* data not yet decrypted */
725 while (p_len >= HAMMER2_CRYPTO_TAG_SIZE + HAMMER2_CRYPTO_CHUNK_SIZE) {
726 bcopy(ioq->buf + ioq->fifo_cdn, buf,
727 HAMMER2_CRYPTO_TAG_SIZE + HAMMER2_CRYPTO_CHUNK_SIZE);
728 error = hammer2_crypto_decrypt_chunk(ioq, buf,
729 ioq->buf + ioq->fifo_cdx,
730 HAMMER2_CRYPTO_CHUNK_SIZE,
733 printf("dec: p_len: %d, used: %d, fifo_cdn: %ju, fifo_cdx: %ju\n",
734 p_len, used, ioq->fifo_cdn, ioq->fifo_cdx);
737 ioq->fifo_cdn += used;
738 ioq->fifo_cdx += HAMMER2_CRYPTO_CHUNK_SIZE;
740 printf("dec: p_len: %d, used: %d, fifo_cdn: %ju, fifo_cdx: %ju\n",
741 p_len, used, ioq->fifo_cdn, ioq->fifo_cdx);
747 * *nactp is set to the number of ORIGINAL bytes consumed by the encrypter.
748 * The FIFO may contain more data.
751 hammer2_crypto_encrypt(hammer2_iocom_t *iocom __unused, hammer2_ioq_t *ioq,
752 struct iovec *iov, int n, size_t *nactp)
754 int p_len, used, ct_used;
759 nmax = sizeof(ioq->buf) - ioq->fifo_end; /* max new bytes */
762 for (i = 0; i < n && nmax; ++i) {
764 p_len = iov[i].iov_len;
765 assert((p_len & HAMMER2_AES_KEY_MASK) == 0);
767 while (p_len >= HAMMER2_CRYPTO_CHUNK_SIZE &&
768 nmax >= HAMMER2_CRYPTO_CHUNK_SIZE + HAMMER2_CRYPTO_TAG_SIZE) {
769 error = hammer2_crypto_encrypt_chunk(ioq,
770 ioq->buf + ioq->fifo_cdx,
771 (char *)iov[i].iov_base + used,
772 HAMMER2_CRYPTO_CHUNK_SIZE, &ct_used);
774 printf("nactp: %ju, p_len: %d, ct_used: %d, used: %d, nmax: %ju\n",
775 *nactp, p_len, ct_used, used, nmax);
778 *nactp += (size_t)HAMMER2_CRYPTO_CHUNK_SIZE; /* plaintext count */
779 used += HAMMER2_CRYPTO_CHUNK_SIZE;
780 p_len -= HAMMER2_CRYPTO_CHUNK_SIZE;
782 ioq->fifo_cdx += (size_t)ct_used; /* crypted count */
783 ioq->fifo_cdn += (size_t)ct_used; /* crypted count */
784 ioq->fifo_end += (size_t)ct_used;
785 nmax -= (size_t)ct_used;
787 printf("nactp: %ju, p_len: %d, ct_used: %d, used: %d, nmax: %ju\n",
788 *nactp, p_len, ct_used, used, nmax);
792 iov[0].iov_base = ioq->buf + ioq->fifo_beg;
793 iov[0].iov_len = ioq->fifo_cdx - ioq->fifo_beg;