0001-Rename-SHA1-functions-to-avoid-conflicts-with-downst.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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
  5. packages.
  6. Backported from upstream commit c270245a94ae9a007202754eb8f7ce9e48f97007
  7. and tweaked to apply on top of v1.5.4.
  8. Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
  9. ---
  10. crypto/hash/hmac.c | 20 ++++++++++----------
  11. crypto/hash/hmac_ossl.c | 18 +++++++++---------
  12. crypto/hash/sha1.c | 32 ++++++++++++++++----------------
  13. crypto/include/hmac.h | 4 ++--
  14. crypto/include/sha1.h | 34 +++++++++++++++++-----------------
  15. crypto/test/sha1_driver.c | 8 ++++----
  16. 6 files changed, 58 insertions(+), 58 deletions(-)
  17. diff --git a/crypto/hash/hmac.c b/crypto/hash/hmac.c
  18. index ddb75ea..4bed61e 100644
  19. --- a/crypto/hash/hmac.c
  20. +++ b/crypto/hash/hmac.c
  21. @@ -141,11 +141,11 @@ hmac_init(hmac_ctx_t *state, const uint8_t *key, int key_len) {
  22. debug_print(mod_hmac, "ipad: %s", octet_string_hex_string(ipad, 64));
  23. /* initialize sha1 context */
  24. - sha1_init(&state->init_ctx);
  25. + srtp_sha1_init(&state->init_ctx);
  26. /* hash ipad ^ key */
  27. - sha1_update(&state->init_ctx, ipad, 64);
  28. - memcpy(&state->ctx, &state->init_ctx, sizeof(sha1_ctx_t));
  29. + srtp_sha1_update(&state->init_ctx, ipad, 64);
  30. + memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
  31. return err_status_ok;
  32. }
  33. @@ -153,7 +153,7 @@ hmac_init(hmac_ctx_t *state, const uint8_t *key, int key_len) {
  34. err_status_t
  35. hmac_start(hmac_ctx_t *state) {
  36. - memcpy(&state->ctx, &state->init_ctx, sizeof(sha1_ctx_t));
  37. + memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
  38. return err_status_ok;
  39. }
  40. @@ -165,7 +165,7 @@ hmac_update(hmac_ctx_t *state, const uint8_t *message, int msg_octets) {
  41. octet_string_hex_string(message, msg_octets));
  42. /* hash message into sha1 context */
  43. - sha1_update(&state->ctx, message, msg_octets);
  44. + srtp_sha1_update(&state->ctx, message, msg_octets);
  45. return err_status_ok;
  46. }
  47. @@ -183,7 +183,7 @@ hmac_compute(hmac_ctx_t *state, const void *message,
  48. /* hash message, copy output into H */
  49. hmac_update(state, (const uint8_t*)message, msg_octets);
  50. - sha1_final(&state->ctx, H);
  51. + srtp_sha1_final(&state->ctx, H);
  52. /*
  53. * note that we don't need to debug_print() the input, since the
  54. @@ -193,16 +193,16 @@ hmac_compute(hmac_ctx_t *state, const void *message,
  55. octet_string_hex_string((uint8_t *)H, 20));
  56. /* re-initialize hash context */
  57. - sha1_init(&state->ctx);
  58. + srtp_sha1_init(&state->ctx);
  59. /* hash opad ^ key */
  60. - sha1_update(&state->ctx, (uint8_t *)state->opad, 64);
  61. + srtp_sha1_update(&state->ctx, (uint8_t *)state->opad, 64);
  62. /* hash the result of the inner hash */
  63. - sha1_update(&state->ctx, (uint8_t *)H, 20);
  64. + srtp_sha1_update(&state->ctx, (uint8_t *)H, 20);
  65. /* the result is returned in the array hash_value[] */
  66. - sha1_final(&state->ctx, hash_value);
  67. + srtp_sha1_final(&state->ctx, hash_value);
  68. /* copy hash_value to *result */
  69. for (i=0; i < tag_len; i++)
  70. diff --git a/crypto/hash/hmac_ossl.c b/crypto/hash/hmac_ossl.c
  71. index f62ce57..2ec8350 100644
  72. --- a/crypto/hash/hmac_ossl.c
  73. +++ b/crypto/hash/hmac_ossl.c
  74. @@ -163,11 +163,11 @@ hmac_init (hmac_ctx_t *state, const uint8_t *key, int key_len)
  75. debug_print(mod_hmac, "ipad: %s", octet_string_hex_string(ipad, sizeof(ipad)));
  76. /* initialize sha1 context */
  77. - sha1_init(&state->init_ctx);
  78. + srtp_sha1_init(&state->init_ctx);
  79. state->init_ctx_initialized = 1;
  80. /* hash ipad ^ key */
  81. - sha1_update(&state->init_ctx, ipad, sizeof(ipad));
  82. + srtp_sha1_update(&state->init_ctx, ipad, sizeof(ipad));
  83. return (hmac_start(state));
  84. }
  85. @@ -192,7 +192,7 @@ hmac_update (hmac_ctx_t *state, const uint8_t *message, int msg_octets)
  86. octet_string_hex_string(message, msg_octets));
  87. /* hash message into sha1 context */
  88. - sha1_update(&state->ctx, message, msg_octets);
  89. + srtp_sha1_update(&state->ctx, message, msg_octets);
  90. return err_status_ok;
  91. }
  92. @@ -211,8 +211,8 @@ hmac_compute (hmac_ctx_t *state, const void *message,
  93. }
  94. /* hash message, copy output into H */
  95. - sha1_update(&state->ctx, message, msg_octets);
  96. - sha1_final(&state->ctx, H);
  97. + srtp_sha1_update(&state->ctx, message, msg_octets);
  98. + srtp_sha1_final(&state->ctx, H);
  99. /*
  100. * note that we don't need to debug_print() the input, since the
  101. @@ -222,16 +222,16 @@ hmac_compute (hmac_ctx_t *state, const void *message,
  102. octet_string_hex_string((uint8_t*)H, sizeof(H)));
  103. /* re-initialize hash context */
  104. - sha1_init(&state->ctx);
  105. + srtp_sha1_init(&state->ctx);
  106. /* hash opad ^ key */
  107. - sha1_update(&state->ctx, (uint8_t*)state->opad, sizeof(state->opad));
  108. + srtp_sha1_update(&state->ctx, (uint8_t*)state->opad, sizeof(state->opad));
  109. /* hash the result of the inner hash */
  110. - sha1_update(&state->ctx, (uint8_t*)H, sizeof(H));
  111. + srtp_sha1_update(&state->ctx, (uint8_t*)H, sizeof(H));
  112. /* the result is returned in the array hash_value[] */
  113. - sha1_final(&state->ctx, hash_value);
  114. + srtp_sha1_final(&state->ctx, hash_value);
  115. /* copy hash_value to *result */
  116. for (i = 0; i < tag_len; i++) {
  117. diff --git a/crypto/hash/sha1.c b/crypto/hash/sha1.c
  118. index c200437..29c2e62 100644
  119. --- a/crypto/hash/sha1.c
  120. +++ b/crypto/hash/sha1.c
  121. @@ -77,17 +77,17 @@ uint32_t SHA_K2 = 0x8F1BBCDC; /* Kt for 40 <= t <= 59 */
  122. uint32_t SHA_K3 = 0xCA62C1D6; /* Kt for 60 <= t <= 79 */
  123. void
  124. -sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
  125. - sha1_ctx_t ctx;
  126. +srtp_sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
  127. + srtp_sha1_ctx_t ctx;
  128. - sha1_init(&ctx);
  129. - sha1_update(&ctx, msg, octets_in_msg);
  130. - sha1_final(&ctx, hash_value);
  131. + srtp_sha1_init(&ctx);
  132. + srtp_sha1_update(&ctx, msg, octets_in_msg);
  133. + srtp_sha1_final(&ctx, hash_value);
  134. }
  135. /*
  136. - * sha1_core(M, H) computes the core compression function, where M is
  137. + * srtp_sha1_core(M, H) computes the core compression function, where M is
  138. * the next part of the message (in network byte order) and H is the
  139. * intermediate state { H0, H1, ...} (in host byte order)
  140. *
  141. @@ -99,7 +99,7 @@ sha1(const uint8_t *msg, int octets_in_msg, uint32_t hash_value[5]) {
  142. */
  143. void
  144. -sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
  145. +srtp_sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
  146. uint32_t H0;
  147. uint32_t H1;
  148. uint32_t H2;
  149. @@ -186,7 +186,7 @@ sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
  150. }
  151. void
  152. -sha1_init(sha1_ctx_t *ctx) {
  153. +srtp_sha1_init(srtp_sha1_ctx_t *ctx) {
  154. /* initialize state vector */
  155. ctx->H[0] = 0x67452301;
  156. @@ -204,7 +204,7 @@ sha1_init(sha1_ctx_t *ctx) {
  157. }
  158. void
  159. -sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
  160. +srtp_sha1_update(srtp_sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
  161. int i;
  162. uint8_t *buf = (uint8_t *)ctx->M;
  163. @@ -227,13 +227,13 @@ sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
  164. /* process a whole block */
  165. - debug_print(mod_sha1, "(update) running sha1_core()", NULL);
  166. + debug_print(mod_sha1, "(update) running srtp_sha1_core()", NULL);
  167. - sha1_core(ctx->M, ctx->H);
  168. + srtp_sha1_core(ctx->M, ctx->H);
  169. } else {
  170. - debug_print(mod_sha1, "(update) not running sha1_core()", NULL);
  171. + debug_print(mod_sha1, "(update) not running srtp_sha1_core()", NULL);
  172. for (i=ctx->octets_in_buffer;
  173. i < (ctx->octets_in_buffer + octets_in_msg); i++)
  174. @@ -247,12 +247,12 @@ sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, int octets_in_msg) {
  175. }
  176. /*
  177. - * sha1_final(ctx, output) computes the result for ctx and copies it
  178. + * srtp_sha1_final(ctx, output) computes the result for ctx and copies it
  179. * into the twenty octets located at *output
  180. */
  181. void
  182. -sha1_final(sha1_ctx_t *ctx, uint32_t *output) {
  183. +srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t *output) {
  184. uint32_t A, B, C, D, E, TEMP;
  185. uint32_t W[80];
  186. int i, t;
  187. @@ -339,11 +339,11 @@ sha1_final(sha1_ctx_t *ctx, uint32_t *output) {
  188. }
  189. - debug_print(mod_sha1, "(final) running sha1_core()", NULL);
  190. + debug_print(mod_sha1, "(final) running srtp_sha1_core()", NULL);
  191. if (ctx->octets_in_buffer >= 56) {
  192. - debug_print(mod_sha1, "(final) running sha1_core() again", NULL);
  193. + debug_print(mod_sha1, "(final) running srtp_sha1_core() again", NULL);
  194. /* we need to do one final run of the compression algo */
  195. diff --git a/crypto/include/hmac.h b/crypto/include/hmac.h
  196. index 875f45c..9fc664e 100644
  197. --- a/crypto/include/hmac.h
  198. +++ b/crypto/include/hmac.h
  199. @@ -51,8 +51,8 @@
  200. typedef struct {
  201. uint8_t opad[64];
  202. - sha1_ctx_t ctx;
  203. - sha1_ctx_t init_ctx;
  204. + srtp_sha1_ctx_t ctx;
  205. + srtp_sha1_ctx_t init_ctx;
  206. #ifdef OPENSSL
  207. int ctx_initialized;
  208. int init_ctx_initialized;
  209. diff --git a/crypto/include/sha1.h b/crypto/include/sha1.h
  210. index f1744ce..e177af6 100644
  211. --- a/crypto/include/sha1.h
  212. +++ b/crypto/include/sha1.h
  213. @@ -56,15 +56,15 @@
  214. #include <openssl/evp.h>
  215. #include <stdint.h>
  216. -typedef EVP_MD_CTX sha1_ctx_t;
  217. +typedef EVP_MD_CTX srtp_sha1_ctx_t;
  218. /*
  219. - * sha1_init(&ctx) initializes the SHA1 context ctx
  220. + * srtp_sha1_init(&ctx) initializes the SHA1 context ctx
  221. *
  222. - * sha1_update(&ctx, msg, len) hashes the len octets starting at msg
  223. + * srtp_sha1_update(&ctx, msg, len) hashes the len octets starting at msg
  224. * into the SHA1 context
  225. *
  226. - * sha1_final(&ctx, output) performs the final processing of the SHA1
  227. + * srtp_sha1_final(&ctx, output) performs the final processing of the SHA1
  228. * context and writes the result to the 20 octets at output
  229. *
  230. * Return values are ignored on the EVP functions since all three
  231. @@ -72,18 +72,18 @@ typedef EVP_MD_CTX sha1_ctx_t;
  232. *
  233. */
  234. -static inline void sha1_init (sha1_ctx_t *ctx)
  235. +static inline void srtp_sha1_init (srtp_sha1_ctx_t *ctx)
  236. {
  237. EVP_MD_CTX_init(ctx);
  238. EVP_DigestInit(ctx, EVP_sha1());
  239. }
  240. -static inline void sha1_update (sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg)
  241. +static inline void srtp_sha1_update (srtp_sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg)
  242. {
  243. EVP_DigestUpdate(ctx, M, octets_in_msg);
  244. }
  245. -static inline void sha1_final (sha1_ctx_t *ctx, uint32_t *output)
  246. +static inline void srtp_sha1_final (srtp_sha1_ctx_t *ctx, uint32_t *output)
  247. {
  248. unsigned int len = 0;
  249. @@ -97,7 +97,7 @@ typedef struct {
  250. uint32_t M[16]; /* message buffer */
  251. int octets_in_buffer; /* octets of message in buffer */
  252. uint32_t num_bits_in_msg; /* total number of bits in message */
  253. -} sha1_ctx_t;
  254. +} srtp_sha1_ctx_t;
  255. /*
  256. * sha1(&ctx, msg, len, output) hashes the len octets starting at msg
  257. @@ -110,33 +110,33 @@ void
  258. sha1(const uint8_t *message, int octets_in_msg, uint32_t output[5]);
  259. /*
  260. - * sha1_init(&ctx) initializes the SHA1 context ctx
  261. + * srtp_sha1_init(&ctx) initializes the SHA1 context ctx
  262. *
  263. - * sha1_update(&ctx, msg, len) hashes the len octets starting at msg
  264. + * srtp_sha1_update(&ctx, msg, len) hashes the len octets starting at msg
  265. * into the SHA1 context
  266. *
  267. - * sha1_final(&ctx, output) performs the final processing of the SHA1
  268. + * srtp_sha1_final(&ctx, output) performs the final processing of the SHA1
  269. * context and writes the result to the 20 octets at output
  270. *
  271. */
  272. void
  273. -sha1_init(sha1_ctx_t *ctx);
  274. +srtp_sha1_init(srtp_sha1_ctx_t *ctx);
  275. void
  276. -sha1_update(sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg);
  277. +srtp_sha1_update(srtp_sha1_ctx_t *ctx, const uint8_t *M, int octets_in_msg);
  278. void
  279. -sha1_final(sha1_ctx_t *ctx, uint32_t output[5]);
  280. +srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t output[5]);
  281. /*
  282. - * The sha1_core function is INTERNAL to SHA-1, but it is declared
  283. + * The srtp_sha1_core function is INTERNAL to SHA-1, but it is declared
  284. * here because it is also used by the cipher SEAL 3.0 in its key
  285. * setup algorithm.
  286. */
  287. /*
  288. - * sha1_core(M, H) computes the core sha1 compression function, where M is
  289. + * srtp_sha1_core(M, H) computes the core sha1 compression function, where M is
  290. * the next part of the message and H is the intermediate state {H0,
  291. * H1, ...}
  292. *
  293. @@ -145,7 +145,7 @@ sha1_final(sha1_ctx_t *ctx, uint32_t output[5]);
  294. */
  295. void
  296. -sha1_core(const uint32_t M[16], uint32_t hash_value[5]);
  297. +srtp_sha1_core(const uint32_t M[16], uint32_t hash_value[5]);
  298. #endif /* else OPENSSL */
  299. diff --git a/crypto/test/sha1_driver.c b/crypto/test/sha1_driver.c
  300. index 6adfad1..2e19479 100644
  301. --- a/crypto/test/sha1_driver.c
  302. +++ b/crypto/test/sha1_driver.c
  303. @@ -102,7 +102,7 @@ hash_test_case_add(hash_test_case_t **list_ptr,
  304. err_status_t
  305. sha1_test_case_validate(const hash_test_case_t *test_case) {
  306. - sha1_ctx_t ctx;
  307. + srtp_sha1_ctx_t ctx;
  308. uint32_t hash_value[5];
  309. if (test_case == NULL)
  310. @@ -113,9 +113,9 @@ sha1_test_case_validate(const hash_test_case_t *test_case) {
  311. if (test_case->data_len > MAX_HASH_DATA_LEN)
  312. return err_status_bad_param;
  313. - sha1_init(&ctx);
  314. - sha1_update(&ctx, test_case->data, test_case->data_len);
  315. - sha1_final(&ctx, hash_value);
  316. + srtp_sha1_init(&ctx);
  317. + srtp_sha1_update(&ctx, test_case->data, test_case->data_len);
  318. + srtp_sha1_final(&ctx, hash_value);
  319. if (0 == memcmp(test_case->hash, hash_value, 20)) {
  320. #if VERBOSE
  321. printf("PASSED: reference value: %s\n",
  322. --
  323. 2.7.3