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 | |
Heinrich Schuchardt | bd198b3 | 2024-12-06 12:37:09 +0100 | [diff] [blame] | 9 | #include <linux/kconfig.h> |
| 10 | |
| 11 | #if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 12 | #include <mbedtls/md5.h> |
| 13 | #endif |
Mike Frysinger | 4ad8e9f | 2009-07-02 19:23:25 -0400 | [diff] [blame] | 14 | #include "compiler.h" |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 15 | |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 16 | #define MD5_SUM_LEN 16 |
Raymond Mao | c35e1a4 | 2024-10-03 14:50:17 -0700 | [diff] [blame] | 17 | #define MD5_DEF_CHUNK_SZ 0x10000 |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 18 | |
Heinrich Schuchardt | bd198b3 | 2024-12-06 12:37:09 +0100 | [diff] [blame] | 19 | #if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO) |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 20 | typedef mbedtls_md5_context MD5Context; |
| 21 | #else |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 22 | typedef struct MD5Context { |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 23 | __u32 buf[4]; |
| 24 | __u32 bits[2]; |
Marek Vasut | e7ab380 | 2012-04-29 00:28:40 +0200 | [diff] [blame] | 25 | union { |
| 26 | unsigned char in[64]; |
| 27 | __u32 in32[16]; |
| 28 | }; |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 29 | } MD5Context; |
Raymond Mao | a571b98 | 2024-10-03 14:50:16 -0700 | [diff] [blame] | 30 | #endif |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 31 | |
Raymond Mao | cdc9318 | 2024-05-16 14:11:51 -0700 | [diff] [blame] | 32 | void MD5Init(MD5Context *ctx); |
| 33 | void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len); |
| 34 | void MD5Final(unsigned char digest[16], MD5Context *ctx); |
Chia-Wei Wang | abc83f9 | 2021-07-30 09:08:02 +0800 | [diff] [blame] | 35 | |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 36 | /* |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 37 | * Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'. |
| 38 | * 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the |
| 39 | * watchdog every 'chunk_sz' bytes of input processed. |
| 40 | */ |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 41 | void md5_wd(const unsigned char *input, unsigned int len, |
| 42 | unsigned char output[16], unsigned int chunk_sz); |
Bartlomiej Sieka | da5045d | 2008-04-22 12:27:56 +0200 | [diff] [blame] | 43 | |
Andy Fleming | 72c23be | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 44 | #endif /* _MD5_H */ |