summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/doc/EVP_DigestInit.pod
diff options
context:
space:
mode:
authorbeck <>2002-05-15 02:29:21 +0000
committerbeck <>2002-05-15 02:29:21 +0000
commitb64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch)
treefa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/doc/EVP_DigestInit.pod
parente471e1ea98d673597b182ea85f29e30c97cd08b5 (diff)
downloadopenbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/doc/EVP_DigestInit.pod')
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod119
1 files changed, 84 insertions, 35 deletions
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
index fefc858f7e..acd4d0167a 100644
--- a/src/lib/libcrypto/doc/EVP_DigestInit.pod
+++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod
@@ -2,9 +2,10 @@
2 2
3=head1 NAME 3=head1 NAME
4 4
5EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal, EVP_MAX_MD_SIZE, 5EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate,
6EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, 6EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE,
7EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type, 7EVP_MD_CTX_copy_ex EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size,
8EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type,
8EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2, 9EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2,
9EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - 10EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj -
10EVP digest routines 11EVP digest routines
@@ -13,15 +14,28 @@ EVP digest routines
13 14
14 #include <openssl/evp.h> 15 #include <openssl/evp.h>
15 16
16 void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); 17 void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
17 void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); 18 EVP_MD_CTX *EVP_MD_CTX_create(void);
18 void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, 19
20 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
21 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
22 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
19 unsigned int *s); 23 unsigned int *s);
20 24
21 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ 25 int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
26 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
27
28 int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
29
30 int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
31 int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
32 unsigned int *s);
22 33
23 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); 34 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
24 35
36 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
37
38
25 #define EVP_MD_type(e) ((e)->type) 39 #define EVP_MD_type(e) ((e)->type)
26 #define EVP_MD_pkey_type(e) ((e)->pkey_type) 40 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
27 #define EVP_MD_size(e) ((e)->md_size) 41 #define EVP_MD_size(e) ((e)->md_size)
@@ -32,15 +46,15 @@ EVP digest routines
32 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) 46 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
33 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) 47 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
34 48
35 EVP_MD *EVP_md_null(void); 49 const EVP_MD *EVP_md_null(void);
36 EVP_MD *EVP_md2(void); 50 const EVP_MD *EVP_md2(void);
37 EVP_MD *EVP_md5(void); 51 const EVP_MD *EVP_md5(void);
38 EVP_MD *EVP_sha(void); 52 const EVP_MD *EVP_sha(void);
39 EVP_MD *EVP_sha1(void); 53 const EVP_MD *EVP_sha1(void);
40 EVP_MD *EVP_dss(void); 54 const EVP_MD *EVP_dss(void);
41 EVP_MD *EVP_dss1(void); 55 const EVP_MD *EVP_dss1(void);
42 EVP_MD *EVP_mdc2(void); 56 const EVP_MD *EVP_mdc2(void);
43 EVP_MD *EVP_ripemd160(void); 57 const EVP_MD *EVP_ripemd160(void);
44 58
45 const EVP_MD *EVP_get_digestbyname(const char *name); 59 const EVP_MD *EVP_get_digestbyname(const char *name);
46 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) 60 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
@@ -50,25 +64,48 @@ EVP digest routines
50 64
51The EVP digest routines are a high level interface to message digests. 65The EVP digest routines are a high level interface to message digests.
52 66
53EVP_DigestInit() initializes a digest context B<ctx> to use a digest 67EVP_MD_CTX_init() initializes digest contet B<ctx>.
54B<type>: this will typically be supplied by a function such as 68
55EVP_sha1(). 69EVP_MD_CTX_create() allocates, initializes and returns a digest contet.
70
71EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest
72B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this
73function. B<type> will typically be supplied by a functionsuch as EVP_sha1().
74If B<impl> is NULL then the default implementation of digest B<type> is used.
56 75
57EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the 76EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
58digest context B<ctx>. This function can be called several times on the 77digest context B<ctx>. This function can be called several times on the
59same B<ctx> to hash additional data. 78same B<ctx> to hash additional data.
60 79
61EVP_DigestFinal() retrieves the digest value from B<ctx> and places 80EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places
62it in B<md>. If the B<s> parameter is not NULL then the number of 81it in B<md>. If the B<s> parameter is not NULL then the number of
63bytes of data written (i.e. the length of the digest) will be written 82bytes of data written (i.e. the length of the digest) will be written
64to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written. 83to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
65After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate() 84After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate()
66can be made, but EVP_DigestInit() can be called to initialize a new 85can be made, but EVP_DigestInit_ex() can be called to initialize a new
67digest operation. 86digest operation.
68 87
69EVP_MD_CTX_copy() can be used to copy the message digest state from 88EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called
89after a digest context is no longer needed.
90
91EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the
92space allocated to it, it should be called only on a context created
93using EVP_MD_CTX_create().
94
95EVP_MD_CTX_copy_ex() can be used to copy the message digest state from
70B<in> to B<out>. This is useful if large amounts of data are to be 96B<in> to B<out>. This is useful if large amounts of data are to be
71hashed which only differ in the last few bytes. 97hashed which only differ in the last few bytes. B<out> must be initialized
98before calling this function.
99
100EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except
101the passed context B<ctx> does not have to be initialized, and it always
102uses the default digest implementation.
103
104EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest
105contet B<ctx> is automatically cleaned up.
106
107EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination
108B<out> does not have to be initialized.
72 109
73EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest 110EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
74when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the 111when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
@@ -107,9 +144,10 @@ using, for example, OpenSSL_add_all_digests() for these functions to work.
107 144
108=head1 RETURN VALUES 145=head1 RETURN VALUES
109 146
110EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() do not return values. 147EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for
148success and 0 for failure.
111 149
112EVP_MD_CTX_copy() returns 1 if successful or 0 for failure. 150EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure.
113 151
114EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the 152EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
115corresponding OBJECT IDENTIFIER or NID_undef if none exists. 153corresponding OBJECT IDENTIFIER or NID_undef if none exists.
@@ -134,6 +172,19 @@ transparent to the digest used and much more flexible.
134SHA1 is the digest of choice for new applications. The other digest algorithms 172SHA1 is the digest of choice for new applications. The other digest algorithms
135are still in common use. 173are still in common use.
136 174
175For most applications the B<impl> parameter to EVP_DigestInit_ex() will be
176set to NULL to use the default digest implementation.
177
178The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
179obsolete but are retained to maintain compatibility with existing code. New
180applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
181EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
182instead of initializing and cleaning it up on each call and allow non default
183implementations of digests to be specified.
184
185In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use
186memory leaks will occur.
187
137=head1 EXAMPLE 188=head1 EXAMPLE
138 189
139This example digests the data "Test Message\n" and "Hello World\n", using the 190This example digests the data "Test Message\n" and "Hello World\n", using the
@@ -165,10 +216,12 @@ digest name passed on the command line.
165 exit(1); 216 exit(1);
166 } 217 }
167 218
168 EVP_DigestInit(&mdctx, md); 219 EVP_MD_CTX_init(&mdctx);
220 EVP_DigestInit_ex(&mdctx, md, NULL);
169 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); 221 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
170 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); 222 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
171 EVP_DigestFinal(&mdctx, md_value, &md_len); 223 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
224 EVP_MD_CTX_cleanup(&mdctx);
172 225
173 printf("Digest is: "); 226 printf("Digest is: ");
174 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]); 227 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
@@ -177,17 +230,10 @@ digest name passed on the command line.
177 230
178=head1 BUGS 231=head1 BUGS
179 232
180Several of the functions do not return values: maybe they should. Although the
181internal digest operations will never fail some future hardware based operations
182might.
183
184The link between digests and signing algorithms results in a situation where 233The link between digests and signing algorithms results in a situation where
185EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS 234EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
186even though they are identical digests. 235even though they are identical digests.
187 236
188The size of an B<EVP_MD_CTX> structure is determined at compile time: this results
189in code that must be recompiled if the size of B<EVP_MD_CTX> increases.
190
191=head1 SEE ALSO 237=head1 SEE ALSO
192 238
193L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>, 239L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
@@ -199,4 +245,7 @@ L<SHA1(3)|SHA1(3)>
199EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are 245EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
200available in all versions of SSLeay and OpenSSL. 246available in all versions of SSLeay and OpenSSL.
201 247
248EVP_DigestInit_ex(), EVP_DigestFinal_ex() and EVP_MD_CTX_copy_ex()
249were added in OpenSSL 0.9.7.
250
202=cut 251=cut