This is a fork of the mbed port of axTLS

Dependents:   TLS_axTLS-Example HTTPSClientExample

Overview

This library is a fork from the mbed port of axTLS. It attempts to :

  • reduce the usage of dynamic memory
  • verify certificates with key size up to 2048 bits
  • provide a simple interface

Encryption

This library uses either RC4 or AES for encryption.

Memory usage

During the establishment of a connection, about 10KB of memory is allocated dynamically (it depends on certificates). Once the connection is established, the memory consumption is relatively low. This means that your program must not use too much static memory or allocate memory before you establish a TLS connection.

Certificates

Certificates are the major source of problem and will often be the reason why your program will crash. Due to memory constraint, there are some limitations on certificates :

  • Each certificate must not be bigger than 2KB
  • TLS client can only handle a chain of up to three certificates (excluding the root certificate). This means that the server must not send more than three certificates.

Also, this library can only load certificates following these specifications :

  • encoded in binary DER format (PKCS1)
  • The public key must use RSA only

Once the connection is established, you should free all loaded certificates by calling CertificateManager::clear(). This will free a few kilobytes (it depends on your certificates). In addition, to enable certificate verification during the connection, this library has a "precomputed mode". This mode uses much less memory than a normal certificate verification.

Normal mode

You need to copy the root certificate in binary-DER format on the mbed. Then in your code, let's say that your root certificate is saved on the mbed as "root.der", assuming that you include CertificateManager.h and that you created a LocalFileSystem, you can load this certificate as this ;

Load root certificate

CertificateManager::add("/local/root.der");
CertificateManager::load();

Do not forget that this mode takes quite a lot of memory ( the memory peak is high while verifying certificates) and will only work if the key size is not bigger than 1024 bits (otherwise it will crash while verifying certificates).

Precomputed mode

In this mode, you need to save the entire chain of certificates (in binary-DER format) including the root certificate on the mbed. In practice, this means that you must first retrieve all certificates that the server sends during a connection and then find the right root certificate. In your code, you must call CertificateManager::add for each certificate and in the right order : from the server certificate to the root certificate. Here is how you shoud load certificates in this mode :

Loadcertificates in precomputed mode

CertificateManager::add("/local/server1.der");
CertificateManager::add("/local/server2.der");
CertificateManager::add("/local/server3.der");
CertificateManager::add("/local/root.der");
CertificateManager::load(true);

Using this mode, you should be able to verify certificates with key size up to 2048 bits.

How do I find these certificates ?

I posted an entry in my notebook detailing how to get certificates from a server. You should be able to get all certificates you need except the root certificate. Here is a way how to get the root certificate on windows :

  1. Open (double-click) the last certificate sent by the server
  2. Go to details panel and click on the entry called Issuer. The first line gives you the name of this certificate and the second line indicates the company who created this certificate
  3. Open firefox
  4. Go to options, advanced panel and click on View Certificates
  5. Go to Authorities panel
  6. Choose the certificate whose name match the issuer of the last certificate sent by the server
  7. Export this certificate to binary-DER format.

Connect to mbed.org !

Import programTLS_axTLS-Example

Establishing a connection to mbed.org using TLS

Committer:
feb11
Date:
Thu Sep 12 15:18:04 2013 +0000
Revision:
0:85fceccc1a7c
intial import

Who changed what in which revision?

UserRevisionLine numberNew contents of line
feb11 0:85fceccc1a7c 1 /*
feb11 0:85fceccc1a7c 2 * Copyright (c) 2007, Cameron Rich
feb11 0:85fceccc1a7c 3 *
feb11 0:85fceccc1a7c 4 * All rights reserved.
feb11 0:85fceccc1a7c 5 *
feb11 0:85fceccc1a7c 6 * Redistribution and use in source and binary forms, with or without
feb11 0:85fceccc1a7c 7 * modification, are permitted provided that the following conditions are met:
feb11 0:85fceccc1a7c 8 *
feb11 0:85fceccc1a7c 9 * * Redistributions of source code must retain the above copyright notice,
feb11 0:85fceccc1a7c 10 * this list of conditions and the following disclaimer.
feb11 0:85fceccc1a7c 11 * * Redistributions in binary form must reproduce the above copyright notice,
feb11 0:85fceccc1a7c 12 * this list of conditions and the following disclaimer in the documentation
feb11 0:85fceccc1a7c 13 * and/or other materials provided with the distribution.
feb11 0:85fceccc1a7c 14 * * Neither the name of the axTLS project nor the names of its contributors
feb11 0:85fceccc1a7c 15 * may be used to endorse or promote products derived from this software
feb11 0:85fceccc1a7c 16 * without specific prior written permission.
feb11 0:85fceccc1a7c 17 *
feb11 0:85fceccc1a7c 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
feb11 0:85fceccc1a7c 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
feb11 0:85fceccc1a7c 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
feb11 0:85fceccc1a7c 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
feb11 0:85fceccc1a7c 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
feb11 0:85fceccc1a7c 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
feb11 0:85fceccc1a7c 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
feb11 0:85fceccc1a7c 25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
feb11 0:85fceccc1a7c 26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
feb11 0:85fceccc1a7c 27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
feb11 0:85fceccc1a7c 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
feb11 0:85fceccc1a7c 29 */
feb11 0:85fceccc1a7c 30
feb11 0:85fceccc1a7c 31 /**
feb11 0:85fceccc1a7c 32 * Implements the RSA public encryption algorithm. Uses the bigint library to
feb11 0:85fceccc1a7c 33 * perform its calculations.
feb11 0:85fceccc1a7c 34 */
feb11 0:85fceccc1a7c 35
feb11 0:85fceccc1a7c 36 #include <stdio.h>
feb11 0:85fceccc1a7c 37 #include <string.h>
feb11 0:85fceccc1a7c 38 #include <time.h>
feb11 0:85fceccc1a7c 39 #include <stdlib.h>
feb11 0:85fceccc1a7c 40 #include "os_port.h"
feb11 0:85fceccc1a7c 41 #include "crypto.h"
feb11 0:85fceccc1a7c 42
feb11 0:85fceccc1a7c 43 void RSA_priv_key_new(RSA_CTX **ctx,
feb11 0:85fceccc1a7c 44 const uint8_t *modulus, int mod_len,
feb11 0:85fceccc1a7c 45 const uint8_t *pub_exp, int pub_len,
feb11 0:85fceccc1a7c 46 const uint8_t *priv_exp, int priv_len
feb11 0:85fceccc1a7c 47 #if CONFIG_BIGINT_CRT
feb11 0:85fceccc1a7c 48 , const uint8_t *p, int p_len,
feb11 0:85fceccc1a7c 49 const uint8_t *q, int q_len,
feb11 0:85fceccc1a7c 50 const uint8_t *dP, int dP_len,
feb11 0:85fceccc1a7c 51 const uint8_t *dQ, int dQ_len,
feb11 0:85fceccc1a7c 52 const uint8_t *qInv, int qInv_len
feb11 0:85fceccc1a7c 53 #endif
feb11 0:85fceccc1a7c 54 )
feb11 0:85fceccc1a7c 55 {
feb11 0:85fceccc1a7c 56 RSA_CTX *rsa_ctx;
feb11 0:85fceccc1a7c 57 BI_CTX *bi_ctx;
feb11 0:85fceccc1a7c 58 RSA_pub_key_new(ctx, modulus, mod_len, pub_exp, pub_len);
feb11 0:85fceccc1a7c 59 rsa_ctx = *ctx;
feb11 0:85fceccc1a7c 60 bi_ctx = rsa_ctx->bi_ctx;
feb11 0:85fceccc1a7c 61 rsa_ctx->d = bi_import(bi_ctx, priv_exp, priv_len);
feb11 0:85fceccc1a7c 62 bi_permanent(rsa_ctx->d);
feb11 0:85fceccc1a7c 63
feb11 0:85fceccc1a7c 64 #ifdef CONFIG_BIGINT_CRT
feb11 0:85fceccc1a7c 65 rsa_ctx->p = bi_import(bi_ctx, p, p_len);
feb11 0:85fceccc1a7c 66 rsa_ctx->q = bi_import(bi_ctx, q, q_len);
feb11 0:85fceccc1a7c 67 rsa_ctx->dP = bi_import(bi_ctx, dP, dP_len);
feb11 0:85fceccc1a7c 68 rsa_ctx->dQ = bi_import(bi_ctx, dQ, dQ_len);
feb11 0:85fceccc1a7c 69 rsa_ctx->qInv = bi_import(bi_ctx, qInv, qInv_len);
feb11 0:85fceccc1a7c 70 bi_permanent(rsa_ctx->dP);
feb11 0:85fceccc1a7c 71 bi_permanent(rsa_ctx->dQ);
feb11 0:85fceccc1a7c 72 bi_permanent(rsa_ctx->qInv);
feb11 0:85fceccc1a7c 73 bi_set_mod(bi_ctx, rsa_ctx->p, BIGINT_P_OFFSET);
feb11 0:85fceccc1a7c 74 bi_set_mod(bi_ctx, rsa_ctx->q, BIGINT_Q_OFFSET);
feb11 0:85fceccc1a7c 75 #endif
feb11 0:85fceccc1a7c 76 }
feb11 0:85fceccc1a7c 77
feb11 0:85fceccc1a7c 78 void RSA_pub_key_new(RSA_CTX **ctx,
feb11 0:85fceccc1a7c 79 const uint8_t *modulus, int mod_len,
feb11 0:85fceccc1a7c 80 const uint8_t *pub_exp, int pub_len)
feb11 0:85fceccc1a7c 81 {
feb11 0:85fceccc1a7c 82 RSA_CTX *rsa_ctx;
feb11 0:85fceccc1a7c 83 BI_CTX *bi_ctx;
feb11 0:85fceccc1a7c 84
feb11 0:85fceccc1a7c 85 if (*ctx) /* if we load multiple certs, dump the old one */
feb11 0:85fceccc1a7c 86 RSA_free(*ctx);
feb11 0:85fceccc1a7c 87
feb11 0:85fceccc1a7c 88 bi_ctx = bi_initialize();
feb11 0:85fceccc1a7c 89 *ctx = (RSA_CTX *)calloc(1, sizeof(RSA_CTX));
feb11 0:85fceccc1a7c 90 rsa_ctx = *ctx;
feb11 0:85fceccc1a7c 91 rsa_ctx->bi_ctx = bi_ctx;
feb11 0:85fceccc1a7c 92 rsa_ctx->num_octets = mod_len;
feb11 0:85fceccc1a7c 93 rsa_ctx->m = bi_import(bi_ctx, modulus, mod_len);
feb11 0:85fceccc1a7c 94 bi_set_mod(bi_ctx, rsa_ctx->m, BIGINT_M_OFFSET);
feb11 0:85fceccc1a7c 95 rsa_ctx->e = bi_import(bi_ctx, pub_exp, pub_len);
feb11 0:85fceccc1a7c 96 bi_permanent(rsa_ctx->e);
feb11 0:85fceccc1a7c 97 }
feb11 0:85fceccc1a7c 98
feb11 0:85fceccc1a7c 99 /**
feb11 0:85fceccc1a7c 100 * Free up any RSA context resources.
feb11 0:85fceccc1a7c 101 */
feb11 0:85fceccc1a7c 102 void RSA_free(RSA_CTX *rsa_ctx)
feb11 0:85fceccc1a7c 103 {
feb11 0:85fceccc1a7c 104 BI_CTX *bi_ctx;
feb11 0:85fceccc1a7c 105 if (rsa_ctx == NULL) /* deal with ptrs that are null */
feb11 0:85fceccc1a7c 106 return;
feb11 0:85fceccc1a7c 107
feb11 0:85fceccc1a7c 108 bi_ctx = rsa_ctx->bi_ctx;
feb11 0:85fceccc1a7c 109
feb11 0:85fceccc1a7c 110 bi_depermanent(rsa_ctx->e);
feb11 0:85fceccc1a7c 111 bi_free(bi_ctx, rsa_ctx->e);
feb11 0:85fceccc1a7c 112 bi_free_mod(rsa_ctx->bi_ctx, BIGINT_M_OFFSET);
feb11 0:85fceccc1a7c 113
feb11 0:85fceccc1a7c 114 if (rsa_ctx->d)
feb11 0:85fceccc1a7c 115 {
feb11 0:85fceccc1a7c 116 bi_depermanent(rsa_ctx->d);
feb11 0:85fceccc1a7c 117 bi_free(bi_ctx, rsa_ctx->d);
feb11 0:85fceccc1a7c 118 #ifdef CONFIG_BIGINT_CRT
feb11 0:85fceccc1a7c 119 bi_depermanent(rsa_ctx->dP);
feb11 0:85fceccc1a7c 120 bi_depermanent(rsa_ctx->dQ);
feb11 0:85fceccc1a7c 121 bi_depermanent(rsa_ctx->qInv);
feb11 0:85fceccc1a7c 122 bi_free(bi_ctx, rsa_ctx->dP);
feb11 0:85fceccc1a7c 123 bi_free(bi_ctx, rsa_ctx->dQ);
feb11 0:85fceccc1a7c 124 bi_free(bi_ctx, rsa_ctx->qInv);
feb11 0:85fceccc1a7c 125 bi_free_mod(rsa_ctx->bi_ctx, BIGINT_P_OFFSET);
feb11 0:85fceccc1a7c 126 bi_free_mod(rsa_ctx->bi_ctx, BIGINT_Q_OFFSET);
feb11 0:85fceccc1a7c 127 #endif
feb11 0:85fceccc1a7c 128 }
feb11 0:85fceccc1a7c 129
feb11 0:85fceccc1a7c 130 bi_terminate(bi_ctx);
feb11 0:85fceccc1a7c 131 free(rsa_ctx);
feb11 0:85fceccc1a7c 132 }
feb11 0:85fceccc1a7c 133
feb11 0:85fceccc1a7c 134 /**
feb11 0:85fceccc1a7c 135 * @brief Use PKCS1.5 for decryption/verification.
feb11 0:85fceccc1a7c 136 * @param ctx [in] The context
feb11 0:85fceccc1a7c 137 * @param in_data [in] The data to encrypt (must be < modulus size-11)
feb11 0:85fceccc1a7c 138 * @param out_data [out] The encrypted data.
feb11 0:85fceccc1a7c 139 * @param is_decryption [in] Decryption or verify operation.
feb11 0:85fceccc1a7c 140 * @return The number of bytes that were originally encrypted. -1 on error.
feb11 0:85fceccc1a7c 141 * @see http://www.rsasecurity.com/rsalabs/node.asp?id=2125
feb11 0:85fceccc1a7c 142 */
feb11 0:85fceccc1a7c 143 int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data,
feb11 0:85fceccc1a7c 144 uint8_t *out_data, int is_decryption)
feb11 0:85fceccc1a7c 145 {
feb11 0:85fceccc1a7c 146 const int byte_size = ctx->num_octets;
feb11 0:85fceccc1a7c 147 int i, size;
feb11 0:85fceccc1a7c 148 bigint *decrypted_bi, *dat_bi;
feb11 0:85fceccc1a7c 149 uint8_t *block = (uint8_t *)alloca(byte_size);
feb11 0:85fceccc1a7c 150
feb11 0:85fceccc1a7c 151 memset(out_data, 0, byte_size); /* initialise */
feb11 0:85fceccc1a7c 152
feb11 0:85fceccc1a7c 153 /* decrypt */
feb11 0:85fceccc1a7c 154 dat_bi = bi_import(ctx->bi_ctx, in_data, byte_size);
feb11 0:85fceccc1a7c 155 #ifdef CONFIG_SSL_CERT_VERIFICATION
feb11 0:85fceccc1a7c 156 decrypted_bi = is_decryption ? /* decrypt or verify? */
feb11 0:85fceccc1a7c 157 RSA_private(ctx, dat_bi) : RSA_public(ctx, dat_bi);
feb11 0:85fceccc1a7c 158 #else /* always a decryption */
feb11 0:85fceccc1a7c 159 decrypted_bi = RSA_private(ctx, dat_bi);
feb11 0:85fceccc1a7c 160 #endif
feb11 0:85fceccc1a7c 161
feb11 0:85fceccc1a7c 162 /* convert to a normal block */
feb11 0:85fceccc1a7c 163 bi_export(ctx->bi_ctx, decrypted_bi, block, byte_size);
feb11 0:85fceccc1a7c 164
feb11 0:85fceccc1a7c 165 i = 10; /* start at the first possible non-padded byte */
feb11 0:85fceccc1a7c 166
feb11 0:85fceccc1a7c 167 #ifdef CONFIG_SSL_CERT_VERIFICATION
feb11 0:85fceccc1a7c 168 if (is_decryption == 0) /* PKCS1.5 signing pads with "0xff"s */
feb11 0:85fceccc1a7c 169 {
feb11 0:85fceccc1a7c 170 while (block[i++] == 0xff && i < byte_size);
feb11 0:85fceccc1a7c 171
feb11 0:85fceccc1a7c 172 if (block[i-2] != 0xff)
feb11 0:85fceccc1a7c 173 i = byte_size; /*ensure size is 0 */
feb11 0:85fceccc1a7c 174 }
feb11 0:85fceccc1a7c 175 else /* PKCS1.5 encryption padding is random */
feb11 0:85fceccc1a7c 176 #endif
feb11 0:85fceccc1a7c 177 {
feb11 0:85fceccc1a7c 178 while (block[i++] && i < byte_size);
feb11 0:85fceccc1a7c 179 }
feb11 0:85fceccc1a7c 180 size = byte_size - i;
feb11 0:85fceccc1a7c 181
feb11 0:85fceccc1a7c 182 /* get only the bit we want */
feb11 0:85fceccc1a7c 183 if (size > 0)
feb11 0:85fceccc1a7c 184 memcpy(out_data, &block[i], size);
feb11 0:85fceccc1a7c 185
feb11 0:85fceccc1a7c 186 return size ? size : -1;
feb11 0:85fceccc1a7c 187 }
feb11 0:85fceccc1a7c 188
feb11 0:85fceccc1a7c 189 /**
feb11 0:85fceccc1a7c 190 * Performs m = c^d mod n
feb11 0:85fceccc1a7c 191 */
feb11 0:85fceccc1a7c 192 bigint *RSA_private(const RSA_CTX *c, bigint *bi_msg)
feb11 0:85fceccc1a7c 193 {
feb11 0:85fceccc1a7c 194 printf("RSA private\n");
feb11 0:85fceccc1a7c 195 #ifdef CONFIG_BIGINT_CRT
feb11 0:85fceccc1a7c 196 return bi_crt(c->bi_ctx, bi_msg, c->dP, c->dQ, c->p, c->q, c->qInv);
feb11 0:85fceccc1a7c 197 #else
feb11 0:85fceccc1a7c 198 BI_CTX *ctx = c->bi_ctx;
feb11 0:85fceccc1a7c 199 ctx->mod_offset = BIGINT_M_OFFSET;
feb11 0:85fceccc1a7c 200 return bi_mod_power(ctx, bi_msg, c->d);
feb11 0:85fceccc1a7c 201 #endif
feb11 0:85fceccc1a7c 202 }
feb11 0:85fceccc1a7c 203
feb11 0:85fceccc1a7c 204 #ifdef CONFIG_SSL_FULL_MODE
feb11 0:85fceccc1a7c 205 /**
feb11 0:85fceccc1a7c 206 * Used for diagnostics.
feb11 0:85fceccc1a7c 207 */
feb11 0:85fceccc1a7c 208 void RSA_print(const RSA_CTX *rsa_ctx)
feb11 0:85fceccc1a7c 209 {
feb11 0:85fceccc1a7c 210 if (rsa_ctx == NULL)
feb11 0:85fceccc1a7c 211 return;
feb11 0:85fceccc1a7c 212
feb11 0:85fceccc1a7c 213 printf("----------------- RSA DEBUG ----------------\n");
feb11 0:85fceccc1a7c 214 printf("Size:\t%d\n", rsa_ctx->num_octets);
feb11 0:85fceccc1a7c 215 bi_print("Modulus", rsa_ctx->m);
feb11 0:85fceccc1a7c 216 bi_print("Public Key", rsa_ctx->e);
feb11 0:85fceccc1a7c 217 bi_print("Private Key", rsa_ctx->d);
feb11 0:85fceccc1a7c 218 }
feb11 0:85fceccc1a7c 219 #endif
feb11 0:85fceccc1a7c 220
feb11 0:85fceccc1a7c 221 #if defined(CONFIG_SSL_CERT_VERIFICATION) || defined(CONFIG_SSL_GENERATE_X509_CERT)
feb11 0:85fceccc1a7c 222 /**
feb11 0:85fceccc1a7c 223 * Performs c = m^e mod n
feb11 0:85fceccc1a7c 224 */
feb11 0:85fceccc1a7c 225 bigint *RSA_public(const RSA_CTX * c, bigint *bi_msg)
feb11 0:85fceccc1a7c 226 {
feb11 0:85fceccc1a7c 227 c->bi_ctx->mod_offset = BIGINT_M_OFFSET;
feb11 0:85fceccc1a7c 228 return bi_mod_power(c->bi_ctx, bi_msg, c->e);
feb11 0:85fceccc1a7c 229 }
feb11 0:85fceccc1a7c 230
feb11 0:85fceccc1a7c 231 /**
feb11 0:85fceccc1a7c 232 * Use PKCS1.5 for encryption/signing.
feb11 0:85fceccc1a7c 233 * see http://www.rsasecurity.com/rsalabs/node.asp?id=2125
feb11 0:85fceccc1a7c 234 */
feb11 0:85fceccc1a7c 235 int RSA_encrypt(const RSA_CTX *ctx, const uint8_t *in_data, uint16_t in_len,
feb11 0:85fceccc1a7c 236 uint8_t *out_data, int is_signing)
feb11 0:85fceccc1a7c 237 {
feb11 0:85fceccc1a7c 238 int byte_size = ctx->num_octets;
feb11 0:85fceccc1a7c 239 int num_pads_needed = byte_size-in_len-3;
feb11 0:85fceccc1a7c 240 bigint *dat_bi, *encrypt_bi;
feb11 0:85fceccc1a7c 241 /* note: in_len+11 must be > byte_size */
feb11 0:85fceccc1a7c 242 out_data[0] = 0; /* ensure encryption block is < modulus */
feb11 0:85fceccc1a7c 243 if (is_signing)
feb11 0:85fceccc1a7c 244 {
feb11 0:85fceccc1a7c 245 out_data[1] = 1; /* PKCS1.5 signing pads with "0xff"'s */
feb11 0:85fceccc1a7c 246 memset(&out_data[2], 0xff, num_pads_needed);
feb11 0:85fceccc1a7c 247 }
feb11 0:85fceccc1a7c 248 else /* randomize the encryption padding with non-zero bytes */
feb11 0:85fceccc1a7c 249 {
feb11 0:85fceccc1a7c 250 out_data[1] = 2;
feb11 0:85fceccc1a7c 251 get_random_NZ(num_pads_needed, &out_data[2]);
feb11 0:85fceccc1a7c 252 }
feb11 0:85fceccc1a7c 253
feb11 0:85fceccc1a7c 254 out_data[2+num_pads_needed] = 0;
feb11 0:85fceccc1a7c 255 memcpy(&out_data[3+num_pads_needed], in_data, in_len);
feb11 0:85fceccc1a7c 256
feb11 0:85fceccc1a7c 257 /* now encrypt it */
feb11 0:85fceccc1a7c 258 dat_bi = bi_import(ctx->bi_ctx, out_data, byte_size);
feb11 0:85fceccc1a7c 259
feb11 0:85fceccc1a7c 260 encrypt_bi = is_signing ? RSA_private(ctx, dat_bi) :
feb11 0:85fceccc1a7c 261 RSA_public(ctx, dat_bi);
feb11 0:85fceccc1a7c 262
feb11 0:85fceccc1a7c 263 bi_export(ctx->bi_ctx, encrypt_bi, out_data, byte_size);
feb11 0:85fceccc1a7c 264 /* save a few bytes of memory */
feb11 0:85fceccc1a7c 265 bi_clear_cache(ctx->bi_ctx);
feb11 0:85fceccc1a7c 266
feb11 0:85fceccc1a7c 267 return byte_size;
feb11 0:85fceccc1a7c 268 }
feb11 0:85fceccc1a7c 269
feb11 0:85fceccc1a7c 270 #endif /* CONFIG_SSL_CERT_VERIFICATION */
feb11 0:85fceccc1a7c 271
feb11 0:85fceccc1a7c 272