1 From f76eb65d008d0c8e06698e4a63a776e91b80155b Mon Sep 17 00:00:00 2001
2 From: jfigus <foleyj@cisco.com>
3 Date: Tue, 4 Nov 2014 14:54:02 -0500
4 Subject: [PATCH] Rename SHA1 functions to avoid conflicts with downstream
7 Backported from upstream commit c270245a94ae9a007202754eb8f7ce9e48f97007
8 and tweaked to apply on top of v1.5.4.
10 Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
12 crypto/hash/hmac.c | 20 ++++++++++----------
13 crypto/hash/hmac_ossl.c | 18 +++++++++---------
14 crypto/hash/sha1.c | 32 ++++++++++++++++----------------
15 crypto/include/hmac.h | 4 ++--
16 crypto/include/sha1.h | 34 +++++++++++++++++-----------------
17 crypto/test/sha1_driver.c | 8 ++++----
18 6 files changed, 58 insertions(+), 58 deletions(-)
20 diff --git a/crypto/hash/hmac.c b/crypto/hash/hmac.c
21 index ddb75ea..4bed61e 100644
22 --- a/crypto/hash/hmac.c
23 +++ b/crypto/hash/hmac.c
24 @@ -141,11 +141,11 @@ hmac_init(hmac_ctx_t *state, const uint8_t *key, int key_len) {
25 debug_print(mod_hmac, "ipad: %s", octet_string_hex_string(ipad, 64));
27 /* initialize sha1 context */
28 - sha1_init(&state->init_ctx);
29 + srtp_sha1_init(&state->init_ctx);
32 - sha1_update(&state->init_ctx, ipad, 64);
33 - memcpy(&state->ctx, &state->init_ctx, sizeof(sha1_ctx_t));
34 + srtp_sha1_update(&state->init_ctx, ipad, 64);
35 + memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
39 @@ -153,7 +153,7 @@ hmac_init(hmac_ctx_t *state, const uint8_t *key, int key_len) {
41 hmac_start(hmac_ctx_t *state) {
43 - memcpy(&state->ctx, &state->init_ctx, sizeof(sha1_ctx_t));
44 + memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
48 @@ -165,7 +165,7 @@ hmac_update(hmac_ctx_t *state, const uint8_t *message, int msg_octets) {
49 octet_string_hex_string(message, msg_octets));
51 /* hash message into sha1 context */
52 - sha1_update(&state->ctx, message, msg_octets);
53 + srtp_sha1_update(&state->ctx, message, msg_octets);
57 @@ -183,7 +183,7 @@ hmac_compute(hmac_ctx_t *state, const void *message,
59 /* hash message, copy output into H */
60 hmac_update(state, (const uint8_t*)message, msg_octets);
61 - sha1_final(&state->ctx, H);
62 + srtp_sha1_final(&state->ctx, H);
65 * note that we don't need to debug_print() the input, since the
66 @@ -193,16 +193,16 @@ hmac_compute(hmac_ctx_t *state, const void *message,
67 octet_string_hex_string((uint8_t *)H, 20));
69 /* re-initialize hash context */
70 - sha1_init(&state->ctx);
71 + srtp_sha1_init(&state->ctx);
74 - sha1_update(&state->ctx, (uint8_t *)state->opad, 64);
75 + srtp_sha1_update(&state->ctx, (uint8_t *)state->opad, 64);
77 /* hash the result of the inner hash */
78 - sha1_update(&state->ctx, (uint8_t *)H, 20);
79 + srtp_sha1_update(&state->ctx, (uint8_t *)H, 20);
81 /* the result is returned in the array hash_value[] */
82 - sha1_final(&state->ctx, hash_value);
83 + srtp_sha1_final(&state->ctx, hash_value);
85 /* copy hash_value to *result */
86 for (i=0; i < tag_len; i++)
87 diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c
88 index f62ce57..2ec8350 100644
89 --- a/crypto/hash/hmac_ossl.c
90 +++ b/crypto/hash/hmac_ossl.c
91 @@ -163,11 +163,11 @@ hmac_init (hmac_ctx_t *state, const uint8_t *key, int key_len)
92 debug_print(mod_hmac, "ipad: %s", octet_string_hex_string(ipad, sizeof(ipad)));
94 /* initialize sha1 context */
95 - sha1_init(&state->init_ctx);
96 + srtp_sha1_init(&state->init_ctx);
97 state->init_ctx_initialized = 1;
100 - sha1_update(&state->init_ctx, ipad, sizeof(ipad));
101 + srtp_sha1_update(&state->init_ctx, ipad, sizeof(ipad));
102 return (hmac_start(state));
105 @@ -192,7 +192,7 @@ hmac_update (hmac_ctx_t *state, const uint8_t *message, int msg_octets)
106 octet_string_hex_string(message, msg_octets));
108 /* hash message into sha1 context */
109 - sha1_update(&state->ctx, message, msg_octets);
110 + srtp_sha1_update(&state->ctx, message, msg_octets);
112 return err_status_ok;
114 @@ -211,8 +211,8 @@ hmac_compute (hmac_ctx_t *state, const void *message,
117 /* hash message, copy output into H */
118 - sha1_update(&state->ctx, message, msg_octets);
119 - sha1_final(&state->ctx, H);
120 + srtp_sha1_update(&state->ctx, message, msg_octets);
121 + srtp_sha1_final(&state->ctx, H);
124 * note that we don't need to debug_print() the input, since the
125 @@ -222,16 +222,16 @@ hmac_compute (hmac_ctx_t *state, const void *message,
126 octet_string_hex_string((uint8_t*)H, sizeof(H)));
128 /* re-initialize hash context */
129 - sha1_init(&state->ctx);
130 + srtp_sha1_init(&state->ctx);
132 /* hash opad ^ key */
133 - sha1_update(&state->ctx, (uint8_t*)state->opad, sizeof(state->opad));
134 + srtp_sha1_update(&state->ctx, (uint8_t*)state->opad, sizeof(state->opad));
136 /* hash the result of the inner hash */
137 - sha1_update(&state->ctx, (uint8_t*)H, sizeof(H));
138 + srtp_sha1_update(&state->ctx, (uint8_t*)H, sizeof(H));
140 /* the result is returned in the array hash_value[] */
141 - sha1_final(&state->ctx, hash_value);
142 + srtp_sha1_final(&state->ctx, hash_value);
144 /* copy hash_value to *result */
145 for (i = 0; i < tag_len; i++) {
146 diff --git a/crypto/hash/sha1.c b/crypto/hash/sha1.c
147 index c200437..29c2e62 100644
148 --- a/crypto/hash/sha1.c
149 +++ b/crypto/hash/sha1.c
150 @@ -77,17 +77,17 @@ uint32_t SHA_K2 = 0x8F1BBCDC; /* Kt for 40 <= t <= 59 */
151 uint32_t SHA_K3 = 0xCA62C1D6; /* Kt for 60 <= t <= 79 */
154 -sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
156 +srtp_sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
157 + srtp_sha1_ctx_t ctx;
160 - sha1_update(&ctx, msg, octets_in_msg);
161 - sha1_final(&ctx, hash_value);
162 + srtp_sha1_init(&ctx);
163 + srtp_sha1_update(&ctx, msg, octets_in_msg);
164 + srtp_sha1_final(&ctx, hash_value);
169 - * sha1_core(M, H) computes the core compression function, where M is
170 + * srtp_sha1_core(M, H) computes the core compression function, where M is
171 * the next part of the message (in network byte order) and H is the
172 * intermediate state { H0, H1, ...} (in host byte order)
174 @@ -99,7 +99,7 @@ sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
178 -sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
179 +srtp_sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
183 @@ -186,7 +186,7 @@ sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
187 -sha1_init(sha1_ctx_t *ctx) {
188 +srtp_sha1_init(srtp_sha1_ctx_t *ctx) {
190 /* initialize state vector */
191 ctx->H[0] = 0x67452301;
192 @@ -204,7 +204,7 @@ sha1_init(sha1_ctx_t *ctx) {
196 -sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
197 +srtp_sha1_update(srtp_sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
199 uint8_t *buf = (uint8_t *)ctx->M;
201 @@ -227,13 +227,13 @@ sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
203 /* process a whole block */
205 - debug_print(mod_sha1, "(update) running sha1_core()", NULL);
206 + debug_print(mod_sha1, "(update) running srtp_sha1_core()", NULL);
208 - sha1_core(ctx->M, ctx->H);
209 + srtp_sha1_core(ctx->M, ctx->H);
213 - debug_print(mod_sha1, "(update) not running sha1_core()", NULL);
214 + debug_print(mod_sha1, "(update) not running srtp_sha1_core()", NULL);
216 for (i=ctx->octets_in_buffer;
217 i < (ctx->octets_in_buffer + octets_in_msg); i++)
218 @@ -247,12 +247,12 @@ sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
222 - * sha1_final(ctx, output) computes the result for ctx and copies it
223 + * srtp_sha1_final(ctx, output) computes the result for ctx and copies it
224 * into the twenty octets located at *output
228 -sha1_final(sha1_ctx_t *ctx, uint32_t *output) {
229 +srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t *output) {
230 uint32_t A, B, C, D, E, TEMP;
233 @@ -339,11 +339,11 @@ sha1_final(sha1_ctx_t *ctx, uint32_t *output) {
237 - debug_print(mod_sha1, "(final) running sha1_core()", NULL);
238 + debug_print(mod_sha1, "(final) running srtp_sha1_core()", NULL);
240 if (ctx->octets_in_buffer >= 56) {
242 - debug_print(mod_sha1, "(final) running sha1_core() again", NULL);
243 + debug_print(mod_sha1, "(final) running srtp_sha1_core() again", NULL);
245 /* we need to do one final run of the compression algo */
247 diff --git a/crypto/include/hmac.h b/crypto/include/hmac.h
248 index 875f45c..9fc664e 100644
249 --- a/crypto/include/hmac.h
250 +++ b/crypto/include/hmac.h
256 - sha1_ctx_t init_ctx;
257 + srtp_sha1_ctx_t ctx;
258 + srtp_sha1_ctx_t init_ctx;
261 int init_ctx_initialized;
262 diff --git a/crypto/include/sha1.h b/crypto/include/sha1.h
263 index f1744ce..e177af6 100644
264 --- a/crypto/include/sha1.h
265 +++ b/crypto/include/sha1.h
267 #include <openssl/evp.h>
270 -typedef EVP_MD_CTX sha1_ctx_t;
271 +typedef EVP_MD_CTX srtp_sha1_ctx_t;
274 - * sha1_init(&ctx) initializes the SHA1 context ctx
275 + * srtp_sha1_init(&ctx) initializes the SHA1 context ctx
277 - * sha1_update(&ctx, msg, len) hashes the len octets starting at msg
278 + * srtp_sha1_update(&ctx, msg, len) hashes the len octets starting at msg
279 * into the SHA1 context
281 - * sha1_final(&ctx, output) performs the final processing of the SHA1
282 + * srtp_sha1_final(&ctx, output) performs the final processing of the SHA1
283 * context and writes the result to the 20 octets at output
285 * Return values are ignored on the EVP functions since all three
286 @@ -72,18 +72,18 @@ typedef EVP_MD_CTX sha1_ctx_t;
290 -static inline void sha1_init (sha1_ctx_t *ctx)
291 +static inline void srtp_sha1_init (srtp_sha1_ctx_t *ctx)
293 EVP_MD_CTX_init(ctx);
294 EVP_DigestInit(ctx, EVP_sha1());
297 -static inline void sha1_update (sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg)
298 +static inline void srtp_sha1_update (srtp_sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg)
300 EVP_DigestUpdate(ctx, M, octets_in_msg);
303 -static inline void sha1_final (sha1_ctx_t *ctx, uint32_t *output)
304 +static inline void srtp_sha1_final (srtp_sha1_ctx_t *ctx, uint32_t *output)
306 unsigned int len = 0;
308 @@ -97,7 +97,7 @@ typedef struct {
309 uint32_t M[16]; /* message buffer */
310 int octets_in_buffer; /* octets of message in buffer */
311 uint32_t num_bits_in_msg; /* total number of bits in message */
316 * sha1(&ctx, msg, len, output) hashes the len octets starting at msg
317 @@ -110,33 +110,33 @@ void
318 sha1(const uint8_t *message, int octets_in_msg, uint32_t output[5]);
321 - * sha1_init(&ctx) initializes the SHA1 context ctx
322 + * srtp_sha1_init(&ctx) initializes the SHA1 context ctx
324 - * sha1_update(&ctx, msg, len) hashes the len octets starting at msg
325 + * srtp_sha1_update(&ctx, msg, len) hashes the len octets starting at msg
326 * into the SHA1 context
328 - * sha1_final(&ctx, output) performs the final processing of the SHA1
329 + * srtp_sha1_final(&ctx, output) performs the final processing of the SHA1
330 * context and writes the result to the 20 octets at output
335 -sha1_init(sha1_ctx_t *ctx);
336 +srtp_sha1_init(srtp_sha1_ctx_t *ctx);
339 -sha1_update(sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg);
340 +srtp_sha1_update(srtp_sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg);
343 -sha1_final(sha1_ctx_t *ctx, uint32_t output[5]);
344 +srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t output[5]);
347 - * The sha1_core function is INTERNAL to SHA-1, but it is declared
348 + * The srtp_sha1_core function is INTERNAL to SHA-1, but it is declared
349 * here because it is also used by the cipher SEAL 3.0 in its key
354 - * sha1_core(M, H) computes the core sha1 compression function, where M is
355 + * srtp_sha1_core(M, H) computes the core sha1 compression function, where M is
356 * the next part of the message and H is the intermediate state {H0,
359 @@ -145,7 +145,7 @@ sha1_final(sha1_ctx_t *ctx, uint32_t output[5]);
363 -sha1_core(const uint32_t M[16], uint32_t hash_value[5]);
364 +srtp_sha1_core(const uint32_t M[16], uint32_t hash_value[5]);
366 #endif /* else OPENSSL */
368 diff --git a/crypto/test/sha1_driver.c b/crypto/test/sha1_driver.c
369 index 6adfad1..2e19479 100644
370 --- a/crypto/test/sha1_driver.c
371 +++ b/crypto/test/sha1_driver.c
372 @@ -102,7 +102,7 @@ hash_test_case_add(hash_test_case_t **list_ptr,
375 sha1_test_case_validate(const hash_test_case_t *test_case) {
377 + srtp_sha1_ctx_t ctx;
378 uint32_t hash_value[5];
380 if (test_case == NULL)
381 @@ -113,9 +113,9 @@ sha1_test_case_validate(const hash_test_case_t *test_case) {
382 if (test_case->data_len > MAX_HASH_DATA_LEN)
383 return err_status_bad_param;
386 - sha1_update(&ctx, test_case->data, test_case->data_len);
387 - sha1_final(&ctx, hash_value);
388 + srtp_sha1_init(&ctx);
389 + srtp_sha1_update(&ctx, test_case->data, test_case->data_len);
390 + srtp_sha1_final(&ctx, hash_value);
391 if (0 == memcmp(test_case->hash, hash_value, 20)) {
393 printf("PASSED: reference value: %s\n",