X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib_generic%2Fsha1.c;h=a192e5f3dd15308330ac40a8bef12a7346529eda;hb=5ea67393b8b554b8165c38912d753a8df043020d;hp=08ffa6b9bacb43382535b664e08334c0c84ae005;hpb=98c80b462f9532f3ff6a62dd9629023b48627a6d;p=oweals%2Fu-boot.git diff --git a/lib_generic/sha1.c b/lib_generic/sha1.c index 08ffa6b9ba..a192e5f3dd 100644 --- a/lib_generic/sha1.c +++ b/lib_generic/sha1.c @@ -29,6 +29,12 @@ #define _CRT_SECURE_NO_DEPRECATE 1 #endif +#ifndef USE_HOSTCC +#include +#else +#include +#endif /* USE_HOSTCC */ +#include #include #include "sha1.h" @@ -308,6 +314,39 @@ void sha1_csum (unsigned char *input, int ilen, unsigned char output[20]) sha1_finish (&ctx, output); } +/* + * Output = SHA-1( input buffer ). Trigger the watchdog every 'chunk_sz' + * bytes of input processed. + */ +void sha1_csum_wd (unsigned char *input, int ilen, unsigned char output[20], + unsigned int chunk_sz) +{ + sha1_context ctx; +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + unsigned char *end, *curr; + int chunk; +#endif + + sha1_starts (&ctx); + +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + curr = input; + end = input + ilen; + while (curr < end) { + chunk = end - curr; + if (chunk > chunk_sz) + chunk = chunk_sz; + sha1_update (&ctx, curr, chunk); + curr += chunk; + WATCHDOG_RESET (); + } +#else + sha1_update (&ctx, input, ilen); +#endif + + sha1_finish (&ctx, output); +} + /* * Output = HMAC-SHA-1( input buffer, hmac key ) */