]> git.ipfire.org Git - people/ms/u-boot.git/blob - include/rsa.h
a5dd676b6b0f0dd2291c0aebef2c2f2870d73edf
[people/ms/u-boot.git] / include / rsa.h
1 /*
2 * Copyright (c) 2013, Google Inc.
3 *
4 * (C) Copyright 2008 Semihalf
5 *
6 * (C) Copyright 2000-2006
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28 #ifndef _RSA_H
29 #define _RSA_H
30
31 #include <errno.h>
32 #include <image.h>
33
34 #if IMAGE_ENABLE_SIGN
35 /**
36 * sign() - calculate and return signature for given input data
37 *
38 * @info: Specifies key and FIT information
39 * @data: Pointer to the input data
40 * @data_len: Data length
41 * @sigp: Set to an allocated buffer holding the signature
42 * @sig_len: Set to length of the calculated hash
43 *
44 * This computes input data signature according to selected algorithm.
45 * Resulting signature value is placed in an allocated buffer, the
46 * pointer is returned as *sigp. The length of the calculated
47 * signature is returned via the sig_len pointer argument. The caller
48 * should free *sigp.
49 *
50 * @return: 0, on success, -ve on error
51 */
52 int rsa_sign(struct image_sign_info *info,
53 const struct image_region region[],
54 int region_count, uint8_t **sigp, uint *sig_len);
55
56 /**
57 * add_verify_data() - Add verification information to FDT
58 *
59 * Add public key information to the FDT node, suitable for
60 * verification at run-time. The information added depends on the
61 * algorithm being used.
62 *
63 * @info: Specifies key and FIT information
64 * @keydest: Destination FDT blob for public key data
65 * @return: 0, on success, -ve on error
66 */
67 int rsa_add_verify_data(struct image_sign_info *info, void *keydest);
68 #else
69 static inline int rsa_sign(struct image_sign_info *info,
70 const struct image_region region[], int region_count,
71 uint8_t **sigp, uint *sig_len)
72 {
73 return -ENXIO;
74 }
75
76 static inline int rsa_add_verify_data(struct image_sign_info *info,
77 void *keydest)
78 {
79 return -ENXIO;
80 }
81 #endif
82
83 #if IMAGE_ENABLE_VERIFY
84 /**
85 * rsa_verify() - Verify a signature against some data
86 *
87 * Verify a RSA PKCS1.5 signature against an expected hash.
88 *
89 * @info: Specifies key and FIT information
90 * @data: Pointer to the input data
91 * @data_len: Data length
92 * @sig: Signature
93 * @sig_len: Number of bytes in signature
94 * @return 0 if verified, -ve on error
95 */
96 int rsa_verify(struct image_sign_info *info,
97 const struct image_region region[], int region_count,
98 uint8_t *sig, uint sig_len);
99 #else
100 static inline int rsa_verify(struct image_sign_info *info,
101 const struct image_region region[], int region_count,
102 uint8_t *sig, uint sig_len)
103 {
104 return -ENXIO;
105 }
106 #endif
107
108 #endif