23
23
24
24
#include " mbedtls/sha256.h"
25
25
26
+ /* *
27
+ * \name SECTION: Compatibility code
28
+ *
29
+ * Depending on whether the alternative (hatdware accelerated) hashing
30
+ * functions are provided or not, different API should be used for hashing.
31
+ * \{
32
+ */
33
+
34
+ #if defined(MBEDTLS_SHA256_ALT)
35
+
36
+ /* *
37
+ * \brief This function starts a SHA-256 checksum calculation.
38
+ *
39
+ * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
40
+ *
41
+ * \param ctx The SHA-256 context to initialize.
42
+ * \param is224 Determines which function to use.
43
+ * <ul><li>0: Use SHA-256.</li>
44
+ * <li>1: Use SHA-224.</li></ul>
45
+ */
46
+ void mbedtls_sha256_starts ( mbedtls_sha256_context *ctx,
47
+ int is224 )
48
+ {
49
+ mbedtls_sha256_starts_ret ( ctx, is224 );
50
+ }
51
+
52
+ /* *
53
+ * \brief This function feeds an input buffer into an ongoing
54
+ * SHA-256 checksum calculation.
55
+ *
56
+ * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
57
+ *
58
+ * \param ctx The SHA-256 context to initialize.
59
+ * \param input The buffer holding the data.
60
+ * \param ilen The length of the input data.
61
+ */
62
+ void mbedtls_sha256_update ( mbedtls_sha256_context *ctx,
63
+ const unsigned char *input,
64
+ size_t ilen )
65
+ {
66
+ mbedtls_sha256_update_ret ( ctx, input, ilen );
67
+ }
68
+
69
+ /* *
70
+ * \brief This function finishes the SHA-256 operation, and writes
71
+ * the result to the output buffer.
72
+ *
73
+ * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
74
+ *
75
+ * \param ctx The SHA-256 context.
76
+ * \param output The SHA-224or SHA-256 checksum result.
77
+ */
78
+ void mbedtls_sha256_finish ( mbedtls_sha256_context *ctx,
79
+ unsigned char output[32 ] )
80
+ {
81
+ mbedtls_sha256_finish_ret ( ctx, output );
82
+ }
83
+
84
+ #endif /* defined(MBEDTLS_SHA256_ALT) */
85
+
86
+ /* \} name SECTION: Compatibility code */
87
+
26
88
using namespace utest ::v1;
27
89
28
90
#if defined(MBEDTLS_SHA256_C)
@@ -41,18 +103,18 @@ void test_case_sha256_split() {
41
103
mbedtls_sha256_context ctx;
42
104
printf (" test sha256\n " );
43
105
mbedtls_sha256_init ( &ctx );
44
- mbedtls_sha256_starts_ret ( &ctx, 0 );
106
+ mbedtls_sha256_starts ( &ctx, 0 );
45
107
#if 0
46
108
printf("test not splitted\n");
47
109
mbedtls_sha256_update( &ctx, test_buf, 168 );
48
110
#else
49
111
printf (" test splitted into 3 pieces\n " );
50
- mbedtls_sha256_update_ret ( &ctx, test_buf, 2 );
51
- mbedtls_sha256_update_ret ( &ctx, test_buf+2 , 66 );
52
- mbedtls_sha256_update_ret ( &ctx, test_buf+68 , 100 );
112
+ mbedtls_sha256_update ( &ctx, test_buf, 2 );
113
+ mbedtls_sha256_update ( &ctx, test_buf+2 , 66 );
114
+ mbedtls_sha256_update ( &ctx, test_buf+68 , 100 );
53
115
#endif
54
116
55
- mbedtls_sha256_finish_ret ( &ctx, outsum );
117
+ mbedtls_sha256_finish ( &ctx, outsum );
56
118
mbedtls_sha256_free ( &ctx );
57
119
58
120
printf (" \n received result : " );
@@ -98,29 +160,29 @@ void test_case_sha256_multi() {
98
160
mbedtls_sha256_init ( &ctx2);
99
161
mbedtls_sha256_init ( &ctx3);
100
162
// Start both contexts
101
- mbedtls_sha256_starts_ret ( &ctx1, 0 );
102
- mbedtls_sha256_starts_ret ( &ctx2, 0 );
163
+ mbedtls_sha256_starts ( &ctx1, 0 );
164
+ mbedtls_sha256_starts ( &ctx2, 0 );
103
165
104
166
printf (" upd ctx1\n " );
105
- mbedtls_sha256_update_ret ( &ctx1, test_buf, 56 );
167
+ mbedtls_sha256_update ( &ctx1, test_buf, 56 );
106
168
printf (" upd ctx2\n " );
107
- mbedtls_sha256_update_ret ( &ctx2, test_buf, 66 );
169
+ mbedtls_sha256_update ( &ctx2, test_buf, 66 );
108
170
printf (" finish ctx1\n " );
109
- mbedtls_sha256_finish_ret ( &ctx1, outsum1 );
171
+ mbedtls_sha256_finish ( &ctx1, outsum1 );
110
172
printf (" upd ctx2\n " );
111
- mbedtls_sha256_update_ret ( &ctx2, test_buf+66 , 46 );
173
+ mbedtls_sha256_update ( &ctx2, test_buf+66 , 46 );
112
174
printf (" clone ctx2 in ctx3\n " );
113
175
mbedtls_sha256_clone (&ctx3, (const mbedtls_sha256_context *)&ctx2);
114
176
printf (" free ctx1\n " );
115
177
mbedtls_sha256_free ( &ctx1 );
116
178
printf (" upd ctx2\n " );
117
- mbedtls_sha256_update_ret ( &ctx2, test_buf+112 , 56 );
179
+ mbedtls_sha256_update ( &ctx2, test_buf+112 , 56 );
118
180
printf (" upd ctx3 with different values than ctx2\n " );
119
- mbedtls_sha256_update_ret ( &ctx3, test_buf2, 56 );
181
+ mbedtls_sha256_update ( &ctx3, test_buf2, 56 );
120
182
printf (" finish ctx2\n " );
121
- mbedtls_sha256_finish_ret ( &ctx2, outsum2 );
183
+ mbedtls_sha256_finish ( &ctx2, outsum2 );
122
184
printf (" finish ctx3\n " );
123
- mbedtls_sha256_finish_ret ( &ctx3, outsum3 );
185
+ mbedtls_sha256_finish ( &ctx3, outsum3 );
124
186
printf (" free ctx2\n " );
125
187
mbedtls_sha256_free ( &ctx2 );
126
188
printf (" free ctx3\n " );
0 commit comments