blob: 979690d9660657712e7dc7e9d26c4e4bf38b8f13 [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 */
18#if IMAGE_ENABLE_SIGN
19/**
20 * sign() - calculate and return signature for given input data
21 *
22 * @info: Specifies key and FIT information
23 * @data: Pointer to the input data
24 * @data_len: Data length
25 * @sigp: Set to an allocated buffer holding the signature
26 * @sig_len: Set to length of the calculated hash
27 *
28 * This computes input data signature according to selected algorithm.
29 * Resulting signature value is placed in an allocated buffer, the
30 * pointer is returned as *sigp. The length of the calculated
31 * signature is returned via the sig_len pointer argument. The caller
32 * should free *sigp.
33 *
34 * @return: 0, on success, -ve on error
35 */
36int ecdsa_sign(struct image_sign_info *info, const struct image_region region[],
37 int region_count, uint8_t **sigp, uint *sig_len);
38
39/**
40 * add_verify_data() - Add verification information to FDT
41 *
42 * Add public key information to the FDT node, suitable for
43 * verification at run-time. The information added depends on the
44 * algorithm being used. I just copypasted this from rsa.h.
45 *
46 * @info: Specifies key and FIT information
47 * @keydest: Destination FDT blob for public key data
48 * @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
49 * other -ve value on error
50 */
51int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest);
52#else
53static inline
54int ecdsa_sign(struct image_sign_info *info, const struct image_region region[],
55 int region_count, uint8_t **sigp, uint *sig_len)
56{
57 return -ENXIO;
58}
59
60static inline
61int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest)
62{
63 return -ENXIO;
64}
65#endif
66
67#if IMAGE_ENABLE_VERIFY_ECDSA
68/**
69 * verify() - Verify a signature against some data
70 *
71 * @info: Specifies key and FIT information
72 * @data: Pointer to the input data
73 * @data_len: Data length
74 * @sig: Signature
75 * @sig_len: Number of bytes in signature
76 * @return 0 if verified, -ve on error
77 */
78int ecdsa_verify(struct image_sign_info *info,
79 const struct image_region region[], int region_count,
80 uint8_t *sig, uint sig_len);
81#else
82static inline
83int ecdsa_verify(struct image_sign_info *info,
84 const struct image_region region[], int region_count,
85 uint8_t *sig, uint sig_len)
86{
87 return -ENXIO;
88}
89#endif
90/** @} */
91
92#define ECDSA256_BYTES (256 / 8)
93
94#endif