diff options
author | schwarze <> | 2023-12-26 22:13:00 +0000 |
---|---|---|
committer | schwarze <> | 2023-12-26 22:13:00 +0000 |
commit | 798623cbaa933d9aa6cb8a1b7a1d8e8b0513eb65 (patch) | |
tree | 32f5cd22e02d0bfe35994071671da3dd51b498d1 /src | |
parent | 5819b47a5811023ede6a0f5e8dad4fcad600e467 (diff) | |
download | openbsd-798623cbaa933d9aa6cb8a1b7a1d8e8b0513eb65.tar.gz openbsd-798623cbaa933d9aa6cb8a1b7a1d8e8b0513eb65.tar.bz2 openbsd-798623cbaa933d9aa6cb8a1b7a1d8e8b0513eb65.zip |
Rename some argument placeholders to be less cryptic,
in particular s/inl/in_len/ and s/outl/out_len/ as suggested by tb@.
While here, also get rid of the "outm" placeholder that has been
around since the file was added to OpenSSL in 2000, replacing it
with the usual "out" in the four function prototypes affected; tb@
and myself suspect it was simply a typo followed by copy and paste.
Slightly improve variable naming in the examples, too, for clarity and
consistency, even though that doesn't turn the examples into good examples.
OK tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/man/EVP_CIPHER_CTX_init.3 | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/man/EVP_EncryptInit.3 | 101 |
2 files changed, 58 insertions, 55 deletions
diff --git a/src/lib/libcrypto/man/EVP_CIPHER_CTX_init.3 b/src/lib/libcrypto/man/EVP_CIPHER_CTX_init.3 index 50df2e764d..f328fc05b2 100644 --- a/src/lib/libcrypto/man/EVP_CIPHER_CTX_init.3 +++ b/src/lib/libcrypto/man/EVP_CIPHER_CTX_init.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: EVP_CIPHER_CTX_init.3,v 1.2 2023/12/26 19:09:08 schwarze Exp $ | 1 | .\" $OpenBSD: EVP_CIPHER_CTX_init.3,v 1.3 2023/12/26 22:13:00 schwarze Exp $ |
2 | .\" full merge up to: | 2 | .\" full merge up to: |
3 | .\" OpenSSL EVP_EncryptInit.pod 0874d7f2 Oct 11 13:13:47 2022 +0100 | 3 | .\" OpenSSL EVP_EncryptInit.pod 0874d7f2 Oct 11 13:13:47 2022 +0100 |
4 | .\" | 4 | .\" |
@@ -91,7 +91,7 @@ | |||
91 | .Fa "EVP_CIPHER_CTX *ctx" | 91 | .Fa "EVP_CIPHER_CTX *ctx" |
92 | .Fa "unsigned char *out" | 92 | .Fa "unsigned char *out" |
93 | .Fa "const unsigned char *in" | 93 | .Fa "const unsigned char *in" |
94 | .Fa "unsigned int inl" | 94 | .Fa "unsigned int in_len" |
95 | .Fc | 95 | .Fc |
96 | .Sh DESCRIPTION | 96 | .Sh DESCRIPTION |
97 | .Fn EVP_CIPHER_CTX_init | 97 | .Fn EVP_CIPHER_CTX_init |
@@ -133,11 +133,11 @@ behaviour depends on | |||
133 | If that argument is | 133 | If that argument is |
134 | .Dv NULL | 134 | .Dv NULL |
135 | and | 135 | and |
136 | .Fa inl | 136 | .Fa in_len |
137 | is 0, behaviour is similar to | 137 | is 0, behaviour is similar to |
138 | .Xr EVP_CipherFinal 3 ; | 138 | .Xr EVP_CipherFinal 3 ; |
139 | if | 139 | if |
140 | .Fa inl | 140 | .Fa in_len |
141 | is not 0, behaviour is undefined. | 141 | is not 0, behaviour is undefined. |
142 | If | 142 | If |
143 | .Fa in | 143 | .Fa in |
@@ -158,7 +158,7 @@ It requires that the previous encryption or decryption operation | |||
158 | using the same | 158 | using the same |
159 | .Fa ctx , | 159 | .Fa ctx , |
160 | if there was any, ended exactly on a block boundary and that | 160 | if there was any, ended exactly on a block boundary and that |
161 | .Fa inl | 161 | .Fa in_len |
162 | is an integer multiple of the cipher block size. | 162 | is an integer multiple of the cipher block size. |
163 | If either of these conditions is violated, | 163 | If either of these conditions is violated, |
164 | .Fn EVP_Cipher | 164 | .Fn EVP_Cipher |
@@ -167,7 +167,7 @@ For that reason, using the function | |||
167 | .Xr EVP_CipherUpdate 3 | 167 | .Xr EVP_CipherUpdate 3 |
168 | instead is strongly recommended. | 168 | instead is strongly recommended. |
169 | The latter can safely handle partial blocks, and even if | 169 | The latter can safely handle partial blocks, and even if |
170 | .Fa inl | 170 | .Fa in_len |
171 | actually is a multiple of the cipher block size for all calls, | 171 | actually is a multiple of the cipher block size for all calls, |
172 | the overhead incurred by using | 172 | the overhead incurred by using |
173 | .Xr EVP_CipherUpdate 3 | 173 | .Xr EVP_CipherUpdate 3 |
diff --git a/src/lib/libcrypto/man/EVP_EncryptInit.3 b/src/lib/libcrypto/man/EVP_EncryptInit.3 index 7deabe92c1..e8d22d8677 100644 --- a/src/lib/libcrypto/man/EVP_EncryptInit.3 +++ b/src/lib/libcrypto/man/EVP_EncryptInit.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: EVP_EncryptInit.3,v 1.50 2023/12/01 13:43:37 schwarze Exp $ | 1 | .\" $OpenBSD: EVP_EncryptInit.3,v 1.51 2023/12/26 22:13:00 schwarze Exp $ |
2 | .\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 | 2 | .\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 |
3 | .\" EVP_bf_cbc.pod EVP_cast5_cbc.pod EVP_idea_cbc.pod EVP_rc2_cbc.pod | 3 | .\" EVP_bf_cbc.pod EVP_cast5_cbc.pod EVP_idea_cbc.pod EVP_rc2_cbc.pod |
4 | .\" 7c6d372a Nov 20 13:20:01 2018 +0000 | 4 | .\" 7c6d372a Nov 20 13:20:01 2018 +0000 |
@@ -69,7 +69,7 @@ | |||
69 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 69 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
70 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 70 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
71 | .\" | 71 | .\" |
72 | .Dd $Mdocdate: December 1 2023 $ | 72 | .Dd $Mdocdate: December 26 2023 $ |
73 | .Dt EVP_ENCRYPTINIT 3 | 73 | .Dt EVP_ENCRYPTINIT 3 |
74 | .Os | 74 | .Os |
75 | .Sh NAME | 75 | .Sh NAME |
@@ -150,15 +150,15 @@ | |||
150 | .Fo EVP_EncryptUpdate | 150 | .Fo EVP_EncryptUpdate |
151 | .Fa "EVP_CIPHER_CTX *ctx" | 151 | .Fa "EVP_CIPHER_CTX *ctx" |
152 | .Fa "unsigned char *out" | 152 | .Fa "unsigned char *out" |
153 | .Fa "int *outl" | 153 | .Fa "int *out_len" |
154 | .Fa "const unsigned char *in" | 154 | .Fa "const unsigned char *in" |
155 | .Fa "int inl" | 155 | .Fa "int in_len" |
156 | .Fc | 156 | .Fc |
157 | .Ft int | 157 | .Ft int |
158 | .Fo EVP_EncryptFinal_ex | 158 | .Fo EVP_EncryptFinal_ex |
159 | .Fa "EVP_CIPHER_CTX *ctx" | 159 | .Fa "EVP_CIPHER_CTX *ctx" |
160 | .Fa "unsigned char *out" | 160 | .Fa "unsigned char *out" |
161 | .Fa "int *outl" | 161 | .Fa "int *out_len" |
162 | .Fc | 162 | .Fc |
163 | .Ft int | 163 | .Ft int |
164 | .Fo EVP_DecryptInit_ex | 164 | .Fo EVP_DecryptInit_ex |
@@ -172,15 +172,15 @@ | |||
172 | .Fo EVP_DecryptUpdate | 172 | .Fo EVP_DecryptUpdate |
173 | .Fa "EVP_CIPHER_CTX *ctx" | 173 | .Fa "EVP_CIPHER_CTX *ctx" |
174 | .Fa "unsigned char *out" | 174 | .Fa "unsigned char *out" |
175 | .Fa "int *outl" | 175 | .Fa "int *out_len" |
176 | .Fa "const unsigned char *in" | 176 | .Fa "const unsigned char *in" |
177 | .Fa "int inl" | 177 | .Fa "int in_len" |
178 | .Fc | 178 | .Fc |
179 | .Ft int | 179 | .Ft int |
180 | .Fo EVP_DecryptFinal_ex | 180 | .Fo EVP_DecryptFinal_ex |
181 | .Fa "EVP_CIPHER_CTX *ctx" | 181 | .Fa "EVP_CIPHER_CTX *ctx" |
182 | .Fa "unsigned char *outm" | 182 | .Fa "unsigned char *out" |
183 | .Fa "int *outl" | 183 | .Fa "int *out_len" |
184 | .Fc | 184 | .Fc |
185 | .Ft int | 185 | .Ft int |
186 | .Fo EVP_CipherInit_ex | 186 | .Fo EVP_CipherInit_ex |
@@ -195,15 +195,15 @@ | |||
195 | .Fo EVP_CipherUpdate | 195 | .Fo EVP_CipherUpdate |
196 | .Fa "EVP_CIPHER_CTX *ctx" | 196 | .Fa "EVP_CIPHER_CTX *ctx" |
197 | .Fa "unsigned char *out" | 197 | .Fa "unsigned char *out" |
198 | .Fa "int *outl" | 198 | .Fa "int *out_len" |
199 | .Fa "const unsigned char *in" | 199 | .Fa "const unsigned char *in" |
200 | .Fa "int inl" | 200 | .Fa "int in_len" |
201 | .Fc | 201 | .Fc |
202 | .Ft int | 202 | .Ft int |
203 | .Fo EVP_CipherFinal_ex | 203 | .Fo EVP_CipherFinal_ex |
204 | .Fa "EVP_CIPHER_CTX *ctx" | 204 | .Fa "EVP_CIPHER_CTX *ctx" |
205 | .Fa "unsigned char *outm" | 205 | .Fa "unsigned char *out" |
206 | .Fa "int *outl" | 206 | .Fa "int *out_len" |
207 | .Fc | 207 | .Fc |
208 | .Ft int | 208 | .Ft int |
209 | .Fo EVP_EncryptInit | 209 | .Fo EVP_EncryptInit |
@@ -216,7 +216,7 @@ | |||
216 | .Fo EVP_EncryptFinal | 216 | .Fo EVP_EncryptFinal |
217 | .Fa "EVP_CIPHER_CTX *ctx" | 217 | .Fa "EVP_CIPHER_CTX *ctx" |
218 | .Fa "unsigned char *out" | 218 | .Fa "unsigned char *out" |
219 | .Fa "int *outl" | 219 | .Fa "int *out_len" |
220 | .Fc | 220 | .Fc |
221 | .Ft int | 221 | .Ft int |
222 | .Fo EVP_DecryptInit | 222 | .Fo EVP_DecryptInit |
@@ -228,8 +228,8 @@ | |||
228 | .Ft int | 228 | .Ft int |
229 | .Fo EVP_DecryptFinal | 229 | .Fo EVP_DecryptFinal |
230 | .Fa "EVP_CIPHER_CTX *ctx" | 230 | .Fa "EVP_CIPHER_CTX *ctx" |
231 | .Fa "unsigned char *outm" | 231 | .Fa "unsigned char *out" |
232 | .Fa "int *outl" | 232 | .Fa "int *out_len" |
233 | .Fc | 233 | .Fc |
234 | .Ft int | 234 | .Ft int |
235 | .Fo EVP_CipherInit | 235 | .Fo EVP_CipherInit |
@@ -242,8 +242,8 @@ | |||
242 | .Ft int | 242 | .Ft int |
243 | .Fo EVP_CipherFinal | 243 | .Fo EVP_CipherFinal |
244 | .Fa "EVP_CIPHER_CTX *ctx" | 244 | .Fa "EVP_CIPHER_CTX *ctx" |
245 | .Fa "unsigned char *outm" | 245 | .Fa "unsigned char *out" |
246 | .Fa "int *outl" | 246 | .Fa "int *out_len" |
247 | .Fc | 247 | .Fc |
248 | .Ft int | 248 | .Ft int |
249 | .Fo EVP_CIPHER_CTX_encrypting | 249 | .Fo EVP_CIPHER_CTX_encrypting |
@@ -378,7 +378,7 @@ This is done when the default cipher parameters are not appropriate. | |||
378 | .Pp | 378 | .Pp |
379 | .Fn EVP_EncryptUpdate | 379 | .Fn EVP_EncryptUpdate |
380 | encrypts | 380 | encrypts |
381 | .Fa inl | 381 | .Fa in_len |
382 | bytes from the buffer | 382 | bytes from the buffer |
383 | .Fa in | 383 | .Fa in |
384 | and writes the encrypted version to | 384 | and writes the encrypted version to |
@@ -387,11 +387,13 @@ This function can be called multiple times to encrypt successive blocks | |||
387 | of data. | 387 | of data. |
388 | The amount of data written depends on the block alignment of the | 388 | The amount of data written depends on the block alignment of the |
389 | encrypted data: as a result the amount of data written may be anything | 389 | encrypted data: as a result the amount of data written may be anything |
390 | from zero bytes to (inl + cipher_block_size - 1) so | 390 | from zero bytes to |
391 | .Pq Fa in_len No + cipher_block_size - 1 | ||
392 | so | ||
391 | .Fa out | 393 | .Fa out |
392 | should contain sufficient room. | 394 | should contain sufficient room. |
393 | The actual number of bytes written is placed in | 395 | The actual number of bytes written is placed in |
394 | .Fa outl . | 396 | .Pf * Fa out_len . |
395 | .Pp | 397 | .Pp |
396 | If padding is enabled (the default) then | 398 | If padding is enabled (the default) then |
397 | .Fn EVP_EncryptFinal | 399 | .Fn EVP_EncryptFinal |
@@ -405,7 +407,7 @@ The encrypted final data is written to | |||
405 | .Fa out | 407 | .Fa out |
406 | which should have sufficient space for one cipher block. | 408 | which should have sufficient space for one cipher block. |
407 | The number of bytes written is placed in | 409 | The number of bytes written is placed in |
408 | .Fa outl . | 410 | .Pf * Fa out_len . |
409 | After this function is called, the encryption operation is finished and | 411 | After this function is called, the encryption operation is finished and |
410 | no further calls to | 412 | no further calls to |
411 | .Fn EVP_EncryptUpdate | 413 | .Fn EVP_EncryptUpdate |
@@ -436,9 +438,10 @@ operations except that if padding is enabled the decrypted data buffer | |||
436 | .Fa out | 438 | .Fa out |
437 | passed to | 439 | passed to |
438 | .Fn EVP_DecryptUpdate | 440 | .Fn EVP_DecryptUpdate |
439 | should have sufficient room for (inl + cipher_block_size) bytes | 441 | should have sufficient room for |
440 | unless the cipher block size is 1 in which case | 442 | .Pq Fa in_len No + cipher_block_size |
441 | .Fa inl | 443 | bytes unless the cipher block size is 1 in which case |
444 | .Fa in_len | ||
442 | bytes is sufficient. | 445 | bytes is sufficient. |
443 | .Pp | 446 | .Pp |
444 | .Fn EVP_CipherInit , | 447 | .Fn EVP_CipherInit , |
@@ -703,7 +706,7 @@ parameters | |||
703 | set to | 706 | set to |
704 | .Dv NULL | 707 | .Dv NULL |
705 | and the length passed in the | 708 | and the length passed in the |
706 | .Fa inl | 709 | .Fa in_len |
707 | parameter. | 710 | parameter. |
708 | .Pp | 711 | .Pp |
709 | The following ctrls are supported in CCM mode: | 712 | The following ctrls are supported in CCM mode: |
@@ -729,25 +732,25 @@ The nonce length is given by 15 - L so it is 7 by default for AES. | |||
729 | Encrypt a string using blowfish: | 732 | Encrypt a string using blowfish: |
730 | .Bd -literal -offset 3n | 733 | .Bd -literal -offset 3n |
731 | int | 734 | int |
732 | do_crypt(char *outfile) | 735 | do_crypt(char *out_filename) |
733 | { | 736 | { |
734 | unsigned char outbuf[1024]; | 737 | unsigned char out_buf[1024]; |
735 | int outlen, tmplen; | 738 | int out_len, tmp_len; |
736 | /* | 739 | /* |
737 | * Bogus key and IV: we'd normally set these from | 740 | * Bogus key and IV: we'd normally set these from |
738 | * another source. | 741 | * another source. |
739 | */ | 742 | */ |
740 | unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | 743 | unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; |
741 | unsigned char iv[] = {1,2,3,4,5,6,7,8}; | 744 | unsigned char iv[] = {1,2,3,4,5,6,7,8}; |
742 | const char intext[] = "Some Crypto Text"; | 745 | const char in_text[] = "Some Crypto Text"; |
743 | EVP_CIPHER_CTX *ctx; | 746 | EVP_CIPHER_CTX *ctx; |
744 | FILE *out; | 747 | FILE *out_fileptr; |
745 | 748 | ||
746 | ctx = EVP_CIPHER_CTX_new(); | 749 | ctx = EVP_CIPHER_CTX_new(); |
747 | EVP_EncryptInit_ex(ctx, EVP_bf_cbc(), NULL, key, iv); | 750 | EVP_EncryptInit_ex(ctx, EVP_bf_cbc(), NULL, key, iv); |
748 | 751 | ||
749 | if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, | 752 | if (!EVP_EncryptUpdate(ctx, out_buf, &out_len, in_text, |
750 | strlen(intext))) { | 753 | strlen(in_text))) { |
751 | /* Error */ | 754 | /* Error */ |
752 | EVP_CIPHER_CTX_free(ctx); | 755 | EVP_CIPHER_CTX_free(ctx); |
753 | return 0; | 756 | return 0; |
@@ -756,12 +759,12 @@ do_crypt(char *outfile) | |||
756 | * Buffer passed to EVP_EncryptFinal() must be after data just | 759 | * Buffer passed to EVP_EncryptFinal() must be after data just |
757 | * encrypted to avoid overwriting it. | 760 | * encrypted to avoid overwriting it. |
758 | */ | 761 | */ |
759 | if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) { | 762 | if (!EVP_EncryptFinal_ex(ctx, out_buf + out_len, &tmp_len)) { |
760 | /* Error */ | 763 | /* Error */ |
761 | EVP_CIPHER_CTX_free(ctx); | 764 | EVP_CIPHER_CTX_free(ctx); |
762 | return 0; | 765 | return 0; |
763 | } | 766 | } |
764 | outlen += tmplen; | 767 | out_len += tmp_len; |
765 | EVP_CIPHER_CTX_free(ctx); | 768 | EVP_CIPHER_CTX_free(ctx); |
766 | /* | 769 | /* |
767 | * Need binary mode for fopen because encrypted data is | 770 | * Need binary mode for fopen because encrypted data is |
@@ -769,13 +772,13 @@ do_crypt(char *outfile) | |||
769 | * it won't be NUL terminated and may contain embedded | 772 | * it won't be NUL terminated and may contain embedded |
770 | * NULs. | 773 | * NULs. |
771 | */ | 774 | */ |
772 | out = fopen(outfile, "wb"); | 775 | out_fileptr = fopen(out_filename, "wb"); |
773 | if (out == NULL) { | 776 | if (out_fileptr == NULL) { |
774 | /* Error */ | 777 | /* Error */ |
775 | return 0; | 778 | return 0; |
776 | } | 779 | } |
777 | fwrite(outbuf, 1, outlen, out); | 780 | fwrite(out_buf, 1, out_len, out_fileptr); |
778 | fclose(out); | 781 | fclose(out_fileptr); |
779 | return 1; | 782 | return 1; |
780 | } | 783 | } |
781 | .Ed | 784 | .Ed |
@@ -792,11 +795,11 @@ General encryption, decryption function example using FILE I/O and AES128 | |||
792 | with a 128-bit key: | 795 | with a 128-bit key: |
793 | .Bd -literal | 796 | .Bd -literal |
794 | int | 797 | int |
795 | do_crypt(FILE *in, FILE *out, int do_encrypt) | 798 | do_crypt(FILE *in_fileptr, FILE *out_fileptr, int do_encrypt) |
796 | { | 799 | { |
797 | /* Allow enough space in output buffer for additional block */ | 800 | /* Allow enough space in output buffer for additional block */ |
798 | unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; | 801 | unsigned char in_buf[1024], out_buf[1024 + EVP_MAX_BLOCK_LENGTH]; |
799 | int inlen, outlen; | 802 | int in_len, out_len; |
800 | EVP_CIPHER_CTX *ctx; | 803 | EVP_CIPHER_CTX *ctx; |
801 | 804 | ||
802 | /* | 805 | /* |
@@ -812,23 +815,23 @@ do_crypt(FILE *in, FILE *out, int do_encrypt) | |||
812 | EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, do_encrypt); | 815 | EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, do_encrypt); |
813 | 816 | ||
814 | for (;;) { | 817 | for (;;) { |
815 | inlen = fread(inbuf, 1, 1024, in); | 818 | in_len = fread(in_buf, 1, 1024, in_fileptr); |
816 | if (inlen <= 0) | 819 | if (in_len <= 0) |
817 | break; | 820 | break; |
818 | if (!EVP_CipherUpdate(ctx, outbuf, &outlen, inbuf, | 821 | if (!EVP_CipherUpdate(ctx, out_buf, &out_len, in_buf, |
819 | inlen)) { | 822 | in_len)) { |
820 | /* Error */ | 823 | /* Error */ |
821 | EVP_CIPHER_CTX_free(ctx); | 824 | EVP_CIPHER_CTX_free(ctx); |
822 | return 0; | 825 | return 0; |
823 | } | 826 | } |
824 | fwrite(outbuf, 1, outlen, out); | 827 | fwrite(out_buf, 1, out_len, out_fileptr); |
825 | } | 828 | } |
826 | if (!EVP_CipherFinal_ex(ctx, outbuf, &outlen)) { | 829 | if (!EVP_CipherFinal_ex(ctx, out_buf, &out_len)) { |
827 | /* Error */ | 830 | /* Error */ |
828 | EVP_CIPHER_CTX_free(ctx); | 831 | EVP_CIPHER_CTX_free(ctx); |
829 | return 0; | 832 | return 0; |
830 | } | 833 | } |
831 | fwrite(outbuf, 1, outlen, out); | 834 | fwrite(out_buf, 1, out_len, out_fileptr); |
832 | 835 | ||
833 | EVP_CIPHER_CTX_free(ctx); | 836 | EVP_CIPHER_CTX_free(ctx); |
834 | return 1; | 837 | return 1; |