xref: /rk3399_rockchip-uboot/include/android_avb/avb_rsa.h (revision 5b69db0720b90f33ecb7fb666b196bfc90404185)
1*5b69db07SJason Zhu /*
2*5b69db07SJason Zhu  * Copyright (C) 2016 The Android Open Source Project
3*5b69db07SJason Zhu  *
4*5b69db07SJason Zhu  * Permission is hereby granted, free of charge, to any person
5*5b69db07SJason Zhu  * obtaining a copy of this software and associated documentation
6*5b69db07SJason Zhu  * files (the "Software"), to deal in the Software without
7*5b69db07SJason Zhu  * restriction, including without limitation the rights to use, copy,
8*5b69db07SJason Zhu  * modify, merge, publish, distribute, sublicense, and/or sell copies
9*5b69db07SJason Zhu  * of the Software, and to permit persons to whom the Software is
10*5b69db07SJason Zhu  * furnished to do so, subject to the following conditions:
11*5b69db07SJason Zhu  *
12*5b69db07SJason Zhu  * The above copyright notice and this permission notice shall be
13*5b69db07SJason Zhu  * included in all copies or substantial portions of the Software.
14*5b69db07SJason Zhu  *
15*5b69db07SJason Zhu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*5b69db07SJason Zhu  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*5b69db07SJason Zhu  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*5b69db07SJason Zhu  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19*5b69db07SJason Zhu  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20*5b69db07SJason Zhu  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21*5b69db07SJason Zhu  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*5b69db07SJason Zhu  * SOFTWARE.
23*5b69db07SJason Zhu  */
24*5b69db07SJason Zhu 
25*5b69db07SJason Zhu /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
26*5b69db07SJason Zhu  * Use of this source code is governed by a BSD-style license that can be
27*5b69db07SJason Zhu  * found in the LICENSE file.
28*5b69db07SJason Zhu  */
29*5b69db07SJason Zhu 
30*5b69db07SJason Zhu #ifdef AVB_INSIDE_LIBAVB_H
31*5b69db07SJason Zhu #error "You can't include avb_rsa.h in the public header libavb.h."
32*5b69db07SJason Zhu #endif
33*5b69db07SJason Zhu 
34*5b69db07SJason Zhu /*
35*5b69db07SJason Zhu #ifndef AVB_COMPILATION
36*5b69db07SJason Zhu #error "Never include this file, it may only be used from internal avb code."
37*5b69db07SJason Zhu #endif
38*5b69db07SJason Zhu */
39*5b69db07SJason Zhu 
40*5b69db07SJason Zhu #ifndef AVB_RSA_H_
41*5b69db07SJason Zhu #define AVB_RSA_H_
42*5b69db07SJason Zhu 
43*5b69db07SJason Zhu #ifdef __cplusplus
44*5b69db07SJason Zhu extern "C" {
45*5b69db07SJason Zhu #endif
46*5b69db07SJason Zhu 
47*5b69db07SJason Zhu #include <android_avb/avb_crypto.h>
48*5b69db07SJason Zhu #include <android_avb/avb_sysdeps.h>
49*5b69db07SJason Zhu 
50*5b69db07SJason Zhu /* Using the key given by |key|, verify a RSA signature |sig| of
51*5b69db07SJason Zhu  * length |sig_num_bytes| against an expected |hash| of length
52*5b69db07SJason Zhu  * |hash_num_bytes|. The padding to expect must be passed in using
53*5b69db07SJason Zhu  * |padding| of length |padding_num_bytes|.
54*5b69db07SJason Zhu  *
55*5b69db07SJason Zhu  * The data in |key| must match the format defined in
56*5b69db07SJason Zhu  * |AvbRSAPublicKeyHeader|, including the two large numbers
57*5b69db07SJason Zhu  * following. The |key_num_bytes| must be the size of the entire
58*5b69db07SJason Zhu  * serialized key.
59*5b69db07SJason Zhu  *
60*5b69db07SJason Zhu  * Returns false if verification fails, true otherwise.
61*5b69db07SJason Zhu  */
62*5b69db07SJason Zhu bool avb_rsa_verify(const uint8_t* key,
63*5b69db07SJason Zhu                     size_t key_num_bytes,
64*5b69db07SJason Zhu                     const uint8_t* sig,
65*5b69db07SJason Zhu                     size_t sig_num_bytes,
66*5b69db07SJason Zhu                     const uint8_t* hash,
67*5b69db07SJason Zhu                     size_t hash_num_bytes,
68*5b69db07SJason Zhu                     const uint8_t* padding,
69*5b69db07SJason Zhu                     size_t padding_num_bytes) AVB_ATTR_WARN_UNUSED_RESULT;
70*5b69db07SJason Zhu 
71*5b69db07SJason Zhu #ifdef __cplusplus
72*5b69db07SJason Zhu }
73*5b69db07SJason Zhu #endif
74*5b69db07SJason Zhu 
75*5b69db07SJason Zhu #endif /* AVB_RSA_H_ */
76