xref: /openbmc/u-boot/lib/libavb/avb_rsa.h (revision afaea1f5)
1 /* SPDX-License-Identifier: MIT OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2016 The Android Open Source Project
4  */
5 
6 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
7  * Use of this source code is governed by a BSD-style license that can be
8  * found in the LICENSE file.
9  */
10 
11 #ifdef AVB_INSIDE_LIBAVB_H
12 #error "You can't include avb_rsa.h in the public header libavb.h."
13 #endif
14 
15 #ifndef AVB_COMPILATION
16 #error "Never include this file, it may only be used from internal avb code."
17 #endif
18 
19 #ifndef AVB_RSA_H_
20 #define AVB_RSA_H_
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "avb_crypto.h"
27 #include "avb_sysdeps.h"
28 
29 /* Using the key given by |key|, verify a RSA signature |sig| of
30  * length |sig_num_bytes| against an expected |hash| of length
31  * |hash_num_bytes|. The padding to expect must be passed in using
32  * |padding| of length |padding_num_bytes|.
33  *
34  * The data in |key| must match the format defined in
35  * |AvbRSAPublicKeyHeader|, including the two large numbers
36  * following. The |key_num_bytes| must be the size of the entire
37  * serialized key.
38  *
39  * Returns false if verification fails, true otherwise.
40  */
41 bool avb_rsa_verify(const uint8_t* key,
42                     size_t key_num_bytes,
43                     const uint8_t* sig,
44                     size_t sig_num_bytes,
45                     const uint8_t* hash,
46                     size_t hash_num_bytes,
47                     const uint8_t* padding,
48                     size_t padding_num_bytes) AVB_ATTR_WARN_UNUSED_RESULT;
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 
54 #endif /* AVB_RSA_H_ */
55