blob: 8f2ede8a6adbe0beec94e892237bcf5c47e4c4f9 [file] [log] [blame]
Gaurav Shah322536d2010-01-28 15:01:23 -08001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#ifndef VBOOT_REFERENCE_RSA_H_
7#define VBOOT_REFERENCE_RSA_H_
8
9#include <inttypes.h>
10
11#define RSA1024NUMBYTES 128 /* 1024 bit key length */
12#define RSA2048NUMBYTES 256 /* 2048 bit key length */
13#define RSA4096NUMBYTES 512 /* 4096 bit key length */
14#define RSA8192NUMBYTES 1024 /* 8192 bit key length */
15
16#define RSA1024NUMWORDS (RSA1024NUMBYTES / sizeof(uint32_t))
17#define RSA2048NUMWORDS (RSA2048NUMBYTES / sizeof(uint32_t))
18#define RSA4096NUMWORDS (RSA4096NUMBYTES / sizeof(uint32_t))
19#define RSA8192NUMWORDS (RSA8192NUMBYTES / sizeof(uint32_t))
20
21typedef struct RSAPublicKey {
22 int len; /* Length of n[] in number of uint32_t */
23 uint32_t n0inv; /* -1 / n[0] mod 2^32 */
24 uint32_t* n; /* modulus as little endian array */
25 uint32_t* rr; /* R^2 as little endian array */
26} RSAPublicKey;
27
28/* Verify a RSA PKCS1.5 signature [sig] of [sig_type] and length [sig_len]
29 * against an expected [hash] using [key]. Returns 0 on failure, 1 on success.
30 */
Gaurav Shahf5564fa2010-03-02 15:40:01 -080031int RSAVerify(const RSAPublicKey *key,
Gaurav Shah322536d2010-01-28 15:01:23 -080032 const uint8_t* sig,
33 const int sig_len,
34 const uint8_t sig_type,
35 const uint8_t* hash);
36
37#endif /* VBOOT_REFERENCE_RSA_H_ */