|
1 --- src/trspi/crypto/openssl/hash.c.old 2011-05-09 06:20:09.505021734 -0700 |
|
2 +++ src/trspi/crypto/openssl/hash.c 2011-05-09 06:19:04.603252090 -0700 |
|
3 @@ -56,45 +56,21 @@ |
|
4 TSS_RESULT |
|
5 Trspi_Hash(UINT32 HashType, UINT32 BufSize, BYTE* Buf, BYTE* Digest) |
|
6 { |
|
7 - EVP_MD_CTX md_ctx; |
|
8 - unsigned int result_size; |
|
9 - int rv; |
|
10 + Trspi_HashCtx ctx; |
|
11 + TSS_RESULT rv; |
|
12 |
|
13 - switch (HashType) { |
|
14 - case TSS_HASH_SHA1: |
|
15 - rv = EVP_DigestInit(&md_ctx, EVP_sha1()); |
|
16 - break; |
|
17 - default: |
|
18 - rv = TSPERR(TSS_E_BAD_PARAMETER); |
|
19 - goto out; |
|
20 - break; |
|
21 - } |
|
22 + rv = Trspi_HashInit(&ctx, HashType); |
|
23 + if (rv != TSS_SUCCESS) |
|
24 + return rv; |
|
25 |
|
26 - if (rv != EVP_SUCCESS) { |
|
27 - rv = TSPERR(TSS_E_INTERNAL_ERROR); |
|
28 - goto err; |
|
29 - } |
|
30 - |
|
31 - rv = EVP_DigestUpdate(&md_ctx, Buf, BufSize); |
|
32 - if (rv != EVP_SUCCESS) { |
|
33 - rv = TSPERR(TSS_E_INTERNAL_ERROR); |
|
34 - goto err; |
|
35 + rv = Trspi_HashUpdate(&ctx, BufSize, Buf); |
|
36 + if (rv != TSS_SUCCESS) { |
|
37 + EVP_MD_CTX_destroy(ctx.ctx); |
|
38 + return rv; |
|
39 } |
|
40 + rv = Trspi_HashFinal(&ctx, Digest); |
|
41 |
|
42 - result_size = EVP_MD_CTX_size(&md_ctx); |
|
43 - rv = EVP_DigestFinal(&md_ctx, Digest, &result_size); |
|
44 - if (rv != EVP_SUCCESS) { |
|
45 - rv = TSPERR(TSS_E_INTERNAL_ERROR); |
|
46 - goto err; |
|
47 - } else |
|
48 - rv = TSS_SUCCESS; |
|
49 - |
|
50 - goto out; |
|
51 - |
|
52 -err: |
|
53 - DEBUG_print_openssl_errors(); |
|
54 -out: |
|
55 - return rv; |
|
56 + return (rv); |
|
57 } |
|
58 |
|
59 TSS_RESULT |
|
60 @@ -112,7 +88,8 @@ |
|
61 break; |
|
62 } |
|
63 |
|
64 - if ((ctx->ctx = malloc(sizeof(EVP_MD_CTX))) == NULL) |
|
65 + ctx->ctx = EVP_MD_CTX_create(); |
|
66 + if (ctx->ctx == NULL) |
|
67 return TSPERR(TSS_E_OUTOFMEMORY); |
|
68 |
|
69 rv = EVP_DigestInit((EVP_MD_CTX *)ctx->ctx, (const EVP_MD *)md); |
|
70 @@ -142,7 +119,7 @@ |
|
71 rv = EVP_DigestUpdate(ctx->ctx, data, size); |
|
72 if (rv != EVP_SUCCESS) { |
|
73 DEBUG_print_openssl_errors(); |
|
74 - free(ctx->ctx); |
|
75 + EVP_MD_CTX_destroy(ctx->ctx); |
|
76 ctx->ctx = NULL; |
|
77 return TSPERR(TSS_E_INTERNAL_ERROR); |
|
78 } |
|
79 @@ -164,7 +141,7 @@ |
|
80 if (rv != EVP_SUCCESS) |
|
81 return TSPERR(TSS_E_INTERNAL_ERROR); |
|
82 |
|
83 - free(ctx->ctx); |
|
84 + EVP_MD_CTX_destroy(ctx->ctx); |
|
85 ctx->ctx = NULL; |
|
86 |
|
87 return TSS_SUCCESS; |