Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (c) 2020, Alexandru Gagniuc <mr.nuke.me@gmail.com>. |
| 4 | */ |
| 5 | |
| 6 | #ifndef _ECDSA_H |
| 7 | #define _ECDSA_H |
| 8 | |
| 9 | #include <errno.h> |
| 10 | #include <image.h> |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * crypto_algo API impementation for ECDSA; |
| 14 | * @see "struct crypto_algo" |
| 15 | * @{ |
| 16 | */ |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 17 | /** |
| 18 | * sign() - calculate and return signature for given input data |
| 19 | * |
| 20 | * @info: Specifies key and FIT information |
| 21 | * @data: Pointer to the input data |
| 22 | * @data_len: Data length |
| 23 | * @sigp: Set to an allocated buffer holding the signature |
| 24 | * @sig_len: Set to length of the calculated hash |
| 25 | * |
| 26 | * This computes input data signature according to selected algorithm. |
| 27 | * Resulting signature value is placed in an allocated buffer, the |
| 28 | * pointer is returned as *sigp. The length of the calculated |
| 29 | * signature is returned via the sig_len pointer argument. The caller |
| 30 | * should free *sigp. |
| 31 | * |
| 32 | * @return: 0, on success, -ve on error |
| 33 | */ |
| 34 | int ecdsa_sign(struct image_sign_info *info, const struct image_region region[], |
| 35 | int region_count, uint8_t **sigp, uint *sig_len); |
| 36 | |
| 37 | /** |
| 38 | * add_verify_data() - Add verification information to FDT |
| 39 | * |
| 40 | * Add public key information to the FDT node, suitable for |
| 41 | * verification at run-time. The information added depends on the |
| 42 | * algorithm being used. I just copypasted this from rsa.h. |
| 43 | * |
| 44 | * @info: Specifies key and FIT information |
| 45 | * @keydest: Destination FDT blob for public key data |
Simon Glass | 94336dc | 2021-11-12 12:28:11 -0700 | [diff] [blame] | 46 | * @return: node offset within the FDT blob where the data was written on |
| 47 | * success, -ENOSPC if the keydest FDT blob ran out of space, other -ve |
| 48 | * value on other error |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 49 | */ |
| 50 | int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest); |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 51 | |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 52 | /** |
| 53 | * verify() - Verify a signature against some data |
| 54 | * |
| 55 | * @info: Specifies key and FIT information |
| 56 | * @data: Pointer to the input data |
| 57 | * @data_len: Data length |
| 58 | * @sig: Signature |
| 59 | * @sig_len: Number of bytes in signature |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 60 | * Return: 0 if verified, -ve on error |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 61 | */ |
| 62 | int ecdsa_verify(struct image_sign_info *info, |
| 63 | const struct image_region region[], int region_count, |
| 64 | uint8_t *sig, uint sig_len); |
Alexandru Gagniuc | 3ebd200 | 2021-02-19 12:45:12 -0600 | [diff] [blame] | 65 | /** @} */ |
| 66 | |
| 67 | #define ECDSA256_BYTES (256 / 8) |
| 68 | |
| 69 | #endif |