summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2018-02-19 10:04:08 +0000
committerschwarze <>2018-02-19 10:04:08 +0000
commitad40d74e260988f1e3315a9252a10f98dadc13f2 (patch)
tree45a25dfadf73dd8ae2a436bab7f30eb26db738a0 /src
parent6977dd89c784e8348026f5282ff90809a7f10a6a (diff)
downloadopenbsd-ad40d74e260988f1e3315a9252a10f98dadc13f2.tar.gz
openbsd-ad40d74e260988f1e3315a9252a10f98dadc13f2.tar.bz2
openbsd-ad40d74e260988f1e3315a9252a10f98dadc13f2.zip
In evp.h rev. 1.57 2018/02/17 16:54:08,
jsing@ provided EVP_CIPHER_CTX_reset(3). Merge the documentation, most from Richard Levitte via OpenSSL commit 05fdb8d3 Dec 18 17:09:45 2015 +0100. Also merge improvements to the EXAMPLES section from OpenSSL, fixing one additional bug that still remains in OpenSSL. While here, improve information on the deprecated functions, sort RETURN VALUES, and add a few missing functions to it, though that section still remains incomplete.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/man/EVP_EncryptInit.3166
1 files changed, 96 insertions, 70 deletions
diff --git a/src/lib/libcrypto/man/EVP_EncryptInit.3 b/src/lib/libcrypto/man/EVP_EncryptInit.3
index f883d1ce2a..a9377b2264 100644
--- a/src/lib/libcrypto/man/EVP_EncryptInit.3
+++ b/src/lib/libcrypto/man/EVP_EncryptInit.3
@@ -1,8 +1,9 @@
1.\" $OpenBSD: EVP_EncryptInit.3,v 1.7 2018/02/14 00:19:03 schwarze Exp $ 1.\" $OpenBSD: EVP_EncryptInit.3,v 1.8 2018/02/19 10:04:08 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.\" selective merge up to: OpenSSL 5c5eb286 Dec 5 00:36:43 2017 +0100 3.\" selective merge up to: OpenSSL 5c5eb286 Dec 5 00:36:43 2017 +0100
4.\" 4.\"
5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>
6.\" and Richard Levitte <levitte@openssl.org>.
6.\" Copyright (c) 2000-2002, 2005, 2012-2016 The OpenSSL Project. 7.\" Copyright (c) 2000-2002, 2005, 2012-2016 The OpenSSL Project.
7.\" All rights reserved. 8.\" All rights reserved.
8.\" 9.\"
@@ -50,11 +51,13 @@
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE. 52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\" 53.\"
53.Dd $Mdocdate: February 14 2018 $ 54.Dd $Mdocdate: February 19 2018 $
54.Dt EVP_ENCRYPTINIT 3 55.Dt EVP_ENCRYPTINIT 3
55.Os 56.Os
56.Sh NAME 57.Sh NAME
57.Nm EVP_CIPHER_CTX_new , 58.Nm EVP_CIPHER_CTX_new ,
59.Nm EVP_CIPHER_CTX_reset ,
60.Nm EVP_CIPHER_CTX_cleanup ,
58.Nm EVP_CIPHER_CTX_init , 61.Nm EVP_CIPHER_CTX_init ,
59.Nm EVP_CIPHER_CTX_free , 62.Nm EVP_CIPHER_CTX_free ,
60.Nm EVP_EncryptInit_ex , 63.Nm EVP_EncryptInit_ex ,
@@ -76,7 +79,6 @@
76.Nm EVP_CIPHER_CTX_set_key_length , 79.Nm EVP_CIPHER_CTX_set_key_length ,
77.Nm EVP_CIPHER_CTX_ctrl , 80.Nm EVP_CIPHER_CTX_ctrl ,
78.Nm EVP_CIPHER_CTX_rand_key , 81.Nm EVP_CIPHER_CTX_rand_key ,
79.Nm EVP_CIPHER_CTX_cleanup ,
80.Nm EVP_get_cipherbyname , 82.Nm EVP_get_cipherbyname ,
81.Nm EVP_get_cipherbynid , 83.Nm EVP_get_cipherbynid ,
82.Nm EVP_get_cipherbyobj , 84.Nm EVP_get_cipherbyobj ,
@@ -164,6 +166,14 @@
164.In openssl/evp.h 166.In openssl/evp.h
165.Ft EVP_CIPHER_CTX * 167.Ft EVP_CIPHER_CTX *
166.Fn EVP_CIPHER_CTX_new void 168.Fn EVP_CIPHER_CTX_new void
169.Ft int
170.Fo EVP_CIPHER_CTX_reset
171.Fa "EVP_CIPHER_CTX *ctx"
172.Fc
173.Ft int
174.Fo EVP_CIPHER_CTX_cleanup
175.Fa "EVP_CIPHER_CTX *ctx"
176.Fc
167.Ft void 177.Ft void
168.Fo EVP_CIPHER_CTX_init 178.Fo EVP_CIPHER_CTX_init
169.Fa "EVP_CIPHER_CTX *ctx" 179.Fa "EVP_CIPHER_CTX *ctx"
@@ -301,10 +311,6 @@
301.Fa "EVP_CIPHER_CTX *ctx" 311.Fa "EVP_CIPHER_CTX *ctx"
302.Fa "unsigned char *key" 312.Fa "unsigned char *key"
303.Fc 313.Fc
304.Ft int
305.Fo EVP_CIPHER_CTX_cleanup
306.Fa "EVP_CIPHER_CTX *ctx"
307.Fc
308.Ft const EVP_CIPHER * 314.Ft const EVP_CIPHER *
309.Fo EVP_get_cipherbyname 315.Fo EVP_get_cipherbyname
310.Fa "const char *name" 316.Fa "const char *name"
@@ -401,15 +407,35 @@ The EVP cipher routines are a high level interface to certain symmetric
401ciphers. 407ciphers.
402.Pp 408.Pp
403.Fn EVP_CIPHER_CTX_new 409.Fn EVP_CIPHER_CTX_new
404creates a cipher context. 410creates a new, empty cipher context.
411.Pp
412.Fn EVP_CIPHER_CTX_reset
413clears all information from
414.Fa ctx
415and frees all allocated memory associated with it, except the
416.Fa ctx
417object itself, such that it can be reused for another series of calls to
418.Fn EVP_CipherInit ,
419.Fn EVP_CipherUpdate ,
420and
421.Fn EVP_CipherFinal .
422It is also suitable for cipher contexts on the stack that were used
423and are no longer needed.
424.Fn EVP_CIPHER_CTX_cleanup
425is a deprecated alias for
426.Fn EVP_CIPHER_CTX_reset .
405.Pp 427.Pp
406.Fn EVP_CIPHER_CTX_init 428.Fn EVP_CIPHER_CTX_init
407initializes the cipher context 429is a deprecated function to clear a cipher context on the stack
408.Fa ctx . 430before use.
431Do not use it on a cipher context returned from
432.Fn EVP_CIPHER_CTX_new
433or one one that was already used.
409.Pp 434.Pp
410.Fn EVP_CIPHER_CTX_free 435.Fn EVP_CIPHER_CTX_free
411clears all information from a cipher context and frees up any 436clears all information from
412allocated memory associate with it, including 437.Fa ctx
438and frees all allocated memory associated with it, including
413.Fa ctx 439.Fa ctx
414itself. 440itself.
415This function should be called after all operations using a cipher 441This function should be called after all operations using a cipher
@@ -428,8 +454,11 @@ for encryption with cipher
428from 454from
429.Vt ENGINE 455.Vt ENGINE
430.Fa impl . 456.Fa impl .
457If
431.Fa ctx 458.Fa ctx
432must be initialized before calling this function. 459points to an unused object on the stack, it must be initialized with
460.Fn EVP_MD_CTX_init
461before calling this function.
433.Fa type 462.Fa type
434is normally supplied by a function such as 463is normally supplied by a function such as
435.Fn EVP_aes_256_cbc . 464.Fn EVP_aes_256_cbc .
@@ -524,25 +553,19 @@ the value unchanged (the actual value of
524.Fa enc 553.Fa enc
525being supplied in a previous call). 554being supplied in a previous call).
526.Pp 555.Pp
527.Fn EVP_CIPHER_CTX_cleanup
528clears all information from a cipher context and free up any allocated
529memory associated with it.
530It should be called after all operations using a cipher are complete so
531sensitive information does not remain in memory.
532.Pp
533.Fn EVP_EncryptInit , 556.Fn EVP_EncryptInit ,
534.Fn EVP_DecryptInit , 557.Fn EVP_DecryptInit ,
535and 558and
536.Fn EVP_CipherInit 559.Fn EVP_CipherInit
537behave in a similar way to 560are deprecated functions behaving like
538.Fn EVP_EncryptInit_ex , 561.Fn EVP_EncryptInit_ex ,
539.Fn EVP_DecryptInit_ex , 562.Fn EVP_DecryptInit_ex ,
540and 563and
541.Fn EVP_CipherInit_ex 564.Fn EVP_CipherInit_ex
542except the 565except that they always use the default cipher implementation
543.Fa ctx 566and that they require
544parameter does not need to be initialized and they always use the 567.Fn EVP_CIPHER_CTX_reset
545default cipher implementation. 568before they can be used on a context that was already used.
546.Pp 569.Pp
547.Fn EVP_EncryptFinal , 570.Fn EVP_EncryptFinal ,
548.Fn EVP_DecryptFinal , 571.Fn EVP_DecryptFinal ,
@@ -556,7 +579,9 @@ and
556In previous releases of OpenSSL, they also used to clean up the 579In previous releases of OpenSSL, they also used to clean up the
557.Fa ctx , 580.Fa ctx ,
558but this is no longer done and 581but this is no longer done and
559.Fn EVP_CIPHER_CTX_cleanup 582.Fn EVP_CIPHER_CTX_reset
583or
584.Fn EVP_CIPHER_CTX_free
560must be called to free any context resources. 585must be called to free any context resources.
561.Pp 586.Pp
562.Fn EVP_get_cipherbyname , 587.Fn EVP_get_cipherbyname ,
@@ -782,31 +807,31 @@ for success or
782.Dv NULL 807.Dv NULL
783for failure. 808for failure.
784.Pp 809.Pp
810.Fn EVP_CIPHER_CTX_reset ,
811.Fn EVP_CIPHER_CTX_cleanup ,
785.Fn EVP_EncryptInit_ex , 812.Fn EVP_EncryptInit_ex ,
786.Fn EVP_EncryptUpdate , 813.Fn EVP_EncryptUpdate ,
814.Fn EVP_EncryptFinal_ex ,
815.Fn EVP_DecryptInit_ex ,
816.Fn EVP_DecryptUpdate ,
817.Fn EVP_DecryptFinal_ex ,
818.Fn EVP_CipherInit_ex ,
819.Fn EVP_CipherUpdate ,
820.Fn EVP_CipherFinal_ex ,
821.Fn EVP_EncryptInit ,
822.Fn EVP_EncryptFinal ,
823.Fn EVP_DecryptInit ,
824.Fn EVP_DecryptFinal ,
825.Fn EVP_CipherInit ,
826.Fn EVP_CipherFinal ,
827.Fn EVP_CIPHER_CTX_set_key_length ,
787and 828and
788.Fn EVP_EncryptFinal_ex
789return 1 for success and 0 for failure.
790.Pp
791.Fn EVP_DecryptInit_ex
792and
793.Fn EVP_DecryptUpdate
794return 1 for success and 0 for failure.
795.Fn EVP_DecryptFinal_ex
796returns 0 if the decrypt failed or 1 for success.
797.Pp
798.Fn EVP_CipherInit_ex
799and
800.Fn EVP_CipherUpdate
801return 1 for success and 0 for failure.
802.Fn EVP_CipherFinal_ex
803returns 0 for a decryption failure or 1 for success.
804.Pp
805.Fn EVP_CIPHER_CTX_rand_key 829.Fn EVP_CIPHER_CTX_rand_key
806and
807.Fn EVP_CIPHER_CTX_cleanup
808return 1 for success or 0 for failure. 830return 1 for success or 0 for failure.
809.Pp 831.Pp
832.Fn EVP_CIPHER_CTX_set_padding
833always returns 1.
834.Pp
810.Fn EVP_get_cipherbyname , 835.Fn EVP_get_cipherbyname ,
811.Fn EVP_get_cipherbynid , 836.Fn EVP_get_cipherbynid ,
812and 837and
@@ -832,9 +857,6 @@ and
832.Fn EVP_CIPHER_CTX_key_length 857.Fn EVP_CIPHER_CTX_key_length
833return the key length. 858return the key length.
834.Pp 859.Pp
835.Fn EVP_CIPHER_CTX_set_padding
836always returns 1.
837.Pp
838.Fn EVP_CIPHER_iv_length 860.Fn EVP_CIPHER_iv_length
839and 861and
840.Fn EVP_CIPHER_CTX_iv_length 862.Fn EVP_CIPHER_CTX_iv_length
@@ -1102,10 +1124,11 @@ do_crypt(char *outfile)
1102 const char intext[] = "Some Crypto Text"; 1124 const char intext[] = "Some Crypto Text";
1103 EVP_CIPHER_CTX *ctx; 1125 EVP_CIPHER_CTX *ctx;
1104 FILE *out; 1126 FILE *out;
1105 EVP_CIPHER_CTX_init(&ctx);
1106 EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
1107 1127
1108 if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, 1128 ctx = EVP_CIPHER_CTX_new();
1129 EVP_EncryptInit_ex(ctx, EVP_bf_cbc(), NULL, key, iv);
1130
1131 if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext,
1109 strlen(intext))) { 1132 strlen(intext))) {
1110 /* Error */ 1133 /* Error */
1111 EVP_CIPHER_CTX_free(ctx); 1134 EVP_CIPHER_CTX_free(ctx);
@@ -1115,13 +1138,13 @@ do_crypt(char *outfile)
1115 * Buffer passed to EVP_EncryptFinal() must be after data just 1138 * Buffer passed to EVP_EncryptFinal() must be after data just
1116 * encrypted to avoid overwriting it. 1139 * encrypted to avoid overwriting it.
1117 */ 1140 */
1118 if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) { 1141 if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) {
1119 /* Error */ 1142 /* Error */
1120 EVP_CIPHER_CTX_free(ctx); 1143 EVP_CIPHER_CTX_free(ctx);
1121 return 0; 1144 return 0;
1122 } 1145 }
1123 outlen += tmplen; 1146 outlen += tmplen;
1124 EVP_CIPHER_CTX_cleanup(&ctx); 1147 EVP_CIPHER_CTX_free(ctx);
1125 /* 1148 /*
1126 * Need binary mode for fopen because encrypted data is 1149 * Need binary mode for fopen because encrypted data is
1127 * binary data. Also cannot use strlen() on it because 1150 * binary data. Also cannot use strlen() on it because
@@ -1147,49 +1170,49 @@ openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F \e
1147 -iv 0102030405060708 -d 1170 -iv 0102030405060708 -d
1148.Ed 1171.Ed
1149.Pp 1172.Pp
1150General encryption, decryption function example using FILE I/O and RC2 1173General encryption, decryption function example using FILE I/O and AES128
1151with an 80-bit key: 1174with an 128-bit key:
1152.Bd -literal 1175.Bd -literal
1153int 1176int
1154do_crypt(FILE *in, FILE *out, int do_encrypt) 1177do_crypt(FILE *in, FILE *out, int do_encrypt)
1155{ 1178{
1156 /* Allow enough space in output buffer for additional block */ 1179 /* Allow enough space in output buffer for additional block */
1157 inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; 1180 unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
1158 int inlen, outlen; 1181 int inlen, outlen;
1182 EVP_CIPHER_CTX *ctx;
1183
1159 /* 1184 /*
1160 * Bogus key and IV: we'd normally set these from 1185 * Bogus key and IV: we'd normally set these from
1161 * another source. 1186 * another source.
1162 */ 1187 */
1163 unsigned char key[] = "0123456789"; 1188 unsigned char key[] = "0123456789abcdeF";
1164 unsigned char iv[] = "12345678"; 1189 unsigned char iv[] = "1234567887654321";
1165 1190
1166 /* Don't set key or IV because we will modify the parameters */ 1191 ctx = EVP_CIPHER_CTX_new();
1167 EVP_CIPHER_CTX_init(&ctx); 1192 EVP_CipherInit_ex(ctx, EVP_aes_128_cbc(), NULL, NULL, NULL,
1168 EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); 1193 do_encrypt);
1169 EVP_CIPHER_CTX_set_key_length(&ctx, 10); 1194 EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, do_encrypt);
1170 /* We finished modifying parameters so now we can set key and IV */
1171 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
1172 1195
1173 for(;;) { 1196 for (;;) {
1174 inlen = fread(inbuf, 1, 1024, in); 1197 inlen = fread(inbuf, 1, 1024, in);
1175 if (inlen <= 0) 1198 if (inlen <= 0)
1176 break; 1199 break;
1177 if (!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, 1200 if (!EVP_CipherUpdate(ctx, outbuf, &outlen, inbuf,
1178 inlen)) { 1201 inlen)) {
1179 /* Error */ 1202 /* Error */
1180 EVP_CIPHER_CTX_cleanup(&ctx); 1203 EVP_CIPHER_CTX_free(ctx);
1181 return 0; 1204 return 0;
1182 } 1205 }
1183 fwrite(outbuf, 1, outlen, out); 1206 fwrite(outbuf, 1, outlen, out);
1184 } 1207 }
1185 if (!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) { 1208 if (!EVP_CipherFinal_ex(ctx, outbuf, &outlen)) {
1186 /* Error */ 1209 /* Error */
1187 EVP_CIPHER_CTX_cleanup(&ctx); 1210 EVP_CIPHER_CTX_free(ctx);
1188 return 0; 1211 return 0;
1189 } 1212 }
1190 fwrite(outbuf, 1, outlen, out); 1213 fwrite(outbuf, 1, outlen, out);
1191 1214
1192 EVP_CIPHER_CTX_cleanup(&ctx); 1215 EVP_CIPHER_CTX_free(ctx);
1193 return 1; 1216 return 1;
1194} 1217}
1195.Ed 1218.Ed
@@ -1206,6 +1229,9 @@ do_crypt(FILE *in, FILE *out, int do_encrypt)
1206and 1229and
1207.Fn EVP_CIPHER_CTX_set_padding 1230.Fn EVP_CIPHER_CTX_set_padding
1208appeared in OpenSSL 0.9.7. 1231appeared in OpenSSL 0.9.7.
1232.Pp
1233.Fn EVP_CIPHER_CTX_reset
1234fist appeared in OpenSSL 1.1.0.
1209.Sh BUGS 1235.Sh BUGS
1210For RC5 the number of rounds can currently only be set to 8, 12 or 16. 1236For RC5 the number of rounds can currently only be set to 8, 12 or 16.
1211This is a limitation of the current RC5 code rather than the EVP 1237This is a limitation of the current RC5 code rather than the EVP