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