diff options
Diffstat (limited to 'src/lib/libcrypto/doc/EVP_DigestInit.pod')
| -rw-r--r-- | src/lib/libcrypto/doc/EVP_DigestInit.pod | 124 |
1 files changed, 89 insertions, 35 deletions
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod index 345b1ddfa7..b3a61f1c5d 100644 --- a/src/lib/libcrypto/doc/EVP_DigestInit.pod +++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod | |||
| @@ -2,21 +2,40 @@ | |||
| 2 | 2 | ||
| 3 | =head1 NAME | 3 | =head1 NAME |
| 4 | 4 | ||
| 5 | EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines | 5 | 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, | ||
| 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, | ||
| 9 | EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2, | ||
| 10 | EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj - | ||
| 11 | EVP digest routines | ||
| 6 | 12 | ||
| 7 | =head1 SYNOPSIS | 13 | =head1 SYNOPSIS |
| 8 | 14 | ||
| 9 | #include <openssl/evp.h> | 15 | #include <openssl/evp.h> |
| 10 | 16 | ||
| 11 | void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); | 17 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx); |
| 12 | void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt); | 18 | EVP_MD_CTX *EVP_MD_CTX_create(void); |
| 13 | 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, | ||
| 14 | unsigned int *s); | 23 | unsigned int *s); |
| 15 | 24 | ||
| 16 | #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); | ||
| 17 | 33 | ||
| 18 | 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); |
| 19 | 35 | ||
| 36 | #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ | ||
| 37 | |||
| 38 | |||
| 20 | #define EVP_MD_type(e) ((e)->type) | 39 | #define EVP_MD_type(e) ((e)->type) |
| 21 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) | 40 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) |
| 22 | #define EVP_MD_size(e) ((e)->md_size) | 41 | #define EVP_MD_size(e) ((e)->md_size) |
| @@ -27,15 +46,15 @@ EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines | |||
| 27 | #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) |
| 28 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | 47 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) |
| 29 | 48 | ||
| 30 | EVP_MD *EVP_md_null(void); | 49 | const EVP_MD *EVP_md_null(void); |
| 31 | EVP_MD *EVP_md2(void); | 50 | const EVP_MD *EVP_md2(void); |
| 32 | EVP_MD *EVP_md5(void); | 51 | const EVP_MD *EVP_md5(void); |
| 33 | EVP_MD *EVP_sha(void); | 52 | const EVP_MD *EVP_sha(void); |
| 34 | EVP_MD *EVP_sha1(void); | 53 | const EVP_MD *EVP_sha1(void); |
| 35 | EVP_MD *EVP_dss(void); | 54 | const EVP_MD *EVP_dss(void); |
| 36 | EVP_MD *EVP_dss1(void); | 55 | const EVP_MD *EVP_dss1(void); |
| 37 | EVP_MD *EVP_mdc2(void); | 56 | const EVP_MD *EVP_mdc2(void); |
| 38 | EVP_MD *EVP_ripemd160(void); | 57 | const EVP_MD *EVP_ripemd160(void); |
| 39 | 58 | ||
| 40 | const EVP_MD *EVP_get_digestbyname(const char *name); | 59 | const EVP_MD *EVP_get_digestbyname(const char *name); |
| 41 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | 60 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) |
| @@ -45,25 +64,48 @@ EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines | |||
| 45 | 64 | ||
| 46 | 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. |
| 47 | 66 | ||
| 48 | EVP_DigestInit() initialises a digest context B<ctx> to use a digest | 67 | EVP_MD_CTX_init() initializes digest contet B<ctx>. |
| 49 | B<type>: this will typically be supplied by a function such as | 68 | |
| 50 | 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. | ||
| 51 | 75 | ||
| 52 | 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 |
| 53 | digest context B<ctx>. This funtion can be called several times on the | 77 | digest context B<ctx>. This function can be called several times on the |
| 54 | same B<ctx> to hash additional data. | 78 | same B<ctx> to hash additional data. |
| 55 | 79 | ||
| 56 | EVP_DigestFinal() retrieves the digest value from B<ctx> and places | 80 | EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places |
| 57 | 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 |
| 58 | 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 |
| 59 | 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. |
| 60 | After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate() | 84 | After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate() |
| 61 | can be made, but EVP_DigestInit() can be called to initialiase a new | 85 | can be made, but EVP_DigestInit_ex() can be called to initialize a new |
| 62 | digest operation. | 86 | digest operation. |
| 63 | 87 | ||
| 64 | 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 | ||
| 65 | 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 |
| 66 | 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. | ||
| 67 | 109 | ||
| 68 | 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 |
| 69 | 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 |
| @@ -97,14 +139,15 @@ returns is of zero length. | |||
| 97 | 139 | ||
| 98 | EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj() | 140 | EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj() |
| 99 | return an B<EVP_MD> structure when passed a digest name, a digest NID or | 141 | return an B<EVP_MD> structure when passed a digest name, a digest NID or |
| 100 | an ASN1_OBJECT structure respectively. The digest table must be initialised | 142 | an ASN1_OBJECT structure respectively. The digest table must be initialized |
| 101 | using, for example, OpenSSL_add_all_digests() for these functions to work. | 143 | using, for example, OpenSSL_add_all_digests() for these functions to work. |
| 102 | 144 | ||
| 103 | =head1 RETURN VALUES | 145 | =head1 RETURN VALUES |
| 104 | 146 | ||
| 105 | 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. | ||
| 106 | 149 | ||
| 107 | 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. |
| 108 | 151 | ||
| 109 | 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 |
| 110 | corresponding OBJECT IDENTIFIER or NID_undef if none exists. | 153 | corresponding OBJECT IDENTIFIER or NID_undef if none exists. |
| @@ -129,6 +172,19 @@ transparent to the digest used and much more flexible. | |||
| 129 | 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 |
| 130 | are still in common use. | 173 | are still in common use. |
| 131 | 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 | |||
| 132 | =head1 EXAMPLE | 188 | =head1 EXAMPLE |
| 133 | 189 | ||
| 134 | 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 |
| @@ -160,10 +216,12 @@ digest name passed on the command line. | |||
| 160 | exit(1); | 216 | exit(1); |
| 161 | } | 217 | } |
| 162 | 218 | ||
| 163 | EVP_DigestInit(&mdctx, md); | 219 | EVP_MD_CTX_init(&mdctx); |
| 220 | EVP_DigestInit_ex(&mdctx, md, NULL); | ||
| 164 | EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); | 221 | EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); |
| 165 | EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); | 222 | EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); |
| 166 | EVP_DigestFinal(&mdctx, md_value, &md_len); | 223 | EVP_DigestFinal_ex(&mdctx, md_value, &md_len); |
| 224 | EVP_MD_CTX_cleanup(&mdctx); | ||
| 167 | 225 | ||
| 168 | printf("Digest is: "); | 226 | printf("Digest is: "); |
| 169 | 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]); |
| @@ -172,17 +230,10 @@ digest name passed on the command line. | |||
| 172 | 230 | ||
| 173 | =head1 BUGS | 231 | =head1 BUGS |
| 174 | 232 | ||
| 175 | Several of the functions do not return values: maybe they should. Although the | ||
| 176 | internal digest operations will never fail some future hardware based operations | ||
| 177 | might. | ||
| 178 | |||
| 179 | 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 |
| 180 | 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 |
| 181 | even though they are identical digests. | 235 | even though they are identical digests. |
| 182 | 236 | ||
| 183 | The size of an B<EVP_MD_CTX> structure is determined at compile time: this results | ||
| 184 | in code that must be recompiled if the size of B<EVP_MD_CTX> increases. | ||
| 185 | |||
| 186 | =head1 SEE ALSO | 237 | =head1 SEE ALSO |
| 187 | 238 | ||
| 188 | 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)>, |
| @@ -194,4 +245,7 @@ L<sha(3)|sha(3)>, L<digest(1)|digest(1)> | |||
| 194 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are | 245 | EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are |
| 195 | available in all versions of SSLeay and OpenSSL. | 246 | available in all versions of SSLeay and OpenSSL. |
| 196 | 247 | ||
| 248 | EVP_DigestInit_ex(), EVP_DigestFinal_ex() and EVP_MD_CTX_copy_ex() | ||
| 249 | were added in OpenSSL 0.9.7. | ||
| 250 | |||
| 197 | =cut | 251 | =cut |
