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
38 #include <sys/endian.h>
41 * Setup crypto for pthreads
43 static pthread_mutex_t *crypto_locks;
48 hammer2_crypto_id_callback(void)
50 return ((unsigned long)(uintptr_t)pthread_self());
55 hammer2_crypto_locking_callback(int mode, int type,
56 const char *file __unused, int line __unused)
58 assert(type >= 0 && type < crypto_count);
59 if (mode & CRYPTO_LOCK) {
60 pthread_mutex_lock(&crypto_locks[type]);
62 pthread_mutex_unlock(&crypto_locks[type]);
67 hammer2_crypto_setup(void)
69 crypto_count = CRYPTO_num_locks();
70 crypto_locks = calloc(crypto_count, sizeof(crypto_locks[0]));
71 CRYPTO_set_id_callback(hammer2_crypto_id_callback);
72 CRYPTO_set_locking_callback(hammer2_crypto_locking_callback);
77 _gcm_init(hammer2_ioq_t *ioq, char *key, int klen, char *iv_fixed, int ivlen,
82 if (klen < 32 /* 256 bits */ || ivlen < 4 /* 32 bits */) {
84 fprintf(stderr, "Not enough key or iv material\n");
88 printf("%s key: ", enc ? "Encryption" : "Decryption");
89 for (i = 0; i < HAMMER2_AES_KEY_SIZE; ++i)
90 printf("%02x", (unsigned char)key[i]);
93 printf("%s iv: ", enc ? "Encryption" : "Decryption");
94 for (i = 0; i < HAMMER2_CRYPTO_IV_FIXED_SIZE; ++i)
95 printf("%02x", (unsigned char)iv_fixed[i]);
96 printf(" (fixed part only)\n");
99 EVP_CIPHER_CTX_init(&ioq->ctx);
102 ok = EVP_EncryptInit_ex(&ioq->ctx, EVP_aes_256_gcm(), NULL,
105 ok = EVP_DecryptInit_ex(&ioq->ctx, EVP_aes_256_gcm(), NULL,
111 * According to the original Galois/Counter Mode of Operation (GCM)
112 * proposal, only IVs that are exactly 96 bits get used without any
113 * further processing. Other IV sizes cause the GHASH() operation
114 * to be applied to the IV, which is more costly.
116 * The NIST SP 800-38D also recommends using a 96 bit IV for the same
117 * reasons. We actually follow the deterministic construction
118 * recommended in NIST SP 800-38D with a 64 bit invocation field as an
119 * integer counter and a random, session-specific fixed field.
121 * This means that we can essentially use the same session key and
122 * IV fixed field for up to 2^64 invocations of the authenticated
123 * encryption or decryption.
125 * With a chunk size of 64 bytes, this adds up to 1 zettabyte of
128 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_SET_IVLEN,
129 HAMMER2_CRYPTO_IV_SIZE, NULL);
133 memset(ioq->iv, 0, HAMMER2_CRYPTO_IV_SIZE);
134 memcpy(ioq->iv, iv_fixed, HAMMER2_CRYPTO_IV_FIXED_SIZE);
137 * Strictly speaking, padding is irrelevant with a counter mode
140 * However, setting padding to 0, even if using a counter mode such
141 * as GCM, will cause an error in _finish if the pt/ct size is not
142 * a multiple of the cipher block size.
144 EVP_CIPHER_CTX_set_padding(&ioq->ctx, 0);
150 fprintf(stderr, "Error during _gcm_init\n");
156 _gcm_iv_increment(char *iv)
159 * Deterministic construction according to NIST SP 800-38D, with
160 * 64 bit invocation field as integer counter.
162 * In other words, our 96 bit IV consists of a 32 bit fixed field
163 * unique to the session and a 64 bit integer counter.
166 uint64_t *c = (uint64_t *)(&iv[HAMMER2_CRYPTO_IV_FIXED_SIZE]);
168 /* Increment invocation field integer counter */
170 * XXX: this should ideally be an atomic update, but we don't have
171 * an atomic_fetchadd_64 for i386 yet
173 *c = htobe64(be64toh(*c)+1);
176 * Detect wrap-around, which means it is time to renegotiate
177 * the session to get a new key and/or fixed field.
179 return (c == 0) ? 0 : 1;
184 hammer2_crypto_encrypt_chunk(hammer2_ioq_t *ioq, char *ct, char *pt,
185 int in_size, int *out_size)
195 /* Re-initialize with new IV (but without redoing the key schedule) */
196 ok = EVP_EncryptInit_ex(&ioq->ctx, NULL, NULL, NULL, ioq->iv);
200 ok = EVP_EncryptUpdate(&ioq->ctx, ct, &u_len, pt, in_size);
204 ok = EVP_EncryptFinal(&ioq->ctx, ct + u_len, &f_len);
208 /* Retrieve auth tag */
209 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_GET_TAG,
210 HAMMER2_CRYPTO_TAG_SIZE,
216 printf("enc_chunk iv: ");
217 for (i = 0; i < HAMMER2_CRYPTO_IV_SIZE; i++)
218 printf("%02x", (unsigned char)ioq->iv[i]);
221 printf("enc_chunk pt: ");
222 for (i = 0; i < in_size; i++)
223 printf("%02x", (unsigned char)pt[i]);
226 printf("enc_chunk ct: ");
227 for (i = 0; i < in_size; i++)
228 printf("%02x", (unsigned char)ct[i]);
231 printf("enc_chunk tag: ");
232 for (i = 0; i < HAMMER2_CRYPTO_TAG_SIZE; i++)
233 printf("%02x", (unsigned char)ct[i + u_len + f_len]);
237 ok = _gcm_iv_increment(ioq->iv);
239 ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
243 *out_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
248 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
251 fprintf(stderr, "error during encrypt_chunk\n");
257 hammer2_crypto_decrypt_chunk(hammer2_ioq_t *ioq, char *ct, char *pt,
258 int out_size, int *consume_size)
268 /* Re-initialize with new IV (but without redoing the key schedule) */
269 ok = EVP_DecryptInit_ex(&ioq->ctx, NULL, NULL, NULL, ioq->iv);
271 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
276 printf("dec_chunk iv: ");
277 for (i = 0; i < HAMMER2_CRYPTO_IV_SIZE; i++)
278 printf("%02x", (unsigned char)ioq->iv[i]);
281 printf("dec_chunk ct: ");
282 for (i = 0; i < out_size; i++)
283 printf("%02x", (unsigned char)ct[i]);
286 printf("dec_chunk tag: ");
287 for (i = 0; i < HAMMER2_CRYPTO_TAG_SIZE; i++)
288 printf("%02x", (unsigned char)ct[out_size + i]);
292 ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_SET_TAG,
293 HAMMER2_CRYPTO_TAG_SIZE,
296 ioq->error = HAMMER2_IOQ_ERROR_ALGO;
300 ok = EVP_DecryptUpdate(&ioq->ctx, pt, &u_len, ct, out_size);
304 ok = EVP_DecryptFinal(&ioq->ctx, pt + u_len, &f_len);
308 ok = _gcm_iv_increment(ioq->iv);
310 ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
314 *consume_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
317 printf("dec_chunk pt: ");
318 for (i = 0; i < out_size; i++)
319 printf("%02x", (unsigned char)pt[i]);
326 ioq->error = HAMMER2_IOQ_ERROR_MACFAIL;
329 fprintf(stderr, "error during decrypt_chunk (likely authentication error)\n");
334 * Synchronously negotiate crypto for a new session. This must occur
335 * within 10 seconds or the connection is error'd out.
337 * We work off the IP address and/or reverse DNS. The IP address is
338 * checked first, followed by the IP address at various levels of granularity,
339 * followed by the full domain name and domain names at various levels of
342 * /etc/hammer2/remote/<name>.pub - Contains a public key
343 * /etc/hammer2/remote/<name>.none - Indicates no encryption (empty file)
344 * (e.g. localhost.none).
346 * We first attempt to locate a public key file based on the peer address or
349 * <name>.none - No further negotiation is needed. We simply return.
350 * All communication proceeds without encryption.
351 * No public key handshake occurs in this situation.
352 * (both ends must match).
354 * <name>.pub - We have located the public key for the peer. Both
355 * sides transmit a block encrypted with their private
356 * keys and the peer's public key.
358 * Both sides receive a block and decrypt it.
360 * Both sides formulate a reply using the decrypted
361 * block and transmit it.
363 * communication proceeds with the negotiated session
364 * key (typically AES-256-CBC).
366 * If we fail to locate the appropriate file and no floating.db exists the
367 * connection is terminated without further action.
369 * If floating.db exists the connection proceeds with a floating negotiation.
373 struct sockaddr_in sa_in;
374 struct sockaddr_in6 sa_in6;
378 hammer2_crypto_negotiate(hammer2_iocom_t *iocom)
381 socklen_t salen = sizeof(sa);
384 hammer2_handshake_t handtx;
385 hammer2_handshake_t handrx;
386 char buf1[sizeof(handtx)];
387 char buf2[sizeof(handtx)];
392 RSA *keys[3] = { NULL, NULL, NULL };
401 * Get the peer IP address for the connection as a string.
403 if (getpeername(iocom->sock_fd, &sa.sa, &salen) < 0) {
404 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOPEER;
405 iocom->flags |= HAMMER2_IOCOMF_EOF;
407 fprintf(stderr, "accept: getpeername() failed\n");
410 if (getnameinfo(&sa.sa, salen, peername, sizeof(peername),
411 NULL, 0, NI_NUMERICHOST) < 0) {
412 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOPEER;
413 iocom->flags |= HAMMER2_IOCOMF_EOF;
415 fprintf(stderr, "accept: cannot decode sockaddr\n");
419 if (realhostname_sa(realname, sizeof(realname),
420 &sa.sa, salen) == HOSTNAME_FOUND) {
421 fprintf(stderr, "accept from %s (%s)\n",
424 fprintf(stderr, "accept from %s\n", peername);
429 * Find the remote host's public key
431 * If the link is not to be encrypted (<ip>.none located) we shortcut
432 * the handshake entirely. No buffers are exchanged.
434 asprintf(&path, "%s/%s.pub", HAMMER2_PATH_REMOTE, peername);
435 if ((fp = fopen(path, "r")) == NULL) {
437 asprintf(&path, "%s/%s.none",
438 HAMMER2_PATH_REMOTE, peername);
439 if (stat(path, &st) < 0) {
440 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NORKEY;
441 iocom->flags |= HAMMER2_IOCOMF_EOF;
443 fprintf(stderr, "auth failure: unknown host\n");
447 fprintf(stderr, "auth succeeded, unencrypted link\n");
451 keys[0] = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
453 if (keys[0] == NULL) {
454 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
455 iocom->flags |= HAMMER2_IOCOMF_EOF;
458 "auth failure: bad key format\n");
464 * Get our public and private keys
467 asprintf(&path, HAMMER2_DEFAULT_DIR "/rsa.pub");
468 if ((fp = fopen(path, "r")) == NULL) {
469 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOLKEY;
470 iocom->flags |= HAMMER2_IOCOMF_EOF;
473 keys[1] = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
475 if (keys[1] == NULL) {
476 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
477 iocom->flags |= HAMMER2_IOCOMF_EOF;
479 fprintf(stderr, "auth failure: bad host key format\n");
484 asprintf(&path, HAMMER2_DEFAULT_DIR "/rsa.prv");
485 if ((fp = fopen(path, "r")) == NULL) {
486 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_NOLKEY;
487 iocom->flags |= HAMMER2_IOCOMF_EOF;
489 fprintf(stderr, "auth failure: bad host key format\n");
492 keys[2] = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
494 if (keys[2] == NULL) {
495 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
496 iocom->flags |= HAMMER2_IOCOMF_EOF;
498 fprintf(stderr, "auth failure: bad host key format\n");
505 * public key encrypt/decrypt block size.
508 blksize = (size_t)RSA_size(keys[0]);
509 if (blksize != (size_t)RSA_size(keys[1]) ||
510 blksize != (size_t)RSA_size(keys[2]) ||
511 sizeof(handtx) % blksize != 0) {
512 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYFMT;
513 iocom->flags |= HAMMER2_IOCOMF_EOF;
515 fprintf(stderr, "auth failure: "
516 "key size mismatch\n");
520 blksize = sizeof(handtx);
522 blkmask = blksize - 1;
524 bzero(&handrx, sizeof(handrx));
525 bzero(&handtx, sizeof(handtx));
528 * Fill all unused fields (particular all junk fields) with random
529 * data, and also set the session key.
531 fd = open("/dev/urandom", O_RDONLY);
533 fstat(fd, &st) < 0 || /* something wrong */
534 S_ISREG(st.st_mode) || /* supposed to be a RNG dev! */
535 read(fd, &handtx, sizeof(handtx)) != sizeof(handtx)) {
539 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_BADURANDOM;
540 iocom->flags |= HAMMER2_IOCOMF_EOF;
542 fprintf(stderr, "auth failure: bad rng\n");
545 if (bcmp(&handrx, &handtx, sizeof(handtx)) == 0)
546 goto urandfail; /* read all zeros */
548 /* ERR_load_crypto_strings(); openssl debugging */
551 * Handshake with the remote.
553 * Encrypt with my private and remote's public
554 * Decrypt with my private and remote's public
556 * When encrypting we have to make sure our buffer fits within the
557 * modulus, which typically requires bit 7 o the first byte to be
558 * zero. To be safe make sure that bit 7 and bit 6 is zero.
560 snprintf(handtx.quickmsg, sizeof(handtx.quickmsg), "Testing 1 2 3");
561 handtx.magic = HAMMER2_MSGHDR_MAGIC;
564 assert(sizeof(handtx.verf) * 4 == sizeof(handtx.sess));
565 bzero(handtx.verf, sizeof(handtx.verf));
567 handtx.pad1[0] &= 0x3f; /* message must fit within modulus */
568 handtx.pad2[0] &= 0x3f; /* message must fit within modulus */
570 for (i = 0; i < sizeof(handtx.sess); ++i)
571 handtx.verf[i / 4] ^= handtx.sess[i];
574 * Write handshake buffer to remote
576 for (i = 0; i < sizeof(handtx); i += blksize) {
577 ptr = (char *)&handtx + i;
580 * Since we are double-encrypting we have to make
581 * sure that the result of the first stage does
582 * not blow out the modulus for the second stage.
584 * The pointer is pointing to the pad*[] area so
585 * we can mess with that until the first stage
590 if (RSA_private_encrypt(blksize, ptr, buf1,
591 keys[2], RSA_NO_PADDING) < 0) {
592 iocom->ioq_rx.error =
593 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
595 } while (buf1[0] & 0xC0);
597 if (RSA_public_encrypt(blksize, buf1, buf2,
598 keys[0], RSA_NO_PADDING) < 0) {
599 iocom->ioq_rx.error =
600 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
603 if (write(iocom->sock_fd, buf2, blksize) != (ssize_t)blksize) {
604 fprintf(stderr, "WRITE ERROR\n");
607 if (iocom->ioq_rx.error) {
608 iocom->flags |= HAMMER2_IOCOMF_EOF;
610 fprintf(stderr, "auth failure: key exchange failure "
611 "during encryption\n");
616 * Read handshake buffer from remote
619 while (i < sizeof(handrx)) {
620 ptr = (char *)&handrx + i;
621 n = read(iocom->sock_fd, ptr, blksize - (i & blkmask));
624 ptr -= (i & blkmask);
626 if (keys[0] && (i & blkmask) == 0) {
627 if (RSA_private_decrypt(blksize, ptr, buf1,
628 keys[2], RSA_NO_PADDING) < 0)
629 iocom->ioq_rx.error =
630 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
631 if (RSA_public_decrypt(blksize, buf1, ptr,
632 keys[0], RSA_NO_PADDING) < 0)
633 iocom->ioq_rx.error =
634 HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
637 if (iocom->ioq_rx.error) {
638 iocom->flags |= HAMMER2_IOCOMF_EOF;
640 fprintf(stderr, "auth failure: key exchange failure "
641 "during decryption\n");
646 * Validate the received data. Try to make this a constant-time
649 if (i != sizeof(handrx)) {
651 iocom->ioq_rx.error = HAMMER2_IOQ_ERROR_KEYXCHGFAIL;
652 iocom->flags |= HAMMER2_IOCOMF_EOF;
654 fprintf(stderr, "auth failure: key exchange failure\n");
658 if (handrx.magic == HAMMER2_MSGHDR_MAGIC_REV) {
659 handrx.version = bswap16(handrx.version);
660 handrx.flags = bswap32(handrx.flags);
662 for (i = 0; i < sizeof(handrx.sess); ++i)
663 handrx.verf[i / 4] ^= handrx.sess[i];
665 for (i = 0; i < sizeof(handrx.verf); ++i)
667 if (handrx.version != 1)
672 assert(HAMMER2_AES_KEY_SIZE * 2 == sizeof(handrx.sess));
674 * Use separate session keys and session fixed IVs for receive and
677 error = _gcm_init(&iocom->ioq_rx, handrx.sess, HAMMER2_AES_KEY_SIZE,
678 handrx.sess + HAMMER2_AES_KEY_SIZE,
679 sizeof(handrx.sess) - HAMMER2_AES_KEY_SIZE,
684 error = _gcm_init(&iocom->ioq_tx, handtx.sess, HAMMER2_AES_KEY_SIZE,
685 handtx.sess + HAMMER2_AES_KEY_SIZE,
686 sizeof(handtx.sess) - HAMMER2_AES_KEY_SIZE,
691 iocom->flags |= HAMMER2_IOCOMF_CRYPTED;
694 fprintf(stderr, "auth success: %s\n", handrx.quickmsg);
707 * Decrypt pending data in the ioq's fifo. The data is decrypted in-place.
710 hammer2_crypto_decrypt(hammer2_iocom_t *iocom __unused, hammer2_ioq_t *ioq)
718 * fifo_beg to fifo_cdx is data already decrypted.
719 * fifo_cdn to fifo_end is data not yet decrypted.
721 p_len = ioq->fifo_end - ioq->fifo_cdn; /* data not yet decrypted */
726 while (p_len >= HAMMER2_CRYPTO_TAG_SIZE + HAMMER2_CRYPTO_CHUNK_SIZE) {
727 bcopy(ioq->buf + ioq->fifo_cdn, buf,
728 HAMMER2_CRYPTO_TAG_SIZE + HAMMER2_CRYPTO_CHUNK_SIZE);
729 error = hammer2_crypto_decrypt_chunk(ioq, buf,
730 ioq->buf + ioq->fifo_cdx,
731 HAMMER2_CRYPTO_CHUNK_SIZE,
734 printf("dec: p_len: %d, used: %d, fifo_cdn: %ju, fifo_cdx: %ju\n",
735 p_len, used, ioq->fifo_cdn, ioq->fifo_cdx);
738 ioq->fifo_cdn += used;
739 ioq->fifo_cdx += HAMMER2_CRYPTO_CHUNK_SIZE;
741 printf("dec: p_len: %d, used: %d, fifo_cdn: %ju, fifo_cdx: %ju\n",
742 p_len, used, ioq->fifo_cdn, ioq->fifo_cdx);
748 * *nactp is set to the number of ORIGINAL bytes consumed by the encrypter.
749 * The FIFO may contain more data.
752 hammer2_crypto_encrypt(hammer2_iocom_t *iocom __unused, hammer2_ioq_t *ioq,
753 struct iovec *iov, int n, size_t *nactp)
755 int p_len, used, ct_used;
760 nmax = sizeof(ioq->buf) - ioq->fifo_end; /* max new bytes */
763 for (i = 0; i < n && nmax; ++i) {
765 p_len = iov[i].iov_len;
766 assert((p_len & HAMMER2_AES_KEY_MASK) == 0);
768 while (p_len >= HAMMER2_CRYPTO_CHUNK_SIZE &&
769 nmax >= HAMMER2_CRYPTO_CHUNK_SIZE + HAMMER2_CRYPTO_TAG_SIZE) {
770 error = hammer2_crypto_encrypt_chunk(ioq,
771 ioq->buf + ioq->fifo_cdx,
772 (char *)iov[i].iov_base + used,
773 HAMMER2_CRYPTO_CHUNK_SIZE, &ct_used);
775 printf("nactp: %ju, p_len: %d, ct_used: %d, used: %d, nmax: %ju\n",
776 *nactp, p_len, ct_used, used, nmax);
779 *nactp += (size_t)HAMMER2_CRYPTO_CHUNK_SIZE; /* plaintext count */
780 used += HAMMER2_CRYPTO_CHUNK_SIZE;
781 p_len -= HAMMER2_CRYPTO_CHUNK_SIZE;
783 ioq->fifo_cdx += (size_t)ct_used; /* crypted count */
784 ioq->fifo_cdn += (size_t)ct_used; /* crypted count */
785 ioq->fifo_end += (size_t)ct_used;
786 nmax -= (size_t)ct_used;
788 printf("nactp: %ju, p_len: %d, ct_used: %d, used: %d, nmax: %ju\n",
789 *nactp, p_len, ct_used, used, nmax);
793 iov[0].iov_base = ioq->buf + ioq->fifo_beg;
794 iov[0].iov_len = ioq->fifo_cdx - ioq->fifo_beg;