git: 757d96ade64c - stable/13 - ossl: Use crypto_cursor_segment().

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 21 Oct 2021 17:07:17 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=757d96ade64c0488512147bcd07117f3b0f9c91c

commit 757d96ade64c0488512147bcd07117f3b0f9c91c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2021-05-25 23:59:19 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2021-10-21 15:52:13 +0000

    ossl: Use crypto_cursor_segment().
    
    Reviewed by:    markj
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D30447
    
    (cherry picked from commit 1c09320d5833fef8a4b6cc0091883fd47ea1eb1b)
---
 sys/crypto/openssl/ossl_chacha20.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/sys/crypto/openssl/ossl_chacha20.c b/sys/crypto/openssl/ossl_chacha20.c
index 7fa1a297052e..a6f56aca1f8f 100644
--- a/sys/crypto/openssl/ossl_chacha20.c
+++ b/sys/crypto/openssl/ossl_chacha20.c
@@ -65,15 +65,13 @@ ossl_chacha20(struct cryptop *crp, const struct crypto_session_params *csp)
 	resid = crp->crp_payload_length;
 	crypto_cursor_init(&cc_in, &crp->crp_buf);
 	crypto_cursor_advance(&cc_in, crp->crp_payload_start);
-	inseg = crypto_cursor_segbase(&cc_in);
-	inlen = crypto_cursor_seglen(&cc_in);
+	inseg = crypto_cursor_segment(&cc_in, &inlen);
 	if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
 		crypto_cursor_init(&cc_out, &crp->crp_obuf);
 		crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
 	} else
 		cc_out = cc_in;
-	outseg = crypto_cursor_segbase(&cc_out);
-	outlen = crypto_cursor_seglen(&cc_out);
+	outseg = crypto_cursor_segment(&cc_out, &outlen);
 	while (resid >= CHACHA_BLK_SIZE) {
 		if (inlen < CHACHA_BLK_SIZE) {
 			crypto_cursor_copydata(&cc_in, CHACHA_BLK_SIZE, block);
@@ -111,16 +109,14 @@ ossl_chacha20(struct cryptop *crp, const struct crypto_session_params *csp)
 
 		if (out == block) {
 			crypto_cursor_copyback(&cc_out, CHACHA_BLK_SIZE, block);
-			outseg = crypto_cursor_segbase(&cc_out);
-			outlen = crypto_cursor_seglen(&cc_out);
+			outseg = crypto_cursor_segment(&cc_out, &outlen);
 		} else {
 			crypto_cursor_advance(&cc_out, todo);
 			outseg += todo;
 			outlen -= todo;
 		}
 		if (in == block) {
-			inseg = crypto_cursor_segbase(&cc_in);
-			inlen = crypto_cursor_seglen(&cc_in);
+			inseg = crypto_cursor_segment(&cc_in, &inlen);
 		} else {
 			crypto_cursor_advance(&cc_in, todo);
 			inseg += todo;
@@ -196,15 +192,13 @@ ossl_chacha20_poly1305_encrypt(struct cryptop *crp,
 	resid = crp->crp_payload_length;
 	crypto_cursor_init(&cc_in, &crp->crp_buf);
 	crypto_cursor_advance(&cc_in, crp->crp_payload_start);
-	inseg = crypto_cursor_segbase(&cc_in);
-	inlen = crypto_cursor_seglen(&cc_in);
+	inseg = crypto_cursor_segment(&cc_in, &inlen);
 	if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
 		crypto_cursor_init(&cc_out, &crp->crp_obuf);
 		crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
 	} else
 		cc_out = cc_in;
-	outseg = crypto_cursor_segbase(&cc_out);
-	outlen = crypto_cursor_seglen(&cc_out);
+	outseg = crypto_cursor_segment(&cc_out, &outlen);
 	while (resid >= CHACHA_BLK_SIZE) {
 		if (inlen < CHACHA_BLK_SIZE) {
 			crypto_cursor_copydata(&cc_in, CHACHA_BLK_SIZE, block);
@@ -243,16 +237,14 @@ ossl_chacha20_poly1305_encrypt(struct cryptop *crp,
 
 		if (out == block) {
 			crypto_cursor_copyback(&cc_out, CHACHA_BLK_SIZE, block);
-			outseg = crypto_cursor_segbase(&cc_out);
-			outlen = crypto_cursor_seglen(&cc_out);
+			outseg = crypto_cursor_segment(&cc_out, &outlen);
 		} else {
 			crypto_cursor_advance(&cc_out, todo);
 			outseg += todo;
 			outlen -= todo;
 		}
 		if (in == block) {
-			inseg = crypto_cursor_segbase(&cc_in);
-			inlen = crypto_cursor_seglen(&cc_in);
+			inseg = crypto_cursor_segment(&cc_in, &inlen);
 		} else {
 			crypto_cursor_advance(&cc_in, todo);
 			inseg += todo;
@@ -368,15 +360,13 @@ ossl_chacha20_poly1305_decrypt(struct cryptop *crp,
 	resid = crp->crp_payload_length;
 	crypto_cursor_init(&cc_in, &crp->crp_buf);
 	crypto_cursor_advance(&cc_in, crp->crp_payload_start);
-	inseg = crypto_cursor_segbase(&cc_in);
-	inlen = crypto_cursor_seglen(&cc_in);
+	inseg = crypto_cursor_segment(&cc_in, &inlen);
 	if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
 		crypto_cursor_init(&cc_out, &crp->crp_obuf);
 		crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
 	} else
 		cc_out = cc_in;
-	outseg = crypto_cursor_segbase(&cc_out);
-	outlen = crypto_cursor_seglen(&cc_out);
+	outseg = crypto_cursor_segment(&cc_out, &outlen);
 	while (resid >= CHACHA_BLK_SIZE) {
 		if (inlen < CHACHA_BLK_SIZE) {
 			crypto_cursor_copydata(&cc_in, CHACHA_BLK_SIZE, block);
@@ -414,16 +404,14 @@ ossl_chacha20_poly1305_decrypt(struct cryptop *crp,
 
 		if (out == block) {
 			crypto_cursor_copyback(&cc_out, CHACHA_BLK_SIZE, block);
-			outseg = crypto_cursor_segbase(&cc_out);
-			outlen = crypto_cursor_seglen(&cc_out);
+			outseg = crypto_cursor_segment(&cc_out, &outlen);
 		} else {
 			crypto_cursor_advance(&cc_out, todo);
 			outseg += todo;
 			outlen -= todo;
 		}
 		if (in == block) {
-			inseg = crypto_cursor_segbase(&cc_in);
-			inlen = crypto_cursor_seglen(&cc_in);
+			inseg = crypto_cursor_segment(&cc_in, &inlen);
 		} else {
 			crypto_cursor_advance(&cc_in, todo);
 			inseg += todo;