diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/doc/EVP_DigestInit.pod | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-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.pod | 119 |
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 | ||
5 | EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal, EVP_MAX_MD_SIZE, | 5 | EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate, |
6 | EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, | 6 | EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE, |
7 | EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type, | 7 | EVP_MD_CTX_copy_ex EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, |
8 | EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type, | ||
8 | EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2, | 9 | EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2, |
9 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - | 10 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - |
10 | EVP digest routines | 11 | EVP 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 | ||
51 | The EVP digest routines are a high level interface to message digests. | 65 | The EVP digest routines are a high level interface to message digests. |
52 | 66 | ||
53 | EVP_DigestInit() initializes a digest context B<ctx> to use a digest | 67 | EVP_MD_CTX_init() initializes digest contet B<ctx>. |
54 | B<type>: this will typically be supplied by a function such as | 68 | |
55 | EVP_sha1(). | 69 | EVP_MD_CTX_create() allocates, initializes and returns a digest contet. |
70 | |||
71 | EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest | ||
72 | B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this | ||
73 | function. B<type> will typically be supplied by a functionsuch as EVP_sha1(). | ||
74 | If B<impl> is NULL then the default implementation of digest B<type> is used. | ||
56 | 75 | ||
57 | EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the | 76 | EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the |
58 | digest context B<ctx>. This function can be called several times on the | 77 | digest context B<ctx>. This function can be called several times on the |
59 | same B<ctx> to hash additional data. | 78 | same B<ctx> to hash additional data. |
60 | 79 | ||
61 | EVP_DigestFinal() retrieves the digest value from B<ctx> and places | 80 | EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places |
62 | it in B<md>. If the B<s> parameter is not NULL then the number of | 81 | it in B<md>. If the B<s> parameter is not NULL then the number of |
63 | bytes of data written (i.e. the length of the digest) will be written | 82 | bytes of data written (i.e. the length of the digest) will be written |
64 | to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written. | 83 | to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written. |
65 | After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate() | 84 | After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate() |
66 | can be made, but EVP_DigestInit() can be called to initialize a new | 85 | can be made, but EVP_DigestInit_ex() can be called to initialize a new |
67 | digest operation. | 86 | digest operation. |
68 | 87 | ||
69 | EVP_MD_CTX_copy() can be used to copy the message digest state from | 88 | EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called |
89 | after a digest context is no longer needed. | ||
90 | |||
91 | EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the | ||
92 | space allocated to it, it should be called only on a context created | ||
93 | using EVP_MD_CTX_create(). | ||
94 | |||
95 | EVP_MD_CTX_copy_ex() can be used to copy the message digest state from | ||
70 | B<in> to B<out>. This is useful if large amounts of data are to be | 96 | B<in> to B<out>. This is useful if large amounts of data are to be |
71 | hashed which only differ in the last few bytes. | 97 | hashed which only differ in the last few bytes. B<out> must be initialized |
98 | before calling this function. | ||
99 | |||
100 | EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except | ||
101 | the passed context B<ctx> does not have to be initialized, and it always | ||
102 | uses the default digest implementation. | ||
103 | |||
104 | EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest | ||
105 | contet B<ctx> is automatically cleaned up. | ||
106 | |||
107 | EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination | ||
108 | B<out> does not have to be initialized. | ||
72 | 109 | ||
73 | EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest | 110 | EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest |
74 | when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the | 111 | when 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 | ||
110 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() do not return values. | 147 | EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for |
148 | success and 0 for failure. | ||
111 | 149 | ||
112 | EVP_MD_CTX_copy() returns 1 if successful or 0 for failure. | 150 | EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure. |
113 | 151 | ||
114 | EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the | 152 | EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the |
115 | corresponding OBJECT IDENTIFIER or NID_undef if none exists. | 153 | corresponding OBJECT IDENTIFIER or NID_undef if none exists. |
@@ -134,6 +172,19 @@ transparent to the digest used and much more flexible. | |||
134 | SHA1 is the digest of choice for new applications. The other digest algorithms | 172 | SHA1 is the digest of choice for new applications. The other digest algorithms |
135 | are still in common use. | 173 | are still in common use. |
136 | 174 | ||
175 | For most applications the B<impl> parameter to EVP_DigestInit_ex() will be | ||
176 | set to NULL to use the default digest implementation. | ||
177 | |||
178 | The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are | ||
179 | obsolete but are retained to maintain compatibility with existing code. New | ||
180 | applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and | ||
181 | EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context | ||
182 | instead of initializing and cleaning it up on each call and allow non default | ||
183 | implementations of digests to be specified. | ||
184 | |||
185 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use | ||
186 | memory leaks will occur. | ||
187 | |||
137 | =head1 EXAMPLE | 188 | =head1 EXAMPLE |
138 | 189 | ||
139 | This example digests the data "Test Message\n" and "Hello World\n", using the | 190 | This 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 | ||
180 | Several of the functions do not return values: maybe they should. Although the | ||
181 | internal digest operations will never fail some future hardware based operations | ||
182 | might. | ||
183 | |||
184 | The link between digests and signing algorithms results in a situation where | 233 | The link between digests and signing algorithms results in a situation where |
185 | EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS | 234 | EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS |
186 | even though they are identical digests. | 235 | even though they are identical digests. |
187 | 236 | ||
188 | The size of an B<EVP_MD_CTX> structure is determined at compile time: this results | ||
189 | in 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 | ||
193 | L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>, | 239 | L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>, |
@@ -199,4 +245,7 @@ L<SHA1(3)|SHA1(3)> | |||
199 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are | 245 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are |
200 | available in all versions of SSLeay and OpenSSL. | 246 | available in all versions of SSLeay and OpenSSL. |
201 | 247 | ||
248 | EVP_DigestInit_ex(), EVP_DigestFinal_ex() and EVP_MD_CTX_copy_ex() | ||
249 | were added in OpenSSL 0.9.7. | ||
250 | |||
202 | =cut | 251 | =cut |