Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file was transplanted with slight modifications from Linux sources |
| 3 | * (fs/cifs/md5.h) into U-Boot by Bartlomiej Sieka <tur@semihalf.com>. |
| 4 | */ |
| 5 | |
| 6 | #ifndef _MD5_H |
| 7 | #define _MD5_H |
| 8 | |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 9 | #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) |
| 10 | #include <mbedtls/md5.h> |
| 11 | #endif |
Mike Frysinger | 4ad8e9f | 2009-07-02 19:23:25 -0400 | [diff] [blame] | 12 | #include "compiler.h" |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 13 | |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 14 | #define MD5_SUM_LEN 16 |
Raymond Mao | c35e1a4 | 2024-10-03 14:50:17 -0700 | [diff] [blame] | 15 | #define MD5_DEF_CHUNK_SZ 0x10000 |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 16 | |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 17 | #if defined(CONFIG_MBEDTLS_LIB_CRYPTO) |
| 18 | typedef mbedtls_md5_context MD5Context; |
| 19 | #else |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 20 | typedef struct MD5Context { |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 21 | __u32 buf[4]; |
| 22 | __u32 bits[2]; |
Marek Vasut | e7ab380 | 2012-04-29 00:28:40 +0200 | [diff] [blame] | 23 | union { |
| 24 | unsigned char in[64]; |
| 25 | __u32 in32[16]; |
| 26 | }; |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 27 | } MD5Context; |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 28 | #endif |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 29 | |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 30 | void MD5Init(MD5Context *ctx); |
| 31 | void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len); |
| 32 | void MD5Final(unsigned char digest[16], MD5Context *ctx); |
Chia-Wei Wang | abc83f9 | 2021-07-30 09:08:02 +0800 | [diff] [blame] | 33 | |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 34 | /* |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 35 | * Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'. |
| 36 | * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the |
| 37 | * watchdog every 'chunk_sz' bytes of input processed. |
| 38 | */ |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 39 | void md5_wd(const unsigned char *input, unsigned int len, |
| 40 | unsigned char output[16], unsigned int chunk_sz); |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 41 | |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 42 | #endif /* _MD5_H */ |