summaryrefslogtreecommitdiffstats
path: root/crypto/digest.c
Commit message (Collapse)AuthorAgeFilesLines
* crypto: digest: match driver name if no algo name matchesAhmad Fatoum2023-05-261-5/+6
| | | | | | | | | | | | The digest command lists all registered digest implementations, but there's no way to select a specific implementation when another higher priority one exists for the same algorithm. Let's support this, by having digest_algo_get_by_name fallback to look up by driver name if an exact match couldn't be found by algo name. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230526063746.1155297-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: use crypto_memneq()Sascha Hauer2021-07-301-2/+5
| | | | | | | When verifying a digest it is important not to leak timing information through memcmp(). Use crypto_memneq() instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: Drop usage of memmapSascha Hauer2020-07-051-26/+1
| | | | | | | | | | | | | | | | | digest_file_window() first tries to memmap the file before it falls back to reading it. This is quite unnecessary, we can just always read. Moreover, memmapping a file has problems with the current code. A "md5sum foo" result in the filesize argument being MAX_LFS_FILESIZE. This is fine for files where the file is just read up to the end in this case, but for memmapped buffers this results in digesting MAX_LFS_FILESIZE bytes which is wrong. This problem is not apparent at the moment as there are only a few files which are memmappable, and on these (/dev/mem, /dev/ram0) digest commands are normally called with an explicit size argument. This changes once ramfs starts supporting memmap, so better drop memmapping in the digest code now. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: fix digesting file windowsSascha Hauer2019-05-091-5/+6
| | | | | | | | | | | When digesting a file we always try toread PAGE_SIZE bytes. When we get a short read because we reached the file end then the code works correctly. If instead we only want to digest a part of the file then we must make sure to only read up to 'size' bytes. Fixes: b77582effd ("crypto: digest: Split memory vs. file code into separate functions") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Return -errno if stat() failsAndrey Smirnov2019-01-171-5/+2
| | | | | | | | | Strictly speaking, stat() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Return -errno if lseek() failsAndrey Smirnov2019-01-171-2/+2
| | | | | | | | | | | Strictly speaking, lseek() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'. In this case this change also allows us to avoid potential problems from downconverting 'loff_t' to 'int'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Return -errno if open() failsAndrey Smirnov2019-01-171-1/+1
| | | | | | | | | Strictly speaking, open() doesn't return a detailed error code as its return value and it can and should be obtained via 'errno'. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Change the signature of digest_file_window()Andrey Smirnov2019-01-161-3/+3
| | | | | | | | | On 32-bit systems "ulong" will limit digest_file_window()'s maximum size to 4 GiB. Convert "start" and "size" to "loff_t" in order to be able to handle maximum file size supported by the rest of the system. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Split memory vs. file code into separate functionsAndrey Smirnov2019-01-161-48/+70
| | | | | | | | | | | Instead of trying to fit two rather different cases into a single loop, split digesting memory and digesting files into separate subroutines. While duplicating some of the code shared by both of the while() loops this makes the body of the loop easier to follow as well as gets rid of poorly named "flags" variable. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Replace 4096 with PAGE_SIZEAndrey Smirnov2019-01-161-2/+2
| | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Remove unused variableAndrey Smirnov2019-01-161-2/+0
| | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Introduce MAP_FAILED and replace ad-hoc constants with itAndrey Smirnov2019-01-161-1/+1
| | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Fix digesting over memory chunks > 4096 bytesUwe Kleine-König2017-07-101-0/+3
| | | | | | | | | | | | | | | | | | | There are two different cases that are handled in digest_file_window: a) the file to digest is memmappable (e.g. /dev/mem) b) it isn't (e.g. files in /) In both cases a file is digested in hunks of (up to) 4096 bytes. After each hunk in b) the buffer that is fed to digest_update() is then overwritten using read() to get the next hunk to digest. In case a) however it was forgotten to step forward in the buffer and instead the same data was handed to digest_update() again and again. So to fix that increase buffer by the number of bytes already digested for case a) which is characterized by flags == 0. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
* whole tree: remove trailing whitespacesDu Huanpeng2016-04-211-1/+1
| | | | | Signed-off-by: Du Huanpeng <u74147@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: add digest_alloc_by_algo()Sascha Hauer2016-01-261-1/+42
| | | | | | | | | | | In barebox the function digest_alloc() allocates a digest based on a string. When a subsystem already uses an integer value to identify a digest it makes no sense to create a string and pass it to digest_alloc(), where it is parsed again. This patch adds the possibility to get a digest by an enum. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: mark signature argument as constMarc Kleine-Budde2015-05-261-5/+5
| | | | | Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: prepare to allow multiple digest driverJean-Christophe PLAGNIOL-VILLARD2015-03-271-12/+19
| | | | | | | | | | This will allow to have hw driver or asm optimised driver. Use a priority level to determine which one to use at runtime. The generic one will be 0. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: allow algo to specify their length at runtimeJean-Christophe PLAGNIOL-VILLARD2015-03-271-2/+1
| | | | | | | | such as RSA as we load a DER key we will detect the key size at runtime and so the algo length. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* command: add generic digest commandJean-Christophe PLAGNIOL-VILLARD2015-03-201-5/+20
| | | | | | | That can be used for digest calculation and verify Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: add digest callbackJean-Christophe PLAGNIOL-VILLARD2015-03-191-0/+18
| | | | | | | | | | | Combination of @init and @update and @final. This function effectively behaves as the entire chain of operations, @init, @update and @final issued in sequence. This is added for hardware which cannot do even the @finup, but can only do the whole transformation in one run. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: add verify callbackJean-Christophe PLAGNIOL-VILLARD2015-03-191-1/+23
| | | | | | | | | | | | this will allow to compare a md with the original one When calling this do not call final For RSA_SIGN verification final does not exist only verify as final will be for signing Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: digest_file_window/digest_file/digest_file_by_name drop key ↵Jean-Christophe PLAGNIOL-VILLARD2015-03-191-8/+2
| | | | | | | | | params expect the key to be set before calling Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: digest_file_window: check every digest_xxx returnJean-Christophe PLAGNIOL-VILLARD2015-03-181-3/+7
| | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Fix coding styleSascha Hauer2015-03-131-4/+4
| | | | | | | | | | When declaring pointer data or a function that returns a pointer type, the preferred use of '*' is adjacent to the data name or function name and not adjacent to the type name. Fix the remaining occurences in crypto/ Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* crypto: digest: Make string arguments constSascha Hauer2015-03-131-9/+9
| | | | | | | Most string arguments for keys and filenames can be const. Change that. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* command: add hmac sum supportfor md5, sha1, sha224, sha256, sha384, sha512Jean-Christophe PLAGNIOL-VILLARD2015-03-131-2/+8
| | | | | | | | | | | | | | | pass the key via -h param barebox@barebox sandbox:/ sha256sum -h test /dev/fd0 c297473e9bb221c5dc51d47ad75c76095f1bdc4ca9dff1d5931c2e22bf11a0de /dev/fd0 0x00000000 ... 0xffffffffffffffff use the same idea as openssl command $ openssl dgst -sha256 -hmac "test" TODO HMAC-SHA256(TODO)= c297473e9bb221c5dc51d47ad75c76095f1bdc4ca9dff1d5931c2e22bf11a0de Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: make it multi-instanceJean-Christophe PLAGNIOL-VILLARD2015-03-121-10/+53
| | | | | | | | | | Now you need to call digest_alloc and when you finish to use it digest_free. We need this for upcomming aes encryption support and secure boot as we will need multiple instance of the same digest. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: introduce digest_{init/update/final/length}Jean-Christophe PLAGNIOL-VILLARD2015-03-121-3/+3
| | | | | | | | This will allow to move from a one at a time digest to a multi-instance with too much impact on the code using it Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* digest: move digest.c to cryptoJean-Christophe PLAGNIOL-VILLARD2015-03-121-0/+174
with not the rest of the implementation Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>