blob: 6e0269e3aed69b136c5664156385f64f4ce866c8 [file] [log] [blame]
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -06001/* 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>
11#include <linux/kconfig.h>
12
13/**
14 * crypto_algo API impementation for ECDSA;
15 * @see "struct crypto_algo"
16 * @{
17 */
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060018/**
19 * sign() - calculate and return signature for given input data
20 *
21 * @info: Specifies key and FIT information
22 * @data: Pointer to the input data
23 * @data_len: Data length
24 * @sigp: Set to an allocated buffer holding the signature
25 * @sig_len: Set to length of the calculated hash
26 *
27 * This computes input data signature according to selected algorithm.
28 * Resulting signature value is placed in an allocated buffer, the
29 * pointer is returned as *sigp. The length of the calculated
30 * signature is returned via the sig_len pointer argument. The caller
31 * should free *sigp.
32 *
33 * @return: 0, on success, -ve on error
34 */
35int ecdsa_sign(struct image_sign_info *info, const struct image_region region[],
36 int region_count, uint8_t **sigp, uint *sig_len);
37
38/**
39 * add_verify_data() - Add verification information to FDT
40 *
41 * Add public key information to the FDT node, suitable for
42 * verification at run-time. The information added depends on the
43 * algorithm being used. I just copypasted this from rsa.h.
44 *
45 * @info: Specifies key and FIT information
46 * @keydest: Destination FDT blob for public key data
Simon Glass94336dc2021-11-12 12:28:11 -070047 * @return: node offset within the FDT blob where the data was written on
48 * success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
49 * value on other error
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060050 */
51int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest);
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060052
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060053/**
54 * verify() - Verify a signature against some data
55 *
56 * @info: Specifies key and FIT information
57 * @data: Pointer to the input data
58 * @data_len: Data length
59 * @sig: Signature
60 * @sig_len: Number of bytes in signature
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010061 * Return: 0 if verified, -ve on error
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060062 */
63int ecdsa_verify(struct image_sign_info *info,
64 const struct image_region region[], int region_count,
65 uint8_t *sig, uint sig_len);
Alexandru Gagniuc3ebd2002021-02-19 12:45:12 -060066/** @} */
67
68#define ECDSA256_BYTES (256 / 8)
69
70#endif