1 /**
2 * \file rsa.h
3 *
4 * \brief The RSA public-key cryptosystem
5 *
6 * Copyright (C) 2006-2010, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; If not, see <http://www.gnu.org/licenses/>.
25 */
26 #ifndef TPMRSA_H
27 #define TPMRSA_H
28
29 #include "tcg.h"
30 #include <polarssl/bignum.h>
31
32 /* tpm software key */
33 typedef struct
34 {
35 size_t len; /*!< size(N) in chars */
36
37 mpi N; /*!< public modulus */
38 mpi E; /*!< public exponent */
39
40 mpi RN; /*!< cached R^2 mod N */
41 }
42 tpmrsa_context;
43
44 #define TPMRSA_CTX_INIT { 0, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}}
45
46 /* Setup the rsa context using tpm public key data */
47 void tpmrsa_set_pubkey(tpmrsa_context* ctx,
48 const unsigned char* key,
49 int keylen,
50 const unsigned char* exponent,
51 int explen);
52
53 /* Check an RSA signature */
54 TPM_RESULT tpmrsa_sigcheck(tpmrsa_context *ctx, const unsigned char *input, const unsigned char *sha1);
55
56 /* Do rsa public crypto */
57 TPM_RESULT tpmrsa_pub_encrypt_oaep( tpmrsa_context *ctx,
58 int (*f_rng)(void *, unsigned char *, size_t),
59 void *p_rng,
60 size_t ilen,
61 const unsigned char *input,
62 unsigned char *output );
63
64 /* free tpmrsa key */
65 static
tpmrsa_free(tpmrsa_context * ctx)66 inline void tpmrsa_free( tpmrsa_context *ctx ) {
67 mpi_free( &ctx->RN ); mpi_free( &ctx->E ); mpi_free( &ctx->N );
68 }
69
70 #endif /* tpmrsa.h */
71