diff options
| author | djm <> | 2012-10-13 21:23:50 +0000 |
|---|---|---|
| committer | djm <> | 2012-10-13 21:23:50 +0000 |
| commit | 228cae30b117c2493f69ad3c195341cd6ec8d430 (patch) | |
| tree | 29ff00b10d52c0978077c4fd83c33b065bade73e /src/lib/libcrypto/doc/EVP_DigestInit.pod | |
| parent | 731838c66b52c0ae5888333005b74115a620aa96 (diff) | |
| download | openbsd-228cae30b117c2493f69ad3c195341cd6ec8d430.tar.gz openbsd-228cae30b117c2493f69ad3c195341cd6ec8d430.tar.bz2 openbsd-228cae30b117c2493f69ad3c195341cd6ec8d430.zip | |
import OpenSSL-1.0.1c
Diffstat (limited to 'src/lib/libcrypto/doc/EVP_DigestInit.pod')
| -rw-r--r-- | src/lib/libcrypto/doc/EVP_DigestInit.pod | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod index 5b477ac6ec..367691cc7a 100644 --- a/src/lib/libcrypto/doc/EVP_DigestInit.pod +++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod | |||
| @@ -6,7 +6,8 @@ EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate, | |||
| 6 | EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE, | 6 | EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE, |
| 7 | EVP_MD_CTX_copy_ex, EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, | 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_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type, |
| 9 | 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_sha224, EVP_sha256, |
| 10 | EVP_sha384, EVP_sha512, EVP_dss, EVP_dss1, EVP_mdc2, | ||
| 10 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - | 11 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - |
| 11 | EVP digest routines | 12 | EVP digest routines |
| 12 | 13 | ||
| @@ -33,16 +34,15 @@ EVP digest routines | |||
| 33 | 34 | ||
| 34 | int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); | 35 | int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); |
| 35 | 36 | ||
| 36 | #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ | 37 | #define EVP_MAX_MD_SIZE 64 /* SHA512 */ |
| 37 | 38 | ||
| 39 | int EVP_MD_type(const EVP_MD *md); | ||
| 40 | int EVP_MD_pkey_type(const EVP_MD *md); | ||
| 41 | int EVP_MD_size(const EVP_MD *md); | ||
| 42 | int EVP_MD_block_size(const EVP_MD *md); | ||
| 38 | 43 | ||
| 39 | #define EVP_MD_type(e) ((e)->type) | 44 | const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); |
| 40 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) | 45 | #define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) |
| 41 | #define EVP_MD_size(e) ((e)->md_size) | ||
| 42 | #define EVP_MD_block_size(e) ((e)->block_size) | ||
| 43 | |||
| 44 | #define EVP_MD_CTX_md(e) (e)->digest) | ||
| 45 | #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest) | ||
| 46 | #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) |
| 47 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | 47 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) |
| 48 | 48 | ||
| @@ -56,6 +56,11 @@ EVP digest routines | |||
| 56 | const EVP_MD *EVP_mdc2(void); | 56 | const EVP_MD *EVP_mdc2(void); |
| 57 | const EVP_MD *EVP_ripemd160(void); | 57 | const EVP_MD *EVP_ripemd160(void); |
| 58 | 58 | ||
| 59 | const EVP_MD *EVP_sha224(void); | ||
| 60 | const EVP_MD *EVP_sha256(void); | ||
| 61 | const EVP_MD *EVP_sha384(void); | ||
| 62 | const EVP_MD *EVP_sha512(void); | ||
| 63 | |||
| 59 | const EVP_MD *EVP_get_digestbyname(const char *name); | 64 | const EVP_MD *EVP_get_digestbyname(const char *name); |
| 60 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | 65 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) |
| 61 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | 66 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) |
| @@ -124,12 +129,14 @@ B<EVP_MD_CTX>. | |||
| 124 | 129 | ||
| 125 | EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated | 130 | EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated |
| 126 | with this digest. For example EVP_sha1() is associated with RSA so this will | 131 | with this digest. For example EVP_sha1() is associated with RSA so this will |
| 127 | return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature | 132 | return B<NID_sha1WithRSAEncryption>. Since digests and signature algorithms |
| 128 | algorithms may not be retained in future versions of OpenSSL. | 133 | are no longer linked this function is only retained for compatibility |
| 134 | reasons. | ||
| 129 | 135 | ||
| 130 | EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160() | 136 | EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_sha224(), EVP_sha256(), |
| 131 | return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest | 137 | EVP_sha384(), EVP_sha512(), EVP_mdc2() and EVP_ripemd160() return B<EVP_MD> |
| 132 | algorithms respectively. The associated signature algorithm is RSA in each case. | 138 | structures for the MD2, MD5, SHA, SHA1, SHA224, SHA256, SHA384, SHA512, MDC2 |
| 139 | and RIPEMD160 digest algorithms respectively. | ||
| 133 | 140 | ||
| 134 | EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest | 141 | EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest |
| 135 | algorithms but using DSS (DSA) for the signature algorithm. Note: there is | 142 | algorithms but using DSS (DSA) for the signature algorithm. Note: there is |
| @@ -171,8 +178,8 @@ The B<EVP> interface to message digests should almost always be used in | |||
| 171 | preference to the low level interfaces. This is because the code then becomes | 178 | preference to the low level interfaces. This is because the code then becomes |
| 172 | transparent to the digest used and much more flexible. | 179 | transparent to the digest used and much more flexible. |
| 173 | 180 | ||
| 174 | SHA1 is the digest of choice for new applications. The other digest algorithms | 181 | New applications should use the SHA2 digest algorithms such as SHA256. |
| 175 | are still in common use. | 182 | The other digest algorithms are still in common use. |
| 176 | 183 | ||
| 177 | For most applications the B<impl> parameter to EVP_DigestInit_ex() will be | 184 | For most applications the B<impl> parameter to EVP_DigestInit_ex() will be |
| 178 | set to NULL to use the default digest implementation. | 185 | set to NULL to use the default digest implementation. |
| @@ -187,6 +194,19 @@ implementations of digests to be specified. | |||
| 187 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use | 194 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use |
| 188 | memory leaks will occur. | 195 | memory leaks will occur. |
| 189 | 196 | ||
| 197 | Stack allocation of EVP_MD_CTX structures is common, for example: | ||
| 198 | |||
| 199 | EVP_MD_CTX mctx; | ||
| 200 | EVP_MD_CTX_init(&mctx); | ||
| 201 | |||
| 202 | This will cause binary compatibility issues if the size of EVP_MD_CTX | ||
| 203 | structure changes (this will only happen with a major release of OpenSSL). | ||
| 204 | Applications wishing to avoid this should use EVP_MD_CTX_create() instead: | ||
| 205 | |||
| 206 | EVP_MD_CTX *mctx; | ||
| 207 | mctx = EVP_MD_CTX_create(); | ||
| 208 | |||
| 209 | |||
| 190 | =head1 EXAMPLE | 210 | =head1 EXAMPLE |
| 191 | 211 | ||
| 192 | This example digests the data "Test Message\n" and "Hello World\n", using the | 212 | This example digests the data "Test Message\n" and "Hello World\n", using the |
| @@ -197,7 +217,7 @@ digest name passed on the command line. | |||
| 197 | 217 | ||
| 198 | main(int argc, char *argv[]) | 218 | main(int argc, char *argv[]) |
| 199 | { | 219 | { |
| 200 | EVP_MD_CTX mdctx; | 220 | EVP_MD_CTX *mdctx; |
| 201 | const EVP_MD *md; | 221 | const EVP_MD *md; |
| 202 | char mess1[] = "Test Message\n"; | 222 | char mess1[] = "Test Message\n"; |
| 203 | char mess2[] = "Hello World\n"; | 223 | char mess2[] = "Hello World\n"; |
| @@ -218,12 +238,12 @@ digest name passed on the command line. | |||
| 218 | exit(1); | 238 | exit(1); |
| 219 | } | 239 | } |
| 220 | 240 | ||
| 221 | EVP_MD_CTX_init(&mdctx); | 241 | mdctx = EVP_MD_CTX_create(); |
| 222 | EVP_DigestInit_ex(&mdctx, md, NULL); | 242 | EVP_DigestInit_ex(mdctx, md, NULL); |
| 223 | EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); | 243 | EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); |
| 224 | EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); | 244 | EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); |
| 225 | EVP_DigestFinal_ex(&mdctx, md_value, &md_len); | 245 | EVP_DigestFinal_ex(mdctx, md_value, &md_len); |
| 226 | EVP_MD_CTX_cleanup(&mdctx); | 246 | EVP_MD_CTX_destroy(mdctx); |
| 227 | 247 | ||
| 228 | printf("Digest is: "); | 248 | printf("Digest is: "); |
| 229 | for(i = 0; i < md_len; i++) printf("%02x", md_value[i]); | 249 | for(i = 0; i < md_len; i++) printf("%02x", md_value[i]); |
